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


##########
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:
   For a given 
[LogSegment](https://github.com/apache/kafka/blob/trunk/core/src/main/scala/kafka/log/LogSegment.scala),
 we know about start-offset (base-offset) but not the end offset. 
`readNextOffset` denotes `end-offset-of-that-segment` + 1.
   
   To exclude the active segments, we are using `log.nonActiveLogSegmentsFrom`. 
With this, we cannot use the active-segment-base-offset as the operations are 
not done atomically. (the active segment might gets rotated in the mean time).
   
   If we want to avoid `LogSegment#nextReadOffset` operation altogether, then 
we can list all the segments including the active and discard/filter the final 
entry.



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

Reply via email to