Skip to content

[fix][client-cpp] Avoid returning permits for acknowledged batch indexes on redelivery - #625

Open
xqw2001-11 wants to merge 1 commit into
apache:mainfrom
xqw2001-11:fix/batch-index-redelivery-permits
Open

xqw2001-11 wants to merge 1 commit into
apache:mainfrom
xqw2001-11:fix/batch-index-redelivery-permits

Conversation

@xqw2001-11

Copy link
Copy Markdown

Motivation

With batch index acknowledgments enabled, the broker charges one permit for each unacknowledged index in a redelivered batch. The C++ client also returns permits for indexes the broker already marked as acknowledged. Repeated partial-batch redelivery can therefore allow the broker to dispatch more messages than the configured receiver queue size.

The Java client addressed the same accounting issue in apache/pulsar#22091.

Modifications

Exclude indexes already acknowledged by the broker from the FLOW permits returned for skipped messages. Count them before the start-message and dead-letter checks so an overlapping skip cannot return a permit either. Keep counting all skipped messages when reporting how many messages reached the application.

Verifying this change

Added AcknowledgeTest.testPermitsAfterPartialBatchRedelivery. A shared consumer with a queue of 16 receives one batch of eight, acknowledges seven indexes, and requests redelivery of the eighth. The test checks the redelivered message ID and redelivery count, acknowledges it, then queries the broker for available permits. The original batch triggered a refill of eight permits. Only one permit was charged on redelivery, and one consumed message is below the next refill threshold. The expected broker balance is 15. Unpatched main reports 23. With the fix, the new test and the existing batch index acknowledgment test both passed on three consecutive runs against a standalone broker.

Documentation

  • doc-not-needed — restores the existing receiver queue behavior without changing any API or configuration.

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.

1 participant