public void ShouldSkipEmptySpaceAtEndOfPage()
        {
            TestUtils.DeleteDirectory(TestUtils.MethodTestDir, wait: true);

            var vlLength = new VLValue();
            var log      = Devices.CreateLogDevice(TestUtils.MethodTestDir + "/hlog-vl-iter.log", deleteOnClose: true);
            var fht      = new FasterKV <Key, VLValue>
                               (128,
                               new LogSettings {
                LogDevice = log, MemorySizeBits = 17, PageSizeBits = 10
            },                                                                               // 1KB page
                               null, null, null, new VariableLengthStructSettings <Key, VLValue> {
                valueLength = vlLength
            }
                               );

            var session = fht.NewSession(new VLFunctions());

            try
            {
                Set(1L, 200, 1); // page#0
                Set(2L, 200, 2); // page#1 because there is not enough space in page#0

                var len = 1024;  // fill page#1 exactly
                len = len - 2 * RecordInfo.GetLength() - 2 * 8 - vlLength.GetLength(ref GetValue(200, 2));

                Set(3, len / 4, 3); // should be in page#1

                Set(4, 64, 4);

                session.CompletePending(true);

                var data = new List <Tuple <long, int, int> >();
                using (var iterator = fht.Log.Scan(fht.Log.BeginAddress, fht.Log.TailAddress))
                {
                    while (iterator.GetNext(out var info))
                    {
                        ref var scanKey   = ref iterator.GetKey();
                        ref var scanValue = ref iterator.GetValue();

                        data.Add(Tuple.Create(scanKey.key, scanValue.length, scanValue.field1));
                    }
                }
        public unsafe void VariableLengthTest1()
        {
            FasterKV <Key, VLValue> fht;
            IDevice log;

            log = Devices.CreateLogDevice(TestContext.CurrentContext.TestDirectory + "/hlog1.log", deleteOnClose: true);
            fht = new FasterKV <Key, VLValue>
                      (128,
                      new LogSettings {
                LogDevice = log, MemorySizeBits = 17, PageSizeBits = 12
            },
                      null, null, null, new VariableLengthStructSettings <Key, VLValue> {
                valueLength = new VLValue()
            }
                      );

            var s = fht.NewSession(new VLFunctions());

            Input  input = default;
            Random r     = new Random(100);

            // Single alloc outside the loop, to the max length we'll need.
            int *val = stackalloc int[StackAllocMax];

            for (int i = 0; i < 5000; i++)
            {
                var key1 = new Key {
                    key = i
                };

                var         len   = GetVarLen(r);
                ref VLValue value = ref *(VLValue *)val;
                for (int j = 0; j < len; j++)
                {
                    *(val + j) = len;
                }

                s.Upsert(ref key1, ref value, Empty.Default, 0);
            }
        public unsafe void VariableLengthTest1()
        {
            FasterKV <Key, VLValue, Input, int[], Empty, VLFunctions> fht;
            IDevice log;

            log = Devices.CreateLogDevice(TestContext.CurrentContext.TestDirectory + "\\hlog1.log", deleteOnClose: true);
            fht = new FasterKV <Key, VLValue, Input, int[], Empty, VLFunctions>
                      (128, new VLFunctions(),
                      new LogSettings {
                LogDevice = log, MemorySizeBits = 17, PageSizeBits = 12
            },
                      null, null, null, new VariableLengthStructSettings <Key, VLValue> {
                valueLength = new VLValue()
            }
                      );
            fht.StartSession();


            Input input = default(Input);

            Random r = new Random(100);

            for (int i = 0; i < 5000; i++)
            {
                var key1 = new Key {
                    key = i
                };

                var         len   = 2 + r.Next(10);
                int *       val   = stackalloc int[len];
                ref VLValue value = ref *(VLValue *)val;
                for (int j = 0; j < len; j++)
                {
                    *(val + j) = len;
                }

                fht.Upsert(ref key1, ref value, Empty.Default, 0);
            }