Module 4 · Dive 4.3
Compaction.
Never overwriting has a price: the file only grows. Every update supersedes nodes that are now dead — still on disk, no longer reachable from the current root. Compaction is the sweep: copy the live data to a fresh file and reclaim the rest. Write a few times to pile up dead blocks, then compact.
Live versus dead
interactiveA background sweep, not a stall
store.design.mdCompaction reads the live data — everything reachable from the current root — and writes it to a new file, then switches over and drops the old one. It runs in the background while normal reads and writes continue against the live tree, because immutability means the data being copied never changes underfoot. The trigger is a ratio, not a clock: when dead data grows past a threshold of the file, sweep. For the durable tier this keeps the page log’s footprint bounded without ever blocking an enqueue, and it reuses the same “copy the live set forward” move that recovery and replication lean on elsewhere.
References & sources
- External
- CubDB · compact/1how compaction works
- lucaong/cubdbauto-compaction thresholds
- Log-structured storagedead space and compaction, generally
- Echo records
- store.design.mdkeeping the page log bounded
- graft.design.mdthe durable tier's footprint