ahuang98 commented on code in PR #18240: URL: https://github.com/apache/kafka/pull/18240#discussion_r1900614259
########## raft/src/main/java/org/apache/kafka/raft/QuorumState.java: ########## @@ -562,6 +653,26 @@ public void transitionToCandidate() { )); } + private void checkValidTransitionToCandidate() { + if (isObserver()) { + throw new IllegalStateException( + String.format( + "Cannot transition to Candidate since the local id (%s) and directory id (%s) " + + "is not one of the voters %s", + localId, + localDirectoryId, + partitionState.lastVoterSet() + ) + ); + } + // Leader state can never transition to Candidate state + // Only Prospective is allowed to transition to Candidate, unless the local replica is the only voter + if (isLeader() || (!isProspective() && !isOnlyVoter())) { Review Comment: Thanks! I'll add the logic for short-circuiting transitions for only-voters. This also allows our invariant - only Prospective can transition to Candidate - to remain simple w/o edge cases. -- 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: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org