chia7712 commented on a change in pull request #9162:
URL: https://github.com/apache/kafka/pull/9162#discussion_r511728437



##########
File path: core/src/main/scala/kafka/log/Log.scala
##########
@@ -1535,42 +1533,48 @@ class Log(@volatile private var _dir: File,
       }
 
       if (startOffset == maxOffsetMetadata.messageOffset) {
-        return emptyFetchDataInfo(maxOffsetMetadata, includeAbortedTxns)
+        emptyFetchDataInfo(maxOffsetMetadata, includeAbortedTxns)
       } else if (startOffset > maxOffsetMetadata.messageOffset) {
         val startOffsetMetadata = convertToOffsetMetadataOrThrow(startOffset)
-        return emptyFetchDataInfo(startOffsetMetadata, includeAbortedTxns)
-      }
+        emptyFetchDataInfo(startOffsetMetadata, 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
-      while (segmentEntry != null) {
-        val segment = segmentEntry.getValue
+        // 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 done = segmentEntry == null
+        var fetchDataInfo: FetchDataInfo = null
+        while (!done) {
+          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 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
+          val fetchInfo = segment.read(startOffset, maxLength, maxPosition, 
minOneMessage)

Review comment:
       good style. Will copy that.




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


Reply via email to