showuon commented on a change in pull request #10749: URL: https://github.com/apache/kafka/pull/10749#discussion_r638544356
########## File path: raft/src/main/java/org/apache/kafka/raft/KafkaRaftClient.java ########## @@ -372,27 +371,23 @@ private void maybeFireLeaderChange() { @Override public void initialize() { - try { - quorum.initialize(new OffsetAndEpoch(log.endOffset().offset, log.lastFetchedEpoch())); + quorum.initialize(new OffsetAndEpoch(log.endOffset().offset, log.lastFetchedEpoch())); - long currentTimeMs = time.milliseconds(); - if (quorum.isLeader()) { - throw new IllegalStateException("Voter cannot initialize as a Leader"); - } else if (quorum.isCandidate()) { - onBecomeCandidate(currentTimeMs); - } else if (quorum.isFollower()) { - onBecomeFollower(currentTimeMs); - } + long currentTimeMs = time.milliseconds(); + if (quorum.isLeader()) { + throw new IllegalStateException("Voter cannot initialize as a Leader"); + } else if (quorum.isCandidate()) { + onBecomeCandidate(currentTimeMs); + } else if (quorum.isFollower()) { + onBecomeFollower(currentTimeMs); + } - // When there is only a single voter, become candidate immediately - if (quorum.isVoter() + // When there is only a single voter, become candidate immediately + if (quorum.isVoter() && quorum.remoteVoters().isEmpty() && !quorum.isCandidate()) { Review comment: No, you can see the change, you move this line `if (quorum.isVoter()` left (4 spaces I guess), so the following 2 lines should also move left. ########## File path: raft/src/main/java/org/apache/kafka/raft/QuorumState.java ########## @@ -116,7 +117,7 @@ public void initialize(OffsetAndEpoch logEndOffsetAndEpoch) throws IOException, if (election == null) { election = ElectionState.withUnknownLeader(0, voters); } - } catch (final IOException e) { + } catch (final Exception e) { Review comment: Yes, but I think `Exception` is covering too many "unexpected" exceptions. You can see the catch block, we are handling IOException case, not other exceptions. I think we can directly catch `UncheckedIOException` here. -- 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: us...@infra.apache.org