Beispiel #1
0
        private static unsafe void Setup_MallocFixedPageSizeRecoveryTest(out int seed, out IDevice device, out int numBucketsToAdd, out long[] logicalAddresses, out ulong numBytesWritten)
        {
            TestUtils.DeleteDirectory(TestUtils.MethodTestDir, wait: true);

            seed = 123;
            var rand1 = new Random(seed);

            device = Devices.CreateLogDevice(TestUtils.MethodTestDir + "/MallocFixedPageSizeRecoveryTest.dat", deleteOnClose: true);
            var allocator = new MallocFixedPageSize <HashBucket>();

            //do something
            numBucketsToAdd  = 16 * allocator.GetPageSize();
            logicalAddresses = new long[numBucketsToAdd];
            for (int i = 0; i < numBucketsToAdd; i++)
            {
                long logicalAddress = allocator.Allocate();
                logicalAddresses[i] = logicalAddress;
                var bucket = (HashBucket *)allocator.GetPhysicalAddress(logicalAddress);
                for (int j = 0; j < Constants.kOverflowBucketIndex; j++)
                {
                    bucket->bucket_entries[j] = rand1.Next();
                }
            }

            //issue call to checkpoint
            allocator.BeginCheckpoint(device, 0, out numBytesWritten);
            //wait until complete
            allocator.IsCheckpointCompletedAsync().AsTask().Wait();

            allocator.Dispose();
        }
Beispiel #2
0
        public unsafe void MallocFixedPageSizeRecoveryTest()
        {
            int seed      = 123;
            var rand1     = new Random(seed);
            var device    = Devices.CreateLogDevice(TestContext.CurrentContext.TestDirectory + "\\MallocFixedPageSizeRecoveryTest.dat", deleteOnClose: true);
            var allocator = new MallocFixedPageSize <HashBucket>();

            //do something
            int numBucketsToAdd = 16 * allocator.GetPageSize();

            long[] logicalAddresses = new long[numBucketsToAdd];
            for (int i = 0; i < numBucketsToAdd; i++)
            {
                long logicalAddress = allocator.Allocate();
                logicalAddresses[i] = logicalAddress;
                var bucket = (HashBucket *)allocator.GetPhysicalAddress(logicalAddress);
                for (int j = 0; j < Constants.kOverflowBucketIndex; j++)
                {
                    bucket->bucket_entries[j] = rand1.Next();
                }
            }

            //issue call to checkpoint
            allocator.BeginCheckpoint(device, 0, out ulong numBytesWritten);
            //wait until complete
            allocator.IsCheckpointCompletedAsync().AsTask().Wait();

            allocator.Dispose();

            var recoveredAllocator = new MallocFixedPageSize <HashBucket>();

            //issue call to recover
            recoveredAllocator.BeginRecovery(device, 0, numBucketsToAdd, numBytesWritten, out ulong numBytesRead);
            //wait until complete
            recoveredAllocator.IsRecoveryCompleted(true);

            Assert.IsTrue(numBytesWritten == numBytesRead);

            var rand2 = new Random(seed);

            for (int i = 0; i < numBucketsToAdd; i++)
            {
                var logicalAddress = logicalAddresses[i];
                var bucket         = (HashBucket *)recoveredAllocator.GetPhysicalAddress(logicalAddress);
                for (int j = 0; j < Constants.kOverflowBucketIndex; j++)
                {
                    Assert.IsTrue(bucket->bucket_entries[j] == rand2.Next());
                }
            }

            recoveredAllocator.Dispose();
        }