This is an automated email from the ASF dual-hosted git repository. szetszwo pushed a commit to branch branch-2_readIndex in repository https://gitbox.apache.org/repos/asf/ratis.git
commit f50965d56103d6e80a050de32219bfca9b74970c Author: Kaijie Chen <[email protected]> AuthorDate: Mon Mar 20 18:02:53 2023 +0800 RATIS-1817. Do not send StartLeaderElection when leaderLastEntry is null (#857) (cherry picked from commit 050dc44b6224054dda01553f5cc9a69a7e32b2da) --- .../org/apache/ratis/server/impl/TransferLeadership.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/ratis-server/src/main/java/org/apache/ratis/server/impl/TransferLeadership.java b/ratis-server/src/main/java/org/apache/ratis/server/impl/TransferLeadership.java index beab02b67..74ada6541 100644 --- a/ratis-server/src/main/java/org/apache/ratis/server/impl/TransferLeadership.java +++ b/ratis-server/src/main/java/org/apache/ratis/server/impl/TransferLeadership.java @@ -184,12 +184,16 @@ public class TransferLeadership { 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()); - } + } + if (leaderLastEntry == null) { + // The transferee is expecting leaderLastEntry to be non-null, + // return NOT_UP_TO_DATE to indicate TransferLeadership should wait. + return new Result(Result.Type.NOT_UP_TO_DATE, "leaderLastEntry is 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; }
