B+tree storage engine with page cache, write-ahead log (WAL), crash recovery, and concurrent snapshot-isolated readers.
$ dotnet add package CSharpDB.StorageB+tree storage engine with page cache, write-ahead log (WAL), crash recovery, and concurrent snapshot-isolated readers for the CSharpDB embedded database engine.
CSharpDB.Storage is the disk-level storage layer for CSharpDB. It manages all physical I/O through a page-oriented architecture with B+tree data structures, a write-ahead log for durability, and snapshot isolation for concurrent readers. Single-file storage, zero external dependencies.
┌─────────────────────────────┐
│ CatalogService │ Schema catalog (B+tree-backed)
├─────────────────────────────┤
│ BTree │ Key-value storage (long -> byte[])
├─────────────────────────────┤
│ Pager + PageCache │ Page I/O, LRU cache, transactions
├──────────────┬──────────────┤
│ WAL (Write │ Storage │ Durability & file I/O
│ Ahead Log) │ Device │
└──────────────┴──────────────┘
long rowid with variable-length payloadsArrayPool for splitsMoveNextAsync and SeekAsyncSemaphoreSlimWalIndex snapshotsTransactionCoordinator with timeout supportusing CSharpDB.Storage;
// Open or create a database file
var options = new StorageEngineOptions { DatabasePath = "mydb.db" };
var context = await StorageEngine.OpenAsync(options);
// Access the pager for page-level operations
var pager = context.Pager;
await pager.BeginTransactionAsync();
// Create a B+tree
var tree = await BTree.CreateNewAsync(pager);
// Insert data
await tree.InsertAsync(1, recordBytes);
// Read data
var data = await tree.FindAsync(1);
// Iterate with a cursor
var cursor = tree.CreateCursor();
while (await cursor.MoveNextAsync())
{
var key = cursor.CurrentKey;
var value = cursor.CurrentValue;
}
await pager.CommitAsync();
File: [Header:100][Page0:4096][Page1:4096][Page2:4096]...
Page: [PageHeader:9][CellPointers:2*N][ free ][cells←]
WAL: [WalHeader:32][Frame:24+4096][Frame:24+4096]...
dotnet add package CSharpDB.Storage
CSharpDB.Core - shared type system and schema definitions| Package | Description |
|---|---|
| CSharpDB.Engine | Embedded database engine built on this storage layer |
| CSharpDB.Storage.Diagnostics | Read-only inspection and integrity checking |
| CSharpDB.Execution | Query operators that read/write through this layer |
MIT - see LICENSE for details.