showuon commented on code in PR #16602:
URL: https://github.com/apache/kafka/pull/16602#discussion_r1746751416
##########
core/src/main/scala/kafka/cluster/Partition.scala:
##########
@@ -1601,21 +1601,25 @@ class Partition(val topicPartition: TopicPartition,
s"high watermark (${localLog.highWatermark}) is lagging behind the " +
s"start offset from the beginning of this epoch ($epochStart)."))
- def getOffsetByTimestamp: Option[TimestampAndOffset] = {
- logManager.getLog(topicPartition).flatMap(log =>
log.fetchOffsetByTimestamp(timestamp, remoteLogManager))
+ def getOffsetByTimestamp: OffsetResultHolder = {
+ logManager.getLog(topicPartition)
+ .map(log => log.fetchOffsetByTimestamp(timestamp, remoteLogManager))
+ .getOrElse(OffsetResultHolder(timestampAndOffsetOpt = None))
}
// If we're in the lagging HW state after a leader election, throw
OffsetNotAvailable for "latest" offset
// or for a timestamp lookup that is beyond the last fetchable offset.
timestamp match {
case ListOffsetsRequest.LATEST_TIMESTAMP =>
maybeOffsetsError.map(e => throw e)
- .orElse(Some(new TimestampAndOffset(RecordBatch.NO_TIMESTAMP,
lastFetchableOffset, Optional.of(leaderEpoch))))
+ .getOrElse(OffsetResultHolder(Some(new
TimestampAndOffset(RecordBatch.NO_TIMESTAMP, lastFetchableOffset,
Optional.of(leaderEpoch)))))
case ListOffsetsRequest.EARLIEST_TIMESTAMP |
ListOffsetsRequest.EARLIEST_LOCAL_TIMESTAMP =>
getOffsetByTimestamp
case _ =>
- getOffsetByTimestamp.filter(timestampAndOffset =>
timestampAndOffset.offset < lastFetchableOffset)
- .orElse(maybeOffsetsError.map(e => throw e))
+ val offsetResultHolder = getOffsetByTimestamp
+ offsetResultHolder.maybeOffsetsError = maybeOffsetsError
+ offsetResultHolder.lastFetchableOffset = Some(lastFetchableOffset)
+ offsetResultHolder
}
Review Comment:
Could you help me understand this change please?
--
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]