GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [fix][broker] Release pending acks for fully acknowledged batches by poorbarcode · Pull Request #27406 · apache/pulsar

Conversation

@poorbarcode

@poorbarcode poorbarcode commented Nov 6, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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.

Screenshot 2026-11-06 at 13 21 29 Screenshot 2026-11-06 at 16 36 15

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.

All reactions
@poorbarcode
[fix][broker] Release pending acks for fully acknowledged batches
3bc6d8e
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
@poorbarcode poorbarcode added ready-to-test release/4.0.15 release/4.2.6 release/5.0.2 labels Nov 6, 2026
@poorbarcode poorbarcode self-assigned this Nov 6, 2026
codelipenghui
codelipenghui approved these changes Nov 6, 2026
View reviewed changes

@codelipenghui codelipenghui left a comment

Copy link
Copy Markdown
Contributor

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.

All reactions
Technoboy-
Technoboy- approved these changes Nov 6, 2026
View reviewed changes
@Technoboy-
Technoboy- merged commit e452bb4 into apache:master Nov 6, 2026
45 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@poorbarcode poorbarcode added this to the 5.1.0 milestone Nov 6, 2026
lhotari pushed a commit that referenced this pull request Nov 6, 2026
@poorbarcode @lhotari
[fix][broker] Release pending acks for fully acknowledged batches (#2…
8c65264
…7406)

(cherry picked from commit e452bb4)
@lhotari lhotari added the cherry-picked/branch-4.2 label Nov 6, 2026
lhotari pushed a commit that referenced this pull request Nov 6, 2026
@poorbarcode @lhotari
[fix][broker] Release pending acks for fully acknowledged batches (#2…
82166eb
…7406)

(cherry picked from commit e452bb4)
@lhotari lhotari added the cherry-picked/branch-4.0 label Nov 6, 2026
@lhotari

lhotari commented Nov 6, 2026

Copy link
Copy Markdown
Member

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:

  • Before [fix][broker] Move pending acks cleanup to selected mark-delete callbacks #25592: a fully acknowledged batch stayed in pendingAcks until the mark-delete position passed it and the next readMoreEntries call ran.
  • After [fix][broker] Move pending acks cleanup to selected mark-delete callbacks #25592: with transactions disabled, no ack-driven path removes that entry, so it stays until the consumer disconnects or redelivery clears it.

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

lhotari pushed a commit that referenced this pull request Nov 6, 2026
@poorbarcode @lhotari
[fix][broker] Release pending acks for fully acknowledged batches (#2…
c05b2d2
…7406)

(cherry picked from commit e452bb4)
@lhotari lhotari added the cherry-picked/branch-5.0 label Nov 6, 2026
@lhotari

lhotari commented Nov 6, 2026

Copy link
Copy Markdown
Member

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:

  • [fix][broker] Release pending acks when a replicated subscription update moves mark-delete #27415: a replicated subscription update from a remote cluster moves the local mark-delete position past entries that local consumers still hold.
  • [fix][broker] Release pending acks when persisting an expiry mark-delete fails #27416: persisting an expiry mark-delete fails, but the cursor keeps the new position in memory, and later expiry checks for that position return early.

Both are separate from the batch case fixed here.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

Reviewers

@Technoboy- Technoboy- Technoboy- approved these changes
@codelipenghui codelipenghui codelipenghui approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@poorbarcode poorbarcode

Labels

cherry-picked/branch-4.0 cherry-picked/branch-4.2 cherry-picked/branch-5.0 ready-to-test release/4.0.15 release/4.2.6 release/5.0.2

Projects

None yet

Milestone

5.1.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@poorbarcode @lhotari @Technoboy- @codelipenghui
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.