Skip to content

fix(store): estimate batch consume queue count up to max offset - #11150

Open
zjncs wants to merge 1 commit into
apache:developfrom
zjncs:fix/batch-cq-estimate-count-boundary
Open

zjncs wants to merge 1 commit into
apache:developfrom
zjncs:fix/batch-cq-estimate-count-boundary

Conversation

@zjncs

@zjncs zjncs commented Sep 11, 2026

Copy link
Copy Markdown

Motivation

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.

Modifications

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.

Verification

Fail-before (new test, run against the unpatched code):

Tests run: 6, Failures: 1, Errors: 0 -- BatchConsumeQueueTest#testEstimateMessageCount
java.lang.AssertionError: expected:<1000> but was:<-1>
  BatchConsumeQueueTest.testEstimateMessageCount:285 -- estimateMessageCount(1, 1001) with to == maxOffsetInQueue

Pass-after:

Tests run: 6, Failures: 0, Errors: 0, Skipped: 0 -- BatchConsumeQueueTest

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.
Copilot AI lite review requested due to automatic review settings September 11, 2026 07:14

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@RockteMQ-AI RockteMQ-AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants