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] Recover Shared and Key_Shared dispatch after exceptions by Denovo1998 · Pull Request #26916 · apache/pulsar

Conversation

@Denovo1998

@Denovo1998 Denovo1998 commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Follow-up to apache/pulsar#26824.

Motivation

An exception during entry filtering or routing can interrupt Shared and Key_Shared dispatch without scheduling another read. Entries still owned by the dispatcher may remain unreleased, and pending-byte accounting may remain unsettled. A send task rejected before handoff can also leave consumer accounting and dispatcher-owned buffers outstanding.

Recovery needs to distinguish entries already transferred to consumers from entries that still require replay, and remove a consumer whose send task was rejected before dispatch resumes. This addresses the dispatcher recovery deferred by that change.

Modifications

  • Track entry ownership for each dispatch and replay and release only entries still owned by the dispatcher, preserving successful transfers when a later batch fails.
  • Settle pending bytes and the send-in-progress state on exceptional exits, complete filtering decisions already made, and recycle batch bookkeeping on filtering failures.
  • Retry failed dispatches with the existing read-failure backoff settings, preventing ACK and Flow notifications from bypassing the delay. Preserve read lifecycle accounting, including aborted dispatches, for Key_Shared replay ordering.
  • Keep permit and quota accounting consistent across successful batches, partial dispatches, and rejected send tasks.
  • Handle known send-task rejections before handoff by recycling batch bookkeeping and recovering dispatcher-owned entries. Close and remove the failed consumer on the existing broker executor outside the dispatcher monitor, then notify the client; gate reads until consumer cleanup and retry backoff complete. Other synchronous consumer failures with uncertain ownership continue to propagate.
  • Clear chunk assignments belonging to a removed consumer so replayed chunked messages can be assigned to an active consumer.
  • Add broker/client tests covering Shared and Key_Shared subscriptions, both dispatch thread modes, partial transfers, rejected entries and send tasks, chunked messages, and malformed routing keys.

Verifying this change

  • Make sure that the change passes the CI checks.

This change added tests and can be verified as follows:

  • EntryFilterDispatchFailureTest covers recovery from entry-filter exceptions, partial transfers, decisions made before a filter failure, message delivery, backlog clearance, pending-byte accounting, and buffer release.

  • PersistentDispatcherMultipleConsumersTest.testRoutingFailureRetriesWithBackoff verifies bounded retries after malformed routing metadata and continued delivery after the poison entry is skipped.

  • The 12 ConsumerSendFailureTest cases cover rejected send tasks with one or multiple consumers, Shared and Key_Shared subscriptions, both dispatch thread modes, and Shared chunked messages. They verify consumer removal, resumed delivery, permit accounting, backlog clearance, and buffer release after cache invalidation, without manually releasing failed entries or recycling batch bookkeeping in test cleanup. All 12 cases fail before the cleanup fix and pass with it.

  • Existing dispatcher filtering, partially acknowledged batch permit-accounting, and the three replay-ordering tests from apache/pulsar#26868 provide regression coverage.

  • 37 focused test cases passed with test retries disabled: 0 failures, errors, or skips.

  • ./gradlew quickCheck --max-workers=2 passed.

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
Denovo1998 added 3 commits October 14, 2026 20:44
@Denovo1998
[fix][broker] Recover Shared and Key_Shared dispatch after exceptions
e831601
@Denovo1998
[fix][broker] Recover Shared and Key_Shared dispatch after exceptions
344ec33
@Denovo1998
[fix][broker] Recover Shared and Key_Shared dispatch after exceptions
530e711
@lhotari

lhotari commented Oct 15, 2026

Copy link
Copy Markdown
Member

@Denovo1998 Thanks for the PR. It would be useful to validate the performance impact of this change once #26922 has been merged. With the performance testing framework, it's possible to ask the coding agent to perform a A-B test and show the report.

It's necessary to run on Linux x86_64 hardware to get accurate results since other platforms (Linux VMs, MacOS) could have a variance of several percents due to thermal throttling, variable CPU frequency (including "turbo"), performance cores, and others. If it's not possible to run on Linux bare metal, running the comparison tests on available hardware is a good reference point in any case.

All reactions

Sorry, something went wrong.

Uh oh!

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

@Denovo1998

Denovo1998 commented Oct 15, 2026

Copy link
Copy Markdown
Contributor Author

@Denovo1998 Thanks for the PR. It would be useful to validate the performance impact of this change once #26922 has been merged. With the performance testing framework, it's possible to ask the coding agent to perform a A-B test and show the report.

It's necessary to run on Linux x86_64 hardware to get accurate results since other platforms (Linux VMs, MacOS) could have a variance of several percents due to thermal throttling, variable CPU frequency (including "turbo"), performance cores, and others. If it's not possible to run on Linux bare metal, running the comparison tests on available hardware is a good reference point in any case.

@lhotari

What you said makes perfect sense, indeed, things related to dispatch do require more caution and extensive testing. #26922 is also a very useful feature, so I might as well give it a try while I have the chance, haha.

I'll handle this PR later. I'll do some stress testing on my R730 server this coming weekend.

Feedback later. Thank you.

All reactions

Sorry, something went wrong.

Uh oh!

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

codelipenghui
codelipenghui requested changes Oct 15, 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.

The dispatcher-level, ownership-aware recovery approach is sound, but two failure paths need to be addressed:

  • P1: Replaying a failed final-chunk suffix without restoring its UUID→consumer assignment can indefinitely block Shared delivery.
  • P2: Deferred rejected-send cleanup can race ordinary consumer removal and decrement topic usage twice.

Reviewed head: 530e711626b3e733b60c473c44f6c10151be2d53. Both findings are supported by source tracing, not runtime reproduction. Focused validation was attempted but cancelled after Kotlin's daemon initialization encountered a filesystem permission denial; no test results or unpatched-baseline reproduction were obtained. Please add deterministic regression coverage for the two sequences described inline.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread .../java/org/apache/pulsar/broker/service/persistent/PersistentDispatcherMultipleConsumers.java

private void handleDispatchFailure(List<Entry> entries, Throwable error) {
log.debug().exception(error).log("Failed to dispatch entries; scheduling replay with backoff");
replayAndReleaseEntries(entries);

@codelipenghui codelipenghui Oct 15, 2026

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.

[P1] Preserve chunk-routing ownership before replaying a failed suffix

For a Shared message split across reads, chunk 0 can already be handed off when SharedConsumerAssignor.getConsumerForUuid assigns the final chunk and removes its UUID→consumer mapping. If filtering that final chunk throws once, this recovery replays only the final chunk. On every retry, the assignor rejects the noninitial chunk because its UUID mapping is absent, so it is requeued without reaching the recovered filter. Shared prioritizes replay, allowing this entry to indefinitely block subsequent normal backlog.

The eager mapping removal predates this PR; the new problem is replaying the orphaned suffix without restoring routing state. Please retain or restore the UUID owner on failure and commit its removal only after successful final-chunk handoff. Add a regression test that splits chunks across reads and throws once on the final chunk; the added chunk-filter cases currently throw only on chunk 0.

Sorry, something went wrong.

Uh oh!

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

All reactions

@Denovo1998 Denovo1998 Oct 16, 2026

Copy link
Copy Markdown
Contributor Author

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.

Thanks, you're right. Fixed in 7b2c70e by restoring UUID ownership for dispatcher-owned chunks before replaying a failed dispatch. Added a regression with one-entry reads and a filter that throws once on the final chunk. It verifies delivery of the chunked message and subsequent messages without replaying the prefix. The test fails before the fix and passes in both dispatch thread modes.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread .../java/org/apache/pulsar/broker/service/persistent/PersistentDispatcherMultipleConsumers.java
// Unregister before notifying the client, so a fast reconnect cannot register its replacement
// while the old consumer is still present. Notification failure must not prevent removal.
try {
consumer.close();

@codelipenghui codelipenghui Oct 15, 2026

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.

[P2] Make deferred failed-send cleanup idempotent with ordinary removal

After a rejected send queues this task, ServerCnx.channelInactive or a client CLOSE can remove the same Shared consumer before the task executes. This then calls consumer.close() a second time. The Shared dispatcher's duplicate-removal branch returns without throwing, so PersistentSubscription.removeConsumer repeats removed-consumer statistics and unconditionally decrements topic usage again; the BrokerServiceException catch below does not protect this path.

Usage can become zero while another consumer remains connected, undermining the connected-client guard used by topic deletion. Please make actual removal idempotent, or atomically check exact-instance membership under the subscription lock while preserving subscription→dispatcher lock order. A deterministic regression should hold the queued cleanup, remove the consumer normally, then release cleanup and assert that usage/statistics change only once.

Sorry, something went wrong.

Uh oh!

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

All reactions

@Denovo1998 Denovo1998 Oct 16, 2026

Copy link
Copy Markdown
Contributor Author

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.

Confirmed and fixed in 7b2c70e. PersistentSubscription.removeConsumer now checks exact-instance membership under the subscription lock, preventing repeated removal from decrementing usage or accumulating statistics twice. The regression forces ordinary removal to finish before deferred cleanup, then verifies usage, message/byte counters, and continued delivery. It fails before the fix and passes in both dispatch thread modes.

Sorry, something went wrong.

Uh oh!

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

All reactions
Denovo1998 added 2 commits October 16, 2026 19:10
@Denovo1998
[fix][broker] Recover Shared and Key_Shared dispatch after exceptions
7b2c70e
@Denovo1998
[fix][broker] Recover Shared and Key_Shared dispatch after exceptions
4c42c36
Merge master at 95e04f0. Preserve instance-based consumer removal and chunk assignment cleanup. Allow late STICKY selector cleanup while accounting for consumer removal only once.
@Denovo1998
Denovo1998 requested a review from codelipenghui October 16, 2026 11:33
@Denovo1998
Denovo1998 marked this pull request as draft October 16, 2026 11:33
@Denovo1998

Denovo1998 commented Oct 16, 2026

Copy link
Copy Markdown
Contributor Author

@Denovo1998 Thanks for the PR. It would be useful to validate the performance impact of this change once #26922 has been merged. With the performance testing framework, it's possible to ask the coding agent to perform a A-B test and show the report.
It's necessary to run on Linux x86_64 hardware to get accurate results since other platforms (Linux VMs, MacOS) could have a variance of several percents due to thermal throttling, variable CPU frequency (including "turbo"), performance cores, and others. If it's not possible to run on Linux bare metal, running the comparison tests on available hardware is a good reference point in any case.

@lhotari

What you said makes perfect sense, indeed, things related to dispatch do require more caution and extensive testing. #26922 is also a very useful feature, so I might as well give it a try while I have the chance, haha.

I'll handle this PR later. I'll do some stress testing on my R730 server this coming weekend.

Feedback later. Thank you.

Let me handle it this weekend first.

All reactions

Sorry, something went wrong.

Uh oh!

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

codelipenghui
codelipenghui approved these changes Oct 20, 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.

Both previously reported issues are addressed at 4c42c366af8cae4c295ee5edb387fe2457484cc0:

  • Failed final-chunk dispatch restores UUID ownership before replay without replaying the transferred prefix.
  • Repeated consumer removal avoids duplicate statistics/usage accounting while preserving late STICKY-selector cleanup.

Validated 27 focused test cases with retries disabled: all passed, with zero failures, errors, or skips. Coverage includes filter recovery, the ordinary-removal/deferred-cleanup race, rejected sends, both dispatch-thread modes, and late STICKY cleanup.

No actionable findings identified within the reviewed scope. This follow-up focused on the fixes and relevant merge interactions; unpatched-baseline reproduction and performance A/B were not run.

Sorry, something went wrong.

Uh oh!

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

All reactions
Denovo1998 added 3 commits October 20, 2026 20:39
@Denovo1998
[fix][broker] Recover Shared and Key_Shared dispatch after exceptions
58bea64
@Denovo1998
Merge branch 'master' into fix_broker_recover_shared_and_key_shared_d…
afe3d7b
…ispatch_after_exceptions
@Denovo1998
[fix][broker] Recover Shared and Key_Shared dispatch after exceptions
15d85e2
lhotari
lhotari reviewed Nov 23, 2026
View reviewed changes

@lhotari lhotari left a comment

Copy link
Copy Markdown
Member

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.

Thanks for following up on #26824 and taking on the recovery work. The ownership tracking is careful, and the test coverage for rejected sends is thorough.

My main concern is the recovery policy rather than the bookkeeping. Every dispatch failure gates reads for the whole subscription behind the read-failure backoff (15 s initial, 60 s max by default). The failed batch goes back to replay, and replay wins over normal reads. So a deterministically failing entry now stops all delivery on the subscription until someone skips it, and it does so silently, because the failure is logged only at DEBUG. Before this change the bad batch leaked but later reads continued. Isolating the failing position after a few attempts, plus a rate-limited WARN, would make this much safer to operate.

Other points inline:

  • a pending normal read can bypass the backoff
  • later consumers' batches are still stranded on other synchronous send failures; this predates the PR, but the ownership tracking now makes it fixable
  • the hot-path additions and the benchmark baseline, for the A/B comparison you mentioned
  • a few test gaps

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread .../java/org/apache/pulsar/broker/service/persistent/PersistentDispatcherMultipleConsumers.java

@Override
protected synchronized void internalReadMoreEntries() {
if (dispatchRetryPending || pendingConsumerSendFailures > 0) {

@lhotari lhotari Nov 23, 2026

Copy link
Copy Markdown
Member

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.

[BUG] A deterministically failing entry now stalls the whole subscription

This gate blocks every read on the subscription while a retry is pending, and the retry uses the read-failure backoff (dispatcherReadFailureBackoffInitialTimeInMs = 15000, max 60000 by default, PersistentDispatcherMultipleConsumers.java:202-205).

Two consequences:

  • One transient filter or interceptor exception pauses delivery to all consumers on the subscription, including healthy and newly connected ones, for at least ~15 s.
  • A deterministic failure is worse. Examples are a filter that always throws for one message, or the malformed routing key in testRoutingFailureRetriesWithBackoff. The failed batch goes back to replay, internalReadMoreEntries prefers the replay set over a normal read (:452), and every retry hits the same entry. Nothing else is delivered until an operator runs skipMessages. Before this change the bad batch leaked, but later reads kept delivering.

Could the failing position be isolated instead? For example, track attempts per position and, after N failures, skip it or dispatch it alone so the rest of the batch can progress. A dispatcher-specific, shorter backoff would also help. If the stall is intended, please document the operator action.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread .../java/org/apache/pulsar/broker/service/persistent/PersistentDispatcherMultipleConsumers.java
}

private void handleDispatchFailure(List<Entry> entries, Throwable error) {
log.debug().exception(error).log("Failed to dispatch entries; scheduling replay with backoff");

@lhotari lhotari Nov 23, 2026

Copy link
Copy Markdown
Member

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.

[QUALITY] Dispatch failures are logged only at DEBUG, and Errors are retried silently

handleDispatchFailure logs only at DEBUG. The catch blocks at :445 and :889 also catch Error. Before this change, the same exceptions escaped readEntriesComplete and were logged at ERROR by OpReadEntry ("readEntriesComplete failed").

Combined with the retry loop above, a permanently failing filter or routing plugin now produces an endless replay/backoff cycle with no WARN or ERROR line. The only symptom is a growing backlog. A plugin NoClassDefFoundError or an OOM would be retried the same way.

Suggestion: log at WARN, rate-limited per dispatcher, with the position and the cause. Also rethrow VirtualMachineError (or all Errors) instead of retrying.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread .../java/org/apache/pulsar/broker/service/persistent/PersistentDispatcherMultipleConsumers.java
for (int i = 0; i < ownedEntries.size(); i++) {
ownedEntries.set(i, EntryAndMetadata.create(ownedEntries.get(i)));
}
if (pendingConsumerSendFailures > 0) {

@lhotari lhotari Nov 23, 2026

Copy link
Copy Markdown
Member

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.

[QUALITY] A normal read already in flight bypasses the retry backoff and resets it

internalReadMoreEntries can start a replay read while a normal read is still pending: the replay branch at :452 runs before the doesntHavePendingRead() check. If dispatching that replay fails, dispatchRetryPending is set. When the pending normal read completes, though, this path checks only pendingConsumerSendFailures, so it dispatches during the backoff. If anything is delivered, :904 also resets dispatchFailureBackoff.

That contradicts the comment at :392 ("ACKs, Flow and completed writes must not bypass failure recovery's backoff"). It also means repeated failures don't always escalate the backoff. For Shared chunked messages it lets a later chunk overtake a middle chunk that is waiting in replay.

Should this also check dispatchRetryPending and send the entries to replay, like the pendingConsumerSendFailures branch does?

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread .../java/org/apache/pulsar/broker/service/persistent/PersistentDispatcherMultipleConsumers.java
if (e.getCause() instanceof Error error) {
throw error;
}
throw (RuntimeException) e.getCause();

@lhotari lhotari Nov 23, 2026

Copy link
Copy Markdown
Member

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.

[BUG] Other synchronous send failures still strand later consumers' batches

When Consumer.sendMessages throws anything other than SendMessageTaskRejectedException, this rethrows without replaying or releasing anything, and no retry is scheduled. Ownership is uncertain only for the failing consumer's slice. The batches meant for consumers after it never reached sendMessages and still have isOwnedByDispatcher() == true:

  • the round-robin loop
  • the Key_Shared groups
  • the chunked per-consumer loop

Those entries are not released. They are not in any pendingAcks and not in replay either, so they stay undelivered until a rewind. In the chunked path, restoreAssignments (:1251) also re-pins UUID owners for chunks that will not be replayed.

This behaviour existed before this PR, but the new ownership tracking makes it fixable. Skip the failing consumer's slice, pass the rest through replayAndReleaseEntries, and schedule a retry.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread .../java/org/apache/pulsar/broker/service/persistent/PersistentDispatcherMultipleConsumers.java
protected synchronized boolean trySendMessagesToConsumers(ReadType readType, List<Entry> entries) {
protected synchronized boolean trySendMessagesToConsumers(ReadType readType, List<Entry> ownedEntries) {
// Trimming and filtering through consumer sublists must preserve the complete ownership list.
List<Entry> entries = new ArrayList<>(ownedEntries);

@lhotari lhotari Nov 23, 2026

Copy link
Copy Markdown
Member

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.

[QUALITY] Extra per-dispatch work on the hot path

The maintainer asked for performance validation, so here are the per-dispatch costs this change adds:

  • trySendMessagesToConsumers always copies the list here. Every slot the working list nulls or removes (filtering, trimDeletedEntries, sendMessages) has already been released through the wrapper, so it is non-owned anyway. A null check in replayAndReleaseEntries might make the copy unnecessary.
  • The wrap loop in handleSendingMessagesAndReadingMore (:860-862) now runs before trimDeletedEntries. Entries that get trimmed are still metadata-parsed and wrapped; before, wrapping happened after the trim.
  • transferEntriesToConsumer traverses each handed-off batch again.
  • acquirePermitsForDeliveredMessages moved into the per-consumer loop (:1190, :1305, PersistentStickyKeyDispatcherMultipleConsumers.java:479). With throttling configured, that is up to readBatchSize / dispatcherMaxRoundRobinBatchSize rate-limiter calls per read instead of one. Accumulating the totals and charging once in a finally would keep partial dispatches correct.

An A/B run against master would show whether these matter.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread pulsar-broker/src/main/java/org/apache/pulsar/broker/service/AbstractBaseDispatcher.java
BrokerInterceptor interceptor = subscription.interceptor();
if (null != interceptor) {
// keep for compatibility if users has implemented the old interface
interceptor.beforeSendMessage(subscription, entry, ackSet, msgMetadata);

@lhotari lhotari Nov 23, 2026

Copy link
Copy Markdown
Member

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.

[QUALITY] Interceptor callbacks and filter metrics repeat for the accepted prefix on every retry

For every accepted entry, filterProcessedMsgs / filterAcceptedMsgs are incremented and interceptor.beforeSendMessage is called. If a later entry in the same batch throws, the accepted prefix is replayed and goes through all of this again on each retry, with no send in between. Under a persistent failure that repeats indefinitely. Filter metrics drift, and auditing or tracing interceptors record sends that never happened. Please either document it or call the interceptor only after a successful handoff.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread ...a/org/apache/pulsar/broker/service/persistent/PersistentDispatcherMultipleConsumersTest.java
assertThat(dispatcher.isHavePendingReplayRead()).isFalse();
}
// An operator removes the poison entry; recovery must resume without reconnecting the client.
admin.topics().skipMessages(topicName, "sub", 1);

@lhotari lhotari Nov 23, 2026

Copy link
Copy Markdown
Member

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.

[QUALITY] This test can pass without ever observing a failed retry

The assertions cover the first failure, the replay count, and the gating of readMoreEntries() while the monitor is held. The poison entry is then skipped before any timer-driven retry has been seen to run and fail again. A regression where the retry doesn't fire, or doesn't re-arm the backoff after a second failure, would still pass, because the skip removes the entry first. Consider asserting that getReadMoreEntriesCallCount() increases across a backoff interval and that isDispatchRetryPending() is set again, before calling skipMessages.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread .../java/org/apache/pulsar/broker/service/persistent/PersistentDispatcherMultipleConsumers.java
dispatchMessagesThread.execute(() -> {
handleSendingMessagesAndReadingMore(readType, entries, false, totalBytesSize);
});
} catch (RejectedExecutionException e) {

@lhotari lhotari Nov 23, 2026

Copy link
Copy Markdown
Member

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.

[QUALITY] The new abort branches have no direct tests

None of the tests reaches these paths:

  • this branch, where dispatchMessagesThread.execute is rejected
  • a read completing while pendingConsumerSendFailures > 0 (:863-869)
  • the Key_Shared onDispatchAborted replay lifecycle (replayReadsInFlight, replayDispatchesQueued, replay additions)

The ConsumerSendFailureTest cases publish one message with dispatcherMaxReadBatchSize=1, so no second read is in flight when the send is rejected. A regression in onDispatchAborted (double-decrementing the queued dispatch, or not ending the replay read) would leave stale replay additions blocking hashes and go unnoticed.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread .../java/org/apache/pulsar/broker/service/persistent/PersistentDispatcherMultipleConsumers.java
onDispatchAborted(readType);
releaseSendInProgress();
updatePendingBytesToDispatch(-totalBytesSize);
handleDispatchFailure(entries, e);

@lhotari lhotari Nov 23, 2026

Copy link
Copy Markdown
Member

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.

[QUALITY] Raw entries here can get a different replay hash in the entry-bucket dispatcher

Minor: this path passes the raw (unwrapped) entries to replayAndReleaseEntries. PersistentEntryBucketDispatcherMultipleConsumers.getStickyKeyHash routes a wrapped stamped entry by entryHashMin but a raw entry by its message key. A stamped batch can therefore be recorded under a different bucket than normal dispatch would use. Wrapping with EntryAndMetadata.create before computing the hash would keep them consistent. This is reachable only when the subscription dispatch thread rejects the task, so it is low impact.

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
dispatcher.removeConsumer(consumer);
// A late STICKY selector addition can need cleanup after dispatcher removal. Always let the dispatcher
// clean up this instance, even when it no longer contributes to subscription statistics or topic usage.
dispatcher.removeConsumer(consumer);

@lhotari lhotari Nov 23, 2026

Copy link
Copy Markdown
Member

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.

[QUALITY] Repeated cleanup now logs an ERROR for an expected race

Nit: dispatcher.removeConsumer is now called even when wasConnected is false. For the race this guard expects (deferred cleanup after an ordinary close), that hits the "Trying to remove a non-connected consumer" ERROR log in PersistentDispatcherMultipleConsumers.java:305. Could that log be downgraded for this case, or the call skipped when the dispatcher no longer knows the consumer?

Sorry, something went wrong.

Uh oh!

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

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

Reviewers

@lhotari lhotari lhotari left review comments
@codelipenghui codelipenghui codelipenghui approved these changes

Uh oh!

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

Assignees

No one assigned

Labels

None yet

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.

3 participants

@Denovo1998 @lhotari @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.