fix: notify pending consensus ops on snapshot apply#8990
Merged
Conversation
When an `AddPeer` / `RemovePeer` / `UpdatePeerMetadata` /
`UpdateClusterMetadata` operation is proposed locally and then committed
remotely, the resulting log entry can be delivered back to us as part of
a raft snapshot rather than as a regular log entry. In that case the
operation never flows through `apply_conf_change_entry` /
`apply_normal_entry`, so the awaiter registered by
`propose_consensus_op_with_await` was never woken and timed out after
10s — manifesting as flaky failures of `test_peer_snapshot_bootstrap`
("Failed to add peer: ... Waiting for consensus operation commit failed").
Resolve awaiters in `apply_snapshot` whenever their effect is directly
observable in the new persistent state.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
timvisee
approved these changes
May 11, 2026
Member
|
Thanks for the clear write up. That made this PR very easily digestable. 🙏 |
generall
added a commit
that referenced
this pull request
May 22, 2026
When an `AddPeer` / `RemovePeer` / `UpdatePeerMetadata` /
`UpdateClusterMetadata` operation is proposed locally and then committed
remotely, the resulting log entry can be delivered back to us as part of
a raft snapshot rather than as a regular log entry. In that case the
operation never flows through `apply_conf_change_entry` /
`apply_normal_entry`, so the awaiter registered by
`propose_consensus_op_with_await` was never woken and timed out after
10s — manifesting as flaky failures of `test_peer_snapshot_bootstrap`
("Failed to add peer: ... Waiting for consensus operation commit failed").
Resolve awaiters in `apply_snapshot` whenever their effect is directly
observable in the new persistent state.
Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
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
Fixes flaky
test_peer_snapshot_bootstrap(tests/consensus_tests/test_peer_snapshot_bootstrap.py), which intermittently fails with:caused by the joining peer panicking with:
Root cause
When a peer proposes an
AddPeer/RemovePeer/UpdatePeerMetadata/UpdateClusterMetadataoperation viapropose_consensus_op_with_await, it registers an awaiter inon_consensus_op_applyand blocks on a broadcast channel. The channel is normally signalled when the corresponding log entry is processed byapply_conf_change_entry/apply_normal_entry.If the operation is committed remotely and the leader truncates past it before we apply our local copy of the log entry, the entry is delivered back as part of a raft snapshot instead. Snapshot application went through
update_from_snapshotonly — it never consultedon_consensus_op_apply, so the awaiter blocked until the 10s timeout fired and the joining peer'sadd_peer_to_knowngRPC call failed.In the failing CI run (
/tmp/flacky/test_peer_snapshot_bootstrap/):AddLearnerNodefor the new peer.MsgSnapshot(at index 14 first, then at index 15) — both clear the WAL.address_by_idandconf_state.learners, but the awaiter is never woken.Fix
In
ConsensusManager::apply_snapshot, afterupdate_from_snapshot, walkon_consensus_op_applyand resolve any awaiter whose effect is now directly observable in persistent state:AddPeer { peer_id, uri }—address_by_id[peer_id] == uriRemovePeer(peer_id)—peer_idno longer inaddress_by_idUpdatePeerMetadata { peer_id, metadata }—metadata_by_id[peer_id] == metadataUpdateClusterMetadata { key, value }—cluster_metadata[key] == valueOther variants (
CollectionMeta,RequestSnapshot,ReportSnapshot) are listed explicitly and left pending — the match is exhaustive, so adding a newConsensusOperationsvariant will force a compile error here.Test plan
apply_snapshot_notifies_pending_add_peer: registers a pendingAddPeerwaiter, applies a snapshot containing the peer, asserts the waiter receivesOk(true)and is removed from the pending map. Confirmed this test fails onmaster(panic:awaiter must be notified by snapshot: Empty) and passes with the fix.apply_snapshot_does_not_notify_unrelated_add_peer: applies a snapshot that does not satisfy the awaited operation, asserts the awaiter stays pending — guards against spurious notifications.content_manager::consensus_manager::testspass.test_peer_snapshot_bootstrapruns cleanly.🤖 Generated with Claude Code