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][meta] Reload the bookie info on a cache miss in PulsarRegistrationClient by merlimat · Pull Request #27052 · apache/pulsar

Conversation

@merlimat

@merlimat merlimat commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Fixes #23020
Supersedes #23021

Motivation

Problem. PulsarRegistrationClient.getBookieServiceInfo only looks in its in-memory writableBookieInfo / readOnlyBookieInfo maps. Those maps are filled when a bookie notification is handled. If that read fails (for example a metadata store timeout), the update is dropped: getBookiesThenFreshCache fails, and the Sequencer swallows the failure without logging it. Nothing retries. Until another bookie changes or a metadata session event fires, the broker can't resolve a running bookie. Reads and recovery of existing ledgers on it fail with BKBookieHandleNotAvailableException / BookieIdNotResolvedException, which is the symptom reported in #23020.

Example. Bookie 127.0.0.1:3181 registers at /ledgers/available/127.0.0.1:3181:

  1. updatedBookies (Created) → getWritableBookies() → readBookieInfoAsWritableBookie(id) → the metadata read fails.
  2. writableBookieInfo has no entry for the bookie, and no further notification comes.
  3. Every getBookieServiceInfo(id) fails:
Versioned<BookieServiceInfo> info;
if ((info = writableBookieInfo.get(bookieId)) == null) {
    info = readOnlyBookieInfo.get(bookieId);
}
if (info != null) {
    return completedFuture(info);
} else {
    return FutureUtils.exception(new BKException.BKBookieHandleNotAvailableException());
}

Modifications

Change. On a miss, getBookieServiceInfo starts a background reload of the bookie info: the writable path first, then the read-only one. The reload fills the maps through the existing readBookieInfoAs* methods. The call itself still fails right away and doesn't wait on the metadata store. That keeps the method's existing constraint against blocking and against completing on the metadata thread. BookKeeper's retry then resolves the bookie.

} else {
    // The bookie can be registered and still missing here, if reading its info failed when it
    // registered. Reload it in background, without waiting, so that a retry can find it.
    readBookieInfoAsWritableBookie(bookieId)
            .thenCompose(writable -> writable.isPresent()
                    ? completedFuture(writable)
                    : readBookieInfoAsReadonlyBookie(bookieId))
            .exceptionally(ex -> {
                log.debug().attr("bookieId", bookieId).exceptionMessage(ex)
                        .log("Failed to reload the bookie info");
                return null;
            });
    return FutureUtils.exception(new BKException.BKBookieHandleNotAvailableException());
}

For a bookie that is really down, the reload hits the negative entry already in the metadata cache, so it doesn't add load on the metadata store. Concurrent misses share one in-flight load in the cache.

Verifying this change

Added PulsarRegistrationClientTest.testBookieInfoReloadedAfterFailedRead, for both writable and read-only bookies. A LocalMemoryMetadataStore subclass fails the first read of the bookie's registration path, so the read triggered by the registration notification fails deterministically. The test then asserts:

  • the first getBookieServiceInfo fails;
  • a retry succeeds.

It fails on master and passes with the fix (5 reruns). The whole PulsarRegistrationClientTest class passes on ZooKeeper, Memory, RocksDB, Oxia and MockZooKeeper.

Does this pull request potentially affect one of the following parts:

If the box was checked, please highlight the changes

  • 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
[fix][meta] Reload the bookie info on a cache miss in PulsarRegistrat…
21069e3
…ionClient

If reading the info of a newly registered bookie fails, the bookie stays
missing from the registration client cache until another bookie change or a
metadata session event, and the broker can't resolve it. Reload the info in
background on a miss in getBookieServiceInfo, so that a retry finds it.
@merlimat merlimat mentioned this pull request Oct 22, 2026
[fix] [broker] PulsarRegistrationClient writableBookieInfo cache and readOnlyBookieInfo cache update fail causing broker to misjudge that the bookie is unavailable #23021
Closed
2 of 15 tasks
codelipenghui
codelipenghui approved these changes Oct 23, 2026
View reviewed changes

@codelipenghui codelipenghui left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Failing fast on a miss and reloading in the background is the right approach. DefaultBookieAddressResolver blocks on this future on the caller's thread, sometimes the ZK event thread, so getBookieServiceInfo can't wait for the read. PerChannelBookieClient re-resolves on the next operation, so a bookie whose info read failed at registration now recovers after one failed attempt. Before, it stayed unresolvable until the next bookie or session event. Concurrent misses share one in-flight load in the metadata cache, and missing bookies are cached as negative entries, so the extra metadata load stays bounded.

I ran the new test locally: it passes for both the writable and read-only cases. With the reload block removed, the writable case times out with BKBookieHandleNotAvailableException, so the test does reproduce the bug.

Non-blocking, for a possible follow-up: when the registration-time read fails, updatedBookies also skips onBookiesChanged. BookKeeper's placement view (BookieWatcherImpl -> onClusterChanged) can therefore still miss the bookie; this change fixes address resolution only. Also minor: Caffeine already logs the failed async load at WARN ("Exception thrown during asynchronous load"). So the read failure itself is logged; what goes unlogged is the dropped map/watcher update.

Sorry, something went wrong.

Uh oh!

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

All reactions
@merlimat merlimat added this to the 5.1.0 milestone Oct 23, 2026
@merlimat
merlimat merged commit fa55275 into apache:master Oct 23, 2026
44 checks passed

Uh oh!

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

@merlimat
merlimat deleted the mmerli/registration-client-reload-on-miss branch October 24, 2026 00:00
lhotari pushed a commit that referenced this pull request Oct 26, 2026
@merlimat @lhotari
[fix][meta] Reload the bookie info on a cache miss in PulsarRegistrat…
53a709e
…ionClient (#27052)

(cherry picked from commit fa55275)
@lhotari lhotari added release/5.0.2 cherry-picked/branch-5.0 labels Oct 26, 2026
This was referenced Oct 28, 2026
[fix][meta] Recover bookie watcher notifications after failed reads Denovo1998/pulsar#72
Open
[fix][meta] Recover bookie watcher notifications after failed reads #27204
Merged
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][meta] Reload the bookie info on a cache miss in PulsarRegistrat…
233c843
…ionClient (apache#27052)

(cherry picked from commit fa55275)
poorbarcode pushed a commit to poorbarcode/pulsar that referenced this pull request Nov 26, 2026
@merlimat @lhotari
[fix][meta] Reload the bookie info on a cache miss in PulsarRegistrat…
2682e97
…ionClient (apache#27052)

(cherry picked from commit fa55275)
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

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

5.1.0

Development

Successfully merging this pull request may close these issues.

[Bug][broker]PulsarRegistrationClient writableBookieInfo cache and readOnlyBookieInfo cache update fail causing broker to misjudge that the bookie is unavailable.

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.