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


##########
raft/src/main/java/org/apache/kafka/raft/KafkaRaftClient.java:
##########
@@ -985,36 +982,54 @@ private boolean handleVoteResponse(
                     maybeTransitionForward(state, currentTimeMs);
                 } else {
                     state.recordRejectedVote(remoteNodeId);
-                    maybeCandidateStartBackingOff(currentTimeMs);
+                    maybeHandleElectionLoss(currentTimeMs);
                 }
             } else {
-                logger.debug("Ignoring vote response {} since we are no longer 
a VotingState " +
-                        "(Prospective or Candidate) in epoch {}",
-                    partitionResponse, quorum.epoch());
+                logger.debug(
+                    "Ignoring vote response {} since we are no longer a 
NomineeState " +
+                    "(Prospective or Candidate) in epoch {}",
+                    partitionResponse,
+                    quorum.epoch()
+                );
             }
             return true;
         } else {
             return handleUnexpectedError(error, responseMetadata);
         }
     }
 
-    private void maybeCandidateStartBackingOff(long currentTimeMs) {
-        // If in candidate state and vote is rejected, go immediately to a 
random, exponential backoff. The
-        // backoff starts low to prevent needing to wait the entire election 
timeout when the vote
-        // result has already been determined. The randomness prevents the 
next election from being
-        // gridlocked with another nominee due to timing. The exponential 
aspect limits epoch churn when
-        // the replica has failed multiple elections in succession.
+    /**
+     * On election loss, if replica is prospective it will transition to 
unattached or follower state.
+     * If replica is candidate, it will start backing off.
+     */
+    private void maybeHandleElectionLoss(long currentTimeMs) {

Review Comment:
   Like the following?
   ```
       private void maybeHandleElectionLoss(NomineeState state, long 
currentTimeMs) {
           if (state instanceof CandidateState) {
               CandidateState candidate = (CandidateState) state;
           ...
           else if (state instanceof ProspectiveState) {
               ProspectiveState prospective = (ProspectiveState) state;
           ...
   ```
   Is the intention of the additional parameter to make it clear this method 
should be called on NomineeState? This seems a bit redundant with the existing 
QuorumState helpers (e.g. isCandidate() and candidateStateOrThrow()).



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