ahuang98 commented on code in PR #18240:
URL: https://github.com/apache/kafka/pull/18240#discussion_r1900621199


##########
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:
   todo: add kafkaraftclienttest which checks initialization of only voter with 
votedKey=localId does not cause it to be brought up in prospective state



-- 
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]

Reply via email to