CalvinConfluent commented on code in PR #14612:
URL: https://github.com/apache/kafka/pull/14612#discussion_r1450765739
##########
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:
Do you mean the partitions in the topic are not consecutive? Just realize it
is possible.
--
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]