Skip to content

[fix][broker] Prevent stale topic unload cleanup from removing active cache entries - #26145

Merged
lhotari merged 2 commits into
apache:masterfrom
void-ptr974:fix/broker-service-unload-cache-cleanup
Jul 25, 2026
Merged

[fix][broker] Prevent stale topic unload cleanup from removing active cache entries#26145
lhotari merged 2 commits into
apache:masterfrom
void-ptr974:fix/broker-service-unload-cache-cleanup

Conversation

@void-ptr974

@void-ptr974 void-ptr974 commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Motivation

BrokerService.topics entries can be replaced when a topic is loaded again after a bundle unload or topic close path has started.

Before this change, cleanUnloadedTopicFromCache could remove a topic by name only, and removeTopicFromCache could still dispatch unload side effects after the matching cache entry had already been replaced. A stale cleanup callback could remove a newer active topic future or clear auxiliary broker-local state for a superseded entry.

Modifications

  • Make cleanUnloadedTopicFromCache clean only topics already fenced by close/unload.
  • Remove topics from BrokerService.topics with the captured topic future when one is available.
  • Skip unload events and related cache/stat cleanup when the topic entry was already removed or superseded.
  • Add regression tests for preserving active topic futures, skipping stale close-callback side effects, and removing matching fenced topic futures.

Verifying this change

  • ./gradlew :pulsar-broker:test --tests org.apache.pulsar.broker.service.BrokerServiceTest.testCleanUnloadedTopicFromCacheDoesNotRemoveNewTopicFuture --tests org.apache.pulsar.broker.service.BrokerServiceTest.testRemoveTopicFromCacheDoesNotRemoveSupersededTopicFuture --tests org.apache.pulsar.broker.service.BrokerServiceTest.testCleanUnloadedTopicFromCacheRemovesInactiveBundleTopicFuture
  • ./gradlew :pulsar-broker:checkstyleMain :pulsar-broker:checkstyleTest
  • git diff --check

@void-ptr974 void-ptr974 changed the title [fix][broker] Avoid stale unload cleanup removing active topics [fix][broker] Prevent stale bundle unload cleanup from removing active topic cache entries Jul 4, 2026
cleanUnloadedTopicFromCache is a best-effort cleanup after bundle unload. It previously removed topics by name and could remove a newer topic future installed after a stale unload cleanup started.

Only clean fenced topics and remove cache entries using the captured topic future. Skip unload side effects when the cache entry was already removed or superseded.

Add tests for stale cleanup preserving a newer topic future and cleanup of inactive fenced topic futures.
@void-ptr974
void-ptr974 force-pushed the fix/broker-service-unload-cache-cleanup branch from d363eb1 to 1c9beb8 Compare July 4, 2026 04:35
@void-ptr974 void-ptr974 changed the title [fix][broker] Prevent stale bundle unload cleanup from removing active topic cache entries [fix][broker] Prevent stale topic unload cleanup from removing active cache entries Jul 4, 2026
Comment thread pulsar-broker/src/main/java/org/apache/pulsar/broker/service/BrokerService.java Outdated
Comment thread pulsar-broker/src/main/java/org/apache/pulsar/broker/service/BrokerService.java Outdated
@lhotari
lhotari merged commit 73549d2 into apache:master Jul 25, 2026
43 checks passed
lhotari pushed a commit that referenced this pull request Jul 25, 2026
lhotari pushed a commit that referenced this pull request Jul 25, 2026
sandeep-ctds pushed a commit to datastax/pulsar that referenced this pull request Jul 31, 2026
sandeep-ctds pushed a commit to datastax/pulsar that referenced this pull request Jul 31, 2026
sandeep-ctds pushed a commit to datastax/pulsar that referenced this pull request Jul 31, 2026
nodece pushed a commit to ascentstream/pulsar that referenced this pull request Aug 28, 2026
… cache entries (apache#26145)

(cherry picked from commit 73549d2)
Signed-off-by: Zixuan Liu <nodeces@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants