ahuang98 commented on code in PR #18240: URL: https://github.com/apache/kafka/pull/18240#discussion_r1900583739
########## raft/src/main/java/org/apache/kafka/raft/QuorumState.java: ########## @@ -529,26 +592,54 @@ public void transitionToFollower(int epoch, int leaderId, Endpoints endpoints) { ); } - public void transitionToCandidate() { + /** + * Transition to the "prospective" state. This means the replica experienced a fetch/election timeout or + * loss of election as candidate. Note, if the replica is transitioning from prospective to add voted state + * and there is no epoch change, it takes the route of prospectiveAddVotedState instead. + */ + public void transitionToProspective() { if (isObserver()) { throw new IllegalStateException( String.format( - "Cannot transition to Candidate since the local id (%s) and directory id (%s) " + + "Cannot transition to Prospective since the local id (%s) and directory id (%s) " + "is not one of the voters %s", localId, localDirectoryId, partitionState.lastVoterSet() ) ); - } else if (isLeader()) { - throw new IllegalStateException("Cannot transition to Candidate since the local broker.id=" + localId + - " since this node is already a Leader with state " + state); + } else if (isLeader() || isProspective()) { + throw new IllegalStateException("Cannot transition to Prospective since the local broker.id=" + localId + + " is state " + state); } int retries = isCandidate() ? candidateStateOrThrow().retries() + 1 : 1; + + durableTransitionTo( Review Comment: 🧠########## raft/src/main/java/org/apache/kafka/raft/QuorumState.java: ########## @@ -529,26 +592,54 @@ public void transitionToFollower(int epoch, int leaderId, Endpoints endpoints) { ); } - public void transitionToCandidate() { + /** + * Transition to the "prospective" state. This means the replica experienced a fetch/election timeout or + * loss of election as candidate. Note, if the replica is transitioning from prospective to add voted state + * and there is no epoch change, it takes the route of prospectiveAddVotedState instead. + */ + public void transitionToProspective() { if (isObserver()) { throw new IllegalStateException( String.format( - "Cannot transition to Candidate since the local id (%s) and directory id (%s) " + + "Cannot transition to Prospective since the local id (%s) and directory id (%s) " + "is not one of the voters %s", localId, localDirectoryId, partitionState.lastVoterSet() ) ); - } else if (isLeader()) { - throw new IllegalStateException("Cannot transition to Candidate since the local broker.id=" + localId + - " since this node is already a Leader with state " + state); + } else if (isLeader() || isProspective()) { + throw new IllegalStateException("Cannot transition to Prospective since the local broker.id=" + localId + + " is state " + state); } int retries = isCandidate() ? candidateStateOrThrow().retries() + 1 : 1; + + durableTransitionTo( Review Comment: 🤯 -- 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