chia7712 commented on code in PR #15618: URL: https://github.com/apache/kafka/pull/15618#discussion_r1543390343
########## core/src/main/scala/kafka/log/UnifiedLog.scala: ########## @@ -1320,10 +1320,8 @@ class UnifiedLog(@volatile var logStartOffset: Long, // constant time access while being safe to use with concurrent collections unlike `toArray`. val segmentsCopy = logSegments.toBuffer val latestTimestampSegment = segmentsCopy.maxBy(_.maxTimestampSoFar) - val latestTimestampAndOffset = latestTimestampSegment.maxTimestampAndOffsetSoFar - - Some(new TimestampAndOffset(latestTimestampAndOffset.timestamp, - latestTimestampAndOffset.offset, + val batch = latestTimestampSegment.log.batches().asScala.maxBy(_.maxTimestamp()) Review Comment: @junrao thanks for feedback. I use the max timestamp to find the "first" batch instead of using offset index. It seems to me using max timestamp is more simple since the offset stored by `maxTimestampAndOffsetSoFar` could be either the last offset or offset of max timestamp. Hence we have to use condition `baseOffset <= offset <= lastOffset` to find batch. I'm ok to use offset if using max timestamp to find first batch have any side effect. -- 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