Expand description
§mnem-backend-redb
Production Blockstore + OpHeadsStore backed by
redb - a pure-Rust embedded
ACID key-value store.
A single .redb file holds two tables:
objects-CID bytes → object bytes. Every Node, Edge, Tree chunk, Commit, View, Operation is a row.op_heads- set-of-CIDs modelled asCID bytes → ()with presence-as-truth. The current op-heads set is the key-set of this table.
Writes are atomic per-call: each put / delete / update opens a
write transaction, mutates, and commits (which fsyncs). No
cross-call batching yet; a future refinement can expose a “batch
mode” that holds a transaction open across multiple puts to reduce
fsync overhead on the mnem_core::repo::Transaction::commit hot
path.
§Concurrency
redb: single-writer, many-reader per database file. Within a
process, Arc<Database> is safe to share across threads - redb
serialises writers internally. Across processes, redb’s
filesystem-locking protects the file format; concurrent write
transactions from two processes will serialise or one will fail.
§Durability
tx.commit() in redb calls fsync on the database file. The Simple
backend’s atomic-rename story is effectively what redb does
internally for each commit - one transaction = one durable
state transition.
§Backend choice notes
redb is the production embedded backend for exactly these reasons: pure Rust, small dep tree, mmap reads, ACID writes, single-file persistence. Note redb majors break on-disk format (1 → 2 → 3 → 4). We pin the major in the crate’s Cargo dependency and document the migration path when we bump.
Re-exports§
pub use blockstore::RedbBlockstore;pub use knn_edges_store::KNN_EDGES_TABLE;pub use knn_edges_store::load_knn_edges;pub use knn_edges_store::store_knn_edges;pub use op_heads::RedbOpHeadsStore;
Modules§
- blockstore
RedbBlockstore- redb-backedBlockstoreimplementation.- knn_
edges_ store - redb persistence for
mnem-ann::KnnEdgeIndex(experiment E0). - op_
heads RedbOpHeadsStore- redb-backedOpHeadsStore.
Functions§
- open_
or_ init - Open or create the redb database at
pathand return wired-up blockstore + op-heads stores.