[fix][broker] Avoid blocking the PulsarAdmin callback thread on the post-unload load-report write#26061
Open
merlimat wants to merge 1 commit into
Open
Conversation
…ost-unload load-report write When a namespace isolation policy changes, ClustersBase .filterAndUnloadMatchedNamespaceAsync unloads the affected namespaces and then writes the load report so the cluster rebalances quickly. That write ran inside FutureUtil.waitForAll(unloadAsync...).thenAccept(...), which executes on the thread that completes the adminClient.namespaces().unloadAsync(...) futures -- a PulsarAdmin async-HTTP-client callback thread. LoadManager .writeLoadReportOnZookeeper(true) blocks there: ModularLoadManagerImpl .writeBrokerDataOnZooKeeper does lock.lock() plus a metadata-store updateValue(...).join(). Run the load-report write via thenAcceptAsync(..., pulsar().getExecutor()) so it executes on the broker executor (where short blocking metadata writes are routine) instead of the admin-client callback thread. The REST response still waits for the write (the chained future completes after it); the write remains best-effort (failure logged and swallowed, as before).
void-ptr974
approved these changes
Jun 19, 2026
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
When a namespace isolation policy changes,
ClustersBase.filterAndUnloadMatchedNamespaceAsyncunloads the affected namespaces and then writes the load report so the cluster rebalances quickly. That write ran insideFutureUtil.waitForAll(unloadAsync...).thenAccept(...), which executes on the thread that completes theadminClient.namespaces().unloadAsync(...)futures — a PulsarAdmin async-HTTP-client callback thread.LoadManager.writeLoadReportOnZookeeper(true)blocks there:ModularLoadManagerImpl.writeBrokerDataOnZooKeeperdoeslock.lock()plus a metadata-storeupdateValue(...).join(). So a brief metadata write blocked the admin-client callback thread.Modifications
Run the load-report write via
thenAcceptAsync(..., pulsar().getExecutor())so it executes on the broker executor (where short blocking metadata writes are routine) instead of the admin-client callback thread. The REST response still waits for the write (the chained future completes after it); the write remains best-effort (failure is logged and swallowed, as before).Verifying this change
Covered by
AdminApi2Test.testIsolationPolicyUnloadsNSWith*(AllScope,ChangedScope1/2,NoneScope,PrimaryChanged,ScopeMissing; persistent + non-persistent) — 12/12 pass.Does this pull request potentially affect one of the following parts:
If the box was checked, please highlight the changes