jonnify·bcs /bcs/store/coherence

B4.3 · dive 3 of 3

Coherence.

An invalidation is two ids — the name and the writer’s mint-time version. Newer wins by eleven snowflake bytes; it rides a broadcast lane through a single-producer ring, or a job lane over EchoMQ.

Two ids, two lanes, a single-producer ring. Select a part.
{name} : {version}two ids, nothing elsenewer? = pa > pb — eleven snowflake bytesidempotent: applied twice answers stale PUBLISH · ecc:{table}:cohat-most-once EchoStore.Ring — the Disruptor’s shapeheadtailsingle producer · single applier · full → counted drop enqueue over EchoMQ — the job laneat-least-once, crash-surviving
readout · Select a part. Coherence is a two-id message, newer-wins by mint-time version, idempotent; it travels a fire-and-forget broadcast lane through a ring, or an at-least-once job lane over EchoMQ.
§1

The idea

echo_store · coherence.ex, ring.ex

When a row is written, the caches holding it must learn. An EchoStore coherence message carries exactly two identities — the cached name and the writer’s mint-time version — and nothing else. Newer wins by comparing the eleven snowflake bytes of the two branded ids: the order theorem makes those bytes lexicographically equal to mint order, regardless of namespace, so coherence needs no coordinator, no lock, and no clock but the one already inside every id. Application is idempotent — applying the same version twice answers stale the second time, so a retry or a duplicate changes nothing.

Two lanes carry that message, chosen by what a stale read costs. The broadcast lane is a PUBLISH on the table’s channel — fire-and-forget, one wire hop, at-most-once — for surfaces where a lost message costs one TTL of staleness. The job lane is an enqueue on the table’s coherence queue over EchoMQ — at-least-once and crash-surviving — for surfaces where a stale read costs money. The same drop runs in Lua on the bus, comparing the same eleven bytes, so the wire and the heap never disagree about which write is current.

The broadcast lane is served by a ring. EchoStore.Ring is the Disruptor’s shape on the BEAM: two atomics for head and tail sequences, an ETS table of preallocated slots reused by index, a single producer and a single applier, and edge-triggered wakes — one message when the ring goes from empty to non-empty, however many items then flow. When the ring is full the publish is refused and counted, never blocked and never overwritten, because the broadcast lane is at-most-once by its substrate’s contract and a counted drop preserves that where silent overwriting would not. Surfaces that cannot accept a drop ride the job lane, which does not pass through here.

§4

The doors

the sibling courses
§2

References

sources · related

Sources

Related