dajac commented on a change in pull request #9630: URL: https://github.com/apache/kafka/pull/9630#discussion_r533975842
########## File path: core/src/main/scala/kafka/server/ReplicaManager.scala ########## @@ -1862,23 +1864,51 @@ class ReplicaManager(val config: KafkaConfig, } } - def lastOffsetForLeaderEpoch(requestedEpochInfo: Map[TopicPartition, OffsetsForLeaderEpochRequest.PartitionData]): Map[TopicPartition, EpochEndOffset] = { - requestedEpochInfo.map { case (tp, partitionData) => - val epochEndOffset = getPartition(tp) match { - case HostedPartition.Online(partition) => - partition.lastOffsetForLeaderEpoch(partitionData.currentLeaderEpoch, partitionData.leaderEpoch, - fetchOnlyFromLeader = true) - - case HostedPartition.Offline => - new EpochEndOffset(Errors.KAFKA_STORAGE_ERROR, UNDEFINED_EPOCH, UNDEFINED_EPOCH_OFFSET) - - case HostedPartition.None if metadataCache.contains(tp) => - new EpochEndOffset(Errors.NOT_LEADER_OR_FOLLOWER, UNDEFINED_EPOCH, UNDEFINED_EPOCH_OFFSET) - - case HostedPartition.None => - new EpochEndOffset(Errors.UNKNOWN_TOPIC_OR_PARTITION, UNDEFINED_EPOCH, UNDEFINED_EPOCH_OFFSET) + def lastOffsetForLeaderEpoch( + requestedEpochInfo: Seq[OffsetForLeaderTopic] + ): Seq[OffsetForLeaderTopicResult] = { + requestedEpochInfo.map { offsetForLeaderTopic => + val partitions = offsetForLeaderTopic.partitions.asScala.map { offsetForLeaderPartition => + val tp = new TopicPartition(offsetForLeaderTopic.topic, offsetForLeaderPartition.partition) + getPartition(tp) match { + case HostedPartition.Online(partition) => + val currentLeaderEpochOpt = + if (offsetForLeaderPartition.currentLeaderEpoch == RecordBatch.NO_PARTITION_LEADER_EPOCH) + Optional.empty[Integer] + else + Optional.of[Integer](offsetForLeaderPartition.currentLeaderEpoch) + + partition.lastOffsetForLeaderEpoch( + currentLeaderEpochOpt, + offsetForLeaderPartition.leaderEpoch, + fetchOnlyFromLeader = true) + + case HostedPartition.Offline => + new OffsetForLeaderPartitionResult() + .setPartition(offsetForLeaderPartition.partition) + .setErrorCode(Errors.KAFKA_STORAGE_ERROR.code) + .setLeaderEpoch(UNDEFINED_EPOCH) Review comment: That makes sense. Let me use them where ever possible. I will also add a default value (-1) for `EndOffset` in the schema. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org