[ISSUE #9728] Fix correctMinOffset handling of incomplete consume queue records#10211
Open
daguimu wants to merge 1 commit intoapache:developfrom
Open
[ISSUE #9728] Fix correctMinOffset handling of incomplete consume queue records#10211daguimu wants to merge 1 commit intoapache:developfrom
daguimu wants to merge 1 commit intoapache:developfrom
Conversation
…me queue records Change the size check from `result.getSize() == 0` to `result.getSize() < CQ_STORE_UNIT_SIZE` to properly handle partially written consume queue records. When the buffer contains fewer bytes than a complete CQ unit (20 bytes), the subsequent getLong() call would throw BufferUnderflowException. Fixes apache#9728
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In
ConsumeQueue.correctMinOffset(), the size check at line 616 only guards against completely empty buffers (result.getSize() == 0). When a consume queue mapped file contains a partially written record (1-19 bytes, less thanCQ_STORE_UNIT_SIZE= 20), the subsequentbuffer.getLong()call throwsBufferUnderflowException.This can happen when:
Root Cause
The check
result.getSize() == 0does not cover the case whereresult.getSize()is between 1 and 19 (less than one complete CQ unit of 20 bytes). A partial record cannot be meaningfully processed.Note: PR #10109 previously added a guard for the last mapped file check (lines 564-570), which resolved the main startup crash. This PR addresses the remaining edge case in the binary search section where a partially written record could still cause a
BufferUnderflowException.Fix
Changed the size check from:
to:
This properly handles both empty buffers and incomplete records.
Tests Added
No new tests needed — existing
ConsumeQueueTest(13 tests coveringcorrectMinOffsetwith various offset scenarios) all pass. The fix is a one-line defensive check improvement.Impact
BufferUnderflowExceptionon partially written consume queue recordsFixes #9728