chia7712 commented on code in PR #18801:
URL: https://github.com/apache/kafka/pull/18801#discussion_r1978888530


##########
metadata/src/main/java/org/apache/kafka/metadata/MetadataCache.java:
##########
@@ -0,0 +1,237 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.metadata;
+
+import org.apache.kafka.admin.BrokerMetadata;
+import org.apache.kafka.common.Cluster;
+import org.apache.kafka.common.Node;
+import org.apache.kafka.common.PartitionInfo;
+import org.apache.kafka.common.TopicPartition;
+import org.apache.kafka.common.Uuid;
+import org.apache.kafka.common.internals.Topic;
+import org.apache.kafka.common.message.DescribeClientQuotasRequestData;
+import org.apache.kafka.common.message.DescribeClientQuotasResponseData;
+import org.apache.kafka.common.message.DescribeTopicPartitionsResponseData;
+import org.apache.kafka.common.message.DescribeUserScramCredentialsRequestData;
+import 
org.apache.kafka.common.message.DescribeUserScramCredentialsResponseData;
+import org.apache.kafka.common.message.MetadataResponseData;
+import org.apache.kafka.common.network.ListenerName;
+import org.apache.kafka.image.MetadataImage;
+import org.apache.kafka.server.common.FinalizedFeatures;
+import org.apache.kafka.server.common.MetadataVersion;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+public interface MetadataCache extends ConfigRepository {
+
+    /**
+     * Return topic metadata for a given set of topics and listener. See 
KafkaApis#handleTopicMetadataRequest for details
+     * on the use of the two boolean flags.
+     *
+     * @param topics                      The set of topics.
+     * @param listenerName                The listener name.
+     * @param errorUnavailableEndpoints   If true, we return an error on 
unavailable brokers. This is used to support
+     *                                    MetadataResponse version 0.
+     * @param errorUnavailableListeners   If true, return LEADER_NOT_AVAILABLE 
if the listener is not found on the leader.
+     *                                    This is used for MetadataResponse 
versions 0-5.
+     * @return                            A collection of topic metadata.
+     */
+    List<MetadataResponseData.MetadataResponseTopic> getTopicMetadata(
+        Set<String> topics,
+        ListenerName listenerName,
+        boolean errorUnavailableEndpoints,
+        boolean errorUnavailableListeners);
+
+    Set<String> getAllTopics();
+
+    Set<TopicPartition> getTopicPartitions(String topicName);

Review Comment:
   it seems the usage of this method is to get the number of partitions. could 
you please rewrite the tests to use `numPartitions` instead?



##########
metadata/src/main/java/org/apache/kafka/metadata/MetadataCache.java:
##########
@@ -0,0 +1,237 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.metadata;
+
+import org.apache.kafka.admin.BrokerMetadata;
+import org.apache.kafka.common.Cluster;
+import org.apache.kafka.common.Node;
+import org.apache.kafka.common.PartitionInfo;
+import org.apache.kafka.common.TopicPartition;
+import org.apache.kafka.common.Uuid;
+import org.apache.kafka.common.internals.Topic;
+import org.apache.kafka.common.message.DescribeClientQuotasRequestData;
+import org.apache.kafka.common.message.DescribeClientQuotasResponseData;
+import org.apache.kafka.common.message.DescribeTopicPartitionsResponseData;
+import org.apache.kafka.common.message.DescribeUserScramCredentialsRequestData;
+import 
org.apache.kafka.common.message.DescribeUserScramCredentialsResponseData;
+import org.apache.kafka.common.message.MetadataResponseData;
+import org.apache.kafka.common.network.ListenerName;
+import org.apache.kafka.image.MetadataImage;
+import org.apache.kafka.server.common.FinalizedFeatures;
+import org.apache.kafka.server.common.MetadataVersion;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+public interface MetadataCache extends ConfigRepository {
+
+    /**
+     * Return topic metadata for a given set of topics and listener. See 
KafkaApis#handleTopicMetadataRequest for details
+     * on the use of the two boolean flags.
+     *
+     * @param topics                      The set of topics.
+     * @param listenerName                The listener name.
+     * @param errorUnavailableEndpoints   If true, we return an error on 
unavailable brokers. This is used to support
+     *                                    MetadataResponse version 0.
+     * @param errorUnavailableListeners   If true, return LEADER_NOT_AVAILABLE 
if the listener is not found on the leader.
+     *                                    This is used for MetadataResponse 
versions 0-5.
+     * @return                            A collection of topic metadata.
+     */
+    List<MetadataResponseData.MetadataResponseTopic> getTopicMetadata(
+        Set<String> topics,
+        ListenerName listenerName,
+        boolean errorUnavailableEndpoints,
+        boolean errorUnavailableListeners);
+
+    Set<String> getAllTopics();
+
+    Set<TopicPartition> getTopicPartitions(String topicName);
+
+    boolean hasAliveBroker(int brokerId);
+
+    List<BrokerMetadata> getAliveBrokers();

Review Comment:
   this is used by test infra only, and we can rewrite the check by 
`hasAliveBroker`. 
   
   *before*
   ```
           TestUtils.waitForCondition(() ->
                   brokers().values().stream().allMatch(brokerServer -> 
brokerServer.metadataCache().getAliveBrokers().size() == brokers.size()),
               "Failed to wait for publisher to publish the metadata update to 
each broker.");
   ```
   
   *after*
   ```
           TestUtils.waitForCondition(() ->
                   brokers.values().stream().map(BrokerServer::metadataCache)
                       .allMatch(cache -> brokers.values().stream().map(b -> 
b.config().brokerId()).allMatch(cache::hasAliveBroker)),
               "Failed to wait for publisher to publish the metadata update to 
each broker.");
   ```



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