Repository navigation
[fix][broker] Avoid blocking metadata read on the IO thread when redirecting migrated producers/consumers - #26051
Merged
lhotari merged 1 commit intoJun 18, 2026
Conversation
…recting migrated producers/consumers AbstractTopic.getMigratedClusterUrl() resolved the migrated cluster URL by blocking on getMigratedClusterUrlAsync().get(timeout). It was reached from Netty event-loop threads and CompletableFuture callbacks (ServerCnx subscribe/produce handlers via Consumer.checkAndApplyTopicMigration(), AbstractBaseDispatcher, and the persistent/non-persistent checkClusterMigration paths), so a slow or contended metadata read could stall the IO thread for up to the metadata operation timeout. Route all callers through the existing async getMigratedClusterUrlAsync() and delete the blocking method: - Consumer.checkAndApplyTopicMigration() -> checkAndApplyTopicMigrationAsync() - ServerCnx subscribe-success uses thenCompose; the producer/consumer migration-redirect exceptionally handlers resolve the URL asynchronously - checkClusterMigration resolves the URL once and reuses it for each consumer A failed metadata resolution is no longer swallowed into 'not migrated'.
lhotari
approved these changes
Jun 18, 2026
Merged
10 tasks
sandeep-ctds
pushed a commit
to datastax/pulsar
that referenced
this pull request
Jul 31, 2026
…recting migrated producers/consumers (apache#26051) (cherry picked from commit ac053c3)
nodece
pushed a commit
to ascentstream/pulsar
that referenced
this pull request
Aug 28, 2026
…recting migrated producers/consumers (apache#26051) (cherry picked from commit ac053c3) Signed-off-by: Zixuan Liu <[email protected]>
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
AbstractTopic.getMigratedClusterUrl()resolved the migrated-cluster URL by blocking ongetMigratedClusterUrlAsync().get(operationTimeoutSeconds). Its clean, non-throwing signature hid that it blocks, and several callers run on threads where blocking is harmful:ServerCnxsubscribe-success path, inside.thenAcceptAsync(..., ctx.executor())(the connection's Netty IO thread), viaConsumer.checkAndApplyTopicMigration();exceptionallyAsync(..., ctx.executor())handlers inServerCnx;AbstractBaseDispatcher.checkAndApplyReachedEndOfTopicOrTopicMigration()on the dispatch path;PersistentTopic/NonPersistentTopic.checkClusterMigration()and the topic write-failed path.A slow or contended metadata read could therefore stall a Netty IO thread for up to the metadata operation timeout (default 30s). Blocking with
get()on one pool while the future is completed on another is also a deadlock hazard if the completing pool is saturated.Modifications
Route every caller through the already-existing async
getMigratedClusterUrlAsync()and delete the blockinggetMigratedClusterUrl()overloads:Consumer.checkAndApplyTopicMigration()→checkAndApplyTopicMigrationAsync()returningCompletableFuture<Boolean>(reusestopicMigrated(...)for the send + disconnect).ServerCnx: subscribe-success usesthenComposeso the migration check stays async onctx.executor(); the three producer/consumer migration-redirect handlers resolve the URL asynchronously and then redirect-or-fail in small helpers that preserve each branch's exact cleanup and logging.AbstractBaseDispatcher,PersistentTopic,NonPersistentTopic: resolve the URL asynchronously.checkClusterMigrationresolves it once and reuses it for each consumer, dropping a redundant per-consumer blocking re-resolve.A failed metadata resolution is no longer swallowed into "not migrated"; it surfaces instead. No public/admin API or wire-protocol change —
getMigratedClusterUrlAsync()already existed and already hops completion topulsar.getExecutor()to avoid the metadata-thread deadlock.Verifying this change
This change is already covered by existing tests:
ClusterMigrationTest— producer & consumer redirect, persistent & non-persistent topics, replication-backlog, resource-created, and namespace-migration cases (18 executions, all passing locally).Does this pull request potentially affect one of the following parts:
If the box was checked, please highlight the changes