[fix][ml] Avoid blocking the factory-shutdown thread on serial managed-ledger close#26063
Open
merlimat wants to merge 1 commit into
Open
[fix][ml] Avoid blocking the factory-shutdown thread on serial managed-ledger close#26063merlimat wants to merge 1 commit into
merlimat wants to merge 1 commit into
Conversation
…d-ledger close ManagedLedgerFactoryImpl.shutdownAsync first initiates an async close (asyncClose) for every managed ledger known at the start of shutdown. A second pass, inside bookkeeperFuture.thenRun(...), then closes any ledgers that were added after that snapshot -- but it did so with a serial, blocking managedLedger.close() (which waits on a CountDownLatch), blocking the thread that completes the shutdown future. Change that second pass from thenRun to thenCompose, and replace the blocking close() with asyncClose(), collecting the per-ledger futures and awaiting them with Futures.waitForAll. In the common case this pass is empty (the first pass has already drained the ledgers map), so it is a no-op; when ledgers were added concurrently during shutdown they now close in parallel without blocking the continuation thread. The first pass and the rest of the shutdown sequence are unchanged.
void-ptr974
reviewed
Jun 19, 2026
| }, null); | ||
| } | ||
| })); | ||
| return Futures.waitForAll(remainingFutures); |
Contributor
There was a problem hiding this comment.
Previously this path used managedLedger.close(), which bounded the wait with AsyncOperationTimeoutSeconds before continuing shutdown. With the new asyncClose() + waitForAll flow, do we still want to keep a bounded wait here?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation
ManagedLedgerFactoryImpl.shutdownAsyncfirst initiates an async close (asyncClose) for every managed ledger known at the start of shutdown. A second pass, insidebookkeeperFuture.thenRun(...), then closes any ledgers that were added after that snapshot — but it did so with a serial, blockingmanagedLedger.close()(which waits on aCountDownLatch), blocking the thread that completes the shutdown future.Modifications
Change that second pass from
thenRuntothenCompose, and replace the blockingclose()withasyncClose(), collecting the per-ledger futures and awaiting them withFutures.waitForAll. In the common case this pass is empty (the first pass has already drained theledgersmap), so it is a no-op; when ledgers were added concurrently during shutdown they now close in parallel without blocking the continuation thread. The first pass and the rest of the shutdown sequence are unchanged.Verifying this change
Covered by
ManagedLedgerFactoryShutdownTest.openEncounteredShutdown(shutdown while a ledger open is in progress) — passes.Does this pull request potentially affect one of the following parts:
If the box was checked, please highlight the changes