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


##########
core/src/main/scala/kafka/server/metadata/KRaftMetadataCache.scala:
##########
@@ -141,17 +144,33 @@ class KRaftMetadataCache(val brokerId: Int) extends 
MetadataCache with Logging w
     }
   }
 
+  /**
+   * Return topic partition metadata for the given topic, listener and index 
range. Also, return a boolean value to
+   * indicate whether there are more partitions with index equal or larger 
than the upper index.
+   *
+   * @param image                       The metadata image
+   * @param topicName                   The name of the topic.
+   * @param listenerName                The listener name.
+   * @param startIndex                  The smallest index of the partitions 
to be included in the result.
+   * @param upperIndex                  The upper limit of the index of the 
partitions to be included in the result.
+   *                                    Note that, the upper index can be 
larger than the largest partition index in
+   *                                    this topic.
+   * @return                            A collection of topic partition 
metadata and whether there are more partitions.
+   */
   private def getPartitionMetadataForDescribeTopicResponse(
     image: MetadataImage,
     topicName: String,
-    listenerName: ListenerName
-  ): Option[List[DescribeTopicPartitionsResponsePartition]] = {
+    listenerName: ListenerName,
+    startIndex: Int,
+    upperIndex: Int
+  ): (Option[List[DescribeTopicPartitionsResponsePartition]], Boolean) = {
     Option(image.topics().getTopic(topicName)) match {
-      case None => None
+      case None => (None, false)
       case Some(topic) => {
-        val partitions = Some(topic.partitions().entrySet().asScala.map { 
entry =>
-          val partitionId = entry.getKey
-          val partition = entry.getValue
+        val result = new ListBuffer[DescribeTopicPartitionsResponsePartition]()
+        val endIndex = upperIndex.min(topic.partitions().size())
+        for (partitionId <- startIndex until endIndex) {
+          val partition = topic.partitions().get(partitionId)

Review Comment:
   Actually it is not possible, the partition index starts with 0 and 
increments by 1.
   Then what is the case if the partition does not exist?



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