junrao commented on code in PR #22963:
URL: https://github.com/apache/kafka/pull/22963#discussion_r4161362900


##########
clients/src/main/java/org/apache/kafka/common/record/internal/FileRecords.java:
##########
@@ -126,15 +126,21 @@ public FileChannel channel() {
     }
 
     /**
-     * Read log batches into the given buffer until there are no bytes 
remaining in the buffer or the end of the file
-     * is reached.
+     * Read log batches into the given buffer until there are no bytes 
remaining in the buffer or the end of these
+     * records is reached. A buffer with more room than the records left from 
{@code position} has its limit lowered
+     * so that only those records are read and the bytes which follow them in 
the file are left alone. The buffer is
+     * flipped before returning, so it is positioned at the first byte read 
and limited to the number of bytes read.
      *
      * @param buffer The buffer to write the batches to
-     * @param position Position in the buffer to read from
+     * @param position Position in these records to read from
+     * @throws IllegalArgumentException If the position is negative or past 
the end of these records
      * @throws IOException If an I/O error occurs, see {@link 
FileChannel#read(ByteBuffer, long)} for details on the
      * possible exceptions
      */
     public void readInto(ByteBuffer buffer, int position) throws IOException {
+        int available = availableBytes(position, buffer.remaining());

Review Comment:
   Even with this fix, this api is a bit dangerous. If called on a non-sliced 
FileRecords, it could expose uncommitted records. So, it would be useful to 
document that client-facing callers should not use this api on non-sliced 
active FileRecords.



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

Reply via email to