Exemplo n.º 1
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>();

            allocator.Acquire();

            //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.IsCheckpointCompleted(true);

            allocator.Release();
            allocator.Dispose();

            var recoveredAllocator = new MallocFixedPageSize <HashBucket>();

            recoveredAllocator.Acquire();

            //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.Release();
            recoveredAllocator.Dispose();
        }