Yunyung commented on code in PR #19613:
URL: https://github.com/apache/kafka/pull/19613#discussion_r2072290801


##########
storage/src/main/java/org/apache/kafka/storage/internals/log/UnifiedLog.java:
##########
@@ -2416,15 +2416,14 @@ public static void 
rebuildProducerState(ProducerStateManager producerStateManage
                                             Time time,
                                             boolean reloadFromCleanShutdown,
                                             String logPrefix) throws 
IOException {
-        List<Optional<Long>> offsetsToSnapshot = new ArrayList<>();
-        if (segments.nonEmpty()) {
-            long lastSegmentBaseOffset = 
segments.lastSegment().get().baseOffset();
-            Optional<LogSegment> lowerSegment = 
segments.lowerSegment(lastSegmentBaseOffset);
-            Optional<Long> nextLatestSegmentBaseOffset = 
lowerSegment.map(LogSegment::baseOffset);
-            offsetsToSnapshot.add(nextLatestSegmentBaseOffset);
-            offsetsToSnapshot.add(Optional.of(lastSegmentBaseOffset));
-        }
-        offsetsToSnapshot.add(Optional.of(lastOffset));
+        List<Long> offsetsToSnapshot = new ArrayList<>();
+        segments.lastSegment().ifPresent(lastSegment -> {
+            long lastSegmentBaseOffset = lastSegment.baseOffset();
+            Optional<Long> nextLatestSegmentBaseOffset = 
segments.lowerSegment(lastSegmentBaseOffset).map(LogSegment::baseOffset);

Review Comment:
   Done. Thanks.



##########
storage/src/main/java/org/apache/kafka/storage/internals/log/UnifiedLog.java:
##########
@@ -2443,11 +2442,9 @@ public static void 
rebuildProducerState(ProducerStateManager producerStateManage
             // To avoid an expensive scan through all the segments, we take 
empty snapshots from the start of the
             // last two segments and the last offset. This should avoid the 
full scan in the case that the log needs
             // truncation.
-            for (Optional<Long> offset : offsetsToSnapshot) {
-                if (offset.isPresent()) {
-                    producerStateManager.updateMapEndOffset(offset.get());
-                    producerStateManager.takeSnapshot();
-                }
+            for (Long offset : offsetsToSnapshot) {

Review Comment:
   Done.



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