showuon commented on code in PR #14128:
URL: https://github.com/apache/kafka/pull/14128#discussion_r1278858498


##########
core/src/main/java/kafka/log/remote/RemoteLogManager.java:
##########
@@ -525,6 +524,26 @@ private void maybeUpdateReadOffset(UnifiedLog log) throws 
RemoteStorageException
             }
         }
 
+        List<EnrichedLogSegment> enrichedLogSegments(UnifiedLog log, Long 
fromOffset, Long lastStableOffset) {
+            List<EnrichedLogSegment> enrichedLogSegments = new ArrayList<>();
+            List<LogSegment> segments = 
JavaConverters.seqAsJavaList(log.nonActiveLogSegmentsFrom(fromOffset).toSeq());
+            if (!segments.isEmpty()) {
+                int idx = 1;
+                for (; idx < segments.size(); idx++) {
+                    LogSegment previous = segments.get(idx - 1);
+                    LogSegment current = segments.get(idx);
+                    enrichedLogSegments.add(new EnrichedLogSegment(previous, 
current.baseOffset()));
+                }
+                // LogSegment#readNextOffset() is an expensive call, so we 
only call it when necessary.
+                int lastIdx = idx - 1;
+                if (segments.get(lastIdx).baseOffset() < lastStableOffset) {
+                    LogSegment last = segments.get(lastIdx);
+                    enrichedLogSegments.add(new EnrichedLogSegment(last, 
last.readNextOffset()));
+                }

Review Comment:
   Why can't we use the next segment's baseOffset here like the above did? 
   Also, I'm not very familiar with this, what's the difference between 
`readNextOffset` and `baseOffset of next segment`?



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