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


##########
raft/src/main/java/org/apache/kafka/raft/KafkaRaftClient.java:
##########
@@ -3356,30 +3366,51 @@ private boolean 
shouldSendAddOrRemoveVoterRequest(FollowerState state, long curr
             quorumConfig.autoJoin() && 
state.hasUpdateVoterSetPeriodExpired(currentTimeMs);
     }
 
+    private boolean shouldSendAddVoterRequest(FollowerState state, long 
currentTimeMs) {
+        return canJoin && autoJoinEnable(state, currentTimeMs);
+    }
+
+    private boolean shouldSendRemoveVoterRequest(FollowerState state, long 
currentTimeMs) {
+        final var localReplicaKey = quorum.localReplicaKeyOrThrow();
+        final var voters = partitionState.lastVoterSet();
+
+        if (voters.voterIds().contains(localReplicaKey.id())) {
+            if (autoJoinEnable(state, currentTimeMs)) {
+                canJoin = true;
+                return true;
+            }
+        }
+        return false;
+    }
+
+
     private long pollFollowerAsObserver(FollowerState state, long 
currentTimeMs) {
         GracefulShutdown shutdown = this.shutdown.get();
+        final RequestSendResult sendResult;
+
         if (shutdown != null) {
             // If we are an observer, then we can shutdown immediately. We 
want to
             // skip potentially sending any add or remove voter RPCs.
             return 0;
-        } else if (shouldSendAddOrRemoveVoterRequest(state, currentTimeMs)) {
+        } else if (nodeId().isPresent() && shouldSendRemoveVoterRequest(state, 
currentTimeMs)) {

Review Comment:
   If the node is broker, its node id is empty so we need to add additional 
check to avoid broker send Remove or add voter request.
   
   see fail test 
[testObserverFetchWithNoLocalId](https://github.com/apache/kafka/pull/20859/commits/5ffb5843aad87dd60e1c8d94d314e43344bc1707)



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