Repository navigation
Fix cluster_ready never fires after restart from persisted Raft state - #70754
Merged
Merged
Conversation
Diagnosis --------- Three cluster masters that bootstrap cleanly on a fresh cachedir leave ``cluster_ready`` unset indefinitely after a clean stop and restart with the same ``cache/consensus`` / ``cache/raft`` state on disk. Minion requests then receive ``cluster_retry`` forever. Root cause is Raft §5.4.2 (commit restriction for prior terms): 1. ``Log.__init__`` loads the persisted log entries from storage — including the founding CONFIG at index 0 in some prior term N. 2. ``commit_index`` is NOT persisted, so it comes back as -1; the ``MembershipStateMachine`` therefore starts empty on restart. 3. ``RaftService.__init__`` wires ``_on_ready`` and calls ``reconcile_membership()``, but the SM has nothing to reconcile because no entries have been applied yet. 4. A new leader is elected in term N+1. Heartbeats propagate the persisted log entries' indices via ``match_index``, but ``advance_commit_index`` refuses to commit index 0 because ``entry.term (= N) != self.term (= N+1)``: Raft forbids a leader from committing a prior-term entry by replication count alone. 5. In steady state there's nothing new to propose, so no current-term entry ever reaches the log, ``commit_index`` stays at -1, the membership SM never applies the founding CONFIG, and ``_on_ready`` / ``_signal_cluster_ready`` never fires. Fix --- ``Node.become_leader`` now appends a ``LogEntryType.NOOP`` barrier in the new leader's term when the log carries uncommitted entries from a prior term. Once the heartbeat path replicates the NOOP to quorum, ``advance_commit_index`` can commit it (same-term entry), which by Raft's commit rules transitively commits every prior entry — including the restored founding CONFIG. ``apply_entries`` then applies the CONFIG to the ``MembershipStateMachine``, which fires ``on_change`` / ``_on_ready`` on every voter. The NOOP has no payload and no state-machine effect; ``apply_entries`` skips it. We gate the append on ``log.index > commit_index AND any prior-term entry`` so a fresh cluster (empty log) still runs the normal founding CONFIG path in ``RaftService._maybe_commit_founding_config`` (which keys on ``log.index < 0``). Regression coverage in ``tests/pytests/functional/cluster/consensus/test_cluster_ready_scenarios.py::TestClusterReadyOnRestart``: * End-to-end restart: bootstrap → stop → rebuild services against the same cachedir → assert every founding node fires ``on_ready`` again, ``commit_index`` advances past the founding CONFIG, and the SM reflects the restored voter set. * ``_signal_cluster_ready`` is idempotent (safe to re-fire). * ``become_leader`` appends the NOOP barrier on a Node whose log already has prior-term entries, and does NOT append one on a Node with an empty log.
twangboy
approved these changes
Nov 10, 2026
4 of 6 tasks
2 tasks done
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Three cluster masters that bootstrap cleanly on a fresh cachedir leave
cluster_readyunset indefinitely after a clean stop + restart with the samecache/consensus/cache/raftstate on disk. Minion requests then receivecluster_retryforever.Root cause is Raft §5.4.2 (the commit restriction for prior-term entries):
Log.__init__loads the persisted log entries from storage (including the founding CONFIG at index 0, in some prior term N).commit_indexis not persisted, so it starts back at -1; theMembershipStateMachineis therefore empty.RaftService.__init__wires_on_readyand callsreconcile_membership(), but the SM has nothing to reconcile — nothing has been applied.match_indexup to the top of the log, butadvance_commit_indexrefuses to commit index 0 becauseentry.term (= N) != self.term (= N+1): Raft forbids a leader from committing a prior-term entry by replication count alone.commit_indexstays at -1, the membership SM never applies the restored founding CONFIG,_on_readynever fires, andcluster_retrypersists.Fix:
Node.become_leadernow appends aLogEntryType.NOOPbarrier in the new leader's term when the log carries uncommitted prior-term entries. Once the heartbeat path replicates the NOOP to quorum,advance_commit_indexcan commit it (same-term entry), which by Raft's commit rules transitively commits every prior entry — including the restored founding CONFIG.apply_entriesthen applies the CONFIG to theMembershipStateMachine, which fireson_change/_on_readyon every voter.The NOOP has no payload and no state-machine effect;
apply_entriesskips it. The append is gated onlog.index > commit_index AND any prior-term entryso a fresh cluster (empty log) still runs the normal founding-CONFIG path inRaftService._maybe_commit_founding_config(which keys onlog.index < 0).Diff scope:
salt/cluster/consensus/raft/log.py: newLogEntryType.NOOP = 6.salt/cluster/consensus/raft/node.py:become_leaderappends NOOP barrier;apply_entrieshandles the NOOP type as a no-op.tests/pytests/functional/cluster/consensus/test_cluster_ready_scenarios.py: newTestClusterReadyOnRestartclass.changelog/70754.fixed.md.Test plan
pytest tests/pytests/unit/cluster/ tests/pytests/functional/cluster/— 724 passed.pytest -k "ready or restart or reconcile or membership"— 136 passed.TestClusterReadyOnRestartregression:test_cluster_ready_fires_on_restart_from_persisted_log— bootstraps 3 nodes, drives the founding CONFIG commit, rebuilds the ServiceCluster against the same cachedir (simulating a process restart against persisted storage), re-elects, asserts every node fireson_ready,commit_indexadvances past the founding CONFIG, and the membership SM reflects the restored voter set. Fails without the fix.test_signal_cluster_ready_idempotent—_signal_cluster_readyis safe to call multiple times.test_noop_barrier_appended_on_become_leader_with_prior_term_log— asserts the NOOP is appended when prior-term entries exist and not appended on an empty log (which would permanently suppress the founding-CONFIG path).pre-commit run --files ...clean.