TaiJuWu commented on code in PR #20859:
URL: https://github.com/apache/kafka/pull/20859#discussion_r2570289277


##########
raft/src/main/java/org/apache/kafka/raft/KafkaRaftClient.java:
##########
@@ -500,11 +501,31 @@ public void initialize(
             kafkaRaftMetrics,
             externalKRaftMetrics
         );
+
+        // Set up listener to track voter set changes
+        partitionState.setVoterSetChangeListener((offset, voterSet) -> {
+            // We dont need to check high watermark here since it already 
check by
+            // hasJoined is not empty.
+            if (nodeId.isPresent() && hasJoined.isPresent()) {
+                ReplicaKey localReplicaKey = ReplicaKey.of(nodeId.getAsInt(), 
nodeDirectoryId);
+                if (voterSet.isVoter(localReplicaKey) && !hasJoined.get()) {
+                    logger.error("Detected that local node {} has been added 
to voter set at offset {}",
+                               localReplicaKey, offset);
+                    hasJoined = Optional.of(true);
+                }
+            }
+        });
+
         // Read the entire log
         logger.info("Reading KRaft snapshot and log as part of the 
initialization");
         partitionState.updateState();
         logger.info("Starting voters are {}", partitionState.lastVoterSet());
 
+        if (nodeId.isPresent() && canBecomeVoter && quorumConfig.autoJoin()
+                && isVoter(ReplicaKey.of(nodeId.getAsInt(), nodeDirectoryId))) 
{
+            hasJoined = Optional.of(true);
+        }
+

Review Comment:
   You are right here but if this is just quick fix for 4.2, I think this is ok 
for temporary solution, otherwise the new add test from me 
(`testRemovedControllerWontJoinAgain` and 
`testBootstrapVoterSetDoesNotSendAddVoterAfterRemove`) will flaky / fail which 
is not I expected.



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