Documentation

CslibFrontier.Computability.Distributed.ChandyLamport.Correctness

Chandy–Lamport consistent-cut permutation, stable-property detection, and liveness #

This module proves the main correctness and liveness theorems of the Chandy–Lamport global snapshot algorithm ([CL85], §3.3, §4 Theorem 1, and §5, pp. 70–75):

  1. FIFO cut invariant (project_chan_eq_preInFlight_append_postInFlight, preRecv_pops_preInFlight, postRecv_records_iff_preInFlight): At every reachable augmented state, each channel (u, v) splits into preInFlight (application messages sent before u recorded) followed by postInFlight (application messages sent after u recorded), separated by .marker while .marker is in transit. Pre-snapshot receives consume exclusively from preInFlight (no post-snapshot message is ever received pre-snapshot), and post-snapshot receives append msg to chanRec if and only if msg came from preInFlight.
  2. Causal permutation & consistent-cut reachability (chandyLamport_perm_mTr, chandyLamport_consistent_cut): For any finite execution S_init →*[xl] S_final starting from a pre-snapshot state S_init and ending at a snapshot-complete state S_final, splitting the underlying application events of xl into pre-snapshot events (tracePreEvents S_init xl) followed by post-snapshot events (tracePostEvents S_init xl) yields a valid permutation of eraseTrace xl in sys.lts whose intermediate state between all pre-snapshot events and all post-snapshot events is literally extractSnapshot S_final. In particular: sys.lts.CanReach (project S_init) (extractSnapshot S_final) ∧ sys.lts.CanReach (extractSnapshot S_final) (project S_final).
  3. Stable-property detection (stablePred_transfer): For every IsStablePred sys Φ, (Φ (extractSnapshot S_final) → Φ (project S_final)) and (¬ Φ (extractSnapshot S_final) → ¬ Φ (project S_init)).
  4. Snapshot completion liveness (snapshot_liveness, snapshot_liveness_complete, System.InputEnabled.exists_fair_snapOmegaExecution): Under weak FIFO channel fairness on any finite strongly connected communication graph (and in particular on the complete network ⊤) with at least one process recording a snapshot, every process eventually records its state and every incoming channel recorder eventually reaches .done (and remains complete thereafter). Every input-enabled system admits fair infinite executions from any well-formed state.

Main definitions #

Main results #

References #

Part 1: FIFO channel cut partition (preInFlight and postInFlight) #

def Cslib.Distributed.ChandyLamport.preInFlight {P : Type u_1} {S : Type u_2} {M : Type u_3} (S_aug : SnapGlobalState P S M) (u v : P) :

In-flight application messages on channel (u, v) sent before u recorded its snapshot.

def Cslib.Distributed.ChandyLamport.postInFlight {P : Type u_1} {S : Type u_2} {M : Type u_3} (S_aug : SnapGlobalState P S M) (u v : P) :

In-flight application messages on channel (u, v) sent after u recorded its snapshot.

theorem Cslib.Distributed.ChandyLamport.project_chan_eq_preInFlight_append_postInFlight {P : Type u_1} {S : Type u_2} {M : Type u_3} (S_aug : SnapGlobalState P S M) (u v : P) :
(project S_aug).chan u v = preInFlight S_aug u v ++ postInFlight S_aug u v

Every channel's underlying queue (project S_aug).chan u v decomposes into preInFlight followed by postInFlight.

Private ghost cut structures for the permutation proof #

theorem Cslib.Distributed.ChandyLamport.System.preRecv_pops_preInFlight {P : Type u_1} {S : Type u_2} {M : Type u_3} (sys : System P S M) [DecidableEq P] [DecidableRel sys.graph.Adj] {S₁ S₂ : SnapGlobalState P S M} {src dest : P} {msg : M} {st' : S} {sent : List (P × M)} (hinv : sys.SnapInv S₁) (htr : sys.snapLts.Tr S₁ (SnapEvent.app (Event.recv src dest msg st' sent)) S₂) (hpre_dest : (S₁.proc dest).snapState = none) :
∃ (tail : List M), preInFlight S₁ src dest = msg :: tail

Zero post-snapshot sends received pre-snapshot: when an unrecorded process dest (snapState = none) receives msg from src, msg comes from the head of preInFlight S₁ src dest (which is non-empty).

theorem Cslib.Distributed.ChandyLamport.System.postRecv_records_iff_preInFlight {P : Type u_1} {S : Type u_2} {M : Type u_3} (sys : System P S M) [DecidableEq P] [DecidableRel sys.graph.Adj] {S₁ S₂ : SnapGlobalState P S M} {src dest : P} {msg : M} {st' : S} {sent : List (P × M)} (hinv : sys.SnapInv S₁) (htr : sys.snapLts.Tr S₁ (SnapEvent.app (Event.recv src dest msg st' sent)) S₂) (hpost_dest : (S₁.proc dest).snapState.isSome = true) :
preInFlight S₁ src dest ≠ [] ∧ (preInFlight S₁ src dest).head? = some msg ∧ ((S₂.proc dest).chanRec src).msgs = ((S₁.proc dest).chanRec src).msgs ++ [msg] ∨ preInFlight S₁ src dest = [] ∧ (postInFlight S₁ src dest).head? = some msg ∧ ((S₂.proc dest).chanRec src).msgs = ((S₁.proc dest).chanRec src).msgs

chanRec captures the exact pre-snapshot sends received post-snapshot: when an already-recorded process dest (snapState.isSome) receives msg from src:

  • if preInFlight S₁ src dest is non-empty, msg is its head and chanRec src appends msg;
  • if preInFlight S₁ src dest = [], msg is the head of postInFlight S₁ src dest and chanRec src is already .done and unchanged.

Part 2: Ghost cut executions & causal permutation (chandyLamport_consistent_cut) #

def Cslib.Distributed.ChandyLamport.System.tracePreEvents {P : Type u_1} {S : Type u_2} {M : Type u_3} (sys : System P S M) [DecidableEq P] [DecidableRel sys.graph.Adj] (S_aug : SnapGlobalState P S M) :
List (SnapEvent P S M) → List (Event P S M)

Subsequence of Pre-snapshot application events along augmented trace xl from S_aug (events whose actor had snapState = none when the event fired).

def Cslib.Distributed.ChandyLamport.System.tracePostEvents {P : Type u_1} {S : Type u_2} {M : Type u_3} (sys : System P S M) [DecidableEq P] [DecidableRel sys.graph.Adj] (S_aug : SnapGlobalState P S M) :
List (SnapEvent P S M) → List (Event P S M)

Subsequence of Post-snapshot application events along augmented trace xl from S_aug (events whose actor had snapState.isSome when the event fired).

Mapping sys.snapLts transitions into CutMTr #

Channel evolution helpers for .app e transitions #

Adjacent inversion swaps in CutMTr #

Pushing cross and post steps past pre and cross blocks #

Identifying the boundary state C₁.s = extractSnapshot S_final #

theorem Cslib.Distributed.ChandyLamport.System.chandyLamport_perm_mTr {P : Type u_1} {S : Type u_2} {M : Type u_3} (sys : System P S M) [DecidableEq P] [DecidableRel sys.graph.Adj] {S_init S_final : SnapGlobalState P S M} {xl : List (SnapEvent P S M)} (hpre : sys.IsPreSnapshot S_init) (hmtr : sys.snapLts.MTr S_init xl S_final) (hcomp : IsSnapshotComplete S_final) :
sys.lts.MTr (project S_init) (sys.tracePreEvents S_init xl) (extractSnapshot S_final) ∧ sys.lts.MTr (extractSnapshot S_final) (sys.tracePostEvents S_init xl) (project S_final) ∧ (sys.tracePreEvents S_init xl ++ sys.tracePostEvents S_init xl).Perm (eraseTrace xl)

Chandy–Lamport explicit causal permutation theorem ([CL85], §4, Theorem 1, pp. 72–73): for any finite execution S_init →*[xl] S_final from a pre-snapshot state S_init to a snapshot-complete state S_final, executing all pre-snapshot events (tracePreEvents S_init xl) from project S_init reaches extractSnapshot S_final in sys.lts, executing all post-snapshot events (tracePostEvents S_init xl) from extractSnapshot S_final reaches project S_final in sys.lts, and tracePreEvents S_init xl ++ tracePostEvents S_init xl is a permutation of eraseTrace xl (any prefix before S_init and suffix after S_final compose unchanged via LTS.MTr.comp).

theorem Cslib.Distributed.ChandyLamport.System.chandyLamport_consistent_cut {P : Type u_1} {S : Type u_2} {M : Type u_3} (sys : System P S M) [DecidableEq P] [DecidableRel sys.graph.Adj] {S_init S_final : SnapGlobalState P S M} {xl : List (SnapEvent P S M)} (hpre : sys.IsPreSnapshot S_init) (hmtr : sys.snapLts.MTr S_init xl S_final) (hcomp : IsSnapshotComplete S_final) :
sys.lts.CanReach (project S_init) (extractSnapshot S_final) ∧ sys.lts.CanReach (extractSnapshot S_final) (project S_final)

Chandy–Lamport consistent-cut reachability theorem ([CL85], §4, Theorem 1, p. 72): if a finite augmented execution starts before any snapshot action (IsPreSnapshot S_init) and ends at a state where the global snapshot is complete (IsSnapshotComplete S_final), then in the underlying FIFO system sys.lts, the assembled snapshot S* = extractSnapshot S_final is reachable from project S_init and project S_final is reachable from S*.

Part 3: Stable-property detection corollary #

theorem Cslib.Distributed.ChandyLamport.System.stablePred_transfer {P : Type u_1} {S : Type u_2} {M : Type u_3} (sys : System P S M) [DecidableEq P] [DecidableRel sys.graph.Adj] {Φ : GlobalState P S M → Prop} (hΦ : IsStablePred sys Φ) {S_init S_final : SnapGlobalState P S M} {xl : List (SnapEvent P S M)} (hpre : sys.IsPreSnapshot S_init) (hmtr : sys.snapLts.MTr S_init xl S_final) (hcomp : IsSnapshotComplete S_final) :
(Φ (extractSnapshot S_final) → Φ (project S_final)) ∧ (¬Φ (extractSnapshot S_final) → ¬Φ (project S_init))

Stable-property detection (stablePred_transfer, [CL85], §5, pp. 74–75): for every stable global predicate Φ of sys, if Φ holds in the recorded snapshot extractSnapshot S_final, then Φ holds in the actual physical state project S_final once the snapshot finishes; contrapositively (matching y(S_ι) → definite on p. 74), if Φ fails in extractSnapshot S_final, then Φ had not yet become true at project S_init.

Part 4: Fair FIFO channel delivery & snapshot completion liveness #

def Cslib.Distributed.ChandyLamport.SnapEvent.deliversOn {P : Type u_1} {S : Type u_2} {M : Type u_3} (a : SnapEvent P S M) (src dest : P) :

Whether augmented event a delivers the head message (application payload or .marker) on channel (src, dest).

def Cslib.Distributed.ChandyLamport.FairChannels {P : Type u_1} {S : Type u_2} {M : Type u_3} (ss : ωSequence (SnapGlobalState P S M)) (xs : ωSequence (SnapEvent P S M)) :

Weak FIFO channel delivery fairness: whenever channel (src, dest) is non-empty at step k, some step j ≥ k delivers from the head of (src, dest).

A directed communication graph G is strongly connected if every vertex v is reachable from every vertex u by a directed path (Relation.ReflTransGen G.Adj u v).

The complete directed graph ⊤ is strongly connected.

Monotonicity of recorded process states and completed channel recorders #

theorem Cslib.Distributed.ChandyLamport.System.snapState_stable_tr {P : Type u_1} {S : Type u_2} {M : Type u_3} (sys : System P S M) [DecidableEq P] [DecidableRel sys.graph.Adj] {S₁ S₂ : SnapGlobalState P S M} {a : SnapEvent P S M} {p : P} {s_p : S} (htr : sys.snapLts.Tr S₁ a S₂) (hs : (S₁.proc p).snapState = some s_p) :
(S₂.proc p).snapState = some s_p

Once process p records snapState = some s_p, every subsequent transition of sys.snapLts preserves snapState = some s_p (write-once local snapshot).

theorem Cslib.Distributed.ChandyLamport.System.chanRec_done_stable_tr {P : Type u_1} {S : Type u_2} {M : Type u_3} (sys : System P S M) [DecidableEq P] [DecidableRel sys.graph.Adj] {S₁ S₂ : SnapGlobalState P S M} {a : SnapEvent P S M} {q p : P} {saved : List M} (htr : sys.snapLts.Tr S₁ a S₂) (hs : (S₁.proc p).snapState.isSome = true) (hd : (S₁.proc p).chanRec q = ChannelRec.done saved) :
(S₂.proc p).chanRec q = ChannelRec.done saved

Once process p has recorded (snapState.isSome) and finalized incoming recorder chanRec q = .done saved, every subsequent transition of sys.snapLts preserves .done saved.

FIFO progress of .marker along a single edge #

theorem Cslib.Distributed.ChandyLamport.System.snapshot_liveness {P : Type u_1} {S : Type u_2} {M : Type u_3} (sys : System P S M) [Finite P] [DecidableEq P] [DecidableRel sys.graph.Adj] (hsc : StronglyConnected sys.graph) {ss : ωSequence (SnapGlobalState P S M)} {xs : ωSequence (SnapEvent P S M)} (hpre₀ : sys.IsPreSnapshot (ss 0)) (hexec : sys.snapLts.OmegaExecution ss xs) (hfair : FairChannels ss xs) {p₀ : P} {k₀ : ℕ} (hinit : ((ss k₀).proc p₀).snapState.isSome = true) :
∃ (K : ℕ), k₀ ≤ K ∧ ∀ (k : ℕ), K ≤ k → IsSnapshotComplete (ss k)

Chandy–Lamport snapshot completion liveness ([CL85], §3.3, p. 71): on any finite strongly connected communication graph, in any infinite execution starting from a pre-snapshot state that satisfies weak FIFO channel delivery fairness (FairChannels, realizing (L1) while atomic marker handling discharges (L2)) and in which at least one process records a snapshot (((ss k₀).proc p₀).snapState.isSome), there exists a step K from which IsSnapshotComplete (ss k) holds permanently (∀ k ≥ K).

theorem Cslib.Distributed.ChandyLamport.System.snapshot_liveness_complete {P : Type u_1} {S : Type u_2} {M : Type u_3} (sys : System P S M) [Finite P] [DecidableEq P] [DecidableRel sys.graph.Adj] (htop : sys.graph = ⊤) {ss : ωSequence (SnapGlobalState P S M)} {xs : ωSequence (SnapEvent P S M)} (hpre₀ : sys.IsPreSnapshot (ss 0)) (hexec : sys.snapLts.OmegaExecution ss xs) (hfair : FairChannels ss xs) {p₀ : P} {k₀ : ℕ} (hinit : ((ss k₀).proc p₀).snapState.isSome = true) :
∃ (K : ℕ), k₀ ≤ K ∧ ∀ (k : ℕ), K ≤ k → IsSnapshotComplete (ss k)

Specialization of snapshot_liveness to the complete directed network sys.graph = ⊤.

Non-vacuity: fair FIFO scheduler for input-enabled systems #

def Cslib.Distributed.ChandyLamport.System.InputEnabled {P : Type u_1} {S : Type u_2} {M : Type u_3} (sys : System P S M) :

A System is input-enabled if receiving a message at the head of an incident channel is never locally blocked: for every edge (src, dest), local state st, and incoming message msg, there exist st' and sent satisfying sys.recv and respecting sys.graph.

Round-robin channel-draining scheduler #

theorem Cslib.Distributed.ChandyLamport.System.InputEnabled.exists_fair_snapOmegaExecution {P : Type u_1} {S : Type u_2} {M : Type u_3} [Finite P] [DecidableEq P] {sys : System P S M} [DecidableRel sys.graph.Adj] (hinp : sys.InputEnabled) {S₀ : SnapGlobalState P S M} (hwf₀ : sys.WellFormedSnapChan S₀) :
∃ (ss : ωSequence (SnapGlobalState P S M)) (xs : ωSequence (SnapEvent P S M)), ss 0 = S₀ ∧ sys.snapLts.OmegaExecution ss xs ∧ FairChannels ss xs

Existence of fair infinite executions (non-vacuity of FairChannels): if sys is input-enabled, every augmented state S₀ with well-formed channels extends to an infinite execution (ss, xs) of sys.snapLts starting at S₀ that satisfies FairChannels ss xs.