[fix][broker] Propagate topic policy initialization failures - #26259
Open
Praveenkumar76 wants to merge 1 commit into
Open
[fix][broker] Propagate topic policy initialization failures#26259Praveenkumar76 wants to merge 1 commit into
Praveenkumar76 wants to merge 1 commit into
Conversation
Praveenkumar76
force-pushed
the
fix/26137-topic-policy-load-failure
branch
from
August 1, 2026 06:41
b5987ce to
84bb5f1
Compare
Praveenkumar76
marked this pull request as ready for review
August 2, 2026 07:57
Praveenkumar76
force-pushed
the
fix/26137-topic-policy-load-failure
branch
from
August 6, 2026 15:32
84bb5f1 to
bae377f
Compare
…d non-persistent topics
Praveenkumar76
force-pushed
the
fix/26137-topic-policy-load-failure
branch
from
August 6, 2026 15:33
bae377f to
304c63b
Compare
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.
Fixes #26137
Motivation
Topic policies are loaded during topic initialization through
AbstractTopic.initTopicPolicy().Previously, both
PersistentTopic.initialize()andNonPersistentTopic.initialize()handled failures frominitTopicPolicy()withexceptionally(...)and returnednull. This converted the failed future into a successful one, allowing the topic to finish loading without its topic-level policies being applied.As a result, the topic could temporarily or indefinitely use namespace-level or broker-level fallback settings. This is unsafe for policies such as retention and TTL because the effective behavior may differ from the policy configured directly on the topic.
For non-persistent topics, propagating the initialization failure also requires complete cleanup. The topic-policy listener is registered before the initial policy fetch finishes. If topic creation fails and the topic is only removed from the broker cache without being closed, the listener can continue retaining the failed topic instance. Retrying the same topic could then accumulate stale listeners.
Modifications
PersistentTopic.initialize()to preserve failures frominitTopicPolicy()instead of converting them into successful initialization.NonPersistentTopic.initialize()to preserve failures frominitTopicPolicy()instead of ignoring them.isEncryptionRequiredwhen persistent-topic policy initialization fails.BrokerService#createNonPersistentTopic()to fully close a partially initialized non-persistent topic when creation fails.stopReplProducers()cleanup withclose(true, true)so registered topic-policy listeners and other topic resources are released.Verifying this change
This change added tests and can be verified as follows:
PersistentTopicTest.testInitializeFailsWhenTopicPolicyLoadingFailsNonPersistentTopicTest.testInitializeFailsWhenTopicPolicyLoadingFailsBrokerServiceTest.testNonPersistentTopicPolicyLoadFailureCleansUpListenerThe following related tests also pass:
BrokerServiceTest.testGetTopicWhenTopicPoliciesFailBrokerServiceTest.testMetricsNonPersistentTopicLoadFailsDoes this pull request potentially affect one of the following parts: