Skip to content

[fix][broker] Decrement unacked counter when removeAllUpTo removes pending acks - #25581

Merged
nodece merged 5 commits into
apache:masterfrom
nodece:fix/unacked-counter-removeAllUpTo
Apr 27, 2026
Merged

[fix][broker] Decrement unacked counter when removeAllUpTo removes pending acks#25581
nodece merged 5 commits into
apache:masterfrom
nodece:fix/unacked-counter-removeAllUpTo

Conversation

@nodece

@nodece nodece commented Apr 27, 2026

Copy link
Copy Markdown
Member

Motivation

When the cursor's mark-delete position advances (e.g., via message expiry), readMoreEntries calls PendingAcksMap.removeAllUpTo to remove entries from the consumer's pendingAcks without decrementing the consumer's unackedMessages counter, causing it to be permanently inflated.

This is especially problematic with batch index level ack enabled: partial acks leave residual unacked counts in the counter, and after removeAllUpTo removes the entry from pendingAcks, subsequent individual batch acks can no longer find the entry to decrement, so the counter never reaches zero.

Modifications

  • PendingAcksMap.removeAllUpTo accepts a callback invoked per removed entry
  • Consumer. removePendingAcksUpToPositionAndDecrementUnacked computes the remaining unacked count per entry (respecting batch index level ack) and decrements the counter
  • PersistentDispatcherMultipleConsumers.readMoreEntries uses the new method instead of directly calling removeAllUpTo

@nodece
nodece requested review from dao-jun and lhotari April 27, 2026 09:28
@nodece nodece self-assigned this Apr 27, 2026

@lhotari lhotari left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, just 2 minor comments. Good work @nodece

Comment thread pulsar-broker/src/main/java/org/apache/pulsar/broker/service/Consumer.java Outdated
Comment thread pulsar-broker/src/main/java/org/apache/pulsar/broker/service/Consumer.java Outdated
Comment thread pulsar-broker/src/main/java/org/apache/pulsar/broker/service/Consumer.java Outdated
@nodece
nodece merged commit 5168fcb into apache:master Apr 27, 2026
80 of 82 checks passed
poorbarcode pushed a commit to poorbarcode/pulsar that referenced this pull request May 6, 2026
coderzc pushed a commit that referenced this pull request May 13, 2026
nodece added a commit to ascentstream/pulsar that referenced this pull request May 27, 2026
priyanshu-ctds pushed a commit to datastax/pulsar that referenced this pull request Jun 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants