State-Based and Operation-Based Conflict-Free Replicated Data Types (CvRDT and CmRDT) #
This module formalizes foundational steps toward #7502 for Conflict-Free Replicated Data Types
and Strong Eventual Consistency (SEC) (after Shapiro, Preguiça, Baquero, and Zawirski
[SPBZ11b], §§2.1–2.4, §3.2, Theorems 2.1–2.2 & 3.1–3.2, and
[SPBZ11a], §§2.2–2.4, Propositions 2.1–2.2 & Specifications 3–4):
State-Based Convergent Replicated Data Types (
CvRDT): Reuses Mathlib'sSemilatticeSup Swith binary state merge(· ⊔ ·)and inflationary local updates (s ≤ update op s). Models asynchronous gossip networks (CvRDT.gossipLTS) over an arbitrary directed communication graphDigraph Pwith out-of-order message arrival, packet drops, and arbitrary packet duplication, proving:- order- and duplicate-independent state-list folding (
foldl_sup_eq_of_mem_iff), - the semilattice causal-history invariant (
CvRDT.replica_eq_evalHistory), - State-Based Strong Convergence (
CvRDT.strong_convergence): any two replicas that have received the same set of updates—in any order and with any duplicates—have identical states, - Strongly Connected Gossip Convergence (
CvRDT.converge_of_allPairsReachable): from any reachable configuration over a strongly connectedDigraph P, a finite gossip wave brings all replicas to identical causal histories and identical states.
- order- and duplicate-independent state-list folding (
Operation-Based Commutative Replicated Data Types (
CmRDT) &CausalBroadcastBridge: Models two-phase(prepare, effect)replicated objects with concurrent downstream commutativity (ConcurrentCommute:¬ prec e₁ e₂ → ¬ prec e₂ e₁ → effect (effOf e₁) (effect (effOf e₂) s) = effect (effOf e₂) (effect (effOf e₁) s)), proving:- Op-Based Strong Convergence (
CmRDT.causalLinearization_eq): every causal linearization (IsCausalLinearization) of the same finite event set produces the exact same replica state, - Vector-Clock Causal Broadcast Bridge (
CmRDT.bss_strong_convergence,CmRDT.bss_quiescent_convergence): connectsCslib.Distributed.CausalBroadcast's Birman–Schiper–StephensonbssLTS Fdirectly toCmRDTstrong convergence across all processes (faulty or correct) and eventual quiescent convergence across all non-crashed processesq ∉ Ffor any static crash-fault setF : Set P.
- Op-Based Strong Convergence (
State/Op Emulation Equivalence (
CvRDT.toCmRDT,CmRDT.toCvRDT):CvRDT.toCmRDTemulates anyCvRDTas an unconditionally commutativeCmRDTby broadcasting post-update states and merging downstream via(· ⊔ ·)(CvRDT.toCmRDT_effectsCommute,CvRDT.toCmRDT_foldl_eq_evalHistory).CmRDT.toCvRDTemulates anyCmRDTas a state-basedCvRDTover finite event setsFinset Evordered by(⊆)with merge(· ∪ ·), extracting the maximaldeps-closed deliverable subset (deliverableEvents) and evaluating any causal linearization (CmRDT.evalCausalSet), agreeing with op-basedCmRDTexecution on all causally closed histories.
Model scope relative to primary sources #
[SPBZ11b] (§5) and [SPBZ11a] (§§3.2, 3.4–3.5,
4) additionally study LWW-Register, MV-Register, graph and sequence CRDTs (2P2P-Graph,
monotonic DAGs, RGA/Treedoc), and Wuu–Bernstein vector-clock garbage collection, which remain
open under #7502. Concrete counter and set data types (GCounter, PNCounter, TwoPhaseSet,
ORSet) are developed in CslibFrontier.Computability.Distributed.CRDT.DataTypes.
Main definitions #
Cslib.Distributed.CRDT.CvRDT: state-based convergent replicated data type over[SemilatticeSup S]withupdate_infl : ∀ op s, s ≤ update op s.Cslib.Distributed.CRDT.evalHistory: semilattice supremum ofinitandpostStateover a finite causal historyFinset UId.Cslib.Distributed.CRDT.GossipPacket,Cslib.Distributed.CRDT.GossipState,Cslib.Distributed.CRDT.GossipAction,Cslib.Distributed.CRDT.CvRDT.gossipLTS: asynchronous state-based gossip transition system with reordering, packet loss, and arbitrary packet duplication.Cslib.Distributed.CRDT.CmRDT: operation-based replicated data type withprepareand downstreameffect.Cslib.Distributed.CRDT.EffectsCommute,Cslib.Distributed.CRDT.ConcurrentCommute,Cslib.Distributed.CRDT.IsCausallyClosed,Cslib.Distributed.CRDT.IsCausalLinearization: unconditional vs. concurrent downstream commutativity, causal closure, and duplicate-free causal linearizations.Cslib.Distributed.CRDT.CmRDT.bssReplicaState:CmRDTreplica state induced by thedeliveredlog ofCslib.Distributed.CausalBroadcast.BSSState.Cslib.Distributed.CRDT.CvRDT.toCmRDT,Cslib.Distributed.CRDT.deliverableEvents,Cslib.Distributed.CRDT.CmRDT.evalCausalSet,Cslib.Distributed.CRDT.CmRDT.toCvRDT: bidirectional emulations betweenCvRDTandCmRDT.
Main results #
Cslib.Distributed.CRDT.foldl_sup_eq_of_mem_iff: merging two state lists via(· ⊔ ·)yields identical results whenever they contain the same set of elements, regardless of order or duplicates.Cslib.Distributed.CRDT.CvRDT.replica_eq_evalHistoryandCslib.Distributed.CRDT.CvRDT.strong_convergence: state-basedSECstep overgossipLTS(s.history p = s.history q → s.replica p = s.replica q).Cslib.Distributed.CRDT.CvRDT.converge_of_allPairsReachable: finite-wave gossip convergence step across any strongly connectedDigraph P.Cslib.Distributed.CRDT.CmRDT.causalLinearization_eq: op-basedSECstep showing any two causal linearizations of a finite event set with commuting concurrent effects evaluate to the exact same state.Cslib.Distributed.CRDT.CmRDT.bss_strong_convergenceandCslib.Distributed.CRDT.CmRDT.bss_quiescent_convergence: causal-broadcast bridge steps overCausalBroadcast.bssLTS Ffor arbitrary crash-fault setsF : Set P.Cslib.Distributed.CRDT.CvRDT.toCmRDT_effectsCommuteandCslib.Distributed.CRDT.CvRDT.toCmRDT_foldl_eq_evalHistory: op-based emulation of anyCvRDT.Cslib.Distributed.CRDT.exists_causalLinearization,Cslib.Distributed.CRDT.CmRDT.evalCausalSet_eq_foldl,Cslib.Distributed.CRDT.CmRDT.evalCausalSet_insert_max, andCslib.Distributed.CRDT.CmRDT.toCvRDT_query_eq: state-basedCvRDTemulation of anyCmRDT.
References #
Semilattice list and history folding #
Order- and duplicate-independence of semilattice merges: folding (· ⊔ ·) over two lists
from s₀ yields the exact same state whenever the lists have the same support set, regardless of
arrival order or multiplicity.
Evaluate the semilattice supremum of init together with the post-states post u of all
update identifiers u ∈ H ([SPBZ11b], §2.1 & §2.3, pp. 5–7).
Universal least-upper-bound characterization of evalHistory init post H.
A state-based Convergent Replicated Data Type (CvRDT) (monotonic semilattice object,
after [SPBZ11b], §2.3, Definition 2.4, p. 6;
[SPBZ11a], §2.3.1, p. 10) over Mathlib's SemilatticeSup S:
replicas start at init, answer local queries via query, merge remote payloads via semilattice
supremum (· ⊔ ·), and advance monotonically across local updates (s ≤ update op s).
- init : S
Initial state
s⁰of every replica. - query : S → Q
Side-effect-free local query
q : S → Q. - update : Op → S → S
Local mutating update operation
u : Op → S → S. Monotonicity (inflationarity) of updates in the semilattice:
s ≤ update op s.
An in-flight gossip packet addressed to dest, carrying state payload : S together with the
ghost causal history ghostHist of update identifiers reflected in payload
([SPBZ11b], §2.1, Definition 2.1, p. 5). Note that replica merge steps
inspect only dest and payload; ghostHist is purely a specification field.
Global configuration of an asynchronous state-based CvRDT gossip network.
- replica : P → S
Current semilattice state at each replica.
- history : P → Finset UId
Ghost causal history
c_pof update identifiers delivered at each replica. - inFlight : Multiset (GossipPacket P UId S)
Unordered multiset of in-flight state gossip packets.
- generated : Finset UId
Ghost set of unique update identifiers generated so far across all replicas.
- postState : UId → S
Ghost map recording the post-update state created when each
uidexecuted at its source.
Transition labels of the asynchronous CvRDT gossip network: local updates, point-to-point
state gossip sends, consuming merges, duplicate-preserving merges, and packet drops.
- update {P : Type u_1} {UId : Type u_2} {Op : Type u_3} {S : Type u_4} (p : P) (uid : UId) (op : Op) : GossipAction P UId Op S
Replica
pexecutesoplocally with fresh update identifieruid. - send {P : Type u_1} {UId : Type u_2} {Op : Type u_3} {S : Type u_4} (src dst : P) : GossipAction P UId Op S
Replica
srcsends its current state to neighbordst. - mergeConsume {P : Type u_1} {UId : Type u_2} {Op : Type u_3} {S : Type u_4} (pkt : GossipPacket P UId S) : GossipAction P UId Op S
- mergeDuplicate {P : Type u_1} {UId : Type u_2} {Op : Type u_3} {S : Type u_4} (pkt : GossipPacket P UId S) : GossipAction P UId Op S
- drop {P : Type u_1} {UId : Type u_2} {Op : Type u_3} {S : Type u_4} (pkt : GossipPacket P UId S) : GossipAction P UId Op S
Network drops an in-flight packet
pkt(modeling lossy links or temporary partitions).
Initial global gossip configuration for C : CvRDT S Op Q: all replicas start at C.init with
empty causal histories and empty channels.
Deterministic state update for one GossipAction of C : CvRDT S Op Q.
Enabledness guard for GossipAction over directed communication graph G : Digraph P.
Instances For
Asynchronous gossip labelled transition system (Cslib.LTS) of C : CvRDT S Op Q over
communication graph G : Digraph P.
Fold a finite list of GossipActions starting from s₀.
Check whether every action in xl is enabled from s₀ over communication graph G.
Instances For
Equivalence between LTS.MTr on C.gossipLTS G and C.gossipValidTrace + C.gossipRun.
Semilattice causal-history invariant step (toward #7502, after
[SPBZ11b], §2.3, Theorem 2.1, pp. 6–7): in any finite execution of
C.gossipLTS G from C.gossipInit, each replica's concrete payload equals the semilattice
supremum evalHistory C.init s.postState (s.history p) of its delivered update history.
State-based Strong Eventual Consistency (SEC) strong-convergence step (toward #7502, after
[SPBZ11b], §2.2 Definition 2.3 & §2.3 Theorem 2.1, pp. 5–7): along any
finite execution of C.gossipLTS G (allowing arbitrary packet delay, reordering, loss, and
duplication), any two replicas p and q that have delivered the same update set (s.history p = s.history q) have identical states (s.replica p = s.replica q) and identical query results.
Strongly connected gossip eventual-convergence step (toward #7502, after
[SPBZ11b], §2.3 Theorem 2.1, pp. 6–7;
[SPBZ11a], §2.3.1 Proposition 2.1, p. 10): from any state s over a
finite strongly connected graph G : Digraph P (∀ p q, Relation.ReflTransGen G.Adj p q), there
exists a finite gossip wave with no new client updates reaching s' where every replica holds the
global supremum Finset.univ.sup' Finset.univ_nonempty s.replica and the global history union
Finset.univ.biUnion s.history.
An operation-based Commutative Replicated Data Type (CmRDT) (after
[SPBZ11b], §2.4, pp. 7–8;
[SPBZ11a], §2.2.2 & §2.3.2, pp. 8–11): local updates execute a
side-effect-free prepare : Op → S → Eff at the originating replica to produce a downstream
effect payload Eff, which is then applied via effect : Eff → S → S at all replicas in causal
order.
- init : S
Initial state
s⁰of every replica. - query : S → Q
Side-effect-free local query
q : S → Q. - prepare : Op → S → Eff
Source-local phase computing the downstream effect payload from
(op, sourceState). - effect : Eff → S → S
Downstream state transformer applied at every replica upon delivery.
Unconditional downstream commutativity: all effect payloads commute on every state s.
Concurrent downstream commutativity over an event set H with causal precedence prec
([SPBZ11b], §2.4 Definition 2.6 & Theorem 2.2, p. 8): any two distinct
concurrent events e₁, e₂ ∈ H (¬ prec e₁ e₂ and ¬ prec e₂ e₁) have commuting downstream
effects.
List l is a duplicate-free causal linearization of finite event set H with respect to
prec: l.Nodup, l has the same elements as H, and prec e₁ e₂ implies e₁ appears strictly
before e₂ in l (l.idxOf e₁ < l.idxOf e₂).
Op-based Strong Eventual Consistency (SEC) strong-convergence step (toward #7502, after
[SPBZ11b], §2.4 Theorem 2.2, p. 8;
[SPBZ11a], §2.3.2 Proposition 2.2, p. 11): for any finite event set
H : Finset Ev whose concurrent events commute under C.effect, any two causal linearizations
l₁ and l₂ of H evaluate from C.init to the exact same state.
Bridge to Cslib.Distributed.CausalBroadcast (CBCAST) #
Replica state of C : CmRDT S Op Eff Q at process q : P induced by applying C.effect
along q's causally delivered packet log (s.proc q).delivered in
Cslib.Distributed.CausalBroadcast.BSSState P Eff.
Every process's delivered log in bssLTS F forms a causally closed, duplicate-free
IsCausalLinearization of (s.proc q).delivered.toFinset under CausalPrec xl.
Causal-broadcast to CmRDT strong-convergence bridge step (toward #7502, connecting
Cslib.Distributed.CausalBroadcast.bssLTS of [BSS91], §5.1, directly to
[SPBZ11b], §2.4 Theorem 2.2, p. 8): for any static crash-fault set
F : Set P, in any finite execution of bssLTS F, if concurrent broadcasts in BroadcastIn xl
have commuting downstream effects under C.effect, then any two processes p and q (faulty or
correct) that have delivered the same set of packets have identical CmRDT states and query
outputs.
Causal-broadcast to CmRDT quiescent eventual-convergence bridge step (toward #7502,
combining bss_live_of_atomic_multicast and CmRDT.bss_strong_convergence): in any fair infinite
execution (ss, xs) of bssLTS F with atomic multicast steps (∀ k, IsAtomicMulticastAction (xs k)), if no new broadcasts occur from step K onward (∀ k ≥ K, emittedPacket (ss k) (xs k) = none) and concurrent broadcasts commute under C.effect, then there exists a convergence step
M ≥ K after which all non-crashed replicas p ∉ F, q ∉ F permanently share identical CmRDT
states (∀ k ≥ M, C.bssReplicaState (ss k) p = C.bssReplicaState (ss k) q).
Operation-based emulation of a state-based CvRDT (step toward #7502, after
[SPBZ11b], §3.2.1 Theorem 3.1, p. 9;
[SPBZ11a], §2.4.1 Specification 3, p. 12): prepare computes the
post-update state C.update op s at the source replica, and effect merges received states
downstream via semilattice supremum (· ⊔ ·).
State-to-op emulation commutativity step (toward #7502, after
[SPBZ11b], §3.2.1 Theorem 3.1, p. 9): the downstream merge effects of
C.toCmRDT commute unconditionally on every state, requiring not even causal delivery order.
Executing prepare followed immediately by effect at the source replica in C.toCmRDT
produces the exact same local state C.update op s as C itself.
Evaluating C.toCmRDT along any event sequence l whose set of events is H yields the exact
same semilattice state evalHistory C.init post H as state-based C.
Every finite event set H : Finset Ev equipped with a strict partial order prec admits a
causal linearization l : List Ev (IsCausalLinearization prec H l).
Evaluate C : CmRDT S Op Eff Q on a finite event set H : Finset Ev ordered by strict
partial order prec via causal linearization ([SPBZ11b], §3.2.2
Theorem 3.2, pp. 9–10). Under ConcurrentCommute, CmRDT.evalCausalSet_eq_foldl proves this value
is independent of the chosen causal linearization.
Under ConcurrentCommute, C.evalCausalSet prec effOf H agrees with folding C.effect over
any causal linearization l of H.
Adding a fresh causally maximal event e ∉ H (∀ x ∈ H, ¬ prec e x) advances
C.evalCausalSet by applying C.effect (effOf e) directly to C.evalCausalSet prec effOf H.
Iterated causal-readiness step starting from ∅: after n rounds against known-event pool
M and explicit dependency map deps : Ev → Finset Ev, returns the subset of events in M whose
transitive deps chains of depth < n all lie inside M ([SPBZ11b],
§3.2.2 Theorem 3.2, pp. 9–10; [SPBZ11a], §2.4.2 Specification 4,
p. 13).
Maximal deps-closed subset D ⊆ M of causally deliverable events in M, computed in
M.card iterations of deliverableIter.
Monotonicity of deliverableEvents: growing the known-event pool M₁ ⊆ M₂ monotonically
grows the causally deliverable subset.
When M is already closed under deps (∀ e ∈ M, deps e ⊆ M) and prec is a strict partial
order with ∀ e x, x ∈ deps e → prec x e, every event in M becomes causally deliverable within
M.card steps (deliverableEvents deps M = M).
State-based CvRDT emulation of an operation-based CmRDT (step toward #7502, after
[SPBZ11b], §3.2.2 Theorem 3.2, pp. 9–10;
[SPBZ11a], §2.4.2 Specification 4, p. 13): replicas maintain known
unique events M : Finset Ev ordered by (⊆) with merge (· ∪ ·), update locally by inserting a
newly generated event insert e M, and answer queries by evaluating C over the causally
deliverable subset deliverableEvents deps M.
On any deps-closed known-event history M whose concurrent events commute, the state-based
emulation (C.toCvRDT prec deps effOf).query M returns the exact same query result as applying C
along any causal linearization l of M.