1
- # PIP-398: Subscription replication on the namespace and topic levels
1
+ # PIP-398: Subscription replication on the broker, namespace and topic levels
2
2
3
3
# Background knowledge
4
4
@@ -18,36 +18,53 @@ large-scale deployments.
18
18
The key motivation behind this PIP is to simplify subscription replication configuration, especially in failover
19
19
scenarios. When a main cluster goes down and a backup cluster is activated, ensuring that subscription states are
20
20
consistently replicated across clusters is critical for failover scenarios. By extending the replication configuration
21
- to the namespace and topic levels, the system reduces the need for explicit consumer-level configuration.
21
+ to the broker, namespace and topic levels, the system reduces the need for explicit consumer-level configuration.
22
22
23
23
# Goals
24
24
25
25
## In Scope
26
26
27
- The PIP aims to provide management of subscription replication at the namespace and topic levels using the Pulsar Admin
28
- CLI and API.
27
+ The PIP aims to provide management of subscription replication at the broker, namespace and topic levels using the
28
+ Pulsar Admin CLI and API.
29
29
30
30
# Out scope
31
31
32
32
This feature depends on https://github.com/apache/pulsar/pull/23757 , which makes the subscription replication nullable
33
- on the consumer level. Otherwise, the namespace and topic levels will be ignored.
33
+ on the consumer level. Otherwise, the broker, namespace and topic levels will be ignored.
34
34
35
35
# High Level Design
36
36
37
- Introduces a configuration used for enabling subscription replication on the namespace and topic levels, when enabled,
38
- all consumers under the topic will automatically replicate their subscription states to remote clusters.
37
+ Introduces a configuration used for enabling subscription replication on the broker, namespace and topic levels, when
38
+ enabled, all consumers under the topic will automatically replicate their subscription states to remote clusters.
39
39
40
40
The priority for the subscription replication configuration is as follows:
41
41
42
- - consumer level > topic level > namespace level.
43
- - If ` replicateSubscriptionState ` is set at the consumer level, configurations at the topic and namespace levels are
42
+ - consumer level > topic level > namespace level > broker level .
43
+ - If ` replicateSubscriptionState ` is set at the consumer level, configurations at the topic, namespace, and broker levels are
44
44
ignored.
45
45
- If set at the topic level, the namespace-level configuration is ignored.
46
+ - If set at the namespace level, the broker-level configuration is ignored.
46
47
47
48
# Detailed Design
48
49
49
50
## Design & Implementation Details
50
51
52
+ ### Broker level
53
+
54
+ Add the field ` Boolean replicate_subscriptions_state ` to the ` org.apache.pulsar.broker.ServiceConfiguration ` class
55
+ to control subscription replication at the broker level:
56
+ ``` java
57
+ public class ServiceConfiguration implements PulsarConfiguration {
58
+ @FieldContext (
59
+ category = CATEGORY_SERVER ,
60
+ required = false ,
61
+ dynamic = true ,
62
+ doc = " The default value for replicating subscription state."
63
+ )
64
+ private Boolean replicate_subscriptions_state;
65
+ }
66
+ ```
67
+
51
68
### Namespace level
52
69
53
70
1 . Add the field ` Boolean replicate_subscriptions_state ` to the ` org.apache.pulsar.common.policies.data.Policies ` class
@@ -91,19 +108,20 @@ The priority for the subscription replication configuration is as follows:
91
108
92
109
### Consumer level
93
110
94
- We currently support the ` replicateSubscriptionState ` flag at the consumer level, which can be set to ` true ` , ` false ` .
95
- If ` true ` , we persist ` pulsar.replicated.subscription=1L ` to the cursor properties, and if ` false ` , we remove that.
111
+ We currently support the ` replicateSubscriptionState ` flag for new subscription at the consumer level, which can be set
112
+ to ` true ` or ` false ` . If ` true ` , we persist ` pulsar.replicated.subscription=1L ` to the cursor properties, and if
113
+ ` false ` , we remove that.
96
114
97
115
To keep the consumer-level configuration, we need to consider the ` false ` case, so propose using
98
116
` pulsar.replicated.subscription=0L ` instead of removing the property.
99
117
100
- The consumer-level configuration takes precedence over both the topic and namespace levels, ensuring that
118
+ The consumer-level configuration takes precedence over both the topic, broker and namespace levels, ensuring that
101
119
consumer-specific configurations can still override the more general settings.
102
120
103
121
### Subscription replication applied
104
122
105
- When the subscription replication is changed on the namespace or topic level, the subscription replication will be
106
- applied to all consumers under the topic.
123
+ When the subscription replication is changed on the broker, namespace or topic level, the subscription replication will
124
+ be applied to all consumers under the topic.
107
125
108
126
Please notice that the ` org.apache.pulsar.client.admin.Topics.setReplicatedSubscriptionStatus() ` can override the
109
127
subscription replication configuration for the special subscription, and equals the consumer level.
@@ -114,7 +132,7 @@ subscription replication configuration for the special subscription, and equals
114
132
115
133
### Client API
116
134
117
- Change the set replicated subscription status method in the ` org.apache.pulsar.client.admin.Topics ` interface to accept the Boolean type:
135
+ Change the set replicated subscription status method in the ` org.apache.pulsar.client.admin.Topics ` interface to accept the ` Boolean ` type:
118
136
119
137
``` java
120
138
void setReplicatedSubscriptionStatus(String topic, String subName, Boolean enabled) throws PulsarAdminException ;
@@ -212,21 +230,38 @@ Both write and read operations require the necessary permissions, which already
212
230
213
231
## Upgrade
214
232
215
- The existing subscription with ` replicateSubscriptionSate=false ` ,the broker will use the policy from the topic or namespace level.
216
-
217
- New subscriptions will be followed as usual.
233
+ Because the consumer's ` replicateSubscriptionSate=false ` does not persist to the cursor properties, it leads to
234
+ compatibility issues:
235
+
236
+ - When the existing subscription with ` replicateSubscriptionSate=false ` on the consumer level, which uses the policy
237
+ from the topic, namespace, or broker level. If you want to use the initial configuration, please use the pulsar-admin
238
+ API orCLI:
239
+ - CLI
240
+ ``` shell
241
+ bin/pulsar-admin topics set-replicated-subscription-status < tenant> /< namespace> /< topic> -s < subName> --disable
242
+ ```
243
+ - API
244
+ ` ` ` java
245
+ admin.topics ().setReplicatedSubscriptionStatus(topic, subName, false);
246
+ ` ` `
218
247
219
248
# # Downgrade / Rollback
220
249
221
- If the broker is downgrade, users will need to ensure that the subscription replication configuration is re-enabled to maintain
222
- the correct replication behavior by the admin CLI or API:
223
- - CLI:
250
+ If the broker is downgrade, users need to ensure that the subscription replication configuration is reset to maintain
251
+ the correct replication behavior by the pulsar- admin CLI or API:
252
+ - CLI
224
253
` ` ` shell
225
- pulsar-admin topics set-replicated-subscription-status < tenant> /< namespace> /< topic> -s < subName> -e
254
+ # enable
255
+ pulsar-admin topics set-replicated-subscription-status < tenant> /< namespace> /< topic> -s < subName> --enable
256
+ # disable
257
+ pulsar-admin topics set-replicated-subscription-status < tenant> /< namespace> /< topic> -s < subName> --disable
226
258
` ` `
227
- - API:
259
+ - API
228
260
` ` ` java
261
+ // enable
229
262
admin.topics ().setReplicatedSubscriptionStatus(topic, subName, true);
263
+ // disable
264
+ admin.topics ().setReplicatedSubscriptionStatus(topic, subName, false);
230
265
` ` `
231
266
232
267
# # Pulsar Geo-Replication Upgrade & Downgrade/Rollback Considerations
0 commit comments