chia7712 commented on code in PR #23737:
URL: https://github.com/apache/kafka/pull/23737#discussion_r4297002651


##########
raft/src/main/java/org/apache/kafka/raft/internals/RecordsIterator.java:
##########
@@ -136,9 +136,13 @@ 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();
+        // firstBatchSize is null when fewer than HEADER_SIZE_UP_TO_MAGIC 
bytes were read, which only
+        // happens at the end of the records. Once all records have been read, 
a trailing partial
+        // batch can't be completed, so return the records read so far instead 
of growing the buffer.
+        if (firstBatchSize == null || firstBatchSize <= buffer.remaining() ||

Review Comment:
   Should we add a log when the slice ends in a partial batch? It should not 
happen in raft, so WARN level seems suitable.



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