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 when a replicated subscription update moves mark-delete by lhotari · Pull Request #27415 · apache/pulsar

Conversation

@lhotari

@lhotari lhotari commented Nov 6, 2026

Copy link
Copy Markdown
Member

Motivation

A subscription update received from a remote cluster moves the local mark-delete position through a cumulative ack, without any ack from the local consumers. On a Shared or Key_Shared subscription, those consumers can still hold entries at or before the new position.

Before #25592, the pending acks sweep in readMoreEntries released these entries. #25592 moved the cleanup to Dispatcher#markDeletePositionMoveForward, and only expiry, skip and clear-backlog call that hook, with #25624 later adding backlog quota eviction. The replicated subscription path doesn't call it, so these entries stay in pendingAcks until the consumer acks them, disconnects or gets a redelivery. Until then, the consumer's unacked count stays inflated and, on Key_Shared, its draining hashes can stay held.

Modifications

  • Call markDeletePositionMoveForward() after a replicated subscription ack succeeds in PersistentSubscription#acknowledgeReplicatedSubscriptionMessage.
  • Attach the call outside the subscription monitor. The ack can complete synchronously, and the hook takes the dispatcher's lock.
  • Don't call it for a rejected update or a failed ack. ReplicatedSubscriptionsController retries a failed update, so the cleanup runs when the retry succeeds.
  • Update the Dispatcher#markDeletePositionMoveForward javadoc to include this path.

Verifying this change

  • Make sure that the change passes the CI checks.

This change added tests and can be verified as follows:

  • Added ReplicatedSubscriptionTest#testSubscriptionUpdateReleasesLocalPendingAcks, which runs on two clusters with Shared and Key_Shared subscriptions. r1 acks every message and r2 never acks. Without the fix, r2's mark-delete position moves past entries that stay in its consumer's pendingAcks, and the test fails.
  • Added PersistentSubscriptionTest cases for the hook running outside the subscription monitor when the ack completes synchronously, and for it not running when the mark-delete fails or the update is rejected. Moving the hook inside the monitor makes the monitor and rejected-update cases fail.

Does this pull request potentially affect one of the following parts:

If the box was checked, please highlight the changes

  • 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
@lhotari
[fix][broker] Release pending acks when a replicated subscription upd…
12da102
…ate moves mark-delete

A subscription update received from a remote cluster moves the local
mark-delete position through a cumulative ack, without any ack from local
consumers. Since the pending acks cleanup moved to markDeletePositionMoveForward
in apache#25592, this path no longer releases the local consumers' pending acks at or
before the new mark-delete position, leaving their unacked counts inflated and
Key_Shared draining hashes held until those consumers ack or disconnect.

Invoke the hook after the replicated ack completes, outside the subscription
monitor since the ack can complete synchronously.

Assisted-by: Claude Code (claude-opus-5-5)
@lhotari lhotari added release/4.2.6 release/4.0.15 release/5.0.2 labels Nov 6, 2026
This was referenced Nov 6, 2026
[fix][broker] Release pending acks when persisting an expiry mark-delete fails #27416
Merged
[fix][broker] Release pending acks for fully acknowledged batches #27406
Merged
poorbarcode
poorbarcode approved these changes Nov 6, 2026
View reviewed changes

@poorbarcode poorbarcode 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.

The successful-ACK path looks good, including attaching the cleanup outside the subscription monitor to handle synchronous completion.

One remaining failure-path gap to address in a follow-up: ackFuture.thenRun(...) skips cleanup when the ACK fails after the in-memory mark-delete position has advanced. ManagedCursorImpl updates that position before persistence. If both the BookKeeper write and metadata-store fallback fail, ReplicatedSubscriptionsController#handleReceivedSubscriptionUpdateFailure sees the target already covered and removes the update instead of retrying it. Local pending acks, unacked counts, and Key_Shared draining hashes can therefore remain stale.

I reproduced the cursor advancement and missing cleanup with a real managed cursor, storage-failure injection, and a mocked dispatcher; five controller retry ticks did not retry the ACK. Please consider handling exceptional completion based on the actual cursor position, while preserving the original failure and keeping cleanup outside the subscription monitor.

Approving this improvement with the remaining failure-path gap noted above.

Sorry, something went wrong.

Uh oh!

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

All reactions
@codelipenghui

codelipenghui commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Building on the failure-path concern already noted, I independently reproduced the missing cleanup at 12da102e9a using a real managed cursor and subscription, injected BookKeeper/metadata-store failures, and a mocked dispatcher.

After both writes failed, the ACK future failed while in-memory mark-delete advanced from entry 2 to entry 5; the persisted position remained at entry 2. After the controller discarded the target, five additional timer ticks left ACK attempts at one, and markDeletePositionMoveForward() was never called. The regression expecting cleanup failed; the success control and three existing PR tests passed.

I suggest retaining the targeted dispatcher hook, but handling both successful and exceptional completion based on actual cursor advancement, outside the subscription monitor. Preserve the original ACK failure and reset/rejected-update safeguards, without restoring the read-path sweep.

This verifies the missing callback and absent retry—not end-to-end pending-ACK/draining-hash effects or a fix implementation.

All reactions

Sorry, something went wrong.

Uh oh!

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

void-ptr974
void-ptr974 reviewed Nov 7, 2026
View reviewed changes

@void-ptr974 void-ptr974 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.

Additional concurrency case noted inline.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread ...broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentSubscription.java Resolved

Uh oh!

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

@lhotari
[fix][broker] Release pending acks after a failed replicated ack and …
d921416
…serialize the cleanup with consumer removal

Assisted-by: Claude Code (claude-opus-5-5)
@lhotari

lhotari commented Nov 10, 2026

Copy link
Copy Markdown
Member Author

@poorbarcode @codelipenghui Thanks for the review and the reproduction. I've addressed the failure-path gap in this PR rather than in a follow-up (d921416):

  • acknowledgeReplicatedSubscriptionMessage now attaches the cleanup with whenComplete. It runs after a successful ack as before. After a failed ack, it runs only if the cursor's in-memory mark-delete position moved past where it was when the ack was admitted. If the position didn't move, the controller retries the update, and the cleanup runs when that retry succeeds.
  • The returned future still completes with the original ack failure. The cleanup is still attached outside the subscription monitor, and the reset/rejected-update checks are unchanged.
  • testFailedReplicatedAckReleasesPendingAcksWhenMarkDeleteMoved covers the case you reproduced (it fails against the previous thenRun), and testFailedReplicatedAckKeepsPendingAcksWhenMarkDeleteDidNotMove covers the retry case.

The same commit also fixes the cleanup/disconnect race raised inline by @void-ptr974.

All reactions

Sorry, something went wrong.

Uh oh!

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

@lhotari lhotari mentioned this pull request Nov 10, 2026
[Bug] Shared/Key_Shared dispatcher unacked count is debited twice when an ack completes after its consumer is removed #27556
Open
3 tasks done
@lhotari
lhotari merged commit 927446c into apache:master Nov 10, 2026
43 checks passed

Uh oh!

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

lhotari added a commit that referenced this pull request Nov 11, 2026
@lhotari
[fix][broker] Release pending acks when a replicated subscription upd…
a8c1292
…ate moves mark-delete (#27415)

(cherry picked from commit 927446c)
@lhotari lhotari added the cherry-picked/branch-5.0 label Nov 11, 2026
This was referenced Nov 21, 2026
[improve][ci] Run CI for the 4.2.6 backports to branch-4.2 (do not merge) #27680
Closed
[improve][ci] Run CI for the 4.2.6 backports to branch-4.2 (do not merge) #27681
Closed
[improve][ci] Run CI for the 4.2.6 backports to branch-4.2 (do not merge) #27684
Closed
@lhotari lhotari added cherry-picked/branch-4.2 cherry-picked/branch-4.0 labels Nov 21, 2026
poorbarcode pushed a commit to poorbarcode/pulsar that referenced this pull request Nov 26, 2026
@lhotari
[fix][broker] Release pending acks when a replicated subscription upd…
38251bd
…ate moves mark-delete (apache#27415)

(cherry picked from commit 927446c)
poorbarcode pushed a commit to poorbarcode/pulsar that referenced this pull request Nov 26, 2026
@lhotari
[fix][broker] Release pending acks when a replicated subscription upd…
62fb6c5
…ate moves mark-delete (apache#27415)

(cherry picked from commit 927446c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@poorbarcode poorbarcode poorbarcode approved these changes
+1 more reviewer
@void-ptr974 void-ptr974 void-ptr974 left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

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

Assignees

No one assigned

Labels

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

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

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

4 participants

@lhotari @codelipenghui @poorbarcode @void-ptr974
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.