Module 4 · Chapter II — The local store
CubDB architecture.
The durable local tier is a single embedded database: CubDB, an append-only, immutable B-tree on one file. Every property the native engine relies on — crash-safe commits, free snapshots, the page log itself — is a consequence of those two words, append-only and immutable. This module builds it from the write path out, by working the figure rather than reading a benchmark.
Two words do the work
store.design.mdAppend-only means a write never modifies an existing byte; it adds to the tail. That alone gives crash-safety — a torn final write is simply ignored, and the last complete header wins — and it makes a commit a single atomic act: write the header. Immutable means the B-tree is copy-on-write, so an update rewrites the path to the changed leaf as new nodes and leaves every old node, and old root, exactly where it was. Together they make old versions free to keep, which is the whole basis of the next module.
The cost of never overwriting is that the file only grows, so dead data accumulates and must occasionally be swept up. Each of those three — the append-only file, the immutable B-tree, and compaction — is a dive.
The three dives
module 4The append-only file
Commits append; the last header is the truth. Append writes, then crash mid-commit and watch the torn tail get discarded with no harm done.
Dive 4.2The immutable B-tree
Copy-on-write. Update a key and watch only the root-to-leaf path get rewritten as new nodes, the old tree left whole and still readable.
Dive 4.3Compaction
The file only grows. Watch dead nodes pile up across writes, then compact — live data copied to a fresh file, the rest reclaimed.
Build & check
A one-paragraph note placing CubDB in the storage ladder from the landing: which tier it is, what it stores (the page log / LSN log), and why an embedded single-file store is the right shape for it — in your own words, no numbers.
Answer without code: why is an append-only commit crash-safe, and why does keeping an old version cost nothing? If both answers point back to “nothing is overwritten,” you have the module.
References & sources
- External
- lucaong/cubdbthe embedded append-only B-tree
- CubDB docs · how it worksfile format, headers, compaction
- B-treethe structure on disk
- Echo records
- store.design.mdCubDB as the durable page tier
- graft.design.mdthe page log layered on CubDB