Chandy–Lamport marker snapshot transformation and FIFO cut invariants #
This module defines the Chandy–Lamport global-state recording transformation ([CL85],
§3.2, p. 70) on top of any asynchronous FIFO message-passing System P S M, without freezing or
blocking underlying application transitions.
Wire channels carry WireMsg M values—either an application message .app m or a control
.marker. Each process p maintains:
- its live application state
appState : S, - its write-once recorded local state
snapState : Option S(nonebefore recording,some s_ponce recorded), and - per-incoming-channel recorders
chanRec : P → ChannelRec M(recording bufwhilephas recorded its local state and is still awaiting.markeron(q, p);done savedonce.markerarrives, or immediately for the triggering channel and any non-edge).
The protocol obeys the two Chandy–Lamport rules:
- Marker-sending rule: When
ptransitions fromsnapState = nonetosome appState—either spontaneously viaSnapEvent.initiateSnapshot por upon receiving its first.markerat the head of an incoming channel(src, p)viaSnapEvent.recvMarker src p—it atomically recordsappState, marks incoming channel(src, p)(if marker-triggered) and non-edges.done [], initializes all other incoming channels(q, p)to.recording [], and appends.markerto every outgoing channel(p, r)ofsys.graph. - Marker-receiving rule: If
phas already recorded (snapState = some _), receiving.app mon(src, p)appendsmtochanRec srcwheneverchanRec src = .recording bufwhile runningsys's normalrecvtransition; receiving.markeron(src, p)transitionschanRec srcfrom.recording bufto.done buf.
In this LTS presentation, SnapEvent.recvMarker src dest executes the marker-sending or
marker-receiving rule atomically upon consuming .marker from the head of (src, dest), and
SnapEvent.stutter extends finite quiescent runs to infinite executions for liveness (whereas the
underlying sys.lts has no stuttering action, so sys.lts.IsTerminal expresses genuine deadlock).
Main definitions #
Cslib.Distributed.ChandyLamport.WireMsg,Cslib.Distributed.ChandyLamport.unmarker,Cslib.Distributed.ChandyLamport.takeBeforeMarker,Cslib.Distributed.ChandyLamport.dropAfterMarker: wire messages and FIFO channel projections before/after a.marker.Cslib.Distributed.ChandyLamport.ChannelRec: incoming-channel recorder (recordingordone).Cslib.Distributed.ChandyLamport.SnapProcState,Cslib.Distributed.ChandyLamport.SnapGlobalState: snapshot-augmented local and global states.Cslib.Distributed.ChandyLamport.project,Cslib.Distributed.ChandyLamport.liftState,Cslib.Distributed.ChandyLamport.extractSnapshot: forgetful projection, pre-snapshot embedding, and assembled global snapshotS*.Cslib.Distributed.ChandyLamport.SnapEvent,Cslib.Distributed.ChandyLamport.eraseTrace: augmented transition labels and marker-step erasure.Cslib.Distributed.ChandyLamport.System.snapLts,Cslib.Distributed.ChandyLamport.System.runSnapEvents,Cslib.Distributed.ChandyLamport.System.snapStates,Cslib.Distributed.ChandyLamport.System.validSnapTrace: LTS of the Chandy–Lamport augmented system and its executable trace runners.Cslib.Distributed.ChandyLamport.System.WellFormedSnapChan,Cslib.Distributed.ChandyLamport.System.IsPreSnapshot,Cslib.Distributed.ChandyLamport.IsSnapshotComplete: channel well-formedness, pre-snapshot initial condition, and snapshot-completion predicate.Cslib.Distributed.ChandyLamport.System.SnapInv: inductive single-marker and FIFO cut invariant.
Main results #
Cslib.Distributed.ChandyLamport.System.snapMTr_iff_validSnapTrace,Cslib.Distributed.ChandyLamport.System.mem_snapStates_iff_split: finite executions ofsys.snapLtsmatchvalidSnapTrace+runSnapEvents, andsnapStatesenumerates their exact intermediate states.Cslib.Distributed.ChandyLamport.System.snapMTr_project: erasing marker-control steps maps any augmented finite execution to a validsys.ltsexecution fromproject S₁toproject S₂.Cslib.Distributed.ChandyLamport.System.snapTr_appInternal_of_tr,Cslib.Distributed.ChandyLamport.System.snapMTr_appRecv_of_tr: non-blocking forward simulation of underlyinginternalandrecvtransitions insys.snapLts.Cslib.Distributed.ChandyLamport.System.snapInv_mTr:SnapInvholds across all executions from anyIsPreSnapshotstate.Cslib.Distributed.ChandyLamport.System.count_marker_le_one: at most one.markeris ever in flight on any channel(u, v).Cslib.Distributed.ChandyLamport.System.isSnapshotComplete_no_markers: onceIsSnapshotCompleteholds, zero.markers remain in flight anywhere in the network.
References #
Wire messages and channel marker projections #
Boolean test checking whether a WireMsg is .marker (without needing DecidableEq M).
Snapshot-augmented local and global configurations #
Per-incoming-channel recorder state at a process that has recorded its local snapshot.
- recording {M : Type u_1} (buf : List M) : ChannelRec M
Actively buffering application messages arriving on this channel until
.markerarrives. - done {M : Type u_1} (saved : List M) : ChannelRec M
Recording finalized with saved message sequence
saved.
Recorded message buffer currently stored in a ChannelRec.
Boolean test checking whether a ChannelRec has reached .done.
Record incoming application message m if still .recording, or leave unchanged if .done.
Augmented local state of a process in the Chandy–Lamport snapshot protocol.
- appState : S
Current local state in the underlying application system.
- snapState : Option S
Recorded local state (
nonebefore recording,some s_ponce recorded). - chanRec : P → ChannelRec M
Per-incoming-channel recorder state (active once
snapState.isSome).
Global configuration of the Chandy–Lamport snapshot-augmented system.
- proc : P → SnapProcState P S M
Augmented local state of each process.
Point-to-point FIFO wire channels carrying application messages and markers.
Project an augmented global configuration to its underlying GlobalState by forgetting snapshot
fields and erasing .markers from every channel.
Embed an underlying GlobalState as an initial pre-snapshot SnapGlobalState with
snapState = none everywhere and no markers in flight.
Assemble the recorded global snapshot S* from S_aug: each process takes its recorded
snapState (falling back to appState only if unrecorded) and each channel (q, p) takes the
saved message sequence ((S_aug.proc p).chanRec q).msgs.
Global snapshot recording is complete when every process has recorded its local state and every
incoming-channel recorder has reached .done.
Instances For
Augmented transition labels and Chandy–Lamport rules #
Transition label of the Chandy–Lamport snapshot-augmented system.
- app {P : Type u_1} {S : Type u_2} {M : Type u_3} (e : Event P S M) : SnapEvent P S M
Normal underlying application event (
internalorrecvof.app m). - initiateSnapshot {P : Type u_1} {S : Type u_2} {M : Type u_3} (p : P) : SnapEvent P S M
Spontaneous snapshot initiation by process
p(whensnapState = none). - recvMarker {P : Type u_1} {S : Type u_2} {M : Type u_3} (src dest : P) : SnapEvent P S M
Delivery of
.markerat the head of channel(src, dest). - stutter {P : Type u_1} {S : Type u_2} {M : Type u_3} : SnapEvent P S M
Stuttering step leaving the augmented state unchanged (used to extend finite executions to infinite executions).
Apply an application event e to an augmented state S_aug: updates appState, pops .app m
if receiving, appends outgoing .app messages, and appends m to chanRec src if dest has
already recorded its local state and chanRec src is still .recording.
Apply spontaneous snapshot initiation at process p (Chandy–Lamport marker-sending rule):
records appState, sets chanRec q := .recording [] on incoming edges (and .done [] on
non-edges), and appends .marker to every outgoing edge (p, r).
Apply .marker receipt on channel (src, dest) (marker-sending rule on first marker arrival;
marker-receiving rule if dest has already recorded).
Whether augmented event a is enabled in S_aug.
Instances For
Next augmented state reached from S_aug under a.
Labelled transition system of the Chandy–Lamport snapshot-augmented network.
Instances For
sys.snapLts is deterministic.
Augmented state reached from S_aug by applying each event in xl sequentially.
Sequence of augmented states (S_0, S_1, ..., S_k) visited when executing xl from S_aug
(including both endpoints S_aug and sys.runSnapEvents S_aug xl).
Executable trace-validity predicate checking that each augmented event in xl is enabled when
reached from S_aug.
Instances For
Because sys.snapLts is deterministic, sys.snapLts.MTr S₁ xl S₂ holds if and only if xl is
a valid augmented trace from S₁ and S₂ = sys.runSnapEvents S₁ xl.
Along any valid execution S_init →*[xl] S_final of sys.snapLts, sys.snapStates S_init xl
is the exact set of intermediate augmented states S_k reached by splitting xl = xl₁ ++ xl₂.
Projection to the underlying system & non-blocking simulation #
Erasing marker-control and stuttering steps maps any valid finite execution of sys.snapLts
to a valid finite execution of the underlying sys.lts from project S₁ to project S₂.
Every spontaneous internal step enabled in project S_aug is immediately enabled as a single
SnapEvent.app step in sys.snapLts without blocking.
Pre-snapshot condition and single-marker FIFO cut invariant #
An augmented state has well-formed channels if every non-edge of sys.graph is empty.
Instances For
Non-edge wire channels remain empty across any finite execution of sys.snapLts.
Pre-snapshot initial condition: no process has recorded yet (snapState = none), no .markers
are in flight, and non-edge channels are empty (WellFormedSnapChan).
Instances For
liftState s satisfies IsPreSnapshot whenever s has well-formed channels.
Inductive invariant of the Chandy–Lamport snapshot protocol:
- Non-edges carry empty channels and (once
vrecords).done []recorders. - Every channel holds at most one
.marker. - While
uhas not recorded (snapState = none),chan u vcontains no.marker, and ifvhas already recorded along edge(u, v),chanRec uatvis.recording buf. - Once
uhas recorded along edge(u, v), either.marker ∈ chan u v(and ifvhas recorded,chanRec uatvis.recording buf), or.marker ∉ chan u v(meaning.markerwas already delivered tov, sovhas recorded andchanRec uatvis.done saved).
- nonEdge (u v : P) : ¬sys.graph.Adj u v → S_aug.chan u v = [] ∧ ((S_aug.proc v).snapState.isSome = true → (S_aug.proc v).chanRec u = ChannelRec.done [])
Non-edge channels stay empty and their recorders are
.done []. At most one
.markeris ever in flight on(u, v).- unrecordedSrc (u v : P) : (S_aug.proc u).snapState = none → WireMsg.marker ∉ S_aug.chan u v ∧ ((S_aug.proc v).snapState.isSome = true → sys.graph.Adj u v → ∃ (buf : List M), (S_aug.proc v).chanRec u = ChannelRec.recording buf)
Unrecorded senders have emitted no
.marker, and recorded receivers on(u, v)are still recording fromu. - recordedSrc (u v : P) : (S_aug.proc u).snapState.isSome = true → sys.graph.Adj u v → WireMsg.marker ∈ S_aug.chan u v ∧ ((S_aug.proc v).snapState.isSome = true → ∃ (buf : List M), (S_aug.proc v).chanRec u = ChannelRec.recording buf) ∨ WireMsg.marker ∉ S_aug.chan u v ∧ (S_aug.proc v).snapState.isSome = true ∧ ∃ (saved : List M), (S_aug.proc v).chanRec u = ChannelRec.done saved
SnapInv is preserved by every single transition of sys.snapLts.
SnapInv holds at the end of every finite execution starting from an IsPreSnapshot state.
Single-marker bound: along any execution from a pre-snapshot state, every channel holds at
most one .marker.
No markers remain upon completion: once every process has recorded (snapState.isSome) and
every channel recorder has reached .done, zero .markers remain in flight on any channel.
Under SnapInv S_aug, any underlying recv transition enabled in project S_aug can execute
in sys.snapLts in at most two steps (optionally delivering a single leading .marker on
(src, dest) first, then delivering .app msg) without waiting on any other channel or process.