Skip to content

[fix][broker] Reject replicated subscriptions on non-replicated topics - #26262

Draft
Praveenkumar76 wants to merge 1 commit into
apache:masterfrom
cognitree:fix/24090-replicated-subscription-validation
Draft

[fix][broker] Reject replicated subscriptions on non-replicated topics#26262
Praveenkumar76 wants to merge 1 commit into
apache:masterfrom
cognitree:fix/24090-replicated-subscription-validation

Conversation

@Praveenkumar76

Copy link
Copy Markdown
Contributor

Fixes #24090

Motivation

Pulsar currently allows a replicated subscription to be created or enabled even when the topic itself is not replicated across multiple clusters.

In this situation, the subscription is marked as replicated on the local cluster, but there is no remote topic or subscription to receive the replicated subscription state. This creates a misleading configuration where replicated subscriptions appear enabled but cannot function.

Modifications

  • Added validation to reject the creation of a new replicated subscription when the topic has fewer than two effective replication clusters.
  • Added validation to reject upgrading an existing non-replicated subscription to a replicated subscription when topic replication is not enabled.
  • Added the same validation to the admin API used by setReplicatedSubscriptionStatus.
  • Continued to allow:
    • disabling replicated subscription status;
    • reconnecting to an existing subscription that is already marked as replicated.
  • Reused the validation when determining whether the replicated-subscription controller should be enabled.
  • Updated existing positive tests to explicitly configure topic replication across two clusters.

Verifying this change

  • Make sure that the change passes the CI checks.

This change added tests and can be verified as follows:

  • Added ReplicatedSubscriptionConfigTest.rejectReplicatedSubscriptionWithoutTopicReplication to verify that consumer-based replicated-subscription creation is rejected on a non-replicated topic.
  • Added PersistentTopicsTest.testCannotEnableReplicatedSubscriptionWithoutTopicReplication to verify that the admin API rejects enabling replicated subscription status on a non-replicated topic.
  • Verified that disabling replicated subscription status is still allowed.
  • Verified existing replicated-subscription creation, upgrade, restart, broker-disabled, and admin API scenarios.

The following targeted tests passed locally:

./gradlew :pulsar-broker:test \
  --tests "org.apache.pulsar.broker.service.persistent.ReplicatedSubscriptionConfigTest.rejectReplicatedSubscriptionWithoutTopicReplication" \
  --tests "org.apache.pulsar.broker.admin.PersistentTopicsTest.testCannotEnableReplicatedSubscriptionWithoutTopicReplication" \
  -PskipJavaVersionCheck \
  -DtestRetryCount=0 \
  --no-daemon \
  --no-configuration-cache
./gradlew :pulsar-broker:test \
  --tests "org.apache.pulsar.broker.service.persistent.ReplicatedSubscriptionConfigTest.createReplicatedSubscription" \
  --tests "org.apache.pulsar.broker.service.persistent.ReplicatedSubscriptionConfigTest.upgradeToReplicatedSubscription" \
  --tests "org.apache.pulsar.broker.service.persistent.ReplicatedSubscriptionConfigTest.upgradeToReplicatedSubscriptionAfterRestart" \
  --tests "org.apache.pulsar.broker.service.persistent.ReplicatedSubscriptionConfigTest.testDisableReplicatedSubscriptions" \
  --tests "org.apache.pulsar.broker.admin.PersistentTopicsTest.testSetReplicatedSubscriptionStatus" \
  -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

The replicated-subscription status REST endpoint now returns a precondition failure when enabling replication for a subscription whose topic is not replicated across multiple clusters.

@lhotari

lhotari commented Aug 4, 2026

Copy link
Copy Markdown
Member

This would cause a breaking change. In some usecases, it might be convenient to first create topics with replicated subscriptions and only after that enable replication. Instead of making code changes, the issue could be resolved by adding clarification in documentation that replicated subscriptions won't have effect unless replication is enabled. There are also other limitations in replicated subscriptions and that's why I don't think that there's a need to prevent creating subscriptions when replication isn't enabled.

The current documentation: https://pulsar.apache.org/docs/5.0.x/administration-geo/#replicated-subscriptions

It does already mention that 2-way replication is required for replicated subscriptions. Configuring 1-way replication isn't sufficient, so the check in this PR wouldn't be useful since the condition is more strict.

@lhotari

lhotari commented Aug 4, 2026

Copy link
Copy Markdown
Member

It would be useful to reject creating replicated subscription if the feature is disabled in the broker. however enableReplicatedSubscriptions defaults to true so there would be marginal benefit in implementing this check. (I didn't check if it's already implemented)

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] Replicated Subscriptions can be created on non-replicated topics

2 participants