Skip to content

Latest commit

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Monolith

Embedded B+ tree storage engine in pure Zig. No C, no dependencies.

MVCC, copy-on-write pages, crash-safe commits via ping-pong meta, and a GC tree that keeps the file size bounded. Compiles to a single object file.


Architecture

Public API — Environment · Transaction · Cursor · DBI
B+ Tree — splits · rebalance · overflow pages · dupsort
MVCC / GC — snapshot isolation · reader slots · FreeDB
OS Layer — mmap · file locking · Windows + POSIX

File layout:

Page 0-1 meta slots (ping-pong, atomic commit)
Page 2 main B+ tree root
Page 3 GC tree root
Page 4+ data pages

Features

  • Copy-on-write: writers never touch pages visible to active readers
  • Readers never block writers, writers never block readers
  • Named sub-databases (DBIs) within a single file
  • DupSort, integer keys, reverse keys, custom comparators
  • Nested transactions
  • Overflow pages for large values
  • Spill list for large write transactions
  • GC coalescing keeps the free-page tree O(1)
  • Hot backup via env.copy()
  • Full page checksums (FNV-1a), verified on read
  • env.check() for integrity audits
  • Windows and POSIX

Usage

constmonolith=@import("monolith");
varenv=trymonolith.Environment.open("data.monolith", .{}, 16, 1<<30);
deferenv.close();
// Writevartxn=trymonolith.Transaction.begin(&env, null, .{});
errdefertxn.abort();
constdbi=trytxn.openDbi("users", .{ .create=true });
trytxn.put(dbi, "alice", "admin", .{});
trytxn.commit();
// Readvarrtxn=trymonolith.Transaction.begin(&env, null, .{ .rdonly=true });
deferrtxn.abort();
constrdbi=tryrtxn.openDbi("users", .{});
constval=tryrtxn.get(rdbi, "alice"); // ?[]const u8

Build

zig build
zig test src/lib.zig

Requires Zig 0.16.


License

MIT

About

Embedded storage engine (B+Tree + Copy-on-Write) made in pure Zig

Resources

Stars

8 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages