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


##########
raft/src/main/java/org/apache/kafka/raft/KafkaRaftClient.java:
##########
@@ -779,39 +781,51 @@ private VoteResponseData handleVoteRequest(
         VoteRequestData.PartitionData partitionRequest =
             request.topics().get(0).partitions().get(0);
 
-        int candidateId = partitionRequest.candidateId();
-        int candidateEpoch = partitionRequest.candidateEpoch();
+        int replicaId = partitionRequest.replicaId();
+        int replicaEpoch = partitionRequest.replicaEpoch();
+        boolean preVote = partitionRequest.preVote();
 
         int lastEpoch = partitionRequest.lastOffsetEpoch();
         long lastEpochEndOffset = partitionRequest.lastOffset();
-        if (lastEpochEndOffset < 0 || lastEpoch < 0 || lastEpoch >= 
candidateEpoch) {
+        boolean isIllegalEpoch = preVote ? lastEpoch > replicaEpoch : 
lastEpoch >= replicaEpoch;
+        if (isIllegalEpoch) {
+            logger.info(
+                "Received a vote request from replica {} with illegal epoch {} 
and last epoch {}",
+                replicaId,
+                replicaEpoch,
+                lastEpoch
+            );
+        }
+        if (lastEpochEndOffset < 0 || lastEpoch < 0 || isIllegalEpoch) {
             return buildVoteResponse(
                 requestMetadata.listenerName(),
                 requestMetadata.apiVersion(),
                 Errors.INVALID_REQUEST,
-                false
+                false,
+                preVote
             );
         }
 
-        Optional<Errors> errorOpt = validateVoterOnlyRequest(candidateId, 
candidateEpoch);
+        Optional<Errors> errorOpt = validateVoterOnlyRequest(replicaId, 
replicaEpoch);
         if (errorOpt.isPresent()) {
             return buildVoteResponse(
                 requestMetadata.listenerName(),
                 requestMetadata.apiVersion(),
                 errorOpt.get(),
-                false
+                false,
+                preVote

Review Comment:
   hm, I see, we don't need this because 
   1. we reset connections on the state transition from Prospective to 
Candidate (so we don't need to worry about improperly handling preVote=true 
responses after the transition to Candidate state)
   2. network client handles sending correct version of vote request to 
recipient - if we try to serialize preVote=true when recipient doesn't support 
preVote, network client will propagate back an `UNSUPPORTED_VERSION` error 
response (recipient will never receive this request and wouldn't send a 
response back with the default false preVote value)



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