示例#1
0
        public unsafe void Continue()
        {
            Console.WriteLine("Ready to Run. version to recover? [Enter]");
            var  line  = Console.ReadLine();
            Guid token = Guid.Parse(line);

            Console.WriteLine("Recovering version {0}", token);
            fht.Recover(token, token);
            Console.WriteLine("Recovery Done!");

            var checkpointInfo = default(HybridLogRecoveryInfo);

            checkpointInfo.Recover(token);

            threadCount = checkpointInfo.numThreads;

            Console.WriteLine("Continuing");
            Thread[] workers = new Thread[threadCount];
            int      idx     = 0;

            for (int i = 0; i < threadCount; i++)
            {
                int  x    = idx++;
                Guid guid = checkpointInfo.guids[i];
                workers[x] = new Thread(() => ContinueWorker(x, guid));
            }

            // Start threads.
            foreach (Thread worker in workers)
            {
                worker.Start();
            }

            // Wait until all are completed
            foreach (Thread worker in workers)
            {
                worker.Join();
            }
        }
        public unsafe void RecoverAndTest(Guid indexToken, Guid hybridLogToken)
        {
            // Recover
            fht.Recover(indexToken, hybridLogToken);

            // Create array for reading
            Empty context;
            var   inputArray = new Input[numUniqueKeys];

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

            // Register with thread
            fht.StartSession();

            // Issue read requests
            fixed(Input *input = inputArray)
            {
                for (var i = 0; i < numUniqueKeys; i++)
                {
                    fht.Read(&((input + i)->adId), null, (Output *)&((input + i)->numClicks), &context, i);
                }
            }

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

            // Release
            fht.StopSession();

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

            checkpointInfo.Recover(hybridLogToken, "logs");

            // 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++)
            {
                if (expected[i] != inputArray[i].numClicks.numClicks)
                {
                    Console.WriteLine("Debug error for AdId {0}: Expected ({1}), Found({2})", inputArray[i].adId.adId, expected[i], inputArray[i].numClicks.numClicks);
                }
            }
            Console.WriteLine("Test successful");

            Console.ReadLine();
        }