コード例 #1
0
        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));
                    }
                }