chb2ab commented on code in PR #14444:
URL: https://github.com/apache/kafka/pull/14444#discussion_r1342844776


##########
core/src/main/scala/kafka/server/KafkaApis.scala:
##########
@@ -559,6 +560,30 @@ class KafkaApis(val requestChannel: RequestChannel,
     }
   }
 
+  case class LeaderNode(leaderId: Int, leaderEpoch: Int, node: Node)
+
+  private def getCurrentLeader(tp: TopicPartition): LeaderNode = {
+    val partitionInfoOrError = replicaManager.getPartitionOrError(tp)
+    var leaderId = -1
+    var leaderEpoch = -1
+    partitionInfoOrError match {
+      case Right(x) =>
+          leaderId = x.leaderReplicaIdOpt.getOrElse(-1)
+          leaderEpoch = x.getLeaderEpoch
+      case Left(x) =>
+        debug(s"Unable to retrieve local leaderId and Epoch with error $x, 
falling back to metadata cache")
+        val partitionInfo = metadataCache.getPartitionInfo(tp.topic, 
tp.partition)

Review Comment:
   I don't think so, getPartitionInfo returns an Option, the equivalent of null 
would be an empty option. We don't seem to null check this value elsewhere 
either.



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