Skip to content

Commit

Permalink
[pulsar-broker] check replicator periodically to avoid issue due to z…
Browse files Browse the repository at this point in the history
…k missing watch (apache#6674)

### Motivation
We have a regular issue when user changes replication-cluster list, many times broker misses the zk watch and broker fails to update replicator which causes either data loss or message backlog based on zk-watch missing at source or destination replication broker.

### Modification
- Broker expires replication policies at every X seconds 
- Starts a background task which checks polices (fetches new policies if it's already expired) and starts/stops replicator if needed.

### Result
Broker can start/stop replicators based on updated policies even if broker misses zk watch.
  • Loading branch information
rdhabalia authored and Addison Higham committed May 5, 2020
1 parent b2b728d commit ad78009
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions conf/broker.conf
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,10 @@ replicationProducerQueueSize=1000
# Replicator prefix used for replicator producer name and cursor name
replicatorPrefix=pulsar.repl

# Duration to check replication policy to avoid replicator inconsistency
# due to missing ZooKeeper watch (disable with value 0)
replicatioPolicyCheckDurationSeconds=600

# Default message retention time
defaultRetentionTimeInMinutes=0

Expand Down
4 changes: 4 additions & 0 deletions conf/standalone.conf
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,10 @@ replicationConnectionsPerBroker=16
# Replicator producer queue size
replicationProducerQueueSize=1000

# Duration to check replication policy to avoid replicator inconsistency
# due to missing ZooKeeper watch (disable with value 0)
replicatioPolicyCheckDurationSeconds=600

# Default message retention time
defaultRetentionTimeInMinutes=0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,12 @@ public class ServiceConfiguration implements PulsarConfiguration {
doc = "Replicator producer queue size"
)
private int replicationProducerQueueSize = 1000;
@FieldContext(
category = CATEGORY_REPLICATION,
doc = "Duration to check replication policy to avoid replicator "
+ "inconsistency due to missing ZooKeeper watch (disable with value 0)"
)
private int replicatioPolicyCheckDurationSeconds = 600;
@Deprecated
@FieldContext(
category = CATEGORY_REPLICATION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ public void start() throws Exception {
this.startConsumedLedgersMonitor();
this.startBacklogQuotaChecker();
this.updateBrokerPublisherThrottlingMaxRate();
this.startCheckReplicationPolicies();
// register listener to capture zk-latency
ClientCnxnAspect.addListener(zkStatsListener);
ClientCnxnAspect.registerExecutor(pulsar.getExecutor());
Expand Down Expand Up @@ -449,6 +450,14 @@ protected void startMessageExpiryMonitor() {
TimeUnit.MINUTES);
}

protected void startCheckReplicationPolicies() {
int interval = pulsar.getConfig().getReplicatioPolicyCheckDurationSeconds();
if (interval > 0) {
messageExpiryMonitor.scheduleAtFixedRate(safeRun(this::checkReplicationPolicies), interval, interval,
TimeUnit.SECONDS);
}
}

protected void startCompactionMonitor() {
int interval = pulsar().getConfiguration().getBrokerServiceCompactionMonitorIntervalInSeconds();
if (interval > 0) {
Expand Down Expand Up @@ -1155,6 +1164,10 @@ public void checkMessageExpiry() {
forEachTopic(Topic::checkMessageExpiry);
}

public void checkReplicationPolicies() {
forEachTopic(Topic::checkReplication);
}

public void checkCompaction() {
forEachTopic((t) -> {
if (t instanceof PersistentTopic) {
Expand Down

0 comments on commit ad78009

Please sign in to comment.