Repository navigation
Conversation
… apply `MembershipStateMachine.apply` unconditionally overwrote the SM's voter / learner view every time a CONFIG command was applied. `Node.on_config_change` is gated by `_applied_config_index=M` so the callback only fires on the newest-index CONFIG, but the SM state itself was not gated: a stale CONFIG re-applied after log truncation (leader stomps a divergent follower tail) or during recovery replay could silently revert the authoritative voter view. Downstream readers of `membership_sm.voters` / `.learners` (ring bring-up, routing) then saw the wrong set until the next real CONFIG. Fix: short-circuit the apply when the incoming log index is at or below the SM's `_membership_version`. The existing field already round-trips through get_snapshot / restore_snapshot as the ``version`` key, so the gate survives snapshot install. `index == -1` (the no-index default used by test harnesses that don't care about replay safety) still always applies, preserving pre-existing behavior. Regression framing originally captured at `agents/scratch/bug-025/NOTES.md` lines 40-50 and 43-50 --- flagged during BUG-025 QA as a pre-existing risk in master, now addressed here. Two unit tests added: the hot-path short-circuit (`test_stale_config_apply_does_not_regress_voters`) and the snapshot-restore round-trip (`test_stale_config_skip_survives_snapshot_roundtrip`); both confirmed RED on pre-fix HEAD via `git stash`. Note: RingRegistryStateMachine.apply and RoutingStateMachine.apply have the same "overwrite + set version on every apply" shape and need the same gate, but the fix there warrants a separate per-SM callsite audit; flagged in agents/scratch/bug-028/NOTES.md as follow-up.
The stale-CONFIG regression fix in MembershipStateMachine.apply left the
three sibling SMs in salt/cluster/consensus/raft/log.py with the identical
"overwrite unconditionally + set version on every apply" pattern:
- RingConfigStateMachine.apply (log.py:911)
- RingRegistryStateMachine.apply (log.py:1047)
- RoutingStateMachine.apply (log.py:1189)
Same truncation/replay regression risk applied to ring policy, ring
registry, and routing-table state: a stale entry re-delivered via log
truncation or recovery replay silently overwrote the authoritative SM
state.
### Fix
Each sibling SM gets the same short-circuit used by MembershipStateMachine:
if (
index >= 0
and self._version >= 0
and index <= self._version
):
log.debug(...)
return
The index=-1 escape hatch for test harnesses still always applies. The
_version field already round-trips through each SM's snapshot envelope
as "version" so the gate survives snapshot install.
### Audit
All production callers in salt/ pass index=entry.index
(salt/cluster/consensus/raft/node.py:840, :857; and
salt/runners/cluster.py:258), so no caller relies on pre-fix no-index
re-apply semantics.
### Regression tests
Added to tests/pytests/unit/cluster/consensus/test_raft_log.py, one per
sibling SM. All four verified RED pre-fix (via git stash) and GREEN
post-fix. Full cluster unit suite: 585 passed.
3 tasks done
Contributor
Author
|
Superseded by #70755 which combines all five cluster-correctness backports into a single PR. |
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
Backport of two commits from the master-topology work on master. Both land correctness fixes for clustered masters on 3008.x.
MembershipStateMachine.applyunconditionally wroteself._version = indexfor every CONFIG entry, including stale ones replayed via log truncation or recovery. A stale entry re-delivered after a snapshot-install or follower truncation would silently overwrite the committed voter set — potential split-brain shape.RingConfigStateMachine,RingRegistryStateMachine,RoutingStateMachine). Ring policy, ring registry, and routing-table state could all be silently regressed by a stale entry.Fix: short-circuit
applywhenindex <= self._version. The_versionfield already round-trips through each SM's snapshot envelope, so the gate survives snapshot install.Test plan
pytest tests/pytests/unit/cluster/consensus/— 394 passed