junrao commented on code in PR #23792:
URL: https://github.com/apache/kafka/pull/23792#discussion_r4418511700


##########
metadata/src/main/java/org/apache/kafka/metadata/KRaftMetadataCache.java:
##########
@@ -210,10 +210,10 @@ private 
Entry<Optional<List<DescribeTopicPartitionsResponsePartition>>, Integer>
             List<Integer> filteredReplicas = maybeFilterAliveReplicas(image, 
partition.replicas, listenerName, false);
             List<Integer> filteredIsr = maybeFilterAliveReplicas(image, 
partition.isr, listenerName, false);
             List<Integer> offlineReplicas = getOfflineReplicas(image, 
partition, listenerName);
-            Optional<Node> maybeLeader = getAliveEndpoint(image, 
partition.leader, listenerName);
+            BrokerRegistration leader = 
image.cluster().broker(partition.leader);

Review Comment:
   leader => leaderBroker ?



##########
metadata/src/main/java/org/apache/kafka/metadata/KRaftMetadataCache.java:
##########
@@ -244,14 +244,11 @@ private boolean isReplicaInOfflineDir(BrokerRegistration 
broker, PartitionRegist
     }
 
     /**
-     * Get the endpoint matching the provided listener if the broker is alive. 
Note that listeners can
+     * Check whether the broker is registered and has a listener named 
`listenerName`. Note that listeners can
      * be added dynamically, so a broker with a missing listener could be a 
transient error.
-     *
-     * @return None if broker is not alive or if the broker does not have a 
listener named `listenerName`.
      */
-    private Optional<Node> getAliveEndpoint(MetadataImage image, int id, 
ListenerName listenerName) {
-        return image.cluster().broker(id) == null ? Optional.empty() :
-            image.cluster().broker(id).node(listenerName.value());
+    private static boolean hasEndpoint(BrokerRegistration broker, ListenerName 
listenerName) {

Review Comment:
   Claude suggested the following.
   
   `isReplicaOffline (:236-238) and maybeFilterAliveReplicas (:102) repeat the 
listeners().containsKey(listenerName.value()) check, so they could reuse 
hasEndpoint.`



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