Consistency Model

MLambda.Data keeps each row on the key’s owners: the first copies distinct nodes of the ring from the key’s hash. A request names how many of them must take part. This page says what each level guarantees, and what it does not.

The levels

Level Write Read Guarantee for one key
Linearizable (the default) asks a majority for the key’s newest stamp, then writes above it to a majority asks a majority, writes the newest copy back until a majority holds it, then answers linearizable: as if the key lived on one machine
Quorum (also named Fast) stamped by the coordinator’s clock, written to a majority asks a majority, answers the newest copy (repairs the others best-effort) last write wins by stamp
All every owner every owner last write wins by stamp
One one owner one owner last write wins by stamp; a read may miss the latest write
Available every owner, hinted to those that missed it one owner last write wins by stamp; always writable while one owner is up

The ORM (Orm.Replicated, the ring store), ORM batches and the REST API use Linearizable when the caller names no level. A caller that wants one round trip a write names Quorum (or Fast) and accepts last write wins.

Linearizable: the protocol

The ABD register (Attiya, Bar-Noy and Dolev) over the key’s owners. No leader and no consensus: it uses the quorums the ring already has.

A write or a delete, two rounds.

  1. Ask a majority of the key’s owners for the key’s newest stamp (a row’s or a delete’s; replica request StampOn).
  2. Take a stamp above the largest answered, and above every stamp the coordinator gave or saw (Distributed.Clock.clockAbove).
  3. Write to the owners; answer once a majority acknowledged.

A read, one round, two when the replicas disagree.

  1. Ask a majority of the key’s owners for their copy.
  2. Take the newest (a row, or the key’s delete).
  3. Write it back to each replica that answered an older copy or none, until the replicas that hold it are a majority.
  4. Only then answer.

Why it is linearizable: two majorities of the same owners always share a replica. A write that completed is on a majority, so the next write’s first round sees its stamp and writes above it; a read that answered a copy left it on a majority, so a later read sees it (or something newer). The order of writes is the order of their stamps, and it agrees with real time whatever the coordinators’ clocks say.

Cost: a write is two round trips to a majority; a read whose answers agree is one.

Conditions, all of them needed:

  • A majority of the key’s owners is up. Below that, a Linearizable request fails (ConsistencyNotMet) rather than answering something weaker.
  • Stamps more than 5 s ahead of a replica’s clock are refused (ClockAhead), on machines whose clock is a calendar’s.
  • Tombstones are dropped only after every copy saw them (compaction keeps them while a backup horizon or a repair needs them).

Stamps

A stamp is milliseconds, raised past every stamp the coordinator gave or saw; its clock’s lease is kept in its node’s engine, so a restart never gives a stamp again. Two writes of one key with equal stamps can only be concurrent ones (a write after a completed one is strictly above it); every replica settles them alike (a delete over a value, else the larger value), so they converge.

What Quorum (Fast) does not guarantee

At Quorum the stamp is the coordinator’s clock. When two coordinators’ clocks differ, a write from the one behind can be acknowledged and still lose to an earlier write from the one ahead: an acknowledged write is lost. The formal model keeps that run (formal/MLambdaDataFast.cfg), and the scene linearizable.dm shows it: coordinator A, 3 s ahead, writes v1; coordinator B then writes v2; a read at Quorum answers v1, a read at Linearizable answers v2.

What no level guarantees

  1. Read, change, write back. Linearizable reads and writes do not make a read-modify-write safe: two clients that read the same value and each write a change both succeed, and one change is lost. Use a conditional write (writeIf / deleteIf, a per-key consensus round) for counters, balances and unique values: the ORM’s saveIf / removeIf, REST’s writeIf / deleteIf routes, or SQL’s UPDATE ... IF STAMP = n and INSERT ... IF NOT EXISTS.
  2. Several keys at once. Each key is linearizable on its own. An ORM batch is all or nothing (its row is written first, then each key), but a reader can see it half applied.
  3. Snapshots across tables. There is no point-in-time view of several tables.

Node-level guarantees

  • Per-actor order. Each actor handles one message at a time; a table’s store sees every write answered before a read, query, flush or compaction it handles.
  • Durability. A write is acknowledged after it is appended to the table’s log and synced (writes that arrive together share one sync). After a crash, the table recovers from its manifest, its snapshot and its log.
  • Integrity. Every SSTable block and index carries a CRC-32; a block that does not match is refused (CorruptBlock), never answered.

How it is checked

  • formal/MLambdaDataRing.tla: the per-key protocol with three owners, two coordinators whose clocks drift, and a replica that goes down. MLambdaDataRing.cfg checks Linearizable (the ABD protocol) and Durable; MLambdaDataFast.cfg runs the same checks on today’s Quorum, which fails Linearizable.
  • Scenes: MLambda.Data.Scenes/scenes/linearizable.dm, tombstones.dm, reads.dm, stamps.dm.