Repository navigation
RATIS-2834. Clear the pending leadership transfer on immediate failure - #1710
Conversation
amaliujia
left a comment
There was a problem hiding this comment.
Thanks for catching the issue!
| pendingRequest.complete(result); | ||
| if (pending.compareAndSet(pendingRequest, null)) { | ||
| pendingRequest.complete(result); | ||
| } |
There was a problem hiding this comment.
Why don't we always complete the result if the result is already in the bad cases. If pending does not refer to the pendingRequest, who will be in charge of complete pendingRequest?
pending.compareAndSet(pendingRequest, null);
pendingRequest.complete(result);
There was a problem hiding this comment.
If the CAS fails, the callback that took this request out of pending is responsible for completing its future. For example, the follower append-reply path calls TransferLeadership.complete(result), which does pending.getAndSet(null) and then r.complete(result) on the request it just removed. start() only installs a new request when the slot is empty.
There is a small window between those two operations: the callback has taken the request, but its future may still be incomplete. Calling pendingRequest.complete(result) unconditionally in that window could publish the immediate failure before the callback publishes its own result. Keeping the call inside the if lets the path that removed the request decide the reply. Completion path
There was a problem hiding this comment.
I see. The implementation contract is then who set the reference as null (thus take the reference) will own the lifecycle.
amaliujia
left a comment
There was a problem hiding this comment.
LGTM
Triggering the CI jobs.
27cb362 to
4a6fae1
Compare
|
The test failure appears unrelated to this PR. I’ve rebased the branch onto the latest master. |
szetszwo
left a comment
There was a problem hiding this comment.
+1 the change looks good.
|
@d-wang-commit , thanks for working on this! @amaliujia , thanks for reviewing this! |
What changes were proposed in this pull request?
When a follower's log is up to date but its state machine is too far behind,
TransferLeadership.startimmediately rejects the transfer withFAILED_APPLIED_INDEX_GAP. It completes the request's future but leaves the request inpending. The current leader then continues to report that it is stepping down and can reject writes and configuration changes.Clear
pendingbefore completing the failed request. The compare-and-set clears it only if it still refers to that request.Generated-by: OpenAI Codex (GPT-6)
What is the link to the Apache JIRA
RATIS-2834
How was this patch tested?
Extended
testRiskyLeadershipTransferto wait for log replication while the follower's state machine is paused. After the transfer is rejected, the test verifies that the original leader accepts a write in the same term.Before the fix, the write failed with
LeaderSteppingDownExceptiononbabaf87d5. With the fix, all 29 tests run againstmasterpassed: the 27 tests inTestLeaderElectionWithGrpcand the regression test with both Netty and simulated RPC.