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(); }
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(); }
public unsafe void MallocFixedPageSizeRecoveryTest() { int seed = 123; var rand1 = new Random(seed); IDevice device = new LocalStorageDevice("test_ofb.dat", false, false, true, true); var allocator = new MallocFixedPageSize <HashBucket>(); //do something int numBucketsToAdd = 16 * MallocFixedPageSize <HashBucket> .PageSize; 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.begin_checkpoint(device, 0, out ulong numBytesWritten); //wait until complete allocator.IsCheckpointCompleted(true); var recoveredAllocator = new MallocFixedPageSize <HashBucket>(); //issue call to recover recoveredAllocator.begin_recovery(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()); } } }
private static unsafe void Finish_MallocFixedPageSizeRecoveryTest(int seed, int numBucketsToAdd, long[] logicalAddresses, ulong numBytesWritten, MallocFixedPageSize <HashBucket> recoveredAllocator, ulong numBytesRead) { 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(); }
private static unsafe void Finish_MallocFixedPageSizeRecoveryTest(int seed, IDevice device, int numBucketsToAdd, long[] logicalAddresses, ulong numBytesWritten, MallocFixedPageSize <HashBucket> recoveredAllocator, ulong numBytesRead) { Assert.AreEqual(numBytesRead, numBytesWritten); 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.AreEqual(rand2.Next(), bucket->bucket_entries[j]); } } recoveredAllocator.Dispose(); device.Dispose(); TestUtils.DeleteDirectory(TestUtils.MethodTestDir); }