Skip to content

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

Open
void-ptr974 wants to merge 1 commit into
apache:masterfrom
void-ptr974:fix/broker-service-unload-cache-cleanup
Open

[fix][broker] Prevent stale topic unload cleanup from removing active cache entries#26145
void-ptr974 wants to merge 1 commit 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant