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


##########
core/src/main/scala/kafka/server/KafkaApis.scala:
##########
@@ -261,6 +264,62 @@ class KafkaApis(val requestChannel: RequestChannel,
     }
   }
 
+  def handleGetReplicaLogInfo(request: RequestChannel.Request): Unit = {
+    authHelper.authorizeClusterOperation(request, CLUSTER_ACTION)
+    val getReplicaLogInfoRequest = request.body[GetReplicaLogInfoRequest]
+    val data = getReplicaLogInfoRequest.data()
+    var partitionCount = 0
+    val topicPartitionIter = data.topicPartitions().iterator()
+    val responseData = new GetReplicaLogInfoResponseData()
+      .setBrokerEpoch(brokerEpochSupplier.get())
+    while (topicPartitionIter.hasNext && partitionCount < 
GetReplicaLogInfoRequest.MAX_PARTITIONS_PER_REQUEST) {
+      val topic = topicPartitionIter.next()
+      val maybeTopicName = metadataCache.getTopicName(topic.topicId())
+      val topicPartitionLogInfo = new 
GetReplicaLogInfoResponseData.TopicPartitionLogInfo()
+          .setTopicId(topic.topicId())
+      val partitionIter = topic.partitions().iterator()
+      if (maybeTopicName.isEmpty) {
+        while (partitionIter.hasNext && partitionCount < 
GetReplicaLogInfoRequest.MAX_PARTITIONS_PER_REQUEST) {
+          val partitionId = partitionIter.next()
+          topicPartitionLogInfo.partitionLogInfo().add(new 
GetReplicaLogInfoResponseData.PartitionLogInfo()
+              .setPartition(partitionId)
+              .setErrorCode(Errors.UNKNOWN_TOPIC_ID.code()))
+          partitionCount += 1
+        }
+      } else {
+        val topicName = maybeTopicName.get()
+        while (partitionIter.hasNext && partitionCount < 
GetReplicaLogInfoRequest.MAX_PARTITIONS_PER_REQUEST) {
+          val partitionId = partitionIter.next()
+          val topicPartition = new TopicPartition(topicName, partitionId)
+          val partitionLogInfo = 
replicaManager.getPartitionOrError(topicPartition) match {
+            case Left(err) => new 
GetReplicaLogInfoResponseData.PartitionLogInfo()
+              .setPartition(topicPartition.partition())
+              .setErrorCode(err.code())
+            case Right(partition) => partition.log match {
+              case None => new GetReplicaLogInfoResponseData.PartitionLogInfo()
+                .setErrorCode(Errors.LOG_DIR_NOT_FOUND.code())
+              case Some(log) => {
+                val logEndOffset = log.logEndOffset
+                val lastLeaderEpoch = log.latestEpoch.orElse(-1)
+                val leaderEpoch = partition.getLeaderEpoch
+                new GetReplicaLogInfoResponseData.PartitionLogInfo()
+                  .setPartition(partitionId)
+                  .setLogEndOffset(logEndOffset)
+                  .setCurrentLeaderEpoch(leaderEpoch)
+                  .setLastWrittenLeaderEpoch(lastLeaderEpoch)
+              }
+            }
+          }
+          topicPartitionLogInfo.partitionLogInfo().add(partitionLogInfo)
+          partitionCount += 1
+        }
+      }
+      responseData.topicPartitionLogInfoList().add(topicPartitionLogInfo)
+    }
+    responseData.setHasMoreData(partitionCount == 
GetReplicaLogInfoRequest.MAX_PARTITIONS_PER_REQUEST)

Review Comment:
   What if the partition count is right at 
GetReplicaLogInfoRequest.MAX_PARTITIONS_PER_REQUEST? Should we still return 
HasMoreData = true?



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