Exemplo n.º 1
0
        private void Populate(FasterKV <AdId, NumClicks> fasterInstance)
        {
            using var session = fasterInstance.NewSession(new Functions());

            // Prepare the dataset
            var inputArray = new AdInput[numOps];

            for (int i = 0; i < numOps; i++)
            {
                inputArray[i].adId.adId           = i % numUniqueKeys;
                inputArray[i].numClicks.numClicks = 1;
            }

            // Process the batch of input data
            for (int i = 0; i < numOps; i++)
            {
                session.RMW(ref inputArray[i].adId, ref inputArray[i], Empty.Default, i);

                if (i % completePendingInterval == 0)
                {
                    session.CompletePending(false);
                }
            }

            // Make sure operations are completed
            session.CompletePending(true);
        }
Exemplo n.º 2
0
        public void Populate(Action <int> checkpointAction)
        {
            logTokens   = new List <Guid>();
            indexTokens = new List <Guid>();
            // Prepare the dataset
            var inputArray = new AdInput[numOps];

            for (int i = 0; i < numOps; i++)
            {
                inputArray[i].adId.adId           = i % numUniqueKeys;
                inputArray[i].numClicks.numClicks = 1;
            }

            // Register thread with FASTER
            using var session = fht.NewSession(new Functions());

            // Process the batch of input data
            for (int i = 0; i < numOps; i++)
            {
                session.RMW(ref inputArray[i].adId, ref inputArray[i], Empty.Default, i);

                checkpointAction(i);

                if (i % completePendingInterval == 0)
                {
                    session.CompletePending(false);
                }
            }

            // Make sure operations are completed
            session.CompletePending(true);

            // Deregister thread from FASTER
            session.Dispose();
        }
Exemplo n.º 3
0
        public void Populate()
        {
            // Prepare the dataset
            var inputArray = new AdInput[numOps];

            for (int i = 0; i < numOps; i++)
            {
                inputArray[i].adId.adId           = i % numUniqueKeys;
                inputArray[i].numClicks.numClicks = 1;
            }

            // Register thread with FASTER
            using var session = fht.NewSession();

            // Prpcess the batch of input data
            bool first = true;

            for (int i = 0; i < numOps; i++)
            {
                session.RMW(ref inputArray[i].adId, ref inputArray[i], Empty.Default, i);

                if ((i + 1) % checkpointInterval == 0)
                {
                    if (first)
                    {
                        while (!fht.TakeFullCheckpoint(out token))
                        {
                            ;
                        }
                    }
                    else
                    {
                        while (!fht.TakeFullCheckpoint(out Guid nextToken))
                        {
                            ;
                        }
                    }

                    fht.CompleteCheckpointAsync().GetAwaiter().GetResult();

                    first = false;
                }

                if (i % completePendingInterval == 0)
                {
                    session.CompletePending(false);
                }
            }

            // Make sure operations are completed
            session.CompletePending(true);

            // Deregister thread from FASTER
            session.Dispose();
        }
Exemplo n.º 4
0
        private void Test(FasterTestInstance fasterInstance, Guid checkpointToken)
        {
            var checkpointInfo = default(HybridLogRecoveryInfo);

            checkpointInfo.Recover(checkpointToken,
                                   new DeviceLogCommitCheckpointManager(
                                       new LocalStorageNamedDeviceFactory(),
                                       new DefaultCheckpointNamingScheme(
                                           new DirectoryInfo(fasterInstance.CheckpointDirectory).FullName)));

            // Create array for reading
            var inputArray = new AdInput[numUniqueKeys];

            for (int i = 0; i < numUniqueKeys; i++)
            {
                inputArray[i].adId.adId           = i;
                inputArray[i].numClicks.numClicks = 0;
            }

            var input  = default(AdInput);
            var output = default(Output);

            using var session = fasterInstance.Faster.NewSession(new Functions());
            // Issue read requests
            for (var i = 0; i < numUniqueKeys; i++)
            {
                var status = session.Read(ref inputArray[i].adId, ref input, ref output, Empty.Default, i);
                Assert.IsTrue(status == Status.OK);
                inputArray[i].numClicks = output.value;
            }

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


            // Compute expected array
            long[] expected = new long[numUniqueKeys];
            foreach (var guid in checkpointInfo.continueTokens.Keys)
            {
                var sno = checkpointInfo.continueTokens[guid].UntilSerialNo;
                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 that expected is same as found
            for (long i = 0; i < numUniqueKeys; i++)
            {
                Assert.IsTrue(
                    expected[i] == inputArray[i].numClicks.numClicks,
                    "Debug error for AdId {0}: Expected ({1}), Found({2})", inputArray[i].adId.adId, expected[i], inputArray[i].numClicks.numClicks);
            }
        }
Exemplo n.º 5
0
        public async ValueTask RecoverAndTestAsync(Guid cprVersion, Guid indexVersion, bool isAsync)
        {
            // Recover
            if (isAsync)
            {
                await fht.RecoverAsync(indexVersion, cprVersion);
            }
            else
            {
                fht.Recover(indexVersion, cprVersion);
            }

            // Create array for reading
            var inputArray = new AdInput[numUniqueKeys];

            for (int i = 0; i < numUniqueKeys; i++)
            {
                inputArray[i].adId.adId           = i;
                inputArray[i].numClicks.numClicks = 0;
            }

            // Register with thread
            var session = fht.NewSession(new Functions());

            AdInput input  = default;
            Output  output = default;

            // Issue read requests
            for (var i = 0; i < numUniqueKeys; i++)
            {
                var status = session.Read(ref inputArray[i].adId, ref input, ref output, Empty.Default, i);
                Assert.IsTrue(status == Status.OK);
                inputArray[i].numClicks = output.value;
            }

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

            // Release
            session.Dispose();

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

            checkpointInfo.Recover(cprVersion,
                                   new DeviceLogCommitCheckpointManager(
                                       new LocalStorageNamedDeviceFactory(),
                                       new DefaultCheckpointNamingScheme(
                                           new DirectoryInfo(test_path).FullName)));

            // Compute expected array
            long[] expected = new long[numUniqueKeys];
            foreach (var guid in checkpointInfo.continueTokens.Keys)
            {
                var cp = checkpointInfo.continueTokens[guid];
                for (long i = 0; i <= cp.UntilSerialNo; 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] == inputArray[i].numClicks.numClicks,
                    "Debug error for AdId {0}: Expected ({1}), Found({2})", inputArray[i].adId.adId, expected[i],
                    inputArray[i].numClicks.numClicks);
            }
        }