jsancio commented on code in PR #19661:
URL: https://github.com/apache/kafka/pull/19661#discussion_r2082432457


##########
clients/src/main/java/org/apache/kafka/common/record/FileRecords.java:
##########
@@ -54,34 +54,62 @@ public class FileRecords extends AbstractRecords implements 
Closeable {
      * The {@code FileRecords.open} methods should be used instead of this 
constructor whenever possible.
      * The constructor is visible for tests.
      */
-    FileRecords(File file,
-                FileChannel channel,
-                int start,
-                int end,
-                boolean isSlice) throws IOException {
+    FileRecords(
+        File file,
+        FileChannel channel,
+        int start,
+        int end
+    ) throws IOException {
         this.file = file;
         this.channel = channel;
         this.start = start;
         this.end = end;
-        this.isSlice = isSlice;
+        this.isSlice = false;
         this.size = new AtomicInteger();
 
-        if (isSlice) {
-            // don't check the file size if this is just a slice view
-            size.set(end - start);
-        } else {
-            if (channel.size() > Integer.MAX_VALUE)
-                throw new KafkaException("The size of segment " + file + " (" 
+ channel.size() +
-                        ") is larger than the maximum allowed segment size of 
" + Integer.MAX_VALUE);
+        if (channel.size() > Integer.MAX_VALUE) {
+            throw new KafkaException(
+                "The size of segment " + file + " (" + channel.size() +
+                ") is larger than the maximum allowed segment size of " + 
Integer.MAX_VALUE
+            );
+        }
+
+        int limit = Math.min((int) channel.size(), end);
+        size.set(limit - start);
 
-            int limit = Math.min((int) channel.size(), end);
-            size.set(limit - start);
+        // if this is not a slice, update the file pointer to the end of the 
file
+        // set the file position to the last byte in the file
+        channel.position(limit);
+
+        batches = batchesFrom(start);
+    }
 
-            // if this is not a slice, update the file pointer to the end of 
the file
-            // set the file position to the last byte in the file
-            channel.position(limit);
+    /**
+     * The {@code FileRecords.open} methods should be used instead of this 
constructor whenever possible.
+     *
+     * isSlice must be true. This overloaded constructor avoids having to 
declare a checked IO exception.
+     */
+    private FileRecords(
+        File file,
+        FileChannel channel,
+        int start,
+        int end,
+        boolean isSlice

Review Comment:
   Yes. I removed this since open doesn't specify the start.



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