Skip to content

[fix][broker] Propagate topic policy initialization failures - #26259

Draft
Praveenkumar76 wants to merge 1 commit into
apache:masterfrom
cognitree:fix/26137-topic-policy-load-failure
Draft

[fix][broker] Propagate topic policy initialization failures#26259
Praveenkumar76 wants to merge 1 commit into
apache:masterfrom
cognitree:fix/26137-topic-policy-load-failure

Conversation

@Praveenkumar76

Copy link
Copy Markdown
Contributor

Fixes #26137

Motivation

Topic policy loading failures during topic initialization were being ignored for both persistent and non-persistent topics.

When initTopicPolicy() failed, the initialization chain recovered through exceptionally(...) and returned a successful result. This allowed the broker to expose a topic even though its topic-level policies had not been loaded. The topic could then operate using lower-priority namespace or broker-level policy values, which could result in incorrect enforcement and potential data loss.

Topic initialization should fail when the initial topic policies cannot be loaded, instead of exposing a partially initialized topic.

Modifications

  • Replaced the terminal exceptionally(...) handlers in PersistentTopic.initialize() and NonPersistentTopic.initialize() with whenComplete(...).
  • Preserved error logging when topic initialization fails.
  • Allowed the original topic policy loading exception to propagate to the topic creation future.
  • Kept isEncryptionRequired set to false when persistent topic initialization fails.
  • Added regression tests for persistent and non-persistent topics to verify that policy loading failures cause topic initialization to fail.

Verifying this change

This change added tests and can be verified as follows:

  • Added PersistentTopicTest.testInitializeFailsWhenTopicPolicyLoadingFails.
  • Added NonPersistentTopicTest.testInitializeFailsWhenTopicPolicyLoadingFails.
  • Verified both tests together with:
./gradlew :pulsar-broker:test \
  --tests "org.apache.pulsar.broker.service.PersistentTopicTest.testInitializeFailsWhenTopicPolicyLoadingFails" \
  --tests "org.apache.pulsar.broker.service.nonpersistent.NonPersistentTopicTest.testInitializeFailsWhenTopicPolicyLoadingFails" \
  -PskipJavaVersionCheck \
  -DtestRetryCount=0 \
  --no-daemon \
  --no-configuration-cache

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

@Praveenkumar76
Praveenkumar76 force-pushed the fix/26137-topic-policy-load-failure branch from b5987ce to 84bb5f1 Compare August 1, 2026 06:41
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.

[Bug] Topic policy loading errors are ignored which can result in data loss

1 participant