kuoche1712003 opened a new pull request, #22200:
URL: https://github.com/apache/kafka/pull/22200
In Cleaner.cleanSegments, the upper bound offset for each LogSegment is
computed as the next segment's baseOffset when available, falling back to the
current segment's readNextOffset() for the last segment.
This is intentional: readNextOffset() reads from disk and is documented as
expensive, so the next segment's baseOffset (an O(1) field access) is preferred
whenever possible.
However, the previous code used:
```java
long upperBoundOffset = nextSegmentOpt.map(LogSegment::baseOffset)
.orElse(currentSegment.readNextOffset());
```
Optional.orElse evaluates its argument eagerly, so readNextOffset() was
invoked once per segment regardless of whether nextSegmentOpt was present,
defeating the optimization.
Replace orElse with a conditional expression so the fallback is only
evaluated when needed. orElseGet cannot be used here because readNextOffset()
declares IOException, which Supplier does not allow.
--
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]