Skip to content

Commit 5935c9b

Browse files
committed
Add broker config and update compatibility
1 parent 8cba4bc commit 5935c9b

File tree

1 file changed

+58
-23
lines changed

1 file changed

+58
-23
lines changed

Diff for: pip/pip-398.md

+58-23
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# PIP-398: Subscription replication on the namespace and topic levels
1+
# PIP-398: Subscription replication on the broker, namespace and topic levels
22

33
# Background knowledge
44

@@ -18,36 +18,53 @@ large-scale deployments.
1818
The key motivation behind this PIP is to simplify subscription replication configuration, especially in failover
1919
scenarios. When a main cluster goes down and a backup cluster is activated, ensuring that subscription states are
2020
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.
2222

2323
# Goals
2424

2525
## In Scope
2626

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.
2929

3030
# Out scope
3131

3232
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.
3434

3535
# High Level Design
3636

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.
3939

4040
The priority for the subscription replication configuration is as follows:
4141

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
4444
ignored.
4545
- 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.
4647

4748
# Detailed Design
4849

4950
## Design & Implementation Details
5051

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+
5168
### Namespace level
5269

5370
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:
91108

92109
### Consumer level
93110

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.
96114

97115
To keep the consumer-level configuration, we need to consider the `false` case, so propose using
98116
`pulsar.replicated.subscription=0L` instead of removing the property.
99117

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
101119
consumer-specific configurations can still override the more general settings.
102120

103121
### Subscription replication applied
104122

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.
107125

108126
Please notice that the `org.apache.pulsar.client.admin.Topics.setReplicatedSubscriptionStatus()` can override the
109127
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
114132

115133
### Client API
116134

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:
118136

119137
```java
120138
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
212230

213231
## Upgrade
214232

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+
```
218247

219248
## Downgrade / Rollback
220249

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
224253
```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
226258
```
227-
- API:
259+
- API
228260
```java
261+
// enable
229262
admin.topics().setReplicatedSubscriptionStatus(topic, subName, true);
263+
// disable
264+
admin.topics().setReplicatedSubscriptionStatus(topic, subName, false);
230265
```
231266

232267
## Pulsar Geo-Replication Upgrade & Downgrade/Rollback Considerations

0 commit comments

Comments
 (0)