[ 
https://issues.apache.org/jira/browse/RATIS-2834?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18150613#comment-18150613
 ] 

dwangcommit1 commented on RATIS-2834:
-------------------------------------

[~szetszwo] please assign to me if possible, will raise a PR to fix it.

> Leader keeps rejecting requests after a leadership transfer fails with 
> FAILED_APPLIED_INDEX_GAP
> -----------------------------------------------------------------------------------------------
>
>                 Key: RATIS-2834
>                 URL: https://issues.apache.org/jira/browse/RATIS-2834
>             Project: Ratis
>          Issue Type: Bug
>          Components: election
>         Environment: org.apache.ratis:ratis-server:3.3.2-babaf87-SNAPSHOT 
> (gRPC)
>            Reporter: dwangcommit1
>            Priority: Major
>
> Peer 5 remained the leader after a transfer to peer 2 failed. It subsequently 
> rejected both configuration changes and client writes with 
> {{LeaderSteppingDownException}}. We observed the same error on the same 
> leader two hours after the transfer returned a failure.
> h3. Sequence of events
> # Peer 2 joined the voting configuration. Both peer 5 and peer 2 recorded the 
> stable configuration {{[1, 2, 3, 5]}} at log index 1613.
> # A client requested a leadership transfer from peer 5 to peer 2. The 
> follower's log had caught up, but its state machine was more than 1000 
> entries behind the leader's last log entry. Ratis immediately rejected the 
> transfer with {{FAILED_APPLIED_INDEX_GAP}}. The reply identified peer 5 as 
> the current leader.
> # Five attempts to change the configuration between 21:22:06 and 21:22:26 
> failed with {{LeaderSteppingDownException}}. At 23:22:22 peer 5 still 
> returned the same exception for a client write.
> h3. Ratis log excerpts
> {noformat}
> 21:22:04,917  5@group-000200000001: start transferring leadership to 2
> org.apache.ratis.protocol.exceptions.TransferLeadershipException: 
> 5@group-000200000001: Failed to transfer leadership to 2 (the current leader 
> is 5): FAILED_APPLIED_INDEX_GAP(follower's applied index gap is greater than 
> 1000)
>     at 
> org.apache.ratis.server.impl.TransferLeadership$PendingRequest.complete(TransferLeadership.java:153)
>     at 
> org.apache.ratis.server.impl.TransferLeadership.start(TransferLeadership.java:320)
> 23:22:22,219  ... FAILED 
> org.apache.ratis.protocol.exceptions.LeaderSteppingDownException: 
> 5@group-000200000001 is stepping down, logIndex=0, commits[5:c1614, 1:c1614, 
> 3:c1614, 2:c1614]
> {noformat}
> h3. Expected behavior
> After rejecting the transfer, peer 5 should clear the pending transfer and 
> resume serving writes and configuration changes as the current leader.
> h3. Cause
> {{TransferLeadership.start(Context)}} installs the request in {{pending}} 
> before calling {{tryTransferLeadership}}. On immediate failure, it calls 
> {{pendingRequest.complete(result)}}, which resolves the reply future but 
> leaves the request in {{pending}}. This branch also skips registration of the 
> transfer timeout. Since {{isSteppingDown()}} checks whether {{pending}} is 
> non-null, later requests can continue to fail after the caller has already 
> received the final transfer result. The asynchronous applied-index-gap 
> failure path calls {{TransferLeadership.complete(result)}}, which clears the 
> reference.
> A regression test could exercise the immediate rejection and verify that the 
> same leader accepts a subsequent write without requiring a new election.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to