kvstorage: destroy old replica in CreateUninitializedReplica #171156
Draft
pav-kv wants to merge 3 commits into
Draft
kvstorage: destroy old replica in CreateUninitializedReplica #171156pav-kv wants to merge 3 commits into
pav-kv wants to merge 3 commits into
Conversation
Contributor
|
Merging to
After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here |
Member
803b5b0 to
e9d874c
Compare
The previous WAG invariant required each RangeID to appear at most once in a node's event list. This was too strict for operations that encompass multiple lifecycle transitions for the same range, such as destroying an old replica and creating a new one in CreateUninitializedReplica. Relax the invariant and update canApplyWAGNode to handle multiple events per RangeID. When a RangeID appears more than once, the replay logic now computes the expected post-event state via advance() and uses it to evaluate subsequent events for the same range, instead of re-loading the persisted state. Epic: none Release note: None Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The LoadReplicaState call at the end of CreateUninitializedReplica was a post-write sanity check that read back the ReplicaMark just written. This required the caller to provide a read-write batch (so own writes are visible), and also required passing storeID and raftRO which were only used by this check. Remove this verification step. The caller (tryGetOrCreateReplica) already calls LoadReplicaState separately after committing the batch, so the check was redundant. Epic: none Release note: None Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When CreateUninitializedReplica finds an existing replica with an older ReplicaID, it must destroy the old replica before creating the new one. Previously, the code fell through and only overwrote the RaftReplicaID, leaving behind stale raft state (HardState, raft log) from the old replica. This could cause a newly created replica to pick up a non-empty HardState.Commit, violating the uninitialized replica invariant. Fix this by calling DestroyReplica on the old replica, which clears all its state and writes a RangeTombstone. This is the same path used by removeUninitializedReplicaRaftMuLocked. The function signature changes from taking State to taking a ReadWriter, since destroying the old replica requires raft write access. Epic: none Release note: None Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
e9d874c to
5190175
Compare
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.
Previously, when
CreateUninitializedReplicafinds an existing replica with an olderReplicaID, it fell through and only overwrote theRaftReplicaID. As a result, the new replica inherited the old replica'sHardState.This is a bug. Fixed by calling
DestroyReplicaon the old replica, which clears all its state and writes aRangeTombstone. This is the same path used byremoveUninitializedReplicaRaftMuLocked.The previous WAG invariant required each
RangeIDto appear at most once in a node's event list. This was too strict for operations that encompass multiple lifecycle transitions for the same range, such as destroying an old replica and creating a new one inCreateUninitializedReplica.Relax the invariant and update
canApplyWAGNodeto handle multiple events perRangeID. When aRangeIDappears more than once, the replay logic now computes the expected post-event state viaadvance()and uses it to evaluate subsequent events for the same range, instead of re-loading the persisted state.