ivandika3 opened a new pull request, #1669: URL: https://github.com/apache/ratis/pull/1669
## What changes were proposed in this pull request? Previously, any step down event (`StateUpdateEvent.STEP_DOWN`) is queued into the `LeaderStateImpl#EventQueue` (see `LeaderStateImpl#submitStepDownEvent`). However, `StateUpdateEvent` equals only checks based on the event type. Therefore, if there is a pending STEP_DOWN event for a lower term, the `LeaderStateImpl#EventQueue` would rejects it to avoid duplicated events. Another case is the `LeaderStateImpl#stop` is called and the event queue stop and not process the remaining step down term. In that case, `LeaderStateImpl#stepDown` will only be called for the lower term `StepDown`. Since `RaftServerImpl#changeToFollowerAndPersistMetadata` would update the Raft metadata `currentTerm` and `votedFor` to the stale term and this leaves the term in an older term and allow it to grant a stale vote. The fix is to handle the higher-term follower reply immediately in `onFollowerTerm`. We still allow step down to triggered locally like for transfer leadership since it is not triggered by a higher term and should not cause the stale term issue. Since now `LogAppender` itself calls the `onFollowerTerm`, we need to ensure that the `LogAppender` will not interrupt itself when it calls `LeaderStateImpl#shutdownLeaderState` (in `RaftServerImpl#changeToFollower`) which calls `LeaderStateImpl#stop` which stops the appenders (including itself). The interrupt will set the interrupt flag in the `LogAppender` and therefore the `InterruptedException` will be thrown when persisting the metadata which will cause similar issues. To handle this, the `LogAppenderDaemon#close` will not close if it's triggered by itself. The `LogAppenderDaemon#run ` will then stop since it detects that the leader is already stopped. ## What is the link to the Apache JIRA https://issues.apache.org/jira/browse/RATIS-2646 ## How was this patch tested? UT. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
