kevin-wu24 commented on code in PR #23737:
URL: https://github.com/apache/kafka/pull/23737#discussion_r4274381201


##########
raft/src/main/java/org/apache/kafka/raft/internals/RecordsIterator.java:
##########
@@ -136,9 +136,11 @@ private MemoryRecords createMemoryRecords(FileRecords 
fileRecords) {
 
         MemoryRecords memoryRecords = readFileRecords(fileRecords, buffer);
 
-        // firstBatchSize() is always non-null because the minimum buffer is 
HEADER_SIZE_UP_TO_MAGIC.
-        int firstBatchSize = memoryRecords.firstBatchSize();
-        if (firstBatchSize <= buffer.remaining()) {
+        Integer firstBatchSize = memoryRecords.firstBatchSize();
+        int bytesAvailable = buffer.remaining() + (fileRecords.sizeInBytes() - 
bytesRead);
+        if (firstBatchSize == null || firstBatchSize <= buffer.remaining() ||
+            firstBatchSize > bytesAvailable

Review Comment:
   I see. Basically, repeated `createMemoryRecords()` invocations no longer 
guarantee that `bytesRead >= recordSize` when: buffer capacity < 
(FileRecords#sizeInBytes − position in buffer) < firstBatchSize. Thanks for the 
explanation.
   
   I am going to revert to the `bytesRead >= fileRecords.sizeInBytes()` 
condition since it is easier to understand. If the extra allocation case ever 
comes up, we can fix it then. My motivation for this over the other approach is 
that raft callers should not be requesting non-batch-aligned offsets, which is 
when the extra allocation would occur.
   
   



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