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


##########
core/src/main/scala/kafka/server/KafkaApis.scala:
##########
@@ -1192,17 +1192,18 @@ class KafkaApis(val requestChannel: RequestChannel,
         if (topicMetadata.head.errorCode != Errors.NONE.code) {
           (Errors.COORDINATOR_NOT_AVAILABLE, Node.noNode)
         } else {
-          val coordinatorEndpoint = topicMetadata.head.partitions.asScala
-            .find(_.partitionIndex == partition)
+          val coordinatorEndpoint = topicMetadata.head.partitions.stream()
+            .filter(_.partitionIndex() == partition)
             .filter(_.leaderId != MetadataResponse.NO_LEADER_ID)
-            .flatMap(metadata => OptionConverters.toScala(metadataCache.
-                getAliveBrokerNode(metadata.leaderId, 
request.context.listenerName)))
+            .map(metadata => 
metadataCache.getAliveBrokerNode(metadata.leaderId, 
request.context.listenerName))
+            .filter(_.isPresent)
+            .map(_.get)

Review Comment:
   I think we could reduce this to a flatMap with Optional#stream



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