You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ratis.apache.org by GitBox <gi...@apache.org> on 2021/01/05 08:20:31 UTC

[GitHub] [incubator-ratis] runzhiwang opened a new pull request #378: RATIS-1268. Fix leader can not vote for candidate

runzhiwang opened a new pull request #378:
URL: https://github.com/apache/incubator-ratis/pull/378


   ## What changes were proposed in this pull request?
   
   **What's the problem ?**
   For example, when s0 is leader, and s1 askForVote, in the first rpc of askForVote, s0 can not vote for s1, even though s1's log catch up. When s1 askForVote the second time, s0 has become follower in the first askForVote, so s0 can vote for s1, waste one rpc call.
   
   **What's the reason ?**
   As the following code shows, when s0 is leader, `role.getFollowerState().orElse(null)` should return null,
   then can not pass check `if (fs != null && candidate != null)` because fs is null,  so s0 can not vote for s1.
   ```
         FollowerState fs = role.getFollowerState().orElse(null);
         if (shouldWithholdVotes(candidateTerm)) {
           ...
         } else if (state.recognizeCandidate(candidateId, candidateTerm)) {
           final boolean termUpdated = changeToFollower(candidateTerm, true, "recognizeCandidate:" + candidateId);
           RaftPeer candidate = getRaftConf().getPeer(candidateId);
           if (fs != null && candidate != null) {
            ...
          }
   ```
   
   **How to fix ?**
   
   After leader `final boolean termUpdated = changeToFollower(candidateTerm, true, "recognizeCandidate:" + candidateId);`, we can get fs again.
   
   
   ## What is the link to the Apache JIRA
   
   https://issues.apache.org/jira/browse/RATIS-1268
   
   ## How was this patch tested?
   
   no need to add new 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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-ratis] runzhiwang closed pull request #378: RATIS-1268. Fix leader can not vote for candidate

Posted by GitBox <gi...@apache.org>.
runzhiwang closed pull request #378:
URL: https://github.com/apache/incubator-ratis/pull/378


   


----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-ratis] runzhiwang commented on pull request #378: RATIS-1268. Fix leader can not vote for candidate

Posted by GitBox <gi...@apache.org>.
runzhiwang commented on pull request #378:
URL: https://github.com/apache/incubator-ratis/pull/378#issuecomment-754469273


   > I somehow have overlooked this pull request.
   
   @szetszwo Thanks for review. It does not matter. 


----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-ratis] runzhiwang commented on a change in pull request #378: RATIS-1268. Fix leader can not vote for candidate

Posted by GitBox <gi...@apache.org>.
runzhiwang commented on a change in pull request #378:
URL: https://github.com/apache/incubator-ratis/pull/378#discussion_r551763473



##########
File path: ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java
##########
@@ -1047,13 +1047,18 @@ private RequestVoteReplyProto requestVote(
     synchronized (this) {
       // Check life cycle state again to avoid the PAUSING/PAUSED state.
       assertLifeCycleState(LifeCycle.States.RUNNING);
-      final FollowerState fs = role.getFollowerState().orElse(null);
+      FollowerState fs = role.getFollowerState().orElse(null);
       if (shouldWithholdVotes(candidateTerm)) {
         LOG.info("{}-{}: Withhold vote from candidate {} with term {}. State: leader={}, term={}, lastRpcElapsed={}",
             getMemberId(), role, candidateId, candidateTerm, state.getLeaderId(), state.getCurrentTerm(),
             fs != null? fs.getLastRpcTime().elapsedTimeMs() + "ms": null);
       } else if (state.recognizeCandidate(candidateId, candidateTerm)) {
         final boolean termUpdated = changeToFollower(candidateTerm, true, "recognizeCandidate:" + candidateId);
+        if (fs == null) {

Review comment:
       @lokeshj1703 Thanks for review. I have updated the patch.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-ratis] lokeshj1703 closed pull request #378: RATIS-1268. Fix leader can not vote for candidate

Posted by GitBox <gi...@apache.org>.
lokeshj1703 closed pull request #378:
URL: https://github.com/apache/incubator-ratis/pull/378


   


----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-ratis] runzhiwang commented on pull request #378: RATIS-1268. Fix leader can not vote for candidate

Posted by GitBox <gi...@apache.org>.
runzhiwang commented on pull request #378:
URL: https://github.com/apache/incubator-ratis/pull/378#issuecomment-754558533


   @lokeshj1703 @szetszwo Thanks for review.


----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-ratis] lokeshj1703 commented on pull request #378: RATIS-1268. Fix leader can not vote for candidate

Posted by GitBox <gi...@apache.org>.
lokeshj1703 commented on pull request #378:
URL: https://github.com/apache/incubator-ratis/pull/378#issuecomment-754531751


   @runzhiwang Thanks for the contribution! @szetszwo Thanks for the review! I have committed the PR to master branch.


----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-ratis] runzhiwang closed pull request #378: RATIS-1268. Fix leader can not vote for candidate

Posted by GitBox <gi...@apache.org>.
runzhiwang closed pull request #378:
URL: https://github.com/apache/incubator-ratis/pull/378


   


----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-ratis] lokeshj1703 commented on a change in pull request #378: RATIS-1268. Fix leader can not vote for candidate

Posted by GitBox <gi...@apache.org>.
lokeshj1703 commented on a change in pull request #378:
URL: https://github.com/apache/incubator-ratis/pull/378#discussion_r551758951



##########
File path: ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java
##########
@@ -1047,13 +1047,18 @@ private RequestVoteReplyProto requestVote(
     synchronized (this) {
       // Check life cycle state again to avoid the PAUSING/PAUSED state.
       assertLifeCycleState(LifeCycle.States.RUNNING);
-      final FollowerState fs = role.getFollowerState().orElse(null);
+      FollowerState fs = role.getFollowerState().orElse(null);
       if (shouldWithholdVotes(candidateTerm)) {
         LOG.info("{}-{}: Withhold vote from candidate {} with term {}. State: leader={}, term={}, lastRpcElapsed={}",
             getMemberId(), role, candidateId, candidateTerm, state.getLeaderId(), state.getCurrentTerm(),
             fs != null? fs.getLastRpcTime().elapsedTimeMs() + "ms": null);
       } else if (state.recognizeCandidate(candidateId, candidateTerm)) {
         final boolean termUpdated = changeToFollower(candidateTerm, true, "recognizeCandidate:" + candidateId);
+        if (fs == null) {

Review comment:
       I think we can remove the if condition here and call `fs = role.getFollowerState().orElse(null);` always




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org