Documentation

CslibFrontier.Computability.Distributed.SetAgreement.AtomicSnapshot.Machine

Unbounded single-writer atomic snapshot transition system #

Defines process states (ActiveScan, ProcSnapshotState), global configurations (SnapshotState), atomic transition labels (SnapshotEvent), single-register transition function (stepSnapshot), and labelled transition system (snapshotLTS, SnapshotReachable) following [AAD+93], §3, Figure 3.

Main definitions #

Unbounded single-writer algorithm state machine (Figure 3) #

Whether an active scan_i is serving an external ScanRequest_i or the embedded scan inside UpdateRequest_i(val).

  • external {Data : Type u_1} : ScanMode Data

    Top-level client scan operation.

  • embedded {Data : Type u_1} (val : Data) : ScanMode Data

    Embedded scan inside update(val) (line 1 of update_i in Figure 3).

@[instance_reducible]
def Cslib.Distributed.SetAgreement.instDecidableEqScanMode.decEq {Data✝ : Type u_1} [DecidableEq Data✝] (x✝ x✝¹ : ScanMode Data✝) :
Decidable (x✝ = x✝¹)

Which of the two sequential collects in Figure 3 lines 2–3 is currently executing.

  • collectA : CollectPhase

    First collect (a[1..n] := collect, line 2).

  • collectB : CollectPhase

    Second collect (b[1..n] := collect, line 3).

structure Cslib.Distributed.SetAgreement.ActiveScan (P : Type u_1) (Data : Type u_2) :
Type (max u_1 u_2)

Local variables of an active scan_i loop ([AAD+93], Figure 3, p. 8).

  • mode : ScanMode Data

    Whether this scan is top-level or embedded inside an update.

  • opId : ℕ

    Index of the enclosing client operation in SnapshotState.history.

  • moved : Finset P

    Processes observed to move once in an earlier double collect (moved[j] = 1).

  • phase : CollectPhase

    Current collect pass (collectA or collectB).

  • rem : List P

    Remaining registers still to read one-by-one in the current collect pass.

  • collectAVal : P → SnapshotReg P Data

    Accumulated register records read during collectA.

  • collectBVal : P → SnapshotReg P Data

    Accumulated register records read during collectB.

theorem Cslib.Distributed.SetAgreement.ActiveScan.ext {P : Type u_1} {Data : Type u_2} {x y : ActiveScan P Data} (mode : x.mode = y.mode) (opId : x.opId = y.opId) (moved : x.moved = y.moved) (phase : x.phase = y.phase) (rem : x.rem = y.rem) (collectAVal : x.collectAVal = y.collectAVal) (collectBVal : x.collectBVal = y.collectBVal) :
x = y
inductive Cslib.Distributed.SetAgreement.ProcSnapshotState (P : Type u_1) (Data : Type u_2) :
Type (max u_1 u_2)

Local control state of a single process i : P in Figure 3.

  • idle {P : Type u_1} {Data : Type u_2} : ProcSnapshotState P Data

    No pending operation (H_i = ⊥).

  • scanning {P : Type u_1} {Data : Type u_2} (st : ActiveScan P Data) : ProcSnapshotState P Data

    Executing the double-collect scan_i loop (top-level or embedded).

  • readyToWrite {P : Type u_1} {Data : Type u_2} (opId : ℕ) (val : Data) (snap : P → Data) : ProcSnapshotState P Data

    Embedded scan_i completed with snap; ready to execute atomic write r_i := (val, r_i.seq + 1, snap) (line 2 of update_i in Figure 3).

Computable test for whether a process control state is .idle.

structure Cslib.Distributed.SetAgreement.SnapshotState (P : Type u_1) (Data : Type u_2) :
Type (max u_1 u_2)

Global configuration of the unbounded single-writer snapshot implementation.

  • reg : P → SnapshotReg P Data

    Array of n single-writer, n-reader atomic registers r_1, …, r_n.

  • proc : P → ProcSnapshotState P Data

    Per-process local control states.

  • history : List (SnapshotOpRecord P Data)

    Recorded client invocation/completion history for linearizability verification.

  • stepCount : ℕ

    Global transition counter (history timestamps).

theorem Cslib.Distributed.SetAgreement.SnapshotState.ext {P : Type u_1} {Data : Type u_2} {x y : SnapshotState P Data} (reg : x.reg = y.reg) (proc : x.proc = y.proc) (history : x.history = y.history) (stepCount : x.stepCount = y.stepCount) :
x = y
def Cslib.Distributed.SetAgreement.SnapshotState.init {P : Type u_1} {Data : Type u_2} (dInit : Data) :

Initial configuration: all registers hold (dInit, 0, fun _ => dInit), all processes are idle, and history is empty.

inductive Cslib.Distributed.SetAgreement.SnapshotEvent (P : Type u_1) (Data : Type u_2) :
Type (max u_1 u_2)

Atomic transition labels of the snapshot implementation: client invocations or one atomic step of process i (reading at most one register reg j or writing reg i).

  • invokeScan {P : Type u_1} {Data : Type u_2} (i : P) : SnapshotEvent P Data

    Idle process i invokes ScanRequest_i.

  • invokeUpdate {P : Type u_1} {Data : Type u_2} (i : P) (val : Data) : SnapshotEvent P Data

    Idle process i invokes UpdateRequest_i(val).

  • step {P : Type u_1} {Data : Type u_2} (i : P) : SnapshotEvent P Data

    Active process i executes one atomic step (a single register read, local loop check, or single-writer register write).

def Cslib.Distributed.SetAgreement.instDecidableEqSnapshotEvent.decEq {P✝ : Type u_1} {Data✝ : Type u_2} [DecidableEq P✝] [DecidableEq Data✝] (x✝ x✝¹ : SnapshotEvent P✝ Data✝) :
Decidable (x✝ = x✝¹)
@[instance_reducible]
instance Cslib.Distributed.SetAgreement.instDecidableEqSnapshotEvent {P✝ : Type u_1} {Data✝ : Type u_2} [DecidableEq P✝] [DecidableEq Data✝] :
DecidableEq (SnapshotEvent P✝ Data✝)
def Cslib.Distributed.SetAgreement.completeHistoryAt {P : Type u_1} {Data : Type u_2} (hist : List (SnapshotOpRecord P Data)) (opId : ℕ) (st : SnapshotOpStatus P Data) :

Mark history record opId with a new status if in bounds.

def Cslib.Distributed.SetAgreement.finishScan {P : Type u_1} {Data : Type u_2} [DecidableEq P] (s : SnapshotState P Data) (i : P) (mode : ScanMode Data) (opId : ℕ) (snap : P → Data) :

Finish a completed scan_i (either returning snap to an external caller or advancing an embedded update_i to readyToWrite).

def Cslib.Distributed.SetAgreement.stepSnapshot {P : Type u_1} {Data : Type u_2} [Fintype P] [DecidableEq P] (ord : ScanOrder P) (dInit : Data) (s : SnapshotState P Data) (ev : SnapshotEvent P Data) :

Deterministic partial step function executing one atomic SnapshotEvent (none when the precondition is not enabled). Every .step i accesses at most one shared register; relative to [AAD+93] Figure 1 (p. 4), external scan completion (finishScan) is fused with .doneScan and update_i's atomic register write (readyToWrite) is fused with .doneUpdate.

def Cslib.Distributed.SetAgreement.snapshotLTS {P : Type u_1} {Data : Type u_2} [Fintype P] [DecidableEq P] (ord : ScanOrder P) (dInit : Data) :
LTS (SnapshotState P Data) (SnapshotEvent P Data)

Cslib.LTS of the unbounded single-writer atomic snapshot implementation.

def Cslib.Distributed.SetAgreement.SnapshotReachable {P : Type u_1} {Data : Type u_2} [Fintype P] [DecidableEq P] (ord : ScanOrder P) (dInit : Data) (s : SnapshotState P Data) :

Reachability from SnapshotState.init dInit in snapshotLTS.