Replication and clustering

Consistency guarantees

What Raft DB guarantees about durability, visibility, ordering and failover, for a single node, for SQL transactions and for clusters, and what it does not.

This page states what you can rely on. Where there is no guarantee, it says so.

Single node, native API#

PropertyGuarantee
DurabilityA write is acknowledged only after its log record is flushed to disk (group commit). A process kill, power loss or kill -9 loses nothing acknowledged. Tested by deterministic crash simulation of the log and whole table (30,000 schedules clean; 1M crash schedules of the WAL with no violation) and by process kills.
Atomicity of one writeA put, insert (atomic insert-if-absent) or delete of one document is atomic.
OrderWrites to one key are applied in the order they reach its shard. A connection's reads see the writes it sent before (the in-process fast paths queue reads behind earlier writes of the same connection).
PagingNot snapshot-consistent: a scan or sorted query sees changes made between pages.
No silent coercionDocuments are stored with their types; a schema, when set, refuses what does not fit.

SQL front-end#

PropertyGuarantee
A statementAll or nothing: every row is checked before the first write, and a write that still fails takes back what the statement did, newest first. A concurrent reader can see a half-way state of a multi-row statement in between.
COMMITThe writes of a transaction wait for the disk once, at COMMIT.
ROLLBACK, savepointsWork, by replaying the session's undo log backwards.
IsolationBy table claims, READ-COMMITTED. A session that writes a table inside a transaction holds that table until COMMIT or ROLLBACK; other sessions that read or write it wait. They never see uncommitted rows. The claim is per table, not per row, and lives in one front-end process. Switch off with isolation = none.
ConflictsTwo writers of one table cannot overlap: the second waits (error 1205 after innodb_lock_wait_timeout, default 50 s; error 1213 at once for a deadlock). No update is lost.
Repeatable readsNot given. A later statement of a transaction sees what others committed in between.
Locking reads and LOCK TABLESAccepted, lock nothing of their own.
Crash of the front-end in a transactionWhat had been written stays; the transaction is not rolled back after a restart. A connection that ends cleanly rolls back.
Uniqueness (primary key, unique indexes)Guaranteed: the primary key is the engine's atomic insert-if-absent; each unique index claims its value atomically. After a crash a claim of a row that was never written is taken over only when older than 30 seconds, so a value can be unavailable for up to 30 seconds.
Foreign keysEnforced by the front-end (cascades, set null, restrict); with no isolation, two sessions can still race (for example insert a child while the parent is deleted).

Snapshot reads (repeatable reads, readers that never wait) need row versions through the shards and the log, a commit record and a read view per transaction (raftdb-mvcc is the building block, not connected), a project of its own that is not scheduled (D57). Because the claim is per table, a long transaction holds up every session that needs the same tables: keep transactions short.

Replicas (asynchronous)#

A replica applies the primary's log in order and is byte-identical up to where it has reached; it is behind by the network delay (typically milliseconds). A read from a replica may be stale. A failover to an asynchronous replica can lose the newest acknowledged writes.

Synchronous replication#

With sync-replicas = N and no degraded commit, an acknowledged write is durable on the primary and on N followers, so a client whose write returned can read it from any confirming replica. After a timeout the write is acknowledged degraded (counted in sync.degradedCommits) and has no such protection.

Managed cluster#

With control = true (strict sync) and a watcher quorum:

PropertyGuarantee
At most one writable node per groupBy the fence: epoch and lease, and the wait after a revoke of contact window + lease + margin. Tested: samplers read all nodes every 100 ms during every test and never saw two writable nodes for a group (554 sweeps in the real-process run).
No acknowledged write is lost in a failoverIf at least members - sync_replicas nodes answer, the node with the highest (data epoch, position) holds every acknowledged write. Tested: 0 missing in all runs (19,527 acknowledged writes in the kill -9 run).
A node with less data never becomes primaryTested.
A minority never accepts writesTested: with two of three nodes down no node was writable.
A partitioned primary stops writingWithin lease plus contact window: measured 2.0 to 2.5 s with a 1.5 s lease.
AvailabilityFailover takes seconds (about 12 s with the default lease). During it, writes to the affected group fail (the writers saw 161 errors and an 8.2 s pause in the 3-group test). Other groups are not affected.
ReadsIn table-group mode, forwarded to the primary: as fresh as the primary; a connection reads its own writes. The records do not say how reads behave on a node whose lease has ended (the interim design of D42 allowed a deposed primary to serve stale reads for up to one election timeout).
LinearizabilityNot verified. No Jepsen-style check has been run; the plan lists one. The tests check that no acknowledged write is lost and that there is never a second writer, which are necessary, not sufficient.

What the tests did not cover#

  • A real network partition between machines, machine and disk failures, clock jumps, slow nodes in a long run; the process-kill runs were on one host over loopback.
  • Mixed versions.
  • Accounts: not replicated, so a client that logs in on one node may be refused on another with different user lines.

See also#