kaijchen commented on code in PR #845:
URL: https://github.com/apache/ratis/pull/845#discussion_r1140975322


##########
ratis-server/src/main/java/org/apache/ratis/server/impl/TransferLeadership.java:
##########
@@ -92,50 +188,135 @@ boolean isSteppingDown() {
     return pending.get() != null;
   }
 
+  static Result isFollowerUpToDate(FollowerInfo follower, TermIndex 
leaderLastEntry) {
+    if (follower == null) {
+      return Result.NULL_FOLLOWER;
+    } else if (leaderLastEntry != null) {
+      final long followerMatchIndex = follower.getMatchIndex();
+      if (followerMatchIndex < leaderLastEntry.getIndex()) {
+        return new Result(Result.Type.NOT_UP_TO_DATE, "followerMatchIndex = " 
+ followerMatchIndex
+            + " < leaderLastEntry.getIndex() = " + leaderLastEntry.getIndex());
+      }
+    }
+    return Result.SUCCESS;
+  }
+
+  private Result sendStartLeaderElection(FollowerInfo follower, TermIndex 
lastEntry) {
+    final Result result = isFollowerUpToDate(follower, lastEntry);
+    if (result != Result.SUCCESS) {
+      return result;
+    }
+
+    final TermIndex currLastEntry = server.getState().getLastEntry();
+    if (ServerState.compareLog(currLastEntry, lastEntry) != 0) {
+      return new Result(Result.Type.LAST_ENTRY_CHANGED,

Review Comment:
   I'm wondering why we should abort TransferLeadership when 
`LAST_ENTRY_CHANGED`.
   The `StartLeaderElection` request shoud be idempotent (by including sender's 
term).
   
   Then, as long as follower is up-to-date, it is OK to send the request.
   i.e. Only check `isFollowerUpToDate(follower, currLastEntry)`.
   



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

Reply via email to