예제 #1
0
        public void LargeObjectTest1()
        {
            log    = FasterFactory.CreateLogDevice(TestContext.CurrentContext.TestDirectory + "\\hlog", deleteOnClose: true);
            objlog = FasterFactory.CreateObjectLogDevice(TestContext.CurrentContext.TestDirectory + "\\hlog", deleteOnClose: true);

            Directory.CreateDirectory(TestContext.CurrentContext.TestDirectory + "\\checkpoints");

            fht1 = FasterFactory.Create
                   <MyKey, MyLargeValue, MyInput, MyLargeOutput, MyContext, MyLargeFunctions>
                       (indexSizeBuckets: 128, functions: new MyLargeFunctions(),
                       logSettings: new LogSettings {
                LogDevice = log, ObjectLogDevice = objlog, MutableFraction = 0.1, MemorySizeBits = 29
            },
                       checkpointSettings: new CheckpointSettings {
                CheckpointDir = TestContext.CurrentContext.TestDirectory + "\\checkpoints", CheckPointType = CheckpointType.Snapshot
            }
                       );

            fht2 = FasterFactory.Create
                   <MyKey, MyLargeValue, MyInput, MyLargeOutput, MyContext, MyLargeFunctions>
                       (indexSizeBuckets: 128, functions: new MyLargeFunctions(),
                       logSettings: new LogSettings {
                LogDevice = log, ObjectLogDevice = objlog, MutableFraction = 0.1, MemorySizeBits = 29
            },
                       checkpointSettings: new CheckpointSettings {
                CheckpointDir = TestContext.CurrentContext.TestDirectory + "\\checkpoints", CheckPointType = CheckpointType.Snapshot
            }
                       );


            int maxSize = 1000;
            int numOps  = 5000;

            //var value = new MyLargeValue(size);

            fht1.StartSession();
            Random r = new Random(33);

            for (int key = 0; key < numOps; key++)
            {
                var value = new MyLargeValue(1 + r.Next(maxSize));
                fht1.Upsert(new MyKey {
                    key = key
                }, value, null, 0);
            }
            fht1.TakeFullCheckpoint(out Guid token);
            fht1.CompleteCheckpoint(true);
            fht1.StopSession();
            fht1.Dispose();

            MyLargeOutput output = new MyLargeOutput();

            fht2.Recover(token);
            fht2.StartSession();
            for (int key = 0; key < numOps; key++)
            {
                var status = fht2.Read(new MyKey {
                    key = key
                }, new MyInput(), ref output, null, 0);

                if (status == Status.PENDING)
                {
                    fht2.CompletePending(true);
                }
                else
                {
                    for (int i = 0; i < output.value.value.Length; i++)
                    {
                        Assert.IsTrue(output.value.value[i] == (byte)(output.value.value.Length + i));
                    }
                }
            }
            fht2.StopSession();
            fht2.Dispose();

            log.Close();
            objlog.Close();
            new DirectoryInfo(TestContext.CurrentContext.TestDirectory + "\\checkpoints").Delete(true);
        }
예제 #2
0
        public unsafe void RecoverAndTest(Guid cprVersion, Guid indexVersion)
        {
            // Recover
            fht.Recover(cprVersion, indexVersion);

            // Create array for reading
            var inputArray = new Tuple <AdId, Input> [numUniqueKeys];

            for (int i = 0; i < numUniqueKeys; i++)
            {
                inputArray[i] = new Tuple <AdId, Input>(new AdId {
                    adId = i
                }, new Input {
                    numClicks = 0
                });
            }

            var outputArray = new Output[numUniqueKeys];

            for (int i = 0; i < numUniqueKeys; i++)
            {
                outputArray[i] = new Output();
            }

            // Register with thread
            fht.StartSession();

            // Issue read requests
            for (var i = 0; i < numUniqueKeys; i++)
            {
                fht.Read(inputArray[i].Item1, null, ref outputArray[i], default(Empty), i);
            }

            // Complete all pending requests
            fht.CompletePending(true);

            // Release
            fht.StopSession();

            // Set checkpoint directory
            Config.CheckpointDirectory = test_path;

            // Test outputs
            var checkpointInfo = default(HybridLogRecoveryInfo);

            checkpointInfo.Recover(cprVersion);

            // Compute expected array
            long[] expected = new long[numUniqueKeys];
            foreach (var guid in checkpointInfo.continueTokens.Keys)
            {
                var sno = checkpointInfo.continueTokens[guid];
                for (long i = 0; i <= sno; i++)
                {
                    var id = i % numUniqueKeys;
                    expected[id]++;
                }
            }

            int threadCount  = 1; // single threaded test
            int numCompleted = threadCount - checkpointInfo.continueTokens.Count;

            for (int t = 0; t < numCompleted; t++)
            {
                var sno = numOps;
                for (long i = 0; i < sno; i++)
                {
                    var id = i % numUniqueKeys;
                    expected[id]++;
                }
            }

            // Assert if expected is same as found
            for (long i = 0; i < numUniqueKeys; i++)
            {
                Assert.IsTrue(
                    expected[i] == outputArray[i].numClicks.numClicks,
                    "Debug error for AdId {0}: Expected ({1}), Found({2})",
                    inputArray[i].Item1.adId,
                    expected[i],
                    outputArray[i].numClicks.numClicks);
            }
        }