Xushaohong commented on a change in pull request #560:
URL: https://github.com/apache/ratis/pull/560#discussion_r766377535
##########
File path:
ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java
##########
@@ -583,6 +583,12 @@ synchronized void changeToCandidate(boolean
forceStartLeaderElection) {
if (state.shouldNotifyExtendedNoLeader()) {
stateMachine.followerEvent().notifyExtendedNoLeader(getRoleInfoProto());
}
+ // Candidate shall not start leader election in these cases in case of
+ // possible NPE caused by conf.getPeer().getPriority()
+ if (!getRaftConf().containsInBothConfs(getId())) {
+ LOG.warn("{} find invalid configuration {}, skip start leader election",
this, getRaftConf());
+ return;
+ }
Review comment:
> The conf may be changed later on. Therefore, let's don't check it here
and check null in LeaderElection.getHigherPriorityPeers(..) as below.
The check here in the getHigherPriorityPeers is not enough. The possible
case I tested is that bootstrapped follower changes role from follower to
candidate and start leader election, as it has an empty conf, it will become
leader directly due to ```if (others.isEmpty()) { r = new
ResultAndTerm(Result.PASSED, electionTerm);```. Once it becomes another leader,
it won't receive any requests from the original leader as the term is
increased. Meanwhile, the original leader stuck in sending appendEntries to
'follower'.
I sightly changed the check place. PTAL
@szetszwo
--
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]