jonnify·bcs /bcs/persistence/the-lazy-reader

B5.2 · dive 2 of 3

The lazy reader.

Replication is lazy and partial: a reader fetches only the pages a read touches, the newest from the L1 ETS head, at a serializable snapshot.

Pages pulled on demand at a snapshot, the head served from ETS. Select a part.
a readersnapshot at LSN N L1 head page — EchoStore.Tablethe newest page, served from ETS pages on demand — only what the read touchesstruck pages are never pulled (partial) serializable snapshotMVCC: reads never block writes
readout · Select a part. A reader fetches only the pages a read touches; the newest page is a caller-side ETS lookup; reads run at a serializable snapshot.
§1

The idea

echo_store · graft/reader.ex, table.ex

Replication here is lazy and partial, the two words that separate this floor from a backup. A reader does not replay a log or wait for a full file to land; it fetches only the pages a read touches, on demand, at a chosen snapshot. Decoupled metadata and data let a replica spin up at once — it learns which pages exist without holding them, and pulls a page the moment a read asks for it.

The hottest page is already in memory. The reader’s L1 is EchoStore.Table, the same read-concurrent ETS cache that fronts Part IV, used here as a write-through head page: a commit writes the head page through to ETS, and a read of the newest page is a caller-side lookup that never touches disk or the remote. The cache and the floor share one structure, so the tier that makes reads fast is the tier that keeps the engine’s head durable.

Consistency is not traded away for laziness. Reads run at a snapshot with serializable isolation, so a partial view is still a correct one — a reader sees a single point in time across every page it pulls, never a mix of an old page and a new one. The floor fetches little and late, and what it returns is exactly what a full, eager replica would have returned, only without the bytes in between.

§4

The doors

the sibling courses
§2

References

sources · related

Sources

Related