public void TestDisposeReleasesFileLocksWithCompletedCommit([Values] TestUtils.DeviceType deviceType) { string path = TestUtils.MethodTestDir + "/"; string filename = path + "TestDisposeRelease" + deviceType.ToString() + ".log"; DirectoryInfo di = Directory.CreateDirectory(path); IDevice device = TestUtils.CreateTestDevice(deviceType, filename); FasterLog fasterLog = new FasterLog(new FasterLogSettings { LogDevice = device, SegmentSizeBits = 22, LogCommitDir = path, LogChecksum = LogChecksumType.PerEntry }); Assert.IsTrue(fasterLog.TryEnqueue(new byte[100], out _)); fasterLog.Commit(spinWait: true); fasterLog.Dispose(); device.Dispose(); while (true) { try { di.Delete(recursive: true); break; } catch { } } }
public async Task FasterLogTest3([Values] LogChecksumType logChecksum) { log = new FasterLog(new FasterLogSettings { LogDevice = device, PageSizeBits = 14, LogChecksum = logChecksum }); byte[] data1 = new byte[10000]; for (int i = 0; i < 10000; i++) { data1[i] = (byte)i; } using (var iter = log.Scan(0, long.MaxValue, scanBufferingMode: ScanBufferingMode.SinglePageBuffering)) { var appendResult = log.TryEnqueue(data1, out _); Assert.IsTrue(appendResult); await log.CommitAsync(); await iter.WaitAsync(); var iterResult = iter.GetNext(out byte[] entry, out _, out _); Assert.IsTrue(iterResult); appendResult = log.TryEnqueue(data1, out _); Assert.IsFalse(appendResult); await iter.WaitAsync(); // Should read the "hole" and return false iterResult = iter.GetNext(out entry, out _, out _); Assert.IsFalse(iterResult); // Should wait for next item var task = iter.WaitAsync(); Assert.IsFalse(task.IsCompleted); appendResult = log.TryEnqueue(data1, out _); Assert.IsTrue(appendResult); await log.CommitAsync(); await task; iterResult = iter.GetNext(out entry, out _, out _); Assert.IsTrue(iterResult); } log.Dispose(); }
public async Task FasterLogTest2([Values] LogChecksumType logChecksum) { log = new FasterLog(new FasterLogSettings { LogDevice = device, LogChecksum = logChecksum, LogCommitManager = manager }); byte[] data1 = new byte[10000]; for (int i = 0; i < 10000; i++) { data1[i] = (byte)i; } using (var iter = log.Scan(0, long.MaxValue, scanBufferingMode: ScanBufferingMode.SinglePageBuffering)) { int i = 0; while (i++ < 500) { var waitingReader = iter.WaitAsync(); Assert.IsTrue(!waitingReader.IsCompleted); while (!log.TryEnqueue(data1, out _)) { ; } // We might have auto-committed at page boundary // Ensure we don't find new entry in iterator while (waitingReader.IsCompleted) { var _next = iter.GetNext(out _, out _, out _); Assert.IsFalse(_next); waitingReader = iter.WaitAsync(); } Assert.IsFalse(waitingReader.IsCompleted); await log.CommitAsync(); while (!waitingReader.IsCompleted) { ; } Assert.IsTrue(waitingReader.IsCompleted); var curr = iter.GetNext(out byte[] result, out _, out _); Assert.IsTrue(curr); Assert.IsTrue(result.SequenceEqual(data1)); var next = iter.GetNext(out _, out _, out _); Assert.IsFalse(next); } } log.Dispose(); }
static void LogWriterThread() { while (true) { // TryEnqueue - can be used with throttling/back-off // Accepts byte[] and ReadOnlySpan<byte> while (!log.TryEnqueue(staticEntry, out _)) { ; } // Synchronous blocking enqueue // Accepts byte[] and ReadOnlySpan<byte> // log.Enqueue(entry); // Batched enqueue - batch must fit on one page // Add this to class: // static readonly ReadOnlySpanBatch spanBatch = new ReadOnlySpanBatch(10); // while (!log.TryEnqueue(spanBatch, out _)) ; } }
public void TestDisposeReleasesFileLocksWithInprogressCommit() { string commitPath = TestContext.CurrentContext.TestDirectory + "/" + TestContext.CurrentContext.Test.Name + "/"; DirectoryInfo di = Directory.CreateDirectory(commitPath); IDevice device = Devices.CreateLogDevice(commitPath + "testDisposeReleasesFileLocksWithInprogressCommit.log", preallocateFile: true, deleteOnClose: false); FasterLog fasterLog = new FasterLog(new FasterLogSettings { LogDevice = device, LogChecksum = LogChecksumType.PerEntry }); Assert.IsTrue(fasterLog.TryEnqueue(new byte[100], out long beginAddress)); fasterLog.Commit(spinWait: false); fasterLog.Dispose(); device.Dispose(); while (true) { try { di.Delete(recursive: true); break; } catch { } } }