Conversation
estimateMessageCount translated the exclusive upper bound 'to' with getBatchMsgIndexBuffer(to), which returns null when 'to' equals maxOffsetInQueue. Every accumulation query that counts up to the queue head therefore hit the null branch and returned -1, and callers such as DefaultMessageStore silently fell back to the raw offset difference, ignoring batch sizes and tag filters. Since 'to' is exclusive, look up the unit containing 'to - 1' instead and advance physicalOffsetTo past that unit so the scan covers it. Interior ranges are unaffected because a 'to' that lands on a batch base resolves to the same mapped position as before.
RockteMQ-AI
approved these changes
Sep 11, 2026
RockteMQ-AI
left a comment
Contributor
There was a problem hiding this comment.
Summary
Fix estimateMessageCount in BatchConsumeQueue — the exclusive upper bound to was used directly as an offset, but getBatchMsgIndexBuffer returns null for offsets >= maxOffsetInQueue, causing counting up to the queue head to fail. Correctly uses to - 1 and adds CQ_STORE_UNIT_SIZE to get the physical end offset. Includes test coverage.
LGTM — focused fix with clear rationale in comments.
Automated review by github-manager-bot
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.
Motivation
estimateMessageCounttranslated the exclusive upper boundtowithgetBatchMsgIndexBuffer(to), which returns null whentoequalsmaxOffsetInQueue. Every accumulation query that counts up to the queue head therefore hit the null branch and returned -1, and callers such asDefaultMessageStoresilently fell back to the raw offset difference, ignoring batch sizes and tag filters.Modifications
Since
tois exclusive, look up the unit containingto - 1instead, and advancephysicalOffsetTopast that unit so the scan covers it. Interior ranges are unaffected because atothat lands on a batch base resolves to the same mapped position as before.Verification
Fail-before (new test, run against the unpatched code):
Pass-after: