jonnify·persistence /echo-persistence/platform/the-door-to-bcs/tables-and-properties

Module 15 · Dive 14.1

Tables & Properties.

The first thing BCS needs from the floor is a place to keep a component, and the floor already has the perfect shape for it: a table keyed by the branded id. A property store is an ordered_set on the 14-byte name, so it is sorted by birth for free; EchoStore.Table is the L1 ETS cache that serves reads without a lock; and EchoStore.Coherence keeps that cache correct with one rule — newer wins — where the version is the id itself. Write, then race a stale message against it, below.

The id is the version. The L1 table caches the head, keyed by branded id and read lock-free. A commit sends a message about a name; EchoStore.Coherence applies it only if its id is greater — newer wins. A stale message (a lesser id) is ignored, so the cache never goes backwards.
durable engine Graft commit log durable + replicated a commit → a message about a name EchoStore.Table · L1 ETS ordered_set keyed by branded id · lock-free reads KEY07h2a · ver KEY07h2a · "tier=3" PLR091kc · ver PLR091kc · "score=40" RND0b5xq · ver RND0b5xq · "open" newer-wins →
readout · rows are keyed by the 14-byte branded id and read from the L1 without a lock. A commit sends a message about a name; coherence applies it only when its id is greater. write, then send a stale message to see newer-wins refuse to go backwards.
§1

State keyed by identity

echo_data/bcs/property_store.ex

A component has to live somewhere, and BCS puts it in the simplest structure that respects the branded id: a property store is a process owning one private ordered_set table keyed by the 14-byte branded string — put(id, value), get(id), and a page_desc(n) that reads the most recent n entries. Because the key is the id, and a branded id sorts lexicographically in mint order, the table is sorted by birth with no extra index — the newest rows are simply the largest keys, so “recent first” is a backward walk of the set. This is the same property the whole course has leaned on, now doing ordinary database work: the snowflake’s time-ordering, which gave free-order compaction on the stream tier and a version for coherence, here gives a sorted table and recent-first paging for free. Nothing about this is queue-specific. It is a generic place to keep any entity’s properties, and it inherits the floor: the authoritative copy is a Graft commit, durable and replicated, while the property store and the L1 are the fast, local view of it.

§2

Coherence by identity

coherence.ex · graft/id.ex

A local cache is only useful if it stays correct, and the elegant part is how cheaply it does. EchoStore.Table is the L1 ETS cache over the engine, read lock-free — a native BEAM strength — and EchoStore.Coherence keeps it consistent with a single rule: newer wins, where the version is the branded id. There is no separate version counter to maintain, no vector clock to merge; a coherence message is “a message about a name,” and the receiver applies it only if the incoming id is greater than the one it holds. Because lexicographic order equals chronological order for branded ids, “greater id” means “more recent write,” so a stale message — one carrying a lesser id, perhaps a late-arriving duplicate or a slow replica’s echo — is simply ignored, and the cache never moves backwards. This is the coherence model the bus already spoke in Chapter 12, surfaced as a table primitive: the same “message about a name” that bound replicas to a cursor now binds an L1 row to its newest writer. With a sorted, durable, identity-keyed table that stays coherent by id alone, the floor has handed BCS everything a component needs — and the next dive can stop talking about storage and start talking about shape.

§3

References & sources