Repository navigation
KAFKA-21234: Fix bug in KRaft where the metadata layer can receive records past the high watermark - #23737
KAFKA-21234: Fix bug in KRaft where the metadata layer can receive records past the high watermark#23737kevin-wu24 wants to merge 1 commit into
Conversation
…s past the requested slice from FileRecords
jsancio
left a comment
There was a problem hiding this comment.
Thanks for the fix @kevin-wu24 . I just have one high-level comment.
| * possible exceptions | ||
| * @throws IllegalArgumentException If the position is negative or greater than the size of this FileRecords object | ||
| */ | ||
| public void readUntil(ByteBuffer buffer, int position) throws IOException { |
There was a problem hiding this comment.
Instead of introducing a new method (readUntil). I would like to understand if we should fix readInto to honor the limit of the FileRecords slice. What do you think @junrao
There was a problem hiding this comment.
I am not opposed to that approach. I mainly need to understand what each of the other users of FileRecords#readInto assumes/can handle. I thought it might be better to see if others already knew some of these things. I will look into them myself, but it just may take some time.
There was a problem hiding this comment.
Take a look at writeTo.
I would expect the read semantic of readInto to be similar to writeTo.
Issue Description
When the metadata layer (e.g.
MetadataLoader) tries to read a slice of records from KRaft which is greater thanKafkaRaftClient#MAX_BATCH_SIZE_BYTES, theRecordsIteratorcan return records which are past the HWM. As it iterates through this slice of records,FileRecords#readIntoreads from disk the minimum of the bytes until end of the file and the remaining space in the associated buffer. In the case of the former, this can lead to a metadata error where the node tries to snapshot with records past the HWM.For the metadata error to occur, the following three pre-conditions must be met:
What Changed
Add
FileRecords#readUntilwhich reads from the underlying file to the minimum of:RecordsIteratoris the minimum of theFileRecords' record size and the batch size defined by KRaft.FileRecordsobject, rather than the end of the underlying file. This ensures when a caller constructs aFileRecordsslice of [start position, HWM), no bytes past the HWM are read into memory.Testing
Added unit tests in
RecordsIteratorTestandFileRecordsTestAlternatives
RecordsIteratorprior to callingFileRecords#readInto. The motivation behind this is that other callers may want to this functionality in the future, so the change belongs inFileRecords, not a caller of that class.FileRecords#readInto. The main concern I had with this was that there are many other callers of this method outside of the raft layer, and it is not clear to me the impact of this change on them. Adding an additional method does not impact existing behavior. The other users ofreadIntoareAbstractFetcherThread,LogSegment,Cleaner,CoordinatorLoaderImpl, andTransactionStateManager.Reviewers: José Armando García Sancio jsancio@apache.org