Add CheckpointAsync and DisposeAsync to DocumentDbContext#120
Merged
Conversation
Agent-Logs-Url: https://github.com/EntglDb/BLite/sessions/8d7dcaa2-4647-4fe7-85f4-e85efd6ba007 Co-authored-by: mrdevrobot <12503462+mrdevrobot@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix DocumentDbContext.Dispose() to checkpoint WAL on close
Add CheckpointAsync and DisposeAsync to DocumentDbContext
May 11, 2026
mrdevrobot
approved these changes
May 11, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds an explicit checkpointing API to DocumentDbContext and introduces async disposal semantics so callers can ensure committed WAL records are merged into the main page file before closing—making the primary .blite/.db file self-contained for cold copy/shipping scenarios.
Changes:
- Extend
IDocumentDbContexttoIAsyncDisposableand addTask CheckpointAsync(CancellationToken ct = default). - Implement
DocumentDbContext.CheckpointAsync()(delegates toStorageEngine.CheckpointAsync) andDocumentDbContext.DisposeAsync()(checkpoint + guaranteed resource cleanup viatry/finally). - Add tests for explicit checkpointing,
await usingauto-checkpoint, and interface-level access.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| tests/BLite.Tests/DbContextTests.cs | Adds tests for explicit CheckpointAsync, DisposeAsync auto-checkpoint, and interface exposure. |
| src/BLite.Core/IDocumentDbContext.cs | Extends the interface with IAsyncDisposable and adds CheckpointAsync(ct). |
| src/BLite.Core/DocumentDbContext.cs | Adds CheckpointAsync(ct) and DisposeAsync() implementation to checkpoint WAL before releasing resources. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+127
to
+143
| [Fact] | ||
| public async Task DbContext_CheckpointAsync_PersistsDataToPageFile() | ||
| { | ||
| // Insert data and call CheckpointAsync explicitly via the public API. | ||
| await using (var db = new TestDbContext(_dbPath)) | ||
| { | ||
| await db.Users.InsertAsync(new User { Name = "Alice", Age = 30 }); | ||
| // Checkpoint flushes the WAL into the main page file. | ||
| await db.CheckpointAsync(); | ||
| } | ||
|
|
||
| // Re-open: data must be visible without replaying the WAL from scratch. | ||
| await using var db2 = new TestDbContext(_dbPath); | ||
| var all = await db2.Users.FindAllAsync().ToListAsync(); | ||
| Assert.Single(all); | ||
| Assert.Equal("Alice", all[0].Name); | ||
| } |
Comment on lines
+145
to
+159
| [Fact] | ||
| public async Task DbContext_DisposeAsync_CheckpointsBeforeClose() | ||
| { | ||
| // Insert data and dispose via DisposeAsync (which checkpoints automatically). | ||
| await using (var db = new TestDbContext(_dbPath)) | ||
| { | ||
| await db.Users.InsertAsync(new User { Name = "Bob", Age = 25 }); | ||
| } | ||
|
|
||
| // Re-open: data must survive without any explicit checkpoint call. | ||
| await using var db2 = new TestDbContext(_dbPath); | ||
| var all = await db2.Users.FindAllAsync().ToListAsync(); | ||
| Assert.Single(all); | ||
| Assert.Equal("Bob", all[0].Name); | ||
| } |
Comment on lines
546
to
557
| @@ -545,6 +557,33 @@ public void Dispose() | |||
| GC.SuppressFinalize(this); | |||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
DocumentDbContext.Dispose()releases the storage engine without flushing the WAL, leaving the.blitefile potentially non-self-contained — fragile to copy or ship cold.Changes
IDocumentDbContext— extendsIAsyncDisposable; addsTask CheckpointAsync(CancellationToken ct = default)DocumentDbContext— implementsCheckpointAsync()(delegates to_storage.CheckpointAsync(ct)); implementsDisposeAsync()which checkpoints under atry/finallyso resources are released even if the checkpoint throwsCheckpointAsync,await usingauto-checkpoint, and interface-level accessUsage
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
av-build-tel-api-v1.avaloniaui.net/usr/share/dotnet/dotnet dotnet exec --runtimeconfig /home/REDACTED/.nuget/packages/avalonia.buildservices/11.3.2/tools/netstandard2.0/runtimeconfig.json /home/REDACTED/.nuget/packages/avalonia.buildservices/11.3.2/tools/netstandard2.0/Avalonia.BuildServices.Collector.dll(dns block)If you need me to access, download, or install something from one of these locations, you can either: