OpenSearch CoordinationState: voting configurations, vote collections, the reduced cluster state, and the seven handlers of the per-node consensus state machine
DefinitionOpenSearchCoordinationA transcription of org.opensearch.cluster.coordination.CoordinationState at OpenSearch revision b2a54ba5c0defba3d1d20423e911d4bf920bab19, the per-node state machine of OpenSearch's cluster coordination ("Zen2"), with the parts of VotingConfiguration, ElectionStrategy, ClusterState and the message classes it reads. Line numbers below are those of CoordinationState.java unless stated.
Nodes. NodeId — a natural number (Java: the node id string). DiscoveryNode — a node id and whether the node has the cluster-manager (master-eligible) role, isClusterManagerNode. ZEN1_BWC_TERM — the term 0 (Coordinator.java:134): the term of the states a node holds before the first election, and of the states an Elasticsearch 6.x (Zen1) cluster-manager publishes during a rolling upgrade.
Voting configurations. VotingConfiguration — a list of node ids that is strictly increasing, so that two configurations are equal exactly when they have the same members (Java compares the sets of ids). EMPTY_CONFIG — the empty configuration; isEmpty. hasQuorum c votes — the number of members of c that occur in the list votes, doubled, exceeds the number of members of c (CoordinationMetadata.java:405-409); an empty configuration has no quorum.
Vote collections. VoteCollection — the list of ids of the nodes whose votes were added, most recent first; empty. addVote v n (755-757) — if n has the cluster-manager role and its id is not yet present, the collection with n.id added and true; otherwise v unchanged and false. isQuorum v c — c.hasQuorum of the ids; containsVoteFor v n — n.id is present; isEmpty.
Cluster states. ClusterState V — the fields CoordinationState reads or writes: term (natural number), version and metadataVersion (integers), lastCommittedConfiguration, lastAcceptedConfiguration, clusterManagerNode (the elected cluster-manager, identified by its ephemeral id, or none for Java null), clusterUUIDKnown, clusterUUIDCommitted, and an opaque payload value : V standing for everything else. versionOrMetadataVersion s — the metadata version when s.term = 0, otherwise the version (ClusterState.java:239-244). markCommitted s (703-740) — if the accepted configuration differs from the committed one, the committed configuration becomes the accepted one; then, if the cluster UUID is known and not committed, it is marked committed.
Messages. StartJoinRequest (source node, term); Join (source node, target node, term, the voter's last accepted term, and its last accepted version or metadata version); PublishRequest V (the accepted state); PublishResponse (term, version); ApplyCommitRequest (source node, term, version).
Election strategies. ElectionStrategy — a function satisfiesAdditionalQuorumConstraints of the local node, the current term, the last accepted term and version, the last committed and last accepted configurations and the vote collection, returning a Boolean (the plugin extension point; isElectionQuorum itself is final in Java). DEFAULT_INSTANCE — the constant true. Monotone es — for all arguments, if every id of v is an id of w and the constraint holds for v, it holds for w.
The state. CoordinationState V — the local node; the persisted current term (natural number) and last accepted cluster state; and the transient joinVotes, startedJoinSinceLastReboot, electionWon, lastPublishedVersion (integer), lastPublishedConfiguration, publishVotes. init n t s (84-106) — node n over the persisted term t and accepted state s: empty join and publish votes, startedJoinSinceLastReboot = false, electionWon = false, lastPublishedVersion = 0, lastPublishedConfiguration the accepted configuration of s. The accessors lastAcceptedTerm, lastAcceptedVersion, lastAcceptedVersionOrMetadataVersion, lastCommittedConfiguration, lastAcceptedConfiguration read the last accepted state. isElectionQuorum es cs votes (144-154) — votes is a quorum of the last committed configuration and of the last accepted configuration, and the strategy's constraint holds for the local node, current term, last accepted term and version, the two configurations and votes. isPublishQuorum cs votes (156-158) — a quorum of the last committed configuration and of lastPublishedConfiguration.
The handlers, each returning a rejection (.error with a message) or the new state, paired with its output for the five that have one (all but setInitialState and handleCommit), checking the Java conditions in the Java order:
setInitialState cs s(180-204) — rejects if the last accepted configuration is nonempty; otherwise the last accepted state becomess.initialStateContract cs s— the method's assertions (190-201): last accepted term 0, empty committed configuration,lastPublishedVersion = 0, emptylastPublishedConfiguration, election not won, empty join and publish votes,s.term = 0,s.versionequal to the last accepted version, and both configurations ofsnonempty.handleStartJoin cs req(213-255) — rejects ifreq.term ≤ currentTerm; otherwise sets the current term toreq.term,lastPublishedVersionto 0,lastPublishedConfigurationto the last accepted configuration,startedJoinSinceLastRebootto true,electionWonto false, empties both vote collections, and returns theJoinfrom the local node toreq.sourceNodein termreq.termwith the last accepted term and version-or-metadata-version.handleJoin es cs j(264-339) — rejects, in order, ifj.term ≠ currentTerm; if no start-join was handled since the last restart; ifj.lastAcceptedTerm > lastAcceptedTerm; if the terms are equal andj.lastAcceptedVersion > lastAcceptedVersionOrMetadataVersion; if the last accepted configuration is empty. Otherwise adds the vote ofj.sourceNode, setselectionWontoisElectionQuorum es csof the new votes, setslastPublishedVersionto the last accepted version if the election has just been won, and returns whether the vote was new.handleClientValue cs s(348-407) — rejects if the election is not won; iflastPublishedVersion ≠ lastAcceptedVersion; ifs.term ≠ currentTerm; ifs.version ≤ lastPublishedVersion; ifschanges the accepted configuration while the committed configuration differs from the accepted one; if the join votes are not a quorum ofs's accepted configuration. Otherwise setslastPublishedVersiontos.version,lastPublishedConfigurationtos's accepted configuration, empties the publish votes and returns thePublishRequestofs.clientValueContract cs s— the assertion of 397-398:shas the node's last committed configuration.handlePublishRequest cs req(416-460) — for the incoming states: rejects ifs.term ≠ currentTerm; ifs.termequals the last accepted term ands.version ≤ lastAcceptedVersion, rejects unlesss.term = 0,snames a cluster-manager, and the last accepted state names none or a different one (the Zen1 compatibility branch; a term-0 state naming no cluster-manager is rejected there, Java'sNullPointerException); otherwise the last accepted state becomessand the response carriess.termands.version.handlePublishResponse cs src r(471-515) — rejects if the election is not won; ifr.term ≠ currentTerm; ifr.version ≠ lastPublishedVersion. Otherwise adds the vote ofsrcto the publish votes, and returns theApplyCommitRequest(local node,r.term,r.version) if the new votes are a publish quorum, nothing otherwise.handleCommit cs c(523-573) — rejects ifc.term ≠ currentTerm, ifc.term ≠ lastAcceptedTerm, or ifc.version ≠ lastAcceptedVersion; otherwise replaces the last accepted state bymarkCommittedof it.
javaInvariant es cs — the five assertions of invariant() (601-611): the last accepted term is at most the current term; electionWon equals isElectionQuorum es cs joinVotes; if the election is won, lastPublishedVersion ≥ lastAcceptedVersion, otherwise lastPublishedVersion = 0; a won election implies startedJoinSinceLastReboot; the publish votes are empty or the election is won.
Formalization Note. Node ids are naturals (only their equality is used); two DiscoveryNodes are equal when their ids and roles are, whereas Java compares ephemeral ids (no handler compares nodes), and clusterManagerNode holds an ephemeral id, a natural number unrelated to the node ids. The election strategy is an argument of isElectionQuorum, handleJoin and javaInvariant rather than a field of the state (Java: a final field); each theorem uses a single strategy. Terms are naturals (Java longs that are never negative: a fresh node's persisted term is 0, and among the handlers only handleStartJoin changes the current term, upwards); init takes the persisted term as a parameter, so a state may be in any term. Versions are integers (Java long; overflow is not modelled). A cluster state keeps only the fields above; the payload is a type parameter. Vote collections keep only voter ids: Java also records the Joins, which only tests read, and Java's equals (used only by tests) compares the map of voters and the recorded joins, whereas = here compares the lists of ids, including their order (the order in which votes were added) and multiplicity; no handler compares vote collections. The remote cluster-state store (the REMOTE persisted state) is omitted: the handlers read it only to decide whether to write it (616-642; the write in handlePublishResponse, handlePreCommit at 510 and 593-599, is gated by the isRemoteStateEnabled setting), every value they compute comes from the LOCAL persisted state, and a failed remote write makes the Java method throw after its local effects, where the transcription returns the result: the Java run is then the transcription's run with that output lost, which a cluster model whose messages may be lost includes. Java asserts are disabled in production; the handlers do not check them, and the asserted preconditions of setInitialState and handleClientValue are stated separately as initialStateContract and clientValueContract, which no other definition and no theorem of this mission uses. Not represented: the assertion that a join targets the local node (265), the assertion of markLastAcceptedStateAsCommitted that a state with an unknown cluster UUID is committed only in term 0 (708-710), and the assertions of the Join and PublishResponse constructors that their versions are non-negative (versions here are unbounded integers; terms are naturals). Rejection messages are fixed strings containing the substrings OpenSearch's tests match. The file has no imports (Lean core only).
/-!
# OpenSearch cluster coordination: `CoordinationState`
Transcription of the per-node consensus state machine of OpenSearch's cluster coordination ("Zen2"),
`org.opensearch.cluster.coordination.CoordinationState`, at OpenSearch revision
`b2a54ba5c0defba3d1d20423e911d4bf920bab19`
(`server/src/main/java/org/opensearch/cluster/coordination/CoordinationState.java`, cited below as `CS:<line>`),
with the parts of `CoordinationMetadata.VotingConfiguration` (`CM:<line>`), `ElectionStrategy` (`ES:<line>`),
`ClusterState` (`CLS:<line>`) and the message classes that it reads.
Abstractions:
* Node ids are `Nat` (Java: `String`); only equality is used.
* Terms are `Nat` (Java `long`s that are never negative: a fresh node's persisted term is `0`, and among the handlers
only `handleStartJoin` changes it, to a strictly larger value); `init` takes the persisted term as a parameter.
* Versions are `Int` (Java `long`).
* A `ClusterState` is reduced to the fields that `CoordinationState` reads or writes; everything else is an opaque
payload `value : V`.
* `VotingConfiguration` stores its node ids strictly sorted, so that `=` is Java's `Set.equals`.
* The REMOTE persisted state (remote cluster-state store) is omitted. The handlers read it only to decide whether to
write it (CS:616-642; the write in `handlePublishResponse`, `handlePreCommit` at CS:510 and CS:593-599, is gated by
the `isRemoteStateEnabled` setting), and every value they compute is read from the LOCAL persisted state. A failed
remote write makes the Java method throw after its local effects (for example after `publishVotes.addVote` in
`handlePublishResponse`, CS:503-510); the transcription returns the result instead, so the Java run is the
transcription's run with that output lost, which a cluster model whose messages may be lost includes.
* Java `assert`s are not checked in production; they are caller contracts. The handlers below do not check them. The
asserted preconditions of `setInitialState` and `handleClientValue` are the predicates `initialStateContract` and
`clientValueContract`, which nothing in this file uses (the cluster model of the `OpenSearchSafety` mission imposes
them at its `bootstrap` and `clientValue` steps, and delivers a join only to its target). The asserted
postconditions (CS:240, CS:323-324, CS:457, CS:572) and the assertions of `invariant()` (`javaInvariant` below) are
the subject of the mission's theorems. Not represented: `join.targetMatches(localNode)` (CS:265), the assertion of
`markLastAcceptedStateAsCommitted` that a state with an unknown cluster UUID is committed only in term 0
(CS:708-710), and the assertions of the `Join` and `PublishResponse` constructors that their versions are
non-negative (Join.java:62, PublishResponse.java:53; their terms are `Nat`).
-/
namespace OpenSearchCoordination
/-- A node id (`DiscoveryNode.getId()`). -/
abbrev NodeId := Nat
/-- `DiscoveryNode`, as far as coordination reads it: the node id and whether the node has the cluster-manager
(master-eligible) role (`DiscoveryNode.isClusterManagerNode()`). The derived equality compares the id and the role;
Java's `equals` compares ephemeral ids. No handler compares nodes. -/
structure DiscoveryNode where
id : NodeId
isClusterManagerNode : Bool
deriving DecidableEq, Repr
/-- `Coordinator.ZEN1_BWC_TERM` (Coordinator.java:134). -/
def ZEN1_BWC_TERM : Nat := 0
/-! ## Voting configurations and vote collections -/
/-- `CoordinationMetadata.VotingConfiguration` (CM:383-449): a set of node ids. Stored strictly sorted, so that
structural equality is set equality (Java `equals` compares the `Set<String> nodeIds`). -/
structure VotingConfiguration where
nodeIds : List NodeId
sorted : nodeIds.Pairwise (· < ·)
instance : DecidableEq VotingConfiguration := fun a b =>
if h : a.nodeIds = b.nodeIds then isTrue (by cases a; cases b; simp at h; subst h; rfl)
else isFalse (by intro e; exact h (e ▸ rfl))
namespace VotingConfiguration
/-- `VotingConfiguration.EMPTY_CONFIG` (CM:385). -/
def EMPTY_CONFIG : VotingConfiguration := ⟨[], List.Pairwise.nil⟩
/-- `isEmpty()` (CM:433-435). -/
def isEmpty (c : VotingConfiguration) : Bool := c.nodeIds.isEmpty
/-- `hasQuorum(votes)` (CM:405-409): `intersection.size() * 2 > nodeIds.size()` where `intersection` is
`nodeIds ∩ votes`. -/
def hasQuorum (c : VotingConfiguration) (votes : List NodeId) : Bool :=
decide ((c.nodeIds.filter (fun x => votes.contains x)).length * 2 > c.nodeIds.length)
end VotingConfiguration
/-- `CoordinationState.VoteCollection` (CS:750-814): the ids of the nodes whose votes were added, most recent first.
(Java keys a `Map<String, DiscoveryNode>` by node id and also records the `Join`s in a set that only tests read. Java's
`equals`, used only by tests, compares that map and the set of joins, CS:798-806, whereas the derived `=` here compares
the lists, including the order and any repetitions of the ids; no handler compares vote collections, and the handlers
read them only through membership.) -/
structure VoteCollection where
nodes : List NodeId
deriving DecidableEq, Repr
namespace VoteCollection
/-- `new VoteCollection()`. -/
def empty : VoteCollection := ⟨[]⟩
/-- `addVote(sourceNode)` (CS:755-757): `sourceNode.isClusterManagerNode() && nodes.put(id, sourceNode) == null`. The
new collection and whether the vote was added. -/
def addVote (v : VoteCollection) (n : DiscoveryNode) : VoteCollection × Bool :=
if n.isClusterManagerNode && !(v.nodes.contains n.id) then (⟨n.id :: v.nodes⟩, true) else (v, false)
/-- `isQuorum(configuration)` (CS:772-774). -/
def isQuorum (v : VoteCollection) (c : VotingConfiguration) : Bool := c.hasQuorum v.nodes
/-- `containsVoteFor(node)` (CS:776-778). -/
def containsVoteFor (v : VoteCollection) (n : DiscoveryNode) : Bool := v.nodes.contains n.id
/-- `isEmpty()` (CS:780-782). -/
def isEmpty (v : VoteCollection) : Bool := v.nodes.isEmpty
end VoteCollection
/-! ## Cluster states, persisted state, messages -/
/-- A cluster state, reduced to what `CoordinationState` reads or writes. -/
structure ClusterState (V : Type) where
/-- `term()` (= `coordinationMetadata().term()`). -/
term : Nat
/-- `version()`. -/
version : Int
/-- `metadata().version()`. -/
metadataVersion : Int
/-- `getLastCommittedConfiguration()`. -/
lastCommittedConfiguration : VotingConfiguration
/-- `getLastAcceptedConfiguration()`. -/
lastAcceptedConfiguration : VotingConfiguration
/-- `nodes().getClusterManagerNode()`, identified by its ephemeral id (`DiscoveryNode.equals` compares ephemeral
ids), a number unrelated to the `NodeId`s; `none` is Java `null`. Read only by the Zen1 compatibility branch of
`handlePublishRequest`. -/
clusterManagerNode : Option Nat
/-- `metadata().clusterUUID()` differs from `Metadata.UNKNOWN_CLUSTER_UUID`. -/
clusterUUIDKnown : Bool
/-- `metadata().clusterUUIDCommitted()`. -/
clusterUUIDCommitted : Bool
/-- Everything else. -/
value : V
namespace ClusterState
variable {V : Type}
/-- `getVersionOrMetadataVersion()` (CLS:239-244). -/
def versionOrMetadataVersion (s : ClusterState V) : Int :=
if s.term = ZEN1_BWC_TERM then s.metadataVersion else s.version
/-- `PersistedState.markLastAcceptedStateAsCommitted()` (CS:703-728) with `commitVotingConfiguration` (CS:730-740):
the committed configuration becomes the accepted one, and a known cluster UUID is marked committed. -/
def markCommitted (s : ClusterState V) : ClusterState V :=
let s₁ := if s.lastAcceptedConfiguration ≠ s.lastCommittedConfiguration then
{ s with lastCommittedConfiguration := s.lastAcceptedConfiguration } else s
if s₁.clusterUUIDKnown && !s₁.clusterUUIDCommitted then { s₁ with clusterUUIDCommitted := true } else s₁
end ClusterState
/-- `StartJoinRequest` (StartJoinRequest.java). -/
structure StartJoinRequest where
sourceNode : DiscoveryNode
term : Nat
deriving DecidableEq, Repr
/-- `Join` (Join.java): a vote from `sourceNode` for `targetNode` in `term`, with the voter's last accepted term and
version (or metadata version, for term-0 states). -/
structure Join where
sourceNode : DiscoveryNode
targetNode : DiscoveryNode
term : Nat
lastAcceptedTerm : Nat
lastAcceptedVersion : Int
deriving DecidableEq, Repr
/-- `PublishRequest` (PublishRequest.java). -/
structure PublishRequest (V : Type) where
acceptedState : ClusterState V
/-- `PublishResponse` (PublishResponse.java). -/
structure PublishResponse where
term : Nat
version : Int
deriving DecidableEq, Repr
/-- `ApplyCommitRequest` (ApplyCommitRequest.java). -/
structure ApplyCommitRequest where
sourceNode : DiscoveryNode
term : Nat
version : Int
deriving DecidableEq, Repr
/-- `ElectionStrategy` (ES): `isElectionQuorum` is final; plugins override only
`satisfiesAdditionalQuorumConstraints(localNode, currentTerm, acceptedTerm, acceptedVersion, lastCommitted,
lastAccepted, joinVotes)`. A Java strategy also sees the voters' `DiscoveryNode`s and the recorded joins; here it sees
the voters' ids. `DEFAULT_INSTANCE`, the only strategy in OpenSearch itself, uses none of them. Java's
`CoordinationState` keeps its strategy in a `final` field; here the strategy is an argument of `isElectionQuorum`,
`handleJoin` and `javaInvariant`. -/
structure ElectionStrategy where
satisfiesAdditionalQuorumConstraints :
DiscoveryNode → Nat → Nat → Int → VotingConfiguration → VotingConfiguration → VoteCollection → Bool
/-- `ElectionStrategy.DEFAULT_INSTANCE`: no additional constraint. -/
def ElectionStrategy.DEFAULT_INSTANCE : ElectionStrategy := ⟨fun _ _ _ _ _ _ _ => true⟩
/-- An election strategy whose additional constraint is monotone in the votes (adding votes never turns a satisfied
constraint into an unsatisfied one). The default strategy is. -/
def ElectionStrategy.Monotone (es : ElectionStrategy) : Prop :=
∀ n t at' av c a (v w : VoteCollection), (∀ x, x ∈ v.nodes → x ∈ w.nodes) →
es.satisfiesAdditionalQuorumConstraints n t at' av c a v = true →
es.satisfiesAdditionalQuorumConstraints n t at' av c a w = true
/-! ## The state machine -/
/-- The fields of `CoordinationState` (CS:64-106): the LOCAL persisted state (current term, last accepted cluster
state) and the transient state that a restart discards. -/
structure CoordinationState (V : Type) where
localNode : DiscoveryNode
/-- persisted: `getCurrentTerm()` -/
currentTerm : Nat
/-- persisted: `getLastAcceptedState()` -/
lastAcceptedState : ClusterState V
joinVotes : VoteCollection
startedJoinSinceLastReboot : Bool
electionWon : Bool
lastPublishedVersion : Int
lastPublishedConfiguration : VotingConfiguration
publishVotes : VoteCollection
namespace CoordinationState
variable {V : Type}
/-- The constructor (CS:84-106): a fresh `CoordinationState` over a persisted state. A restart. -/
def init (localNode : DiscoveryNode) (currentTerm : Nat) (lastAcceptedState : ClusterState V) :
CoordinationState V where
localNode := localNode
currentTerm := currentTerm
lastAcceptedState := lastAcceptedState
joinVotes := VoteCollection.empty
startedJoinSinceLastReboot := false
electionWon := false
lastPublishedVersion := 0
lastPublishedConfiguration := lastAcceptedState.lastAcceptedConfiguration
publishVotes := VoteCollection.empty
def lastAcceptedTerm (cs : CoordinationState V) : Nat := cs.lastAcceptedState.term
def lastAcceptedVersion (cs : CoordinationState V) : Int := cs.lastAcceptedState.version
def lastAcceptedVersionOrMetadataVersion (cs : CoordinationState V) : Int :=
cs.lastAcceptedState.versionOrMetadataVersion
def lastCommittedConfiguration (cs : CoordinationState V) : VotingConfiguration :=
cs.lastAcceptedState.lastCommittedConfiguration
def lastAcceptedConfiguration (cs : CoordinationState V) : VotingConfiguration :=
cs.lastAcceptedState.lastAcceptedConfiguration
/-- `isElectionQuorum(joinVotes)` (CS:144-154, ES:68-88). -/
def isElectionQuorum (es : ElectionStrategy) (cs : CoordinationState V) (votes : VoteCollection) : Bool :=
votes.isQuorum cs.lastCommittedConfiguration && votes.isQuorum cs.lastAcceptedConfiguration &&
es.satisfiesAdditionalQuorumConstraints cs.localNode cs.currentTerm cs.lastAcceptedTerm cs.lastAcceptedVersion
cs.lastCommittedConfiguration cs.lastAcceptedConfiguration votes
/-- `isPublishQuorum(votes)` (CS:156-158). -/
def isPublishQuorum (cs : CoordinationState V) (votes : VoteCollection) : Bool :=
votes.isQuorum cs.lastCommittedConfiguration && votes.isQuorum cs.lastPublishedConfiguration
/-- `setInitialState(initialState)` (CS:180-204). The asserted preconditions are `initialStateContract`. -/
def setInitialState (cs : CoordinationState V) (initialState : ClusterState V) :
Except String (CoordinationState V) :=
if !cs.lastAcceptedConfiguration.isEmpty then
.error "initial state already set: last-accepted configuration now nonempty"
else
.ok { cs with lastAcceptedState := initialState }
/-- The assertions of `setInitialState` (CS:190-201): the caller's contract. -/
def initialStateContract (cs : CoordinationState V) (initialState : ClusterState V) : Prop :=
cs.lastAcceptedTerm = 0 ∧ cs.lastCommittedConfiguration.isEmpty ∧ cs.lastPublishedVersion = 0 ∧
cs.lastPublishedConfiguration.isEmpty ∧ cs.electionWon = false ∧ cs.joinVotes.isEmpty ∧
cs.publishVotes.isEmpty ∧ initialState.term = 0 ∧ initialState.version = cs.lastAcceptedVersion ∧
initialState.lastAcceptedConfiguration.isEmpty = false ∧ initialState.lastCommittedConfiguration.isEmpty = false
/-- `handleStartJoin(startJoinRequest)` (CS:213-255). -/
def handleStartJoin (cs : CoordinationState V) (req : StartJoinRequest) :
Except String (CoordinationState V × Join) :=
if req.term ≤ cs.currentTerm then
.error "incoming term not greater than current term"
else
let cs' : CoordinationState V :=
{ cs with
currentTerm := req.term
lastPublishedVersion := 0
lastPublishedConfiguration := cs.lastAcceptedConfiguration
startedJoinSinceLastReboot := true
electionWon := false
joinVotes := VoteCollection.empty
publishVotes := VoteCollection.empty }
.ok (cs', ⟨cs.localNode, req.sourceNode, req.term, cs.lastAcceptedTerm, cs.lastAcceptedVersionOrMetadataVersion⟩)
/-- `handleJoin(join)` (CS:264-339). Returns whether the vote was new. (Asserted: `join.targetNode` is this node.) -/
def handleJoin (es : ElectionStrategy) (cs : CoordinationState V) (join : Join) :
Except String (CoordinationState V × Bool) :=
if join.term ≠ cs.currentTerm then
.error "incoming term does not match current term"
else if !cs.startedJoinSinceLastReboot then
.error "ignored join as term has not been incremented yet after reboot"
else if join.lastAcceptedTerm > cs.lastAcceptedTerm then
.error "incoming last accepted term of join higher than current last accepted term"
else if join.lastAcceptedTerm = cs.lastAcceptedTerm ∧
join.lastAcceptedVersion > cs.lastAcceptedVersionOrMetadataVersion then
.error "incoming last accepted version of join higher than current last accepted version"
else if cs.lastAcceptedConfiguration.isEmpty then
.error "rejecting join since this node has not received its initial configuration yet"
else
let (votes, added) := cs.joinVotes.addVote join.sourceNode
let won := isElectionQuorum es cs votes
let cs₁ : CoordinationState V := { cs with joinVotes := votes, electionWon := won }
let cs₂ := if won && !cs.electionWon then { cs₁ with lastPublishedVersion := cs.lastAcceptedVersion } else cs₁
.ok (cs₂, added)
/-- `handleClientValue(clusterState)` (CS:348-407). The assertion of CS:397-398 is `clientValueContract`. -/
def handleClientValue (cs : CoordinationState V) (clusterState : ClusterState V) :
Except String (CoordinationState V × PublishRequest V) :=
if !cs.electionWon then
.error "election not won"
else if cs.lastPublishedVersion ≠ cs.lastAcceptedVersion then
.error "cannot start publishing next value before accepting previous one"
else if clusterState.term ≠ cs.currentTerm then
.error "incoming term does not match current term"
else if clusterState.version ≤ cs.lastPublishedVersion then
.error "incoming cluster state version lower or equal to last published version"
else if clusterState.lastAcceptedConfiguration ≠ cs.lastAcceptedConfiguration ∧
cs.lastCommittedConfiguration ≠ cs.lastAcceptedConfiguration then
.error "only allow reconfiguration while not already reconfiguring"
else if !cs.joinVotes.isQuorum clusterState.lastAcceptedConfiguration then
.error "only allow reconfiguration if joinVotes have quorum for new config"
else
.ok ({ cs with
lastPublishedVersion := clusterState.version
lastPublishedConfiguration := clusterState.lastAcceptedConfiguration
publishVotes := VoteCollection.empty },
⟨clusterState⟩)
/-- The assertion of `handleClientValue` (CS:397-398): the last committed configuration does not change. -/
def clientValueContract (cs : CoordinationState V) (clusterState : ClusterState V) : Prop :=
clusterState.lastCommittedConfiguration = cs.lastCommittedConfiguration
/-- `handlePublishRequest(publishRequest)` (CS:416-460). In the Zen1 compatibility branch, Java's
`getClusterManagerNode().equals(...)` on a `null` incoming cluster-manager throws (a rejection). -/
def handlePublishRequest (cs : CoordinationState V) (req : PublishRequest V) :
Except String (CoordinationState V × PublishResponse) :=
let s := req.acceptedState
let accept : Except String (CoordinationState V × PublishResponse) :=
.ok ({ cs with lastAcceptedState := s }, ⟨s.term, s.version⟩)
if s.term ≠ cs.currentTerm then
.error "incoming term does not match current term"
else if s.term = cs.lastAcceptedTerm ∧ s.version ≤ cs.lastAcceptedVersion then
if s.term = ZEN1_BWC_TERM then
match s.clusterManagerNode with
| none => .error "NullPointerException"
| some m =>
if some m ≠ cs.lastAcceptedState.clusterManagerNode then accept
else .error "incoming version lower or equal to current version"
else
.error "incoming version lower or equal to current version"
else
accept
/-- `handlePublishResponse(sourceNode, publishResponse)` (CS:471-515). The optional `ApplyCommitRequest`. -/
def handlePublishResponse (cs : CoordinationState V) (sourceNode : DiscoveryNode) (resp : PublishResponse) :
Except String (CoordinationState V × Option ApplyCommitRequest) :=
if !cs.electionWon then
.error "election not won"
else if resp.term ≠ cs.currentTerm then
.error "incoming term does not match current term"
else if resp.version ≠ cs.lastPublishedVersion then
.error "incoming version does not match current version"
else
let votes := (cs.publishVotes.addVote sourceNode).1
let cs' : CoordinationState V := { cs with publishVotes := votes }
if isPublishQuorum cs' votes then
.ok (cs', some ⟨cs.localNode, resp.term, resp.version⟩)
else
.ok (cs', none)
/-- `handleCommit(applyCommit)` (CS:523-573). -/
def handleCommit (cs : CoordinationState V) (c : ApplyCommitRequest) : Except String (CoordinationState V) :=
if c.term ≠ cs.currentTerm then
.error "incoming term does not match current term"
else if c.term ≠ cs.lastAcceptedTerm then
.error "incoming term does not match last accepted term"
else if c.version ≠ cs.lastAcceptedVersion then
.error "incoming version does not match current version"
else
.ok { cs with lastAcceptedState := cs.lastAcceptedState.markCommitted }
/-- `invariant()` (CS:601-611), the assertions Java checks in tests. -/
def javaInvariant (es : ElectionStrategy) (cs : CoordinationState V) : Prop :=
cs.lastAcceptedTerm ≤ cs.currentTerm ∧
cs.electionWon = isElectionQuorum es cs cs.joinVotes ∧
(if cs.electionWon then cs.lastPublishedVersion ≥ cs.lastAcceptedVersion else cs.lastPublishedVersion = 0) ∧
(cs.electionWon = true → cs.startedJoinSinceLastReboot = true) ∧
(cs.publishVotes.isEmpty = true ∨ cs.electionWon = true)
end CoordinationState
end OpenSearchCoordination
Read-back
What the Lean code literally says, in plain math · claude-opus-5-5 (independent sub-agent, blind: Lean code + auditor instructions only)
Read-back: Def_OpenSearchCoordination.lean
The file has no import lines, so it uses only Lean's core library. After a module docstring it declares everything in the namespace OpenSearchCoordination. In source order, it declares:
- node and configuration types;
- a vote-collection type with five operations;
- a reduced cluster state with two operations;
- five message structures;
- an election-strategy structure with a default instance and a monotonicity predicate;
- the coordination state with its constructor, five accessors and two quorum tests;
- seven handlers, two "contract" predicates and the Java invariant.
Each declaration is rendered below in that order.
Notation. For a Boolean used as a proposition, "" means . Lean's Except String α has two outcomes, written and for a message string ; no theorem inspects the messages. " with " is a record update that leaves all other fields unchanged.
Citation check. The docstrings cite source files at revision b2a54ba5c0defba3d1d20423e911d4bf920bab19:
CS:<line>isserver/src/main/java/org/opensearch/cluster/coordination/CoordinationState.java.CM:<line>isCoordinationMetadata.javain the same directory.ES:<line>isElectionStrategy.javain the same directory.CLS:<line>isserver/src/main/java/org/opensearch/cluster/ClusterState.java.Coordinator.java:134is also cited.
The local checkout /home/user/opensearch-project/OpenSearch has exactly that HEAD. Every cited range delimits the Java member it names: CS:84-106 (the constructor), 144-154, 156-158, 180-204, 190-201, 213-255, 264-339, 348-407, 397-398, 416-460, 471-515, 523-573, 601-611, 703-728, 730-740, 750-814, 755-757, 772-774, 776-778, 780-782 and 798-806; CM:383-449, 385, 405-409 and 433-435; ES:68-88; CLS:239-244; Coordinator.java:134. CS:64-106 runs from the class declaration to the end of the constructor and so covers the fields. CS:616-642 covers the three remote-state helpers (617-642). Each declaration below has its own verdict.
Module docstring (claims, checked against the code)
- "Transcription of the per-node consensus state machine ...
CoordinationState... at OpenSearch revisionb2a54ba…." The revision matches the local checkout. - "Node ids are
Nat(Java:String); only equality is used." In the file, ids are compared by equality and list membership. The order<on ids appears only in the sortedness proof field ofVotingConfiguration. - "Terms are
Nat: the persisted term starts at0and onlyhandleStartJoinchanges it, to a strictly larger value."handleStartJoinis the only handler that writescurrentTerm, and it writes only a strictly larger value. Every other handler copiescurrentTermunchanged. The "starts at0" part is not encoded: the constructorinitaccepts an arbitrarycurrentTerm : ℕ. - "Versions are
Int(Javalong)." Lean'sIntis unbounded. Java's message constructors assert non-negative versions (Join.java:60-62, PublishResponse.java:52-53). Nothing in the Lean excludes negative versions. - "A
ClusterStateis reduced to the fields thatCoordinationStatereads or writes; everything else is an opaque payloadvalue : V." See declaration 15. - "
VotingConfigurationstores its node ids strictly sorted, so that=is Java'sSet.equals." This holds (declarations 4–5). - "The REMOTE persisted state ... is omitted. The handlers read it only to decide whether to write it (CS:616-642), and every value they compute is read from the LOCAL persisted state."
- In Java,
handlePublishRequest(CS:454-456) andhandleCommit(CS:569-571) consult the helpers at CS:617-642. - The third remote write inside a transcribed handler is
handlePreCommit()(CS:593-599), called fromhandlePublishResponseat CS:510. It is governed by the settings flagisRemoteStateEnabled(CS:595), not by those helpers, and it feeds no computed value. - "A failed remote write makes the Java method throw after its local effects (for example after
publishVotes.addVoteinhandlePublishResponse, CS:503-510)":addVoteis at CS:503 andhandlePreCommit()at CS:510, so this is accurate. - "the transcription returns the result instead, which only adds behaviours": in the Lean, each handler has a single deterministic outcome per input. No outcome represents "local effect done, then failure". Whether returning the result "only adds behaviours" depends on how a caller consumes results, which is not in this file. It cannot be checked here.
- In Java,
- "Java
asserts ... are caller contracts. The handlers below do not check them; the cluster model states them as preconditions of the corresponding steps." No cluster model is in this file. The file names two assertion groups as propositions,initialStateContractandclientValueContract, and no definition in the file uses either. Several other Java assertions have no Lean counterpart here:join.targetMatches(localNode)(CS:265);- "won never becomes not won" (CS:323);
- committed equals accepted after commit (CS:572);
- the cluster-UUID/Zen1 assertion (CS:708-710);
- non-negativity in the message constructors.
1. NodeId
abbrev NodeId := Nat: node ids are natural numbers.
2. DiscoveryNode
A structure with fields id : NodeId and isClusterManagerNode : Bool, deriving DecidableEq and Repr. Two nodes are equal iff both fields are equal.
Java check. Java's DiscoveryNode has more fields. Its equals compares ephemeral ids (DiscoveryNode.java:606-617), which this structure lacks. isClusterManagerNode() means "roles contain MASTER_ROLE or CLUSTER_MANAGER_ROLE" (DiscoveryNode.java:507-509); here it is a free Boolean.
No definition in the file compares two DiscoveryNodes. Nodes are inspected only through id and isClusterManagerNode.
3. ZEN1_BWC_TERM
def ZEN1_BWC_TERM : Nat := 0. This matches public static final long ZEN1_BWC_TERM = 0; at Coordinator.java:134.
4. VotingConfiguration
A structure with two fields:
nodeIds : List NodeId;sorted, a proof thatnodeIdsis pairwise strictly increasing: every earlier entry is every later entry.
So the list has no duplicates, and every finite set of naturals has exactly one representation.
Java check. CM:383-449 wraps an unmodifiable Set<String> nodeIds. The constant MUST_JOIN_ELECTED_CLUSTER_MANAGER (CM:386-388) is not transcribed.
5. instance : DecidableEq VotingConfiguration
Two configurations are equal iff their nodeIds lists are equal; the proof field is irrelevant. With sortedness, this is equality of the represented sets.
Java check. equals compares the nodeIds sets (CM:420-426). Matches.
6. VotingConfiguration.EMPTY_CONFIG
The configuration with nodeIds = []. Matches CM:385. Equality is by nodeIds, so every configuration whose list is empty equals EMPTY_CONFIG.
7. VotingConfiguration.isEmpty
. Matches CM:433-435.
8. VotingConfiguration.hasQuorum
For a configuration and a list of ids:
The bracket is the sublist of whose entries occur in ; membership is tested with List.contains on ℕ. Let be the set of ids of . Since is duplicate-free, the condition is : a strict majority of .
- Duplicates in do not matter.
- Entries of outside do not matter.
- For the empty configuration the test is , which is false for every .
Java check. CM:405-409 computes intersection = copy of nodeIds; intersection.retainAll(votes); intersection.size() * 2 > nodeIds.size(). Matches. Java uses int arithmetic; the Lean uses ℕ.
9. VoteCollection
A structure with one field, nodes : List NodeId (the docstring says "most recent first"). It derives DecidableEq and Repr, so two collections are equal iff their lists are equal: order and multiplicity matter.
Java check. CS:750-814 keeps a Map<String, DiscoveryNode> keyed by id plus a Set<Join>.
- The docstring says the joins are read only by tests. Confirmed: in the repository's main code, the only reader of
getJoins()iscontainsJoin(CS:164-167, commented "used for tests"). - Java's
equals(CS:798-806) compares the map and the join set without regard to order. The Lean equality is list equality.
The type does not forbid duplicate ids or ids of ineligible nodes. Such values cannot arise from empty and addVote, but they can appear in an arbitrary CoordinationState.
10. VoteCollection.empty
. Matches Java new VoteCollection().
11. VoteCollection.addVote
For a collection and a node , it returns a pair (new collection, added?):
- if and : , with the id prepended;
- otherwise: .
Java check. CS:755-757 is sourceNode.isClusterManagerNode() && nodes.put(sourceNode.getId(), sourceNode) == null. Matches:
- Because
&&short-circuits, an ineligible node is not inserted. - For an eligible node that is already present, Java's
putreplaces the storedDiscoveryNodeobject but leaves the key set unchanged and returns non-null. The ids-only model cannot see the replacement.
12. VoteCollection.isQuorum
. Matches CS:772-774.
13. VoteCollection.containsVoteFor
. Matches CS:776-778. No other declaration in the file uses it.
14. VoteCollection.isEmpty
. Matches CS:780-782.
15. ClusterState V
For any type , a structure with nine independent fields and no deriving clause:
| field | type | docstring / Java |
|---|---|---|
term | ℕ | term(), i.e. coordinationMetadata().term() (CLS:227-229) |
version | ℤ | version() |
metadataVersion | ℤ | metadata().version() |
lastCommittedConfiguration | VotingConfiguration | getLastCommittedConfiguration() |
lastAcceptedConfiguration | VotingConfiguration | getLastAcceptedConfiguration() |
clusterManagerNode | Option ℕ | nodes().getClusterManagerNode(), identified by its ephemeral id; none is Java null |
clusterUUIDKnown | Bool | cluster UUID ≠ UNKNOWN_CLUSTER_UUID |
clusterUUIDCommitted | Bool | metadata().clusterUUIDCommitted() |
value | "everything else" |
Three points about these fields:
- No constraints among fields. Nothing forces
clusterUUIDCommitted → clusterUUIDKnown, non-negative versions, or any relation betweenversionandmetadataVersion. clusterManagerNodeuses its own numbering. It is a natural number in a separate identifier space fromNodeId, and nothing links the two.- Its docstring checks out. It says the field is read only by the Zen1 branch of
handlePublishRequest; that is accurate within this file. Java'sDiscoveryNode.equalsdoes compare ephemeral ids, andDiscoveryNodes.getClusterManagerNode()returnsnullwhen no cluster manager is set (DiscoveryNodes.java:287-292).
16. ClusterState.versionOrMetadataVersion
Matches CLS:239-244 (term() == ZEN1_BWC_TERM ? metadata().version() : version()).
17. ClusterState.markCommitted
The function runs in two steps:
- Let be " with
lastCommittedConfiguration" if the two configurations of differ, and otherwise. - If and , return with
clusterUUIDCommitted. Otherwise return .
In both branches of step 1, ends with committed configuration equal to 's accepted configuration. The net effect is:
lastCommittedConfigurationbecomeslastAcceptedConfiguration;clusterUUIDCommittedbecomesclusterUUIDCommitted || clusterUUIDKnown;term,version,metadataVersion,lastAcceptedConfiguration,clusterManagerNode,clusterUUIDKnownandvalueare unchanged.
Java check. CS:703-728 with CS:730-740 matches:
commitVotingConfigurationbuilds new metadata with the committed configuration replaced only if the two configurations differ.- The UUID test runs on the original state; it reads the same flags as .
- The state is rewritten only if something changed.
- The Java rebuild preserves the version and the metadata version:
ClusterState.Builder(ClusterState)copiesversion(ClusterState.java:618-629), andMetadata.Builder(Metadata)copiesversion(Metadata.java:1231-1243). - The assertion at CS:708-710 (cluster UUID known, or term = Zen1 term) is not modelled.
- In
server/src/main/javathe default method is overridden only by the remoteRemotePersistedState(GatewayMetaState.java:830). The LOCAL persisted states inherit the default, so the default is what is transcribed.
18–22. Message structures
All five structures except PublishRequest derive DecidableEq and Repr:
StartJoinRequest:sourceNode : DiscoveryNode,term : ℕ. Matches StartJoinRequest.java:53.Join:sourceNode,targetNode : DiscoveryNode,term : ℕ,lastAcceptedTerm : ℕ,lastAcceptedVersion : ℤ, in Java's constructor order (Join.java:59). Java asserts all three numbers are ≥ 0 (Join.java:60-62); the Lean allows a negativelastAcceptedVersion.PublishRequest V:acceptedState : ClusterState V, with no deriving clause. Matches PublishRequest.java:48.PublishResponse:term : ℕ,version : ℤ. Matches PublishResponse.java:51, which asserts both are ≥ 0.ApplyCommitRequest:sourceNode : DiscoveryNode,term : ℕ,version : ℤ. Matches ApplyCommitRequest.java:49.
23. ElectionStrategy
A structure with one field, satisfiesAdditionalQuorumConstraints : DiscoveryNode → ℕ → ℕ → ℤ → VotingConfiguration → VotingConfiguration → VoteCollection → Bool. It is an arbitrary total Boolean function, written below. Its arguments are, in order: local node, current term, accepted term, accepted version, committed configuration, accepted configuration, votes.
Java check. The argument order matches ES:101-109.
- "
isElectionQuorumis final" matches ES:68. - "
DEFAULT_INSTANCE, the only strategy in OpenSearch itself": a repository-wide search finds no other subclass or anonymous instance ofElectionStrategy. - A Java strategy sees
DiscoveryNodeobjects and the recorded joins. Here it sees only the vote ids, as the docstring says.
The CoordinationState structure has no strategy field (see 26). The strategy is an explicit argument to isElectionQuorum, handleJoin and javaInvariant. So nothing in the Lean ties one state to one strategy across calls, whereas Java stores it as a final field.
24. ElectionStrategy.DEFAULT_INSTANCE
for all arguments. Matches ES:46-59.
25. ElectionStrategy.Monotone
is the proposition
Every argument other than the votes is held fixed, and inclusion is by membership. This is a Lean-only notion with no Java counterpart. The docstring's "The default strategy is" is the separate theorem default_monotone.
26. CoordinationState V
A structure with nine fields and no deriving clause:
localNode : DiscoveryNode;currentTerm : ℕ(persisted,getCurrentTerm());lastAcceptedState : ClusterState V(persisted,getLastAcceptedState());joinVotes : VoteCollection;startedJoinSinceLastReboot : Bool;electionWon : Bool;lastPublishedVersion : ℤ;lastPublishedConfiguration : VotingConfiguration;publishVotes : VoteCollection.
Java check. CS:64-106 has these, plus three things not represented: the electionStrategy field, the persistedStateRegistry (whose LOCAL state's two components become currentTerm and lastAcceptedState), and isRemoteStateEnabled. No field constraints are imposed.
27. CoordinationState.init
init(n, t, S) takes any node , any and any cluster state , and returns the state:
localNode;currentTerm;lastAcceptedState;joinVotes=empty;startedJoinSinceLastReboot= false;electionWon= false;lastPublishedVersion;lastPublishedConfiguration;publishVotes=empty.
No relation between and is required. Matches CS:84-106, including the defaults at lines 97-104.
28. Accessors (no docstrings)
Each reads a field of the last accepted state:
- (
lastAcceptedTerm); - (
lastAcceptedVersion); - (
lastAcceptedVersionOrMetadataVersion); - ;
- .
These match CS:116-134.
29. CoordinationState.isElectionQuorum
The function never reads cs.joinVotes; the votes are the argument . The strategy receives the plain version , not . Matches CS:144-154 and ES:68-88.
30. CoordinationState.isPublishQuorum
. Matches CS:156-158.
31. CoordinationState.setInitialState
setInitialState(cs, S) : Except String (CoordinationState V):
- If is non-empty: ("initial state already set…").
- Otherwise: .
Nothing about is checked: not its term, version or configurations. lastPublishedConfiguration is not updated.
Java check. CS:180-204 matches. Java's assertions are not checked; they appear as initialStateContract.
32. CoordinationState.initialStateContract
A proposition about : the conjunction, in Java's order (CS:190-201), of
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- .
All 11 Java assertions are present. No other declaration in this file uses it, and none of the mission's theorem statements does.
33. CoordinationState.handleStartJoin
handleStartJoin(cs, r) : Except String (CoordinationState V × Join):
- If : .
- Otherwise: , where:
- is with
currentTerm,lastPublishedVersion,lastPublishedConfiguration,startedJoinSinceLastReboottrue,electionWonfalse,joinVotesempty,publishVotesempty.localNodeandlastAcceptedStateare unchanged. - .
- is with
Nothing about is checked.
Java check. CS:213-255 matches: same guard, same assignments, the same Join (Java's getCurrentTerm() at line 251 is the new term), and setCurrentTerm does not affect the accepted state (CS:661-666). The log-only branch at CS:227-237 has no effect.
34. CoordinationState.handleJoin
handleJoin(es, cs, j) : Except String (CoordinationState V × Bool). The guards are tested in this order, and the first that fires gives :
- ;
- ;
- ;
- and , compared against the version-or-metadata-version;
- .
Otherwise the handler computes:
- ;
- , evaluated on the old state , whose relevant fields are unchanged;
- with
joinVotes,electionWon; - with
lastPublishedVersionif and ; otherwise .
The result is .
Two points:
electionWonis recomputed, not only raised. In a state whose flag disagrees with the quorum test, a join can lower it.- is never read. Java asserts it is the local node (CS:265).
Java check. CS:264-339 matches: guard order, addJoinVote reducing to addVote on the source node (CS:759-765), the election test using getLastAcceptedVersion() (CS:149), and lastPublishedVersion = getLastAcceptedVersion() on a fresh win (CS:334-337). The assertion at CS:323 is not checked.
35. CoordinationState.handleClientValue
handleClientValue(cs, S) : Except String (CoordinationState V × PublishRequest V). The guards are tested in this order, and the first that fires gives :
- ;
- ;
- ;
- ;
- and ;
- .
Otherwise the result is .
is not checked; the Java assertion appears as clientValueContract. Nor are 's other fields.
Java check. CS:348-407 matches.
36. CoordinationState.clientValueContract
. Matches CS:397-398. No other declaration in this file uses it, and none of the mission's theorem statements does.
37. CoordinationState.handlePublishRequest
handlePublishRequest(cs, R) : Except String (CoordinationState V × PublishResponse). Let . Define . Then:
- If : .
- Else if and (a stale or equal version in the accepted term):
- if (the Zen1 branch, so here):
- if : ("NullPointerException");
- if : when (the stored value is
noneor a different number), and otherwise;
- otherwise: .
- if (the Zen1 branch, so here):
- Else: .
The handler touches only lastAcceptedState. Every field of (configurations included) is adopted unchecked, and electionWon is left as is.
Java check. CS:416-460 matches.
- When the incoming cluster manager is
null, Java'sgetClusterManagerNode().equals(...)throws aNullPointerException(not aCoordinationStateRejectedException). The Lean merges this into . x.equals(null)is false, which matches accepting when the stored value isnone.
38. CoordinationState.handlePublishResponse
handlePublishResponse(cs, n, r) : Except String (CoordinationState V × Option ApplyCommitRequest). The guards are tested in this order, and the first that fires gives :
- ;
- ;
- .
Otherwise the handler computes:
- ; the "added" Boolean is discarded;
- with
publishVotes; - the result is if , that is, is a quorum of and of . Otherwise the result is .
A commit request is returned on every successful call once the votes form a publish quorum, including repeated responses from the same node.
Java check. CS:471-515 matches. The remote handlePreCommit() (CS:510) is omitted, as discussed above.
39. CoordinationState.handleCommit
handleCommit(cs, c) : Except String (CoordinationState V). The guards are tested in this order:
- : ;
- : ;
- : .
Otherwise the result is . is never read.
Java check. CS:523-573 matches: the LOCAL markLastAcceptedStateAsCommitted, the default method (see 17). The REMOTE commit is omitted.
40. CoordinationState.javaInvariant
is the conjunction of:
- (i) ;
- (ii) , an equality of Booleans;
- (iii) if then , else ;
- (iv) ;
- (v) .
Matches invariant() at CS:601-611, assertion by assertion.
Summary of transcription fidelity
Every handler, quorum test and helper reproduces the cited Java (local persisted state only):
- the order of guards;
- the comparisons, including the asymmetric use of in
handleJoin's guard versus in the strategy call and in the new published version; - the assignments;
- the returned messages.
The deliberate deviations are all stated in the docstrings:
- the remote store and its write failures are omitted;
- assertions are not checked;
- a
nullincoming cluster manager becomes an error; - vote collections hold ids only;
- a strategy sees ids only.
Things the docstrings do not spell out:
- the strategy is passed per call rather than fixed per state;
initdoes not force the initial term to be 0;VoteCollectionequality is order- and multiplicity-sensitive;- message-constructor non-negativity is not modelled.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.