kevin-wu24 commented on code in PR #23737:
URL: https://github.com/apache/kafka/pull/23737#discussion_r4259511417
##########
clients/src/main/java/org/apache/kafka/common/record/internal/FileRecords.java:
##########
@@ -128,15 +126,19 @@ 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
+ * this FileRecords object is reached.
*
* @param buffer The buffer to write the batches to
- * @param position Position in the buffer to read from
+ * @param position Position to start reading from, relative to the start
of this FileRecords object
* @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());
+ if (buffer.remaining() > available) {
Review Comment:
> This check is unnecessary since it's always true.
I am not sure if I agree with this statement. For example, on the first call
for an 8MiB buffer at position 0 and trying to read a `FileRecords` slice of >
8MiB, `available = availableBytes(position, buffer.remaining()) =
buffer.remaining() == 8MiB`, which makes this if evaluate to false. What do you
think?
> Also, the error message in availableBytes() seems very specific to the
slice() call
Sure, I think it is fine to add this before entering `availableBytes`.
##########
clients/src/main/java/org/apache/kafka/common/record/internal/FileRecords.java:
##########
@@ -128,15 +126,19 @@ 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
+ * this FileRecords object is reached.
*
* @param buffer The buffer to write the batches to
- * @param position Position in the buffer to read from
+ * @param position Position to start reading from, relative to the start
of this FileRecords object
* @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());
+ if (buffer.remaining() > available) {
Review Comment:
> This check is unnecessary since it's always true.
I am not sure if I agree with this statement. For example, on the first call
for an 8MiB buffer at position 0 and trying to read a `FileRecords` slice of >
8MiB, `available = availableBytes(position, buffer.remaining()) =
buffer.remaining() == 8MiB`, which makes this if evaluate to false. What do you
think?
> Also, the error message in availableBytes() seems very specific to the
slice() call
Sure, I think it is fine to add this before entering `availableBytes`.
--
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]