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


##########
raft/src/main/java/org/apache/kafka/raft/QuorumState.java:
##########
@@ -402,58 +417,100 @@ public void transitionToUnattached(int epoch) {
     }
 
     /**
-     * Grant a vote to a candidate. We will transition/remain in Unattached
-     * state until either the election timeout expires or a leader is elected. 
In particular,
-     * we do not begin fetching until the election has concluded and
-     * {@link #transitionToFollower(int, int, Endpoints)} is invoked.
+     * Grant a vote to a candidate as Unattached. We will transition to 
Unattached with votedKey
+     * state and remain there until either the election timeout expires or we 
discover the leader.
      */
-    public void transitionToUnattachedVotedState(
+    public void unattachedAddVotedState(
         int epoch,
         ReplicaKey candidateKey
     ) {
         int currentEpoch = state.epoch();
         if (localId.isPresent() && candidateKey.id() == localId.getAsInt()) {
             throw new IllegalStateException(
                 String.format(
-                    "Cannot transition to Voted for %s and epoch %d since it 
matches the local " +
+                    "Cannot add voted key (%s) to current state (%s) in epoch 
%d since it matches the local " +
                     "broker.id",
                     candidateKey,
+                    state,
                     epoch
                 )
             );
         } else if (localId.isEmpty()) {
-            throw new IllegalStateException("Cannot transition to voted 
without a replica id");
-        } else if (epoch < currentEpoch) {
+            throw new IllegalStateException("Cannot add voted state without a 
replica id");
+        } else if (epoch != currentEpoch || !isUnattachedNotVoted()) {

Review Comment:
   this method is solely for the case of adding voted state to unattached in 
the same epoch (if higher epoch, we take the path of transitionToUnattached)
   
   the transitionToUnattached method has the following comment, I will 
duplicate it for this method too
   ```
        * Note, if we are transitioning from unattached and there is no epoch 
change, we take the path of
        * unattachedAddVotedState instead.
   ```



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

Reply via email to