Consistency

Writes are linearizable#

Every write is a Raft log entry. A write returns when the entry is committed, that is, stored by a majority, and applied on the node that made it. Writes appear to happen one at a time, in an order every node agrees on, and each between its call and its return.

Each operation is atomic#

Every write method of a dict, list or set, a file write, and a transaction each run as one step on every node. A read followed by a write, d[k] = d[k] + 1, is two steps, and another node can write in between: put them in a transaction.

Reads are local#

A read is a SQLite query on the node's own copy, with no network round trip. It sees every write its own node made, and may lag writes from other nodes by the time it takes to replicate them, usually a millisecond or two on a LAN. A node cut off from the others keeps serving reads of what it has.

To see every write that completed before, anywhere, call clusterio.sync() first. It is one write's round trip, a no-op through the log; once this node has applied it, a local read is linearizable:

python
import clusterio

clusterio.sync()
print(clusterio.dict("config").get("mode"))

When a decision must see the latest state and act on it in one step, make it a transaction: a transaction reads the state as of its place in the log, on every node.

A write needs a majority#

Without one, a write raises clusterio.Unavailable (a TimeoutError) after the cluster's timeout, 5 seconds by default. The write may still be applied later, if the entry reached a node that goes on to lead, so retry writes that are safe to repeat, or make them transactions that check whether they already happened.

A write that is sent again after a lost reply is applied once: each carries a request id, and the nodes remember the ids of the last 10,000 entries.

Durability#

Each node stores its log and its state in SQLite in WAL mode with synchronous=FULL, and an entry and the index it was applied at commit together. A node that crashes and restarts applies no entry twice and loses none it acknowledged.

Time#

clusterio.now() in a transaction is the time the node that made the write stamped on its entry. Leases compare it with the holders' clocks, so locks and semaphores assume the clocks differ by much less than ttl. Nothing else depends on clocks.

Limits#

  • Membership is fixed by CLUSTERIO_PEERS.
  • The log is not compacted, so it grows with every write.
  • Values are read and written whole; a file is held in memory. One write, value and all, is at most 64 MiB of JSON (a file, about 48 MiB); a larger one raises ValueError.
  • Traffic between nodes is neither authenticated nor encrypted.

Each can come later without changing the API.