FrankYang0529 commented on code in PR #19596:
URL: https://github.com/apache/kafka/pull/19596#discussion_r2067638473


##########
raft/src/main/java/org/apache/kafka/snapshot/Snapshots.java:
##########
@@ -159,23 +160,26 @@ public static Path markForDelete(Path logDir, 
OffsetAndEpoch snapshotId) {
         }
     }
 
-    public static long lastContainedLogTimestamp(RawSnapshotReader reader) {
-        try (RecordsSnapshotReader<ByteBuffer> recordsSnapshotReader =
-             RecordsSnapshotReader.of(
-                 reader,
-                 IdentitySerde.INSTANCE,
-                 new BufferSupplier.GrowableBufferSupplier(),
-                 KafkaRaftClient.MAX_BATCH_SIZE_BYTES,
-                 true
-             )
-        ) {
-            return recordsSnapshotReader.lastContainedLogTimestamp();
+    public static long lastContainedLogTimestamp(RawSnapshotReader reader, 
LogContext logContext) {
+        try (var bufferSupplier = new BufferSupplier.GrowableBufferSupplier()) 
{
+            try (RecordsSnapshotReader<ByteBuffer> recordsSnapshotReader =
+                RecordsSnapshotReader.of(
+                    reader,
+                    IdentitySerde.INSTANCE,
+                    bufferSupplier,
+                    KafkaRaftClient.MAX_BATCH_SIZE_BYTES,
+                    true,
+                    logContext
+                )
+            ) {
+                return recordsSnapshotReader.lastContainedLogTimestamp();
+            }
         }

Review Comment:
   How about using a single try block for this?
   ```suggestion
           try (var bufferSupplier = new 
BufferSupplier.GrowableBufferSupplier();
                RecordsSnapshotReader<ByteBuffer> recordsSnapshotReader = 
RecordsSnapshotReader.of(
                    reader,
                    IdentitySerde.INSTANCE,
                    bufferSupplier,
                    KafkaRaftClient.MAX_BATCH_SIZE_BYTES,
                    true,
                    logContext
                )) {
               return recordsSnapshotReader.lastContainedLogTimestamp();
           }
   ```



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