Repository navigation
[fix][broker] Recover bucket delayed delivery tracker asynchronously to avoid blocking dispatcher threads - #26105
Conversation
…to avoid blocking dispatcher threads
a8e8932 to
b497567
Compare
lhotari
left a comment
There was a problem hiding this comment.
Thanks for tackling the blocking recovery in the delayed delivery path. Moving recovery off the dispatcher thread is the right direction.
I found no blocking wait left on the async path. Delayed messages are held in the pending map and handed to the tracker once it is ready. Close and clearDelayedMessages() both complete the create future.
A few things need another look:
- A failed creation installs
DelayedDeliveryTracker.DISABLEfor the life of the dispatcher. - The two close tests verify
close()on a plain mock, but the code callscloseAsync(). - A
trackDelayedDeliverycall afterclose()leaves a completed create future set. - The install step is not exception safe.
For context, #26401 changes the same deletion loop in recoverBucketSnapshot. Whichever PR lands second will need a manual merge there. #26420 makes cursor reset call clearDelayedMessages(), which now waits for a pending creation.
- Drop the PersistentDispatcherMultipleConsumersClassic changes and tests: the classic dispatcher was removed in apache#26687. - Re-port the async snapshot recovery onto the BucketContext / index code from apache#26251, keeping the recovery synchronized on the tracker. - Keep the dispatcher's delayed-delivery stats reads lock-free (apache#25990). - A failed tracker creation keeps the delayed messages pending and dispatch paused, and retries with a backoff, instead of installing DelayedDeliveryTracker.DISABLE for the life of the dispatcher. - A closed dispatcher doesn't start a tracker creation. - Handing the pending messages to the new tracker is exception safe: the creation still completes, the remaining messages are replayed and dispatch resumes. - The bucket factory falls back to the in-memory tracker on any async recovery failure. - Tracker creation logs at DEBUG; only failures and a creation still pending after 30 s log a WARN. - Tests verify closeAsync(), cover the closed dispatcher, elapsed messages, a throwing tracker and the retry, check that the dispatcher lock is free during recovery, and restore the shared broker's topic map.
|
Thanks @void-ptr974 for the fix. I've picked this up to get it merged, and pushed a merge of
Other changes from the merge:
Locally, #26401 changes the same recovery loop, so whichever of the two lands second will need a manual merge there. |
…ated inline A factory that completes newTrackerAsync() inline, such as the in-memory one, never paused the dispatch: the read that found the delayed message is still in progress. Only resume the dispatch with readMoreEntriesAsync() when the creation completed later, or on a retry. testGetMessagesToReplayNowChecksDelayedTrackerOnce (added by apache#26954) stubbed only newTracker(), so its factory mock returned no tracker from newTrackerAsync(). It now stubs newTrackerAsync().
…to avoid blocking dispatcher threads (#26105) Co-authored-by: Matteo Merli <[email protected]> (cherry picked from commit c9a95df)
Fixes #26103
Motivation
When a dispatcher reads its first delayed message, it creates its delayed delivery tracker inline, while holding the dispatcher lock. The bucket tracker recovers its bucket snapshots in its constructor and waits for that recovery for up to 300 seconds:
If reading the snapshots from BookKeeper or the metadata store is slow, the subscription stalls. The
broker-topic-workersthread stalls with it, along with every other topic and subscription served by that thread.Modifications
DelayedDeliveryTrackerFactorygains anewTrackerAsync()method. By default it wrapsnewTracker(), so the in-memory factory and custom factories keep working unchanged.BucketDelayedDeliveryTrackerFactory.newTrackerAsync()creates the tracker without recovery, then recovers the bucket snapshots asynchronously with the same 300 s timeout. On any failure or timeout it closes the bucket tracker and falls back to the in-memory tracker, as the synchronous path already did.PersistentDispatcherMultipleConsumers:close()completes a pending creation, and a tracker that is created later is closed.clearDelayedMessages()waits for a pending creation before it clears the tracker.ConcurrentHashMap, guarded by the dispatcher lock for writes.DelayedDeliveryTracker.DISABLE.clear()returns a completed future instead ofnull.Verifying this change
New tests:
PersistentDispatcherMultipleConsumersTest: async tracker creation covering pending messages, elapsed messages, a tracker that throws, close, a closed dispatcher,clearDelayedMessages(), and a failed creation that is retried.DelayedDeliveryTrackerFactoryTest: async bucket creation, fallback after a recovery failure, and a broker-path test. In that test a delayed message waits for a bucket snapshot recovery that is held back, the dispatcher lock stays free meanwhile, and the message is delivered once the recovery completes.Does this pull request potentially affect one of the following parts: