Exemplo n.º 1
0
        public void UpsertDefaultsTest([Values] TestUtils.DeviceType deviceType)
        {
            string filename = path + "UpsertDefaultsTest" + deviceType.ToString() + ".log";

            log = TestUtils.CreateTestDevice(deviceType, filename);
            fht = new FasterKV <KeyStruct, ValueStruct>
                      (128, new LogSettings {
                LogDevice = log, MemorySizeBits = 22, SegmentSizeBits = 22, PageSizeBits = 10
            });
            session = fht.For(new Functions()).NewSession <Functions>();

            InputStruct  input  = default;
            OutputStruct output = default;

            var key1 = new KeyStruct {
                kfield1 = 13, kfield2 = 14
            };
            var value = new ValueStruct {
                vfield1 = 23, vfield2 = 24
            };

            Assert.AreEqual(0, fht.EntryCount);

            session.Upsert(ref key1, ref value);
            var status = session.Read(ref key1, ref input, ref output, Empty.Default, 0);

            AssertCompleted(Status.OK, status);

            Assert.AreEqual(1, fht.EntryCount);
            Assert.AreEqual(value.vfield1, output.value.vfield1);
            Assert.AreEqual(value.vfield2, output.value.vfield2);
        }
Exemplo n.º 2
0
        public void UpsertNoRefNoDefaultsTest()
        {
            // Just checking more parameter values so one device is enough
            deviceType = TestUtils.DeviceType.MLSD;

            string filename = path + "UpsertNoRefNoDefaultsTest" + deviceType.ToString() + ".log";

            log = TestUtils.CreateTestDevice(deviceType, filename);
            fht = new FasterKV <KeyStruct, ValueStruct>
                      (128, new LogSettings {
                LogDevice = log, MemorySizeBits = 29
            });
            session = fht.For(new Functions()).NewSession <Functions>();

            InputStruct  input  = default;
            OutputStruct output = default;

            var key1 = new KeyStruct {
                kfield1 = 13, kfield2 = 14
            };
            var value = new ValueStruct {
                vfield1 = 23, vfield2 = 24
            };

            session.Upsert(key1, value, Empty.Default, 0);
            var status = session.Read(ref key1, ref input, ref output, Empty.Default, 0);

            AssertCompleted(Status.OK, status);

            Assert.AreEqual(value.vfield1, output.value.vfield1);
            Assert.AreEqual(value.vfield2, output.value.vfield2);
        }
Exemplo n.º 3
0
        public void ReadAtAddressReadFlagsNone()
        {
            // Just functional test of ReadFlag so one device is enough
            deviceType = TestUtils.DeviceType.MLSD;

            string filename = path + "ReadAtAddressReadFlagsNone" + deviceType.ToString() + ".log";

            log = TestUtils.CreateTestDevice(deviceType, filename);
            fht = new FasterKV <KeyStruct, ValueStruct>
                      (128, new LogSettings {
                LogDevice = log, MemorySizeBits = 29
            });
            session = fht.For(new Functions()).NewSession <Functions>();

            InputStruct  input  = default;
            OutputStruct output = default;

            var key1 = new KeyStruct {
                kfield1 = 13, kfield2 = 14
            };
            var value = new ValueStruct {
                vfield1 = 23, vfield2 = 24
            };
            var readAtAddress = fht.Log.BeginAddress;

            session.Upsert(ref key1, ref value, Empty.Default, 0);
            var status = session.ReadAtAddress(readAtAddress, ref input, ref output, ReadFlags.None, Empty.Default, 0);

            AssertCompleted(Status.OK, status);

            Assert.AreEqual(value.vfield1, output.value.vfield1);
            Assert.AreEqual(value.vfield2, output.value.vfield2);
            Assert.AreEqual(key1.kfield1, 13);
            Assert.AreEqual(key1.kfield2, 14);
        }
Exemplo n.º 4
0
        public void UpsertDefaultsTest([Values] TestUtils.DeviceType deviceType)
        {
            Setup(128, new LogSettings {
                MemorySizeBits = 22, SegmentSizeBits = 22, PageSizeBits = 10
            }, deviceType);

            InputStruct  input  = default;
            OutputStruct output = default;

            var key1 = new KeyStruct {
                kfield1 = 13, kfield2 = 14
            };
            var value = new ValueStruct {
                vfield1 = 23, vfield2 = 24
            };

            Assert.AreEqual(0, fht.EntryCount);

            session.Upsert(ref key1, ref value);
            var status = session.Read(ref key1, ref input, ref output, Empty.Default, 0);

            AssertCompleted(new(StatusCode.Found), status);

            Assert.AreEqual(1, fht.EntryCount);
            Assert.AreEqual(value.vfield1, output.value.vfield1);
            Assert.AreEqual(value.vfield2, output.value.vfield2);
        }
Exemplo n.º 5
0
        public void UpsertNoRefNoDefaultsTest()
        {
            InputStruct  input  = default;
            OutputStruct output = default;

            var key1 = new KeyStruct {
                kfield1 = 13, kfield2 = 14
            };
            var value = new ValueStruct {
                vfield1 = 23, vfield2 = 24
            };

            session.Upsert(key1, value, Empty.Default, 0);
            var status = session.Read(ref key1, ref input, ref output, Empty.Default, 0);

            if (status == Status.PENDING)
            {
                session.CompletePending(true);
            }
            else
            {
                Assert.IsTrue(status == Status.OK);
            }

            Assert.IsTrue(output.value.vfield1 == value.vfield1);
            Assert.IsTrue(output.value.vfield2 == value.vfield2);
        }
Exemplo n.º 6
0
        public void UpsertNoRefNoDefaultsTest()
        {
            // Just checking more parameter values so one device is enough
            deviceType = TestUtils.DeviceType.MLSD;

            Setup(128, new LogSettings {
                MemorySizeBits = 29
            }, deviceType);

            InputStruct  input  = default;
            OutputStruct output = default;

            var key1 = new KeyStruct {
                kfield1 = 13, kfield2 = 14
            };
            var value = new ValueStruct {
                vfield1 = 23, vfield2 = 24
            };

            session.Upsert(key1, value, Empty.Default, 0);
            var status = session.Read(ref key1, ref input, ref output, Empty.Default, 0);

            AssertCompleted(new(StatusCode.Found), status);

            Assert.AreEqual(value.vfield1, output.value.vfield1);
            Assert.AreEqual(value.vfield2, output.value.vfield2);
        }
Exemplo n.º 7
0
        public void ReadNoRefKeyInputOutput()
        {
            InputStruct  input  = default;
            OutputStruct output = default;

            var key1 = new KeyStruct {
                kfield1 = 13, kfield2 = 14
            };
            var value = new ValueStruct {
                vfield1 = 23, vfield2 = 24
            };

            session.Upsert(ref key1, ref value, Empty.Default, 0);
            var status = session.Read(key1, input, out output, Empty.Default, 111);

            if (status == Status.PENDING)
            {
                session.CompletePending(true);
            }
            else
            {
                Assert.IsTrue(status == Status.OK);
            }

            // Verify the read data
            Assert.IsTrue(output.value.vfield1 == value.vfield1);
            Assert.IsTrue(output.value.vfield2 == value.vfield2);
            Assert.IsTrue(13 == key1.kfield1);
            Assert.IsTrue(14 == key1.kfield2);
        }
Exemplo n.º 8
0
        public void ReadAtAddressReadFlagsNone()
        {
            InputStruct  input  = default;
            OutputStruct output = default;

            var key1 = new KeyStruct {
                kfield1 = 13, kfield2 = 14
            };
            var value = new ValueStruct {
                vfield1 = 23, vfield2 = 24
            };
            var readAtAddress = fht.Log.BeginAddress;

            session.Upsert(ref key1, ref value, Empty.Default, 0);
            var status = session.ReadAtAddress(readAtAddress, ref input, ref output, ReadFlags.None, Empty.Default, 0);

            if (status == Status.PENDING)
            {
                session.CompletePending(true);
            }
            else
            {
                Assert.IsTrue(status == Status.OK);
            }

            Assert.IsTrue(output.value.vfield1 == value.vfield1);
            Assert.IsTrue(output.value.vfield2 == value.vfield2);
            Assert.IsTrue(13 == key1.kfield1);
            Assert.IsTrue(14 == key1.kfield2);
        }
Exemplo n.º 9
0
        public void ReadAtAddressReadFlagsNone()
        {
            // Just functional test of ReadFlag so one device is enough
            deviceType = TestUtils.DeviceType.MLSD;

            Setup(128, new LogSettings {
                MemorySizeBits = 29
            }, deviceType);

            InputStruct  input  = default;
            OutputStruct output = default;

            var key1 = new KeyStruct {
                kfield1 = 13, kfield2 = 14
            };
            var value = new ValueStruct {
                vfield1 = 23, vfield2 = 24
            };
            ReadOptions readOptions = new() { StartAddress = fht.Log.BeginAddress };

            session.Upsert(ref key1, ref value, Empty.Default, 0);
            var status = session.ReadAtAddress(ref input, ref output, ref readOptions, Empty.Default, 0);

            AssertCompleted(new(StatusCode.Found), status);

            Assert.AreEqual(value.vfield1, output.value.vfield1);
            Assert.AreEqual(value.vfield2, output.value.vfield2);
            Assert.AreEqual(key1.kfield1, 13);
            Assert.AreEqual(key1.kfield2, 14);
        }
Exemplo n.º 10
0
        public void NativeInMemWriteRead()
        {
            InputStruct  input  = default(InputStruct);
            OutputStruct output = default(OutputStruct);

            var key1 = new KeyStruct {
                kfield1 = 13, kfield2 = 14
            };
            var value = new ValueStruct {
                vfield1 = 23, vfield2 = 24
            };

            fht.Upsert(ref key1, ref value, Empty.Default, 0);
            var status = fht.Read(ref key1, ref input, ref output, Empty.Default, 0);

            if (status == Status.PENDING)
            {
                fht.CompletePending(true);
            }
            else
            {
                Assert.IsTrue(status == Status.OK);
            }

            Assert.IsTrue(output.value.vfield1 == value.vfield1);
            Assert.IsTrue(output.value.vfield2 == value.vfield2);
        }
Exemplo n.º 11
0
 public override bool InPlaceUpdater(ref KeyStruct key, ref InputStruct input, ref ValueStruct value, ref OutputStruct output, ref RMWInfo rmwInfo)
 {
     value.vfield1 += input.ifield1;
     value.vfield2 += input.ifield2;
     output.value   = value;
     return(true);
 }
Exemplo n.º 12
0
        public void ReadNoRefKeyInputOutput([Values] TestUtils.DeviceType deviceType)
        {
            InputStruct input = default;

            Setup(128, new LogSettings {
                MemorySizeBits = 22, SegmentSizeBits = 22, PageSizeBits = 10
            }, deviceType);

            var key1 = new KeyStruct {
                kfield1 = 13, kfield2 = 14
            };
            var value = new ValueStruct {
                vfield1 = 23, vfield2 = 24
            };

            session.Upsert(ref key1, ref value, Empty.Default, 0);
            var status = session.Read(key1, input, out OutputStruct output, Empty.Default, 111);

            AssertCompleted(new(StatusCode.Found), status);

            // Verify the read data
            Assert.AreEqual(value.vfield1, output.value.vfield1);
            Assert.AreEqual(value.vfield2, output.value.vfield2);
            Assert.AreEqual(key1.kfield1, 13);
            Assert.AreEqual(key1.kfield2, 14);
        }
Exemplo n.º 13
0
 public override bool CopyUpdater(ref KeyStruct key, ref InputStruct input, ref ValueStruct oldValue, ref ValueStruct newValue, ref OutputStruct output, ref RMWInfo rmwInfo)
 {
     newValue.vfield1 = oldValue.vfield1 + input.ifield1;
     newValue.vfield2 = oldValue.vfield2 + input.ifield2;
     output.value     = newValue;
     return(true);
 }
Exemplo n.º 14
0
 public override bool InPlaceUpdater(ref KeyStruct key, ref InputStruct input, ref ValueStruct value, ref OutputStruct output, ref RecordInfo recordInfo, long address)
 {
     value.vfield1 += input.ifield1;
     value.vfield2 += input.ifield2;
     output.value   = value;
     return(true);
 }
Exemplo n.º 15
0
 public override void RMWCompletionCallback(ref KeyStruct key, ref InputStruct input, ref OutputStruct output, TContext ctx, Status status, RecordMetadata recordMetadata)
 {
     Assert.IsTrue(status.Found);
     Assert.IsTrue(status.Record.CopyUpdated);
     Assert.AreEqual(key.kfield1 + input.ifield1, output.value.vfield1);
     Assert.AreEqual(key.kfield2 + input.ifield2, output.value.vfield2);
 }
Exemplo n.º 16
0
        public void ReadNoRefKeyInputOutput([Values] TestUtils.DeviceType deviceType)
        {
            InputStruct input = default;

            string filename = path + "ReadNoRefKeyInputOutput" + deviceType.ToString() + ".log";

            log = TestUtils.CreateTestDevice(deviceType, filename);
            fht = new FasterKV <KeyStruct, ValueStruct>
                      (128, new LogSettings {
                LogDevice = log, MemorySizeBits = 22, SegmentSizeBits = 22, PageSizeBits = 10
            });
            session = fht.For(new Functions()).NewSession <Functions>();

            var key1 = new KeyStruct {
                kfield1 = 13, kfield2 = 14
            };
            var value = new ValueStruct {
                vfield1 = 23, vfield2 = 24
            };

            session.Upsert(ref key1, ref value, Empty.Default, 0);
            var status = session.Read(key1, input, out OutputStruct output, Empty.Default, 111);

            AssertCompleted(Status.OK, status);

            // Verify the read data
            Assert.AreEqual(value.vfield1, output.value.vfield1);
            Assert.AreEqual(value.vfield2, output.value.vfield2);
            Assert.AreEqual(key1.kfield1, 13);
            Assert.AreEqual(key1.kfield2, 14);
        }
Exemplo n.º 17
0
        public void NativeInMemWriteReadDelete2()
        {
            // Just set this one since Write Read Delete already does all four devices
            deviceType = TestUtils.DeviceType.MLSD;

            const int count = 10;

            // Setup(128, new LogSettings { MemorySizeBits = 22, SegmentSizeBits = 22, PageSizeBits = 10 }, deviceType);
            Setup(128, new LogSettings {
                MemorySizeBits = 29
            }, deviceType);

            InputStruct  input  = default;
            OutputStruct output = default;

            for (int i = 0; i < 10 * count; i++)
            {
                var key1 = new KeyStruct {
                    kfield1 = i, kfield2 = 14
                };
                var value = new ValueStruct {
                    vfield1 = i, vfield2 = 24
                };

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

            for (int i = 0; i < 10 * count; i++)
            {
                var key1 = new KeyStruct {
                    kfield1 = i, kfield2 = 14
                };
                session.Delete(ref key1, Empty.Default, 0);
            }

            for (int i = 0; i < 10 * count; i++)
            {
                var key1 = new KeyStruct {
                    kfield1 = i, kfield2 = 14
                };
                var value = new ValueStruct {
                    vfield1 = i, vfield2 = 24
                };

                var status = session.Read(ref key1, ref input, ref output, Empty.Default, 0);
                AssertCompleted(new(StatusCode.NotFound), status);

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

            for (int i = 0; i < 10 * count; i++)
            {
                var key1 = new KeyStruct {
                    kfield1 = i, kfield2 = 14
                };
                var status = session.Read(ref key1, ref input, ref output, Empty.Default, 0);
                AssertCompleted(new(StatusCode.Found), status);
            }
        }
Exemplo n.º 18
0
        public unsafe void TestShiftHeadAddress()
        {
            InputStruct input = default(InputStruct);

            Random r = new Random(10);

            for (int c = 0; c < 1000; c++)
            {
                var i    = r.Next(10000);
                var key1 = new KeyStruct {
                    kfield1 = i, kfield2 = i + 1
                };
                var value = new ValueStruct {
                    vfield1 = i, vfield2 = i + 1
                };
                fht.Upsert(ref key1, ref value, Empty.Default, 0);
            }

            r = new Random(10);

            for (int c = 0; c < 1000; c++)
            {
                var          i      = r.Next(10000);
                OutputStruct output = default(OutputStruct);
                var          key1   = new KeyStruct {
                    kfield1 = i, kfield2 = i + 1
                };
                var value = new ValueStruct {
                    vfield1 = i, vfield2 = i + 1
                };

                if (fht.Read(ref key1, ref input, ref output, Empty.Default, 0) == Status.PENDING)
                {
                    fht.CompletePending(true);
                }

                Assert.IsTrue(output.value.vfield1 == value.vfield1);
                Assert.IsTrue(output.value.vfield2 == value.vfield2);
            }

            // Shift head and retry - should not find in main memory now
            fht.ShiftHeadAddress(fht.LogTailAddress, true);

            r = new Random(10);
            for (int c = 0; c < 1000; c++)
            {
                var          i      = r.Next(10000);
                OutputStruct output = default(OutputStruct);
                var          key1   = new KeyStruct {
                    kfield1 = i, kfield2 = i + 1
                };
                var value = new ValueStruct {
                    vfield1 = i, vfield2 = i + 1
                };

                Assert.IsTrue(fht.Read(ref key1, ref input, ref output, Empty.Default, 0) == Status.PENDING);
                fht.CompletePending(true);
            }
        }
Exemplo n.º 19
0
        public void NativeInMemWriteReadDelete()
        {
            InputStruct  input  = default;
            OutputStruct output = default;

            var key1 = new KeyStruct {
                kfield1 = 13, kfield2 = 14
            };
            var value = new ValueStruct {
                vfield1 = 23, vfield2 = 24
            };

            session.Upsert(ref key1, ref value, Empty.Default, 0);
            var status = session.Read(ref key1, ref input, ref output, Empty.Default, 0);

            if (status == Status.PENDING)
            {
                session.CompletePending(true);
            }
            else
            {
                Assert.IsTrue(status == Status.OK);
            }

            session.Delete(ref key1, Empty.Default, 0);

            status = session.Read(ref key1, ref input, ref output, Empty.Default, 0);

            if (status == Status.PENDING)
            {
                session.CompletePending(true);
            }
            else
            {
                Assert.IsTrue(status == Status.NOTFOUND);
            }

            var key2 = new KeyStruct {
                kfield1 = 14, kfield2 = 15
            };
            var value2 = new ValueStruct {
                vfield1 = 24, vfield2 = 25
            };

            session.Upsert(ref key2, ref value2, Empty.Default, 0);
            status = session.Read(ref key2, ref input, ref output, Empty.Default, 0);

            if (status == Status.PENDING)
            {
                session.CompletePending(true);
            }
            else
            {
                Assert.IsTrue(status == Status.OK);
            }

            Assert.IsTrue(output.value.vfield1 == value2.vfield1);
            Assert.IsTrue(output.value.vfield2 == value2.vfield2);
        }
Exemplo n.º 20
0
 // RMW functions
 public override bool InitialUpdater(ref KeyStruct key, ref InputStruct input, ref ValueStruct value, ref OutputStruct output, ref RMWInfo rmwInfo)
 {
     Assert.IsFalse(rmwInfo.RecordInfo.IsNull());
     value.vfield1 = input.ifield1;
     value.vfield2 = input.ifield2;
     output.value  = value;
     return(true);
 }
Exemplo n.º 21
0
 public override bool CopyUpdater(ref KeyStruct key, ref InputStruct input, ref ValueStruct oldValue, ref ValueStruct newValue, ref OutputStruct output, ref RMWInfo rmwInfo)
 {
     Assert.IsFalse(rmwInfo.RecordInfo.IsNull());
     newValue.vfield1 = oldValue.vfield1 + input.ifield1;
     newValue.vfield2 = oldValue.vfield2 + input.ifield2;
     output.value     = newValue;
     return(true);
 }
Exemplo n.º 22
0
        public unsafe void NativeInMemWriteRead2()
        {
            InputStruct input = default(InputStruct);

            Random r = new Random(10);

            for (int c = 0; c < 1000; c++)
            {
                var i    = r.Next(10000);
                var key1 = new KeyStruct {
                    kfield1 = i, kfield2 = i + 1
                };
                var value = new ValueStruct {
                    vfield1 = i, vfield2 = i + 1
                };
                fht.Upsert(ref key1, ref value, Empty.Default, 0);
            }

            r = new Random(10);

            for (int c = 0; c < 1000; c++)
            {
                var          i      = r.Next(10000);
                OutputStruct output = default(OutputStruct);
                var          key1   = new KeyStruct {
                    kfield1 = i, kfield2 = i + 1
                };
                var value = new ValueStruct {
                    vfield1 = i, vfield2 = i + 1
                };

                if (fht.Read(ref key1, ref input, ref output, Empty.Default, 0) == Status.PENDING)
                {
                    fht.CompletePending(true);
                }

                Assert.IsTrue(output.value.vfield1 == value.vfield1);
                Assert.IsTrue(output.value.vfield2 == value.vfield2);
            }

            // Clean up and retry - should not find now
            fht.ShiftBeginAddress(fht.LogTailAddress);

            r = new Random(10);
            for (int c = 0; c < 1000; c++)
            {
                var          i      = r.Next(10000);
                OutputStruct output = default(OutputStruct);
                var          key1   = new KeyStruct {
                    kfield1 = i, kfield2 = i + 1
                };
                var value = new ValueStruct {
                    vfield1 = i, vfield2 = i + 1
                };

                Assert.IsTrue(fht.Read(ref key1, ref input, ref output, Empty.Default, 0) == Status.NOTFOUND);
            }
        }
        public void BlittableLogCompactionTest1([Values] CompactionType compactionType)
        {
            using var session = fht.For(new FunctionsCompaction()).NewSession <FunctionsCompaction>();

            InputStruct input = default;

            const int totalRecords = 2000;
            var       start        = fht.Log.TailAddress;
            long      compactUntil = 0;

            for (int i = 0; i < totalRecords; i++)
            {
                if (i == 1000)
                {
                    compactUntil = fht.Log.TailAddress;
                }

                var key1 = new KeyStruct {
                    kfield1 = i, kfield2 = i + 1
                };
                var value = new ValueStruct {
                    vfield1 = i, vfield2 = i + 1
                };
                session.Upsert(ref key1, ref value, 0, 0);
            }

            compactUntil = session.Compact(compactUntil, compactionType);
            fht.Log.Truncate();

            Assert.AreEqual(compactUntil, fht.Log.BeginAddress);

            // Read 2000 keys - all should be present
            for (int i = 0; i < totalRecords; i++)
            {
                OutputStruct output = default;
                var          key1   = new KeyStruct {
                    kfield1 = i, kfield2 = i + 1
                };
                var value = new ValueStruct {
                    vfield1 = i, vfield2 = i + 1
                };

                var status = session.Read(ref key1, ref input, ref output, 0, 0);
                if (status.IsPending)
                {
                    session.CompletePending(true);
                }
                else
                {
                    Assert.IsTrue(status.Found);
                    Assert.AreEqual(value.vfield1, output.value.vfield1);
                    Assert.AreEqual(value.vfield2, output.value.vfield2);
                }
            }
        }
Exemplo n.º 24
0
        public void BlittableLogCompactionTest1()
        {
            using var session = fht.NewSession();

            InputStruct input = default;

            const int totalRecords = 2000;
            var       start        = fht.Log.TailAddress;
            long      compactUntil = 0;

            for (int i = 0; i < totalRecords; i++)
            {
                if (i == 1000)
                {
                    compactUntil = fht.Log.TailAddress;
                }

                var key1 = new KeyStruct {
                    kfield1 = i, kfield2 = i + 1
                };
                var value = new ValueStruct {
                    vfield1 = i, vfield2 = i + 1
                };
                session.Upsert(ref key1, ref value, 0, 0);
            }

            fht.Log.Compact(compactUntil);
            Assert.IsTrue(fht.Log.BeginAddress == compactUntil);

            // Read 2000 keys - all should be present
            for (int i = 0; i < totalRecords; i++)
            {
                OutputStruct output = default;
                var          key1   = new KeyStruct {
                    kfield1 = i, kfield2 = i + 1
                };
                var value = new ValueStruct {
                    vfield1 = i, vfield2 = i + 1
                };

                var status = session.Read(ref key1, ref input, ref output, 0, 0);
                if (status == Status.PENDING)
                {
                    session.CompletePending(true);
                }
                else
                {
                    Assert.IsTrue(status == Status.OK);
                    Assert.IsTrue(output.value.vfield1 == value.vfield1);
                    Assert.IsTrue(output.value.vfield2 == value.vfield2);
                }
            }
        }
        static void VerifyStructs(int key, ref KeyStruct keyStruct, ref InputStruct inputStruct, ref OutputStruct outputStruct, ref ContextStruct contextStruct)
        {
            Assert.AreEqual(key, keyStruct.kfield1);
            Assert.AreEqual(key + numRecords * 10, keyStruct.kfield2);
            Assert.AreEqual(key + numRecords * 30, inputStruct.ifield1);
            Assert.AreEqual(key + numRecords * 40, inputStruct.ifield2);

            Assert.AreEqual(key, outputStruct.value.vfield1);
            Assert.AreEqual(key + numRecords * 10, outputStruct.value.vfield2);
            Assert.AreEqual(key + numRecords * 50, contextStruct.cfield1);
            Assert.AreEqual(key + numRecords * 60, contextStruct.cfield2);
        }
Exemplo n.º 26
0
        static void VerifyStructs(int key, ref KeyStruct keyStruct, ref InputStruct inputStruct, ref OutputStruct outputStruct, ref ContextStruct contextStruct, bool useRMW)
        {
            Assert.AreEqual(key, keyStruct.kfield1);
            Assert.AreEqual(key + numRecords * 10, keyStruct.kfield2);
            Assert.AreEqual(key + numRecords * 30, inputStruct.ifield1);
            Assert.AreEqual(key + numRecords * 40, inputStruct.ifield2);

            // RMW causes the InPlaceUpdater to be called, which adds input fields to the value.
            Assert.AreEqual(key + (useRMW ? inputStruct.ifield1 : 0), outputStruct.value.vfield1);
            Assert.AreEqual(key + numRecords * 10 + (useRMW ? inputStruct.ifield2 : 0), outputStruct.value.vfield2);
            Assert.AreEqual(key + numRecords * 50, contextStruct.cfield1);
            Assert.AreEqual(key + numRecords * 60, contextStruct.cfield2);
        }
Exemplo n.º 27
0
        public void ReadAtAddressReadFlagsSkipReadCache()
        {
            InputStruct  input  = default;
            OutputStruct output = default;

            long invalidAddress = Constants.kInvalidAddress;

            var key1 = new KeyStruct {
                kfield1 = 13, kfield2 = 14
            };
            var value = new ValueStruct {
                vfield1 = 23, vfield2 = 24
            };
            var readAtAddress = fht.Log.BeginAddress;



            session.Upsert(ref key1, ref value, Empty.Default, 0);
            //**** When Bug Fixed ... use the invalidAddress line
            // Bug #136259
            //        Ah—slight bug here.I took a quick look to verify that the logicalAddress passed to SingleReader was kInvalidAddress(0),
            //and while I got that right for the SingleWriter call, I missed it on the SingleReader.
            //This is because we streamlined it to no longer expose RecordAccessor.IsReadCacheAddress, and I missed it here.
            //   test that the record retrieved on Read variants that do find the record in the readCache
            //pass Constants.kInvalidAddress as the ‘address’ parameter to SingleReader.
            // Reading the same record using Read(…, ref RecordInfo…)
            //and ReadFlags.SkipReadCache should return a valid record there.
            //For now, write the same test, and instead of testing for address == kInvalidAddress,
            //test for (address & Constants.kReadCacheBitMask) != 0.


            //var status = session.ReadAtAddress(invalidAddress, ref input, ref output, ReadFlags.SkipReadCache);
            var status = session.ReadAtAddress(readAtAddress, ref input, ref output, ReadFlags.SkipReadCache);

            if (status == Status.PENDING)
            {
                session.CompletePending(true);
            }
            else
            {
                Assert.IsTrue(status == Status.OK);
            }

            Assert.IsTrue(output.value.vfield1 == value.vfield1);
            Assert.IsTrue(output.value.vfield2 == value.vfield2);
            Assert.IsTrue(13 == key1.kfield1);
            Assert.IsTrue(14 == key1.kfield2);
        }
Exemplo n.º 28
0
        public void NativeInMemWriteReadDelete([Values] TestUtils.DeviceType deviceType)
        {
            string filename = path + "NativeInMemWriteReadDelete" + deviceType.ToString() + ".log";

            log = TestUtils.CreateTestDevice(deviceType, filename);
            fht = new FasterKV <KeyStruct, ValueStruct>
                      (128, new LogSettings {
                LogDevice = log, PageSizeBits = 10, MemorySizeBits = 12, SegmentSizeBits = 22
            });
            session = fht.For(new Functions()).NewSession <Functions>();

            InputStruct  input  = default;
            OutputStruct output = default;

            var key1 = new KeyStruct {
                kfield1 = 13, kfield2 = 14
            };
            var value = new ValueStruct {
                vfield1 = 23, vfield2 = 24
            };

            session.Upsert(ref key1, ref value, Empty.Default, 0);
            var status = session.Read(ref key1, ref input, ref output, Empty.Default, 0);

            AssertCompleted(Status.OK, status);

            session.Delete(ref key1, Empty.Default, 0);

            status = session.Read(ref key1, ref input, ref output, Empty.Default, 0);
            AssertCompleted(Status.NOTFOUND, status);

            var key2 = new KeyStruct {
                kfield1 = 14, kfield2 = 15
            };
            var value2 = new ValueStruct {
                vfield1 = 24, vfield2 = 25
            };

            session.Upsert(ref key2, ref value2, Empty.Default, 0);
            status = session.Read(ref key2, ref input, ref output, Empty.Default, 0);

            AssertCompleted(Status.OK, status);
            Assert.AreEqual(value2.vfield1, output.value.vfield1);
            Assert.AreEqual(value2.vfield2, output.value.vfield2);
        }
Exemplo n.º 29
0
        public void UpsertSerialNumberTest()
        {
            // Simple Upsert of Serial Number test so one device is enough
            deviceType = TestUtils.DeviceType.MLSD;

            string filename = path + "UpsertSerialNumberTest" + deviceType.ToString() + ".log";

            log = TestUtils.CreateTestDevice(deviceType, filename);
            fht = new FasterKV <KeyStruct, ValueStruct>
                      (128, new LogSettings {
                LogDevice = log, MemorySizeBits = 29
            });
            session = fht.For(new Functions()).NewSession <Functions>();

            int          numKeys = 100;
            int          keyMod  = 10;
            int          maxLap  = numKeys / keyMod;
            InputStruct  input   = default;
            OutputStruct output  = default;

            var value = new ValueStruct {
                vfield1 = 23, vfield2 = 24
            };
            var key = new KeyStruct {
                kfield1 = 13, kfield2 = 14
            };

            for (int i = 0; i < numKeys; i++)
            {
                // lap is used to illustrate the changing values
                var lap = i / keyMod;
                session.Upsert(ref key, ref value, serialNo: lap);
            }

            // Now verify
            for (int j = 0; j < numKeys; j++)
            {
                var status = session.Read(ref key, ref input, ref output, serialNo: maxLap + 1);

                AssertCompleted(Status.OK, status);
                Assert.AreEqual(value.vfield1, output.value.vfield1);
                Assert.AreEqual(value.vfield2, output.value.vfield2);
            }
        }
Exemplo n.º 30
0
        public void NativeDiskWriteRead()
        {
            InputStruct input = default(InputStruct);

            Random r = new Random(10);

            for (int i = 0; i < 2000; i++)
            {
                var key1 = new KeyStruct {
                    kfield1 = i, kfield2 = i + 1
                };
                var value = new ValueStruct {
                    vfield1 = i, vfield2 = i + 1
                };
                fht.Upsert(ref key1, ref value, Empty.Default, 0);
            }
            fht.CompletePending(true);

            r = new Random(10);

            for (int i = 0; i < 2000; i++)
            {
                OutputStruct output = default(OutputStruct);
                var          key1   = new KeyStruct {
                    kfield1 = i, kfield2 = i + 1
                };
                var value = new ValueStruct {
                    vfield1 = i, vfield2 = i + 1
                };

                if (fht.Read(ref key1, ref input, ref output, Empty.Default, 0) == Status.PENDING)
                {
                    fht.CompletePending(true);
                }
                else
                {
                    Assert.IsTrue(output.value.vfield1 == value.vfield1);
                    Assert.IsTrue(output.value.vfield2 == value.vfield2);
                }
            }
        }