B5.1 · dive 1 of 3
The single-writer engine.
A volume has exactly one writer: VolumeServer, whose mailbox is the global write lock. Its store is CubDB’s append-only B-tree, where a snapshot costs nothing.
The idea
echo_store · graft.ex, graft/volume_server.ex, graft/store.exThe floor begins with a volume, and a volume has exactly one writer. EchoStore.Graft.VolumeServer is one process per volume, and its mailbox is Graft’s global write lock: every commit to that volume passes through one GenServer, serialized by the BEAM’s mailbox, so there is no lock to acquire and no contention to lose. A write begins, stages its pages, and commits; the pages of one business write land at low indices, a page per table row counting up from zero.
The store beneath the writer is CubDB, an append-only immutable B-tree. Entries are never changed in place; a write appends, and a read takes a zero-cost immutable snapshot, so concurrent reads neither block writes nor are blocked by them. A Graft snapshot is a CubDB snapshot — the same structure gives the engine its consistency and the reader its isolation, and it is pure Elixir, with no C extension to build or trust.
Identity runs through the engine as it runs through the rest of BCS. A volume, a segment, and a commit each carry a branded GID — VOL, SEG, CMT — minted from the same Snowflake the cache and the bus use, so a commit sorts by when it happened and a segment names itself on the wire. The engine is single-writer where it must be and immutable where it can be; the rest of the floor is what that one commit becomes once it leaves the node.
The doors
the sibling coursesEchoMQ — the protocol, in depth
The bus B3 narrates, taught rung by rung: the keyspace, the Lua inventory, and the 3.0 Stream Tier — XADD, XREADGROUP, XACK — with conformance on Valkey.
Redis Patterns Applied
The substrate patterns under the bus: sorted sets, atomic Lua moves, locks, and streams — the judgement layer.
/echo-persistenceEcho Persistence — the durable floor
Beneath the volatile tiers: the Graft page engine built twice, the commit-LSN loop, and the stream archive on Tigris. Where Part I says state lives somewhere, this says where it lives durably.
References
sources · relatedSources
- orbitinghail — Graft: lazy, partial, strongly consistent replicationthe page-replication engine echo_store builds natively on the BEAM
- Ong — CubDB, an Elixir embedded key-value storethe append-only immutable B-tree the volume commits onto
- Thompson et al. — The LMAX Disruptor (2011)the single-writer principle the volume server applies to commits
Related
- BCS — the course homethe law, the id anatomy, the chapter map
- Echo Persistencethe durable floor beneath the bus