shantanukawale-stripe commented on code in PR #23880:
URL: https://github.com/apache/kafka/pull/23880#discussion_r4423075367


##########
storage/src/main/java/org/apache/kafka/storage/internals/log/UnifiedLog.java:
##########
@@ -1815,9 +1815,18 @@ public boolean isEmpty() {
     private Optional<FileRecords.TimestampAndOffset> 
searchOffsetInLocalLog(long targetTimestamp, long startOffset) throws 
IOException {
         // Cache to avoid race conditions.
         List<LogSegment> segments = logSegments();
-        for (LogSegment segment : segments) {
+        // Use base offsets to skip segments before the one containing 
startOffset without reading their tails.
+        int firstSegmentIndex = 0;
+        for (int i = 1; i < segments.size() && segments.get(i).baseOffset() <= 
startOffset; i++) {
+            firstSegmentIndex = i;
+        }
+        for (LogSegment segment : segments.subList(firstSegmentIndex, 
segments.size())) {
             if (segment.largestTimestamp() >= targetTimestamp) {
-                return segment.findOffsetByTimestamp(targetTimestamp, 
startOffset, config().maxDecompressedMessageBytes());
+                Optional<FileRecords.TimestampAndOffset> timestampAndOffset =
+                        segment.findOffsetByTimestamp(targetTimestamp, 
startOffset, config().maxDecompressedMessageBytes());

Review Comment:
   Opened both follow-up PRs under KAFKA-21317:
   
   - #24028 fixes both early-return paths in `RemoteLogManager`; all 101 
`RemoteLogManagerTest` cases pass locally on Java 17.
   - #24027 fixes `MAX_TIMESTAMP` returning records below the log start offset; 
all 215 `UnifiedLogTest` cases pass locally on Java 17.
   
   Both also pass storage Checkstyle, Spotless, and SpotBugs. The 
`MAX_TIMESTAMP` follow-up addresses the lower offset bound; #23780 separately 
addresses the fetchable upper bound.



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

Reply via email to