Documentation

CslibFrontier.Computability.Distributed.SharedMemory.Universal

Finite-batch log-append universal construction over single-use consensus cells #

This module formalizes the finite-invocation-batch (P), unhelped log-append step over idealized single-use ConsensusCell slots (after [Her91], §4.1, pp. 143–146, Figure 14 p. 145 & Theorem 14 p. 146) toward #7199. As Herlihy observes ([Her91], §4.1, p. 144), omitting the announce[1..n] helping array makes log-append nonblocking rather than wait-free across unbounded invocation streams: here P indexes a finite batch of invocations (Fintype P), slots are modeled as idealized predetermined-winner ConsensusCells under ValidSlotSchedule rather than Protocol executions, and [Her91]'s announce/helping array and §4.2 cell reclamation remain open in #7199.

Within this finite-batch log-append model:

Main definitions #

Main results #

References #

structure Cslib.Distributed.SharedMemory.SeqSpec (State : Type u_1) (Op : Type u_2) (Resp : Type u_3) :
Type (max (max u_1 u_2) u_3)

Deterministic sequential object specification with state type State, initial state init, operation type Op, response type Resp, and transition step returning (nextState, response).

  • init : State

    Initial state of the sequential state machine.

  • step : State → Op → State × Resp

    Sequential transition taking (state, op) to (nextState, response).

Idealized single-use consensus cell over α: every caller invoking propose receives the same agreed winning value (propose_eq).

  • propose : α → α

    Propose a candidate value to this consensus slot and receive the slot's winning value.

  • propose_eq (x y : α) : self.propose x = self.propose y

    Agreement: all proposals to the same slot return the identical winning value.

Construct a ConsensusCell with predetermined winning value w (useful for executable test schedules).

def Cslib.Distributed.SharedMemory.applyLog {P : Type u_1} {State : Type u_2} {Op : Type u_3} {Resp : Type u_4} (M : SeqSpec State Op Resp) (log : List (P × Op)) :
State

Replay sequential specification M from M.init along a list of (caller, operation) log entries, returning the resulting sequential state.

@[simp]
theorem Cslib.Distributed.SharedMemory.applyLog_nil {P : Type u_1} {State : Type u_2} {Op : Type u_3} {Resp : Type u_4} (M : SeqSpec State Op Resp) :
@[simp]
theorem Cslib.Distributed.SharedMemory.applyLog_append_singleton {P : Type u_1} {State : Type u_2} {Op : Type u_3} {Resp : Type u_4} (M : SeqSpec State Op Resp) (log : List (P × Op)) (entry : P × Op) :
applyLog M (log ++ [entry]) = (M.step (applyLog M log) entry.2).1
def Cslib.Distributed.SharedMemory.slotLog {P : Type u_1} {Op : Type u_2} (slot : ℕ → ConsensusCell (P × Op)) (probe : P × Op) (n : ℕ) :
List (P × Op)

Reconstruct the agreed log prefix of length n from consensus slots 0, ..., n - 1 using any probe proposal probe.

@[simp]
theorem Cslib.Distributed.SharedMemory.length_slotLog {P : Type u_1} {Op : Type u_2} (slot : ℕ → ConsensusCell (P × Op)) (probe : P × Op) (n : ℕ) :
(slotLog slot probe n).length = n
theorem Cslib.Distributed.SharedMemory.slotLog_eq {P : Type u_1} {Op : Type u_2} (slot : ℕ → ConsensusCell (P × Op)) (x y : P × Op) (n : ℕ) :
slotLog slot x n = slotLog slot y n

Log agreement: every caller reconstructs the exact same prefix log from slot, regardless of the proposal argument it supplies.

theorem Cslib.Distributed.SharedMemory.applyLog_slotLog_succ {P : Type u_1} {State : Type u_2} {Op : Type u_3} {Resp : Type u_4} (M : SeqSpec State Op Resp) (slot : ℕ → ConsensusCell (P × Op)) (probe : P × Op) (k : ℕ) :
applyLog M (slotLog slot probe (k + 1)) = (M.step (applyLog M (slotLog slot probe k)) ((slot k).propose probe).2).1

Advancing the agreed consensus log from k to k + 1 steps the sequential state machine M by the winning command of slot k.

Output of a completed universal-construction invocation: its winning consensus slot slotIdx (the linearization index in the global log) and its sequential response resp.

  • slotIdx : ℕ

    Consensus log index won by this invocation.

  • resp : Resp

    Sequential state-machine response produced at slotIdx.

def Cslib.Distributed.SharedMemory.universalInvokeAux {P : Type u_1} {State : Type u_2} {Op : Type u_3} {Resp : Type u_4} [DecidableEq P] (M : SeqSpec State Op Resp) (slot : ℕ → ConsensusCell (P × Op)) (p : P) (op : Op) (k : ℕ) :

Bounded-fuel loop of Herlihy's log-append universal construction: starting at consensus slot k, caller p proposes (p, op) to consecutive slots until p wins a slot, then replays the agreed log prefix 0 ..< k on M and returns M.step's response.

def Cslib.Distributed.SharedMemory.universalInvoke {P : Type u_1} {State : Type u_2} {Op : Type u_3} {Resp : Type u_4} [Fintype P] [DecidableEq P] (M : SeqSpec State Op Resp) (slot : ℕ → ConsensusCell (P × Op)) (p : P) (op : Op) (startSlot : ℕ := 0) :

Execute invocation (p, op) via Herlihy's universal construction starting from settled prefix index startSlot, using Fintype.card P consensus attempts (the exact worst-case wait-free bound when P bounds concurrent invocations).

def Cslib.Distributed.SharedMemory.SlotActive {P : Type u_1} {Op : Type u_2} (slot : ℕ → ConsensusCell (P × Op)) (ops : P → Op) (startSlot : P → ℕ) (k : ℕ) :

Consensus slot k is active under invocation operations ops and start prefix lengths startSlot if either k lies in the pre-settled prefix observed before some invocation started (k < startSlot r) or some already-started invocation r (startSlot r ≤ k) has not yet won any earlier slot j < k.

structure Cslib.Distributed.SharedMemory.ValidSlotSchedule {P : Type u_1} {Op : Type u_2} (slot : ℕ → ConsensusCell (P × Op)) (ops : P → Op) (startSlot : P → ℕ) :

Validity and real-time causality of a sequence of consensus slots slot for a family of invocations indexed by P with operations ops and start prefix lengths startSlot: at every active slot k, the agreed winner (q, cmd) = (slot k).propose probe carries q's own operation ops q, q had already started by slot k (startSlot q ≤ k), and q had not already won an earlier slot j < k.

  • winner_op (k : ℕ) : SlotActive slot ops startSlot k → ∀ (probe : P × Op), ((slot k).propose probe).2 = ops ((slot k).propose probe).1

    Every active slot's winning entry carries its winning caller's operation ops.

  • start_le (k : ℕ) : SlotActive slot ops startSlot k → ∀ (probe : P × Op), startSlot ((slot k).propose probe).1 ≤ k

    Only an invocation that has begun (startSlot q ≤ k) can win active slot k.

  • fresh_winner (k : ℕ) : SlotActive slot ops startSlot k → ∀ j < k, ∀ (probe : P × Op), ((slot j).propose probe).1 ≠ ((slot k).propose probe).1

    An invocation stops proposing once it wins a slot, so no caller wins two slots j < k.

theorem Cslib.Distributed.SharedMemory.universalInvoke_terminates {P : Type u_1} {State : Type u_2} {Op : Type u_3} {Resp : Type u_4} [DecidableEq P] {M : SeqSpec State Op Resp} {slot : ℕ → ConsensusCell (P × Op)} {ops : P → Op} {startSlot : P → ℕ} [Fintype P] (hsched : ValidSlotSchedule slot ops startSlot) (p : P) :
∃ (res : UniversalResult Resp), universalInvoke M slot p (ops p) (startSlot p) = some res

Wait-free bounded termination of universalInvoke: under ValidSlotSchedule, every invocation p : P wins a consensus slot and returns some res within at most Fintype.card P attempts from startSlot p.

theorem Cslib.Distributed.SharedMemory.universalInvoke_spec {P : Type u_1} {State : Type u_2} {Op : Type u_3} {Resp : Type u_4} [DecidableEq P] {M : SeqSpec State Op Resp} {slot : ℕ → ConsensusCell (P × Op)} {ops : P → Op} {startSlot : P → ℕ} [Fintype P] (hsched : ValidSlotSchedule slot ops startSlot) {p : P} {res : UniversalResult Resp} (hres : universalInvoke M slot p (ops p) (startSlot p) = some res) (probe : P × Op) :
startSlot p ≤ res.slotIdx ∧ res.slotIdx < startSlot p + Fintype.card P ∧ (slot res.slotIdx).propose probe = (p, ops p) ∧ res.resp = (M.step (applyLog M (slotLog slot probe res.slotIdx)) (ops p)).2 ∧ applyLog M (slotLog slot probe (res.slotIdx + 1)) = (M.step (applyLog M (slotLog slot probe res.slotIdx)) (ops p)).1

State-machine safety of universalInvoke: when universalInvoke returns some res for invocation p under ValidSlotSchedule:

  1. startSlot p ≤ res.slotIdx < startSlot p + Fintype.card P,
  2. slot res.slotIdx is active and its agreed entry is (p, ops p) for every probe,
  3. res.resp equals the exact sequential transition response of M.step after replaying the agreed log prefix of length res.slotIdx, and
  4. the replayed sequential state after res.slotIdx + 1 slots equals the post-step state (M.step (applyLog M (slotLog slot probe res.slotIdx)) (ops p)).1.
theorem Cslib.Distributed.SharedMemory.universalInvoke_slotIdx_injective {P : Type u_1} {State : Type u_2} {Op : Type u_3} {Resp : Type u_4} [DecidableEq P] {M : SeqSpec State Op Resp} {slot : ℕ → ConsensusCell (P × Op)} {ops : P → Op} {startSlot : P → ℕ} [Fintype P] (hsched : ValidSlotSchedule slot ops startSlot) {p q : P} {res_p res_q : UniversalResult Resp} (hp : universalInvoke M slot p (ops p) (startSlot p) = some res_p) (hq : universalInvoke M slot q (ops q) (startSlot q) = some res_q) (hidx : res_p.slotIdx = res_q.slotIdx) :
p = q

Injectivity of linearization slots: distinct invocations p ≠ q never win the same consensus log index slotIdx.

theorem Cslib.Distributed.SharedMemory.universalInvoke_linearizable_of_validSlotSchedule {P : Type u_1} {State : Type u_2} {Op : Type u_3} {Resp : Type u_4} [DecidableEq P] {slot : ℕ → ConsensusCell (P × Op)} {ops : P → Op} {startSlot : P → ℕ} [Fintype P] (M : SeqSpec State Op Resp) (hsched : ValidSlotSchedule slot ops startSlot) :
∃ (res : P → UniversalResult Resp), (∀ (p : P), universalInvoke M slot p (ops p) (startSlot p) = some (res p)) ∧ (Function.Injective fun (p : P) => (res p).slotIdx) ∧ (∀ (p q : P), (res p).slotIdx < startSlot q → (res p).slotIdx < (res q).slotIdx) ∧ ∀ (p : P) (probe : P × Op), startSlot p ≤ (res p).slotIdx ∧ (res p).slotIdx < startSlot p + Fintype.card P ∧ (slot (res p).slotIdx).propose probe = (p, ops p) ∧ (res p).resp = (M.step (applyLog M (slotLog slot probe (res p).slotIdx)) (ops p)).2 ∧ applyLog M (slotLog slot probe ((res p).slotIdx + 1)) = (M.step (applyLog M (slotLog slot probe (res p).slotIdx)) (ops p)).1

Finite-batch linearizability of universalInvoke under ValidSlotSchedule (unhelped idealized ConsensusCell log-append step after [Her91], §4.1, pp. 143–146, Figure 14 p. 145 & Theorem 14 p. 146, without announce/helping or §4.2 cell reclamation): for any finite invocation batch P, there is a total assignment res : P → UniversalResult Resp of completed invocation outcomes such that:

  1. every invocation p : P terminates in [startSlot p, startSlot p + Fintype.card P),
  2. winning log indices (res p).slotIdx are injective across P,
  3. real-time precedence is preserved ((res p).slotIdx < startSlot q → (res p).slotIdx < (res q).slotIdx), and
  4. at (res p).slotIdx, the agreed log records (p, ops p) and (res p).resp equals the exact sequential transition response of M on the replayed prefix.
theorem Cslib.Distributed.SharedMemory.universalInvoke_slotIdx_bijective_of_validSlotSchedule {P : Type u_1} {State : Type u_2} {Op : Type u_3} {Resp : Type u_4} [DecidableEq P] {M : SeqSpec State Op Resp} {slot : ℕ → ConsensusCell (P × Op)} {ops : P → Op} [Fintype P] (hsched : ValidSlotSchedule slot ops fun (x : P) => 0) {res : P → UniversalResult Resp} (hres : ∀ (p : P), universalInvoke M slot p (ops p) = some (res p)) :
∃ (order : P ≃ Fin (Fintype.card P)), ∀ (p : P), ↑(order p) = (res p).slotIdx

Under ValidSlotSchedule with startSlot = 0, the winning consensus indices of a finite invocation batch P form a bijection P ≃ Fin (Fintype.card P) ordering all Fintype.card P concurrent invocations without gaps.