runzhiwang commented on pull request #372:
URL: https://github.com/apache/incubator-ratis/pull/372#issuecomment-750245608


   > Let's add new TransferLeadership class and put all the code there.
   
   @szetszwo Do I need to put the following check code in TransferLeadership 
class ? if so, I need to change some method from private to publibc, such as 
`checkLeaderState`
        ```
   CompletableFuture<RaftClientReply> reply = checkLeaderState(request, null, 
false);
         if (reply != null) {
           return reply;
         }
   
         if (getId().equals(request.getNewLeader())) {
           return CompletableFuture.completedFuture(newSuccessReply(request));
         }
   
         final RaftConfigurationImpl conf = getRaftConf();
         final LeaderStateImpl leaderState = role.getLeaderStateNonNull();
   
         // make sure there is no raft reconfiguration in progress
         if (!conf.isStable() || leaderState.inStagingState() || 
!state.isConfCommitted()) {
           String msg = getMemberId() + " refused to transfer leadership to 
peer " + request.getNewLeader() +
               " when raft reconfiguration in progress.";
           return logAndReturnTransferLeadershipFail(request, msg);
         }
   
         if (!conf.containsInConf(request.getNewLeader())) {
           String msg = getMemberId() + " refused to transfer leadership to 
peer " + request.getNewLeader() +
               " as it is not in " + conf;
           return logAndReturnTransferLeadershipFail(request, msg);
         }
   
         if (!conf.isHighestPriority(request.getNewLeader())) {
           String msg = getMemberId() + " refused to transfer leadership to 
peer " + request.getNewLeader() +
               " as it does not has highest priority " + conf;
           return logAndReturnTransferLeadershipFail(request, msg);
         }
   ```


----------------------------------------------------------------
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:
[email protected]


Reply via email to