CalvinConfluent commented on code in PR #15265:
URL: https://github.com/apache/kafka/pull/15265#discussion_r1505043369


##########
tools/src/main/java/org/apache/kafka/tools/TopicCommand.java:
##########
@@ -558,20 +568,53 @@ public void describeTopic(TopicCommandOptions opts) 
throws ExecutionException, I
             } else {
                 ensureTopicExists(topics, opts.topic().orElse(""), 
!opts.ifExists());
             }
-            List<org.apache.kafka.clients.admin.TopicDescription> 
topicDescriptions = new ArrayList<>();
 
             if (!topicIds.isEmpty()) {
                 Map<Uuid, org.apache.kafka.clients.admin.TopicDescription> 
descTopics =
                     
adminClient.describeTopics(TopicCollection.ofTopicIds(topicIds)).allTopicIds().get();
-                topicDescriptions = new ArrayList<>(descTopics.values());
+                describeTopicsFollowUp(new ArrayList<>(descTopics.values()), 
opts);
+                return;
             }
 
             if (!topics.isEmpty()) {
-                Map<String, org.apache.kafka.clients.admin.TopicDescription> 
descTopics =
-                    
adminClient.describeTopics(TopicCollection.ofTopicNames(topics)).allTopicNames().get();
-                topicDescriptions = new ArrayList<>(descTopics.values());
+                final int partitionSizeLimit = 
opts.partitionSizeLimitPerResponse().orElse(2000);
+                try {
+                    Iterator<Map.Entry<String, 
KafkaFuture<org.apache.kafka.clients.admin.TopicDescription>>> 
descTopicIterator =
+                        
adminClient.describeTopics(TopicCollection.ofTopicNames(topics),
+                            new 
DescribeTopicsOptions().useDescribeTopicsApi(true)
+                                
.partitionSizeLimitPerResponse(partitionSizeLimit)).topicNameValuesIterator();
+                    while (descTopicIterator.hasNext()) {
+                        List<org.apache.kafka.clients.admin.TopicDescription> 
topicDescriptions = new ArrayList<>();
+                        for (int counter = 0; counter < partitionSizeLimit && 
descTopicIterator.hasNext();) {
+                            org.apache.kafka.clients.admin.TopicDescription 
topicDescription = descTopicIterator.next().getValue().get();
+                            topicDescriptions.add(topicDescription);
+                            counter += topicDescription.partitions().size();
+                        }
+                        describeTopicsFollowUp(topicDescriptions, opts);

Review Comment:
   Refactored.



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