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] Register the extensible load manager's unload and split waits before publishing the event by merlimat · Pull Request #27550 · apache/pulsar

Conversation

@merlimat

@merlimat merlimat commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Motivation

An admin unload or transfer with the extensible load manager can wait out namespaceBundleUnloadingTimeoutMs (60 s by default) although the bundle was unloaded in a few milliseconds. The bundle split has the same race.

The source broker publishes Releasing on the service unit state channel, and UnloadManager.waitAsync() registers the in-flight request only once the publish future completes:

// ExtensibleLoadManagerImpl.unloadAsync()
CompletableFuture<Void> future = serviceUnitStateChannel.publishUnloadEventAsync(unload);
return unloadManager.waitAsync(future, unload.serviceUnit(), unloadDecision, timeout, timeoutUnit) ...

// UnloadManager.waitAsync()
return eventPubFuture.thenCompose(__ -> {
    CompletableFuture<Void> future = inFlightUnloadRequest.computeIfAbsent(bundle, ...);

When this broker's channel handles the unload's last state (Owned for a transfer, Free for an unload), UnloadManager.complete() removes the in-flight request. If none is registered yet, it drops the event. The request registered afterwards waits until the timeout, or until some later event of the bundle completes it.

The publish future can complete after the unload is done. With the metadata store table view, put() completes only after the view has handled a new read of the key:

// MetadataStoreTableViewImpl.put()
return cache.readModifyUpdateOrCreate(path, ...)
        .thenCompose(__ -> doHandleNotification(path)) // immediately notify local tableview

Meanwhile, the source broker's own watch notification for Releasing drives the transfer: it closes the bundle and writes Assigning, the destination writes Owned, and the source handles Owned. All of this can happen before the put's read returns.

This is why ExtensibleLoadManagerImplTest.testUnloadAdminAPI and ExtensibleLoadManagerImplWithTransactionCoordinatorTest.testUnloadAdminAPI failed their first attempt in 4 CI runs since 2026-11-07:

org.testng.internal.thread.ThreadTimeoutException: Method ...testUnloadAdminAPI() didn't finish within the time-out 30000

Example

A Docker reproduction (4 JVMs on 2 CPUs, the transaction coordinator test class repeated on fresh clusters) hung once, with the CI signature. The test thread was waiting in the transfer:

org.testng.internal.thread.ThreadTimeoutException: Method ...ExtensibleLoadManagerImplWithTransactionCoordinatorTest.testUnloadAdminAPI() didn't finish within the time-out 30000
	at org.apache.pulsar.client.admin.internal.NamespacesImpl.unloadNamespaceBundle(NamespacesImpl.java:916)
	at ...ExtensibleLoadManagerImplWithTransactionCoordinatorTest.testUnloadAdminAPI(ExtensibleLoadManagerImplWithTransactionCoordinatorTest.java:53)

The source broker, 46795, handled the transfer's Owned 7 ms after the request. UnloadManager.complete() ran (the DISCONNECT measurement ended), but nothing was registered, so no "Complete unload bundle" was logged:

03:01:48,089 [pulsar-web-1269-8] Unloading namespace bundle {bundleRange=0x06000000_0x08000000, namespace=public/test-elb-with-tx}
03:01:48,092 [metadata-store-worker-...] received a handle request {broker=localhost:46795, data=...[state=Releasing, dstBroker=localhost:43631, sourceBroker=localhost:46795, versionId=3]
03:01:48,095 [metadata-store-worker-...] received a handle request {broker=localhost:46795, data=...[state=Owned, dstBroker=localhost:43631, sourceBroker=localhost:46795, versionId=5]
03:01:48,096 [metadata-store-worker-...] Operation for service unit took ms {operation=DISCONNECT, took=0, unit=public/test-elb-with-tx/0x06000000_0x08000000}
03:01:48,097 [metadata-store-worker-...] Handled event for serviceUnit {broker=localhost:46795, cur=...[state=Owned, ..., versionId=5], event=Transfer:Owned}

The request was registered later and was still waiting. The test cleanup's next ownership change of the bundle completed it, 30 s later:

03:02:18,341 [metadata-store-worker-...] Complete unload bundle {bundle=public/test-elb-with-tx/0x06000000_0x08000000}

The thread dump taken at the timeout shows no blocked thread.

Modifications

UnloadManager.waitAsync() and SplitManager.waitAsync() take a Supplier that publishes the event. They register the request before they call it:

public CompletableFuture<Void> waitAsync(Supplier<CompletableFuture<Void>> eventPublisher, String bundle,
                                         UnloadDecision decision, long timeout, TimeUnit timeoutUnit) {
    InFlightUnload request = inFlightUnloadRequest.computeIfAbsent(bundle, ignore ->
            new InFlightUnload(decision.getUnload().sourceBroker(),
                    new CompletableFuture<Void>().orTimeout(timeout, timeoutUnit)));
    ...
    return eventPublisher.get().whenComplete((__, ex) -> {
        // No event will complete the request, which the waiters of the bundle share: fail it
        if (ex != null && inFlightUnloadRequest.remove(bundle, request)) {
            future.completeExceptionally(ex);
        }
    }).thenCompose(__ -> unloaded) ...

ExtensibleLoadManagerImpl, UnloadScheduler and SplitScheduler pass () -> channel.publishXxxEventAsync(...).

Registering first opens a new window: an earlier unload's event that this broker handles after the registration could complete the new request. For example, a transfer to this broker completes the lookup that an unload request is waiting for inside handleOwnEvent(), before the channel notifies its listeners of that same Owned. All of an unload's events carry its source broker (Releasing, then Free, or Assigning and Owned). So UnloadManager now completes a request only on events whose sourceBroker is the request's, or on Init. A split completes only on its parent's tombstone (Init), so SplitManager needs no such check.

As before, a failed publish fails the caller, and concurrent waiters of a bundle share one request. A failed publish now also removes the request instead of leaving it to time out.

Verifying this change

  • New unit tests:

    • UnloadManagerTest.testUnloadDoneBeforeItsPublishCompletes and SplitManagerTest.testSplitDoneBeforeItsPublishCompletes: the last state is handled before the publish future completes.
    • UnloadManagerTest.testEventsOfAnotherUnloadDoNotCompleteTheRequest: the events of another unload don't complete the request.

    With the old ordering behind the new signature, all three fail: the first two with a TimeoutException. The other manager and scheduler tests pass. The scheduler tests now invoke the publisher from their mocked managers.

  • End to end: a scratch change that completes the metadata store table view's put of Releasing 500 ms late makes ExtensibleLoadManagerImplWithTransactionCoordinatorTest.testUnloadAdminAPI fail on master with the CI's ThreadTimeoutException after 30.0 s. With this change it passes in 0.66 s.

  • After merging master, with retries off, these 246 tests pass: ExtensibleLoadManagerImplTest (104), ExtensibleLoadManagerImplWithAdvertisedListenersTest (12), ExtensibleLoadManagerImplWithTransactionCoordinatorTest (2), ServiceUnitStateChannelTest (70), and the manager and scheduler packages (58).

    • Under CPU stress, the full ExtensibleLoadManagerImplTest class's only failure is testDeployAndRollbackLoadManager ("Maximum redirect reached: 5"). It fails the same way on master (3 of 3 runs).
    • One earlier run had testDeleteNamespace fail with an HTTP 503 from a lookup right after the bundle delete. That is a separate race, also seen on master: a broker whose view lags publishes Assigning with a stale version.
  • ./gradlew quickCheck passes.

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
merlimat added 2 commits November 9, 2026 19:51
@merlimat
[fix][broker] Register the extensible load manager's unload and split…
4d61194
… waits before publishing the event

UnloadManager.waitAsync() registered the in-flight request only once the
Releasing publish future completed, and complete() drops a terminal event
(Owned/Free) when no request is registered. The publish future can complete
after the unload is done: the metadata store table view completes a put only
after it has handled a new read of the key, while the source broker's watch
notification already drives Releasing -> Assigning -> Owned. The admin unload
then waited namespaceBundleUnloadingTimeoutMs (60 s), which made
ExtensibleLoadManagerImpl(WithTransactionCoordinator)Test.testUnloadAdminAPI
time out after 30 s. SplitManager had the same ordering.

waitAsync() now takes a Supplier that publishes the event and registers the
request before calling it; a failed publish removes and fails the request.
Because the request now exists before the unload's own events, UnloadManager
completes it only on events whose source broker is the unload's (or Init), so
the Owned of the transfer that made this broker the owner can't complete it.
@merlimat
Merge remote-tracking branch 'apache/master' into wt/elm-unload-admin…
3ccd5a8
…-api-flake-97cc98
@merlimat merlimat added the area/broker label Nov 10, 2026
codelipenghui
codelipenghui approved these changes Nov 10, 2026
View reviewed changes
@codelipenghui
codelipenghui merged commit e04dea5 into apache:master Nov 10, 2026
44 checks passed

Uh oh!

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

lhotari pushed a commit that referenced this pull request Nov 11, 2026
@merlimat @lhotari
[fix][broker] Register the extensible load manager's unload and split…
540b8f0
… waits before publishing the event (#27550)

(cherry picked from commit e04dea5)
@lhotari lhotari added release/5.0.2 cherry-picked/branch-5.0 labels Nov 11, 2026
This was referenced Nov 21, 2026
[improve][ci] Run CI for the 4.2.6 backports to branch-4.2 (do not merge) #27680
Closed
[improve][ci] Run CI for the 4.2.6 backports to branch-4.2 (do not merge) #27681
Closed
[improve][ci] Run CI for the 4.2.6 backports to branch-4.2 (do not merge) #27684
Closed
@lhotari lhotari added cherry-picked/branch-4.2 release/4.2.6 cherry-picked/branch-4.0 release/4.0.15 labels Nov 21, 2026
poorbarcode pushed a commit to poorbarcode/pulsar that referenced this pull request Nov 26, 2026
@merlimat @lhotari
[fix][broker] Register the extensible load manager's unload and split…
e494d34
… waits before publishing the event (apache#27550)

(cherry picked from commit e04dea5)
poorbarcode pushed a commit to poorbarcode/pulsar that referenced this pull request Nov 26, 2026
@merlimat @lhotari
[fix][broker] Register the extensible load manager's unload and split…
ec22687
… waits before publishing the event (apache#27550)

(cherry picked from commit e04dea5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@codelipenghui codelipenghui codelipenghui approved these changes

Uh oh!

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

Assignees

No one assigned

Labels

area/broker cherry-picked/branch-4.0 cherry-picked/branch-4.2 cherry-picked/branch-5.0 release/4.0.15 release/4.2.6 release/5.0.2

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

@merlimat @codelipenghui @lhotari
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.