Skip to content

[improve][broker] Centralize mark-delete position change handling#25571

Closed
nodece wants to merge 1 commit intoapache:masterfrom
nodece:improve/centralize-mark-delete-position-cleanup
Closed

[improve][broker] Centralize mark-delete position change handling#25571
nodece wants to merge 1 commit intoapache:masterfrom
nodece:improve/centralize-mark-delete-position-cleanup

Conversation

@nodece
Copy link
Copy Markdown
Member

@nodece nodece commented Apr 23, 2026

Motivation

Dispatcher notification logic (afterAckMessages + markDeletePositionMoveForward) was scattered across multiple callback sites in PersistentSubscription (markDeleteCallback, deleteCallback, clearBacklog, skipMessages, resetCursor). This led to:

  • Duplicated dispatcher.afterAckMessages() calls that could fire even when the mark-delete position hadn't actually changed.
  • Redelivery tracker and pending acks cleanup was only performed inside readMoreEntries() for the PersistentDispatcherMultipleConsumers base class, meaning Key_Shared subscriptions had to duplicate the logic. Other subscription types (Shared, Failover) missed cleanup opportunities when messages expired via TTL.
  • PersistentMessageExpiryMonitor only triggered markDeletePositionMoveForward() for Key_Shared subscriptions, leaving other subscription types without proper cleanup after message expiry.

Changes

  • PersistentSubscription

    • Consolidated all dispatcher.afterAckMessages() calls into the single notifyTheMarkDeletePositionChanged() method, which now also calls dispatcher.markDeletePositionMoveForward().
    • Removed scattered afterAckMessages calls from markDeleteCallback, deleteCallback, clearBacklog, skipMessages, and resetCursor.
    • Added oldMarkDeletePosition capture in clearBacklog, skipMessages, and resetCursor to route through the centralized path.
  • PersistentDispatcherMultipleConsumers

    • Moved redelivery tracker and pending acks cleanup from readMoreEntries() into markDeletePositionMoveForward(), so it fires precisely when the mark-delete position advances rather than opportunistically on the next read cycle.
    • Removed lastMarkDeletePositionBeforeReadMoreEntries field.
  • PersistentStickyKeyDispatcherMultipleConsumers

    • Added super.markDeletePositionMoveForward() call so Key_Shared subscriptions also clean up stale entries from the redelivery tracker and pending acks.
  • PersistentMessageExpiryMonitor

    • Changed the post-expiry dispatcher notification from a Key_Shared-only check to a general dispatcher != null check, so all subscription types benefit from cleanup after message TTL expiry.

Comment on lines +349 to +355
redeliveryMessages.removeAllUpTo(mdp.getLedgerId(), mdp.getEntryId());
for (Consumer consumer : consumerList) {
PendingAcksMap pendingAcks = consumer.getPendingAcks();
if (pendingAcks != null) {
pendingAcks.removeAllUpTo(mdp.getLedgerId(), mdp.getEntryId());
}
}
Copy link
Copy Markdown
Member

@lhotari lhotari Apr 23, 2026

Choose a reason for hiding this comment

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

Is there a significant different in the frequency that this gets called? When this logic was previously in readMoreEntries, it would only get called there if the mark delete position moved since the last call to readMoreEntries, which is not as frequent as the mark delete position might move forward. This has been intentional behavior in the past and I have a concern that this change would cause a performance regression.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

There's likely a performance impact due to the higher invocation frequency. Thanks for pointing that out. I'll revisit the change and adjust it to avoid unnecessary executions!

@nodece nodece marked this pull request as draft April 23, 2026 10:30
@nodece
Copy link
Copy Markdown
Member Author

nodece commented Apr 28, 2026

Closed by #25592

@nodece nodece closed this Apr 28, 2026
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.

2 participants