chia7712 commented on a change in pull request #9162: URL: https://github.com/apache/kafka/pull/9162#discussion_r468999490
########## File path: core/src/main/scala/kafka/log/Log.scala ########## @@ -1501,43 +1501,36 @@ class Log(@volatile private var _dir: File, case FetchTxnCommitted => fetchLastStableOffsetMetadata } - if (startOffset == maxOffsetMetadata.messageOffset) { - return emptyFetchDataInfo(maxOffsetMetadata, includeAbortedTxns) - } else if (startOffset > maxOffsetMetadata.messageOffset) { - val startOffsetMetadata = convertToOffsetMetadataOrThrow(startOffset) - return emptyFetchDataInfo(startOffsetMetadata, includeAbortedTxns) - } - - // Do the read on the segment with a base offset less than the target offset - // but if that segment doesn't contain any messages with an offset greater than that - // continue to read from successive segments until we get some messages or we reach the end of the log - while (segmentEntry != null) { - val segment = segmentEntry.getValue - - val maxPosition = { - // Use the max offset position if it is on this segment; otherwise, the segment size is the limit. - if (maxOffsetMetadata.segmentBaseOffset == segment.baseOffset) { - maxOffsetMetadata.relativePositionInSegment - } else { - segment.size - } - } - - val fetchInfo = segment.read(startOffset, maxLength, maxPosition, minOneMessage) - if (fetchInfo == null) { - segmentEntry = segments.higherEntry(segmentEntry.getKey) - } else { - return if (includeAbortedTxns) - addAbortedTransactions(startOffset, segmentEntry, fetchInfo) - else - fetchInfo - } + if (startOffset == maxOffsetMetadata.messageOffset) + emptyFetchDataInfo(maxOffsetMetadata, includeAbortedTxns) + else if (startOffset > maxOffsetMetadata.messageOffset) + emptyFetchDataInfo(convertToOffsetMetadataOrThrow(startOffset), includeAbortedTxns) + else { + // Do the read on the segment with a base offset less than the target offset + // but if that segment doesn't contain any messages with an offset greater than that + // continue to read from successive segments until we get some messages or we reach the end of the log + var currentEntry = segmentFloorEntry + Iterator.continually(currentEntry) Review comment: your are right! ---------------------------------------------------------------- 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