Expand description
2n: the reader table – how the writer learns the oldest generation any live snapshot reader still needs, so page recycling never pulls a page out from under one.
LMDB’s shape, flock-based so it cannot go stale: each snapshot reader
creates readers/r-<pid>-<n> holding its pinned generation and KEEPS an
exclusive flock on it for the snapshot’s lifetime. Close or crash, the
kernel drops the lock with the fd. The writer, when it wants the oldest,
walks the directory: a file whose lock it can grab is a dead reader’s
leavings (unlinked on the spot); a file whose lock is busy is a live
reader. Its generation is stored in two identical framed copies, each with
magic, version and CRC. Any malformed copy or disagreement means generation
zero: ambiguity leaks space but cannot recycle a live snapshot’s pages.
Failure posture (the 2n risk ladder): an unreadable directory or file means “assume a reader at generation 0” – recycling stops, the file grows like it always did, nothing can be wrongly reused.
Structs§
- Reader
Slot - Held by a snapshot reader for its lifetime; the registration disappears (unlink + lock release) on drop, and the LOCK disappears even on crash.
Functions§
- oldest_
live_ reader - The oldest generation any live reader pins, or
u64::MAXwhen none. Dead readers’ files are swept as they are met. Any ambiguity – a file that cannot be opened or parsed while its lock is busy – reports generation 0: recycling halts rather than guesses.