kevin-wu24 commented on code in PR #20859:
URL: https://github.com/apache/kafka/pull/20859#discussion_r2567198996


##########
raft/src/main/java/org/apache/kafka/raft/KafkaRaftClient.java:
##########
@@ -501,6 +503,14 @@ public void initialize(
         logger.info("Reading KRaft snapshot and log as part of the 
initialization");
         partitionState.updateState();
         logger.info("Starting voters are {}", partitionState.lastVoterSet());
+        if (nodeId.isPresent()) {
+            // if the the VotersRecord with the highest offset contain the 
node id of this node,
+            // mark it as already joined because it is already in the voter 
set.
+            // Check using ReplicaKey (id + directoryId) to handle KIP-853 
properly
+            hasJoined = partitionState.lastVoterSet().isVoter(
+                ReplicaKey.of(nodeId.getAsInt(), nodeDirectoryId)
+            );
+        }

Review Comment:
   ```
   if (quorumConfig.autoJoin() && partitionState.lastVoterSet().size() == 1
               && 
partitionState.lastVoterSet().isVoter(ReplicaKey.of(nodeId.getAsInt(), 
nodeDirectoryId)) {
   hasJoined = Optional.of(true);
   ```
   is the correct check. The code you have always evaluates to true because the 
left hand side of the || is always true for a controller in `intialize()`.



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