release-21.1: kv: don't clear raftRequestQueue of right-hand side of Range split #65356
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.
Backport 1/1 commits from #64028.
/cc @cockroachdb/release
This commit fixes a test flake of
TestLeaderAfterSplit
I observed in CI andwhich we've seen at least once in #43564 (comment).
I bisected the flake back to a591707, but that wasn't the real source of the
flakiness - the move from
multiTestContext
toTestCluster
just changedtransport mechanism between replicas and revealed an existing bug.
The real issue here was that, upon applying a split, any previously established
raftRequestQueue
to the RHS replica was discarded. The effect of this is thatwe could see the following series of events:
Of course, in real deployments,
RaftElectionTimeoutTicks
will never be set sohigh, so a new election will be called again after about 3 seconds. Still, this
could cause unavailability immediately after a split for about 3s even in real
deployments, so it seems worthwhile to fix.
This commit fixes the issue by removing the logic to discard an uninitialized
replica's
raftRequestQueue
upon applying a split that initializes the replica.That logic looks quite intentional, but if we look back at when it was added, we
see that it wasn't entirely deliberate. The code was added in d3b0e73, which
extracted everything except the call to
s.mu.replicas.Delete(int64(rangeID))
from
unlinkReplicaByRangeIDLocked
. So the change wasn't intentionallydiscarding the queue, it was just trying not to change the existing behavior.
This change is safe and does not risk leaking the
raftRequestQueue
becausewe are removing from
s.mu.uninitReplicas
but will immediately call intoaddReplicaInternalLocked
to add an initialized replica.Release notes (bug fix): Fix a rare race that could lead to a 3 second stall
before a Raft leader was elected on a Range immediately after it was split off
from its left-hand neighbor.