GeezerVison is showing github.com — [fix][broker] Release pending acks for fully acknowledged batches by poorbarcode · Pull Request #27406 · apache/pulsar
Conversation
poorbarcode
commented
Nov 6, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Background
We encountered a broker OOM while using batched messages with transactions disabled. The investigation found that consumers retained large numbers of fully acknowledged entries in their pending-ack maps, including entries whose remainingUnacked was already zero.
Motivation
When an individual ACK carries a non-empty ack_set, even one containing only zero words, applyPendingAckCompletions takes the partial-batch path. The remaining unacked count can reach zero while the pending entry stays in the map. With transactions disabled, the additional transaction-specific cleanup does not run, allowing these entries to accumulate.
A batch can also become fully acknowledged by merging multiple non-empty ACK bitmaps. An earlier unacknowledged entry may prevent mark-delete from advancing even when a later batch is complete. Cleanup therefore needs to use the cursor's merged entry-deletion state after the ACK succeeds.
Modifications
- On successful non-transactional individual ACK completion, treat cursor-deleted batches as fully acknowledged and use the existing atomic pending-ack removal path. Deduct the owning consumer's stored remaining count once, while retaining partial batches for redelivery.
- Add in-process integration tests with a real broker, BookKeeper, and client connections. Explicit ACK frames preserve zero-valued
ack_set words that the Java client's normal ACK builder omits. Cover Shared and Key_Shared subscriptions, single- and multi-word bitmaps, ACK holes, merged/repeated/stale ACKs, acknowledgments from another consumer, ACK receipts, and reconnect/redelivery.
Validation: before the fix, 21 regression scenarios failed because completed entries remained tracked with remainingUnacked=0, while four control scenarios passed. With the fix, all 25 scenarios pass. Another 27 existing cases covering ACK completion failures, disabled batch-index acknowledgment, and transactional ACK/abort behavior also pass, with retries disabled. Broker Checkstyle and Spotless checks pass. Full quickCheck was attempted but stopped at Apache RAT on six pre-existing untracked files under output/, outside this PR.
The regression suite can be run with:
./gradlew :pulsar-broker:test \
--tests org.apache.pulsar.broker.service.BatchIndexAckPendingAcksTest \
-PtestRetryCount=0 -PtestFailFast=false
Does this pull request potentially affect one of the following parts:
- Dependencies (add or upgrade a dependency)
- The public API
- The schema
- The default values of configurations
- The threading model
- The binary protocol
- The REST endpoints
- The admin CLI options
- The metrics
- Anything that affects deployment
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Use the cursor's merged deletion state after successful ACK completion to
remove completed batches from the owning consumer's pending-ack map and
account for the remaining count once, including batches beyond ACK holes.
Add integration coverage for batch-index ACK completion, cross-consumer
ACKs, duplicate bitmaps, ACK receipts, and partial-batch redelivery.
Assisted-by: OpenAI Codex
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review approval for commit 3bc6d8e.
Summary:
No actionable findings identified within the reviewed scope. The cursor-based cleanup correctly reuses atomic removal and owner accounting while retaining partial batches. The original retention bug was reproduced, and all 52 focused tests passed after restoring the patch.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
|
For the record, this looks like a regression from #25592 (138595f6256), rather than a long-standing issue.
The non-transactional ack path has never removed a pending ack entry when the ack carries an ack_set. Those entries used to be cleared later, by this block in PersistentDispatcherMultipleConsumers.readMoreEntries(), which was added in #23352:
// remove possible expired messages from redelivery tracker and pending acks
Position markDeletePosition = cursor.getMarkDeletedPosition();
if (lastMarkDeletePositionBeforeReadMoreEntries != markDeletePosition) {
redeliveryMessages.removeAllUpTo(markDeletePosition.getLedgerId(), markDeletePosition.getEntryId());
for (Consumer consumer : consumerList) {
consumer.removePendingAcksUpToPositionAndDecrementUnacked(
markDeletePosition.getLedgerId(), markDeletePosition.getEntryId());
}
lastMarkDeletePositionBeforeReadMoreEntries = markDeletePosition;
}
#25592 removed that block and moved the cleanup to markDeletePositionMoveForward(). It also removed that hook's call from the regular mark-delete path in PersistentSubscription, so it no longer runs for ack-driven mark-delete updates. As a result:
The ack-hole scenarios covered here aren't entirely part of the regression. Before #25592, entries beyond a hole were also retained, but only until the hole was filled and the mark-delete position advanced. The isMessageDeleted check in this PR releases them earlier than the old cleanup did.
The first releases containing #25592 are v4.0.11, v4.2.2 and v5.0.0-M1, so users on those lines or later may be affected until they upgrade to a release with this fix.
This is based on reading the code and the commit history. I haven't confirmed it by running the new tests against the commit before #25592.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Follow-ups for two remaining gaps in the pending acks cleanup after #25592. In both, the mark-delete position moves without the cleanup hook running:
Both are separate from the batch case fixed here.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|