showuon commented on code in PR #14128:
URL: https://github.com/apache/kafka/pull/14128#discussion_r1278970321
##########
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:
> 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.
Yes, that's my thought, given the `LogSegment#nextReadOffset` is expensive.
Any drawbacks for this solution?
--
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]