Skip to content

Commit

Permalink
zk client config update and bugfix for ZKMetadataClientDriver (apache…
Browse files Browse the repository at this point in the history
…#2958)

### Motivation

1. bug fix for error config for BoundExponentialBackoffRetryPolicy in class ZKMetadataClientDriver,if set MaxRetries zero, zk client will throw ConnectionLossException when the zk has some changing,for example: zk leader node changed.

2. In Bookie's ZKClient, different BoundExponentialBackoffRetryPolicy set different MaxRetries,so change zkRetryBackoffMaxRetries to config in Bookie's AbstractConfiguration

### Changes

1. update a error config for BoundExponentialBackoffRetryPolicy in class ZKMetadataClientDriver
2. change zkRetryBackoffMaxRetries to config

Master Issue: apache#2760
  • Loading branch information
StevenLuMT authored Jan 10, 2022
1 parent 27e7973 commit 84ddc91
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public abstract class AbstractConfiguration<T extends AbstractConfiguration>
// Zookeeper Parameters
protected static final String ZK_TIMEOUT = "zkTimeout";
protected static final String ZK_SERVERS = "zkServers";
protected static final String ZK_RETRY_BACKOFF_MAX_RETRIES = "zkRetryBackoffMaxRetries";

// Ledger Manager
protected static final String LEDGER_MANAGER_TYPE = "ledgerManagerType";
Expand Down Expand Up @@ -345,6 +346,27 @@ public T setZkTimeout(int zkTimeout) {
return getThis();
}

/**
* Get zookeeper client backoff max retry times.
*
* @return zk backoff max retry times.
*/
public int getZkRetryBackoffMaxRetries() {
return getInt(ZK_RETRY_BACKOFF_MAX_RETRIES, Integer.MAX_VALUE);
}

/**
* Set zookeeper client backoff max retry times.
*
* @param maxRetries
* backoff max retry times
* @return server configuration.
*/
public T setZkRetryBackoffMaxRetries(int maxRetries) {
setProperty(ZK_RETRY_BACKOFF_MAX_RETRIES, Integer.toString(maxRetries));
return getThis();
}

/**
* Set Ledger Manager Type.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public synchronized MetadataBookieDriver initialize(ServerConfiguration conf,
conf,
statsLogger.scope(BOOKIE_SCOPE),
new BoundExponentialBackoffRetryPolicy(conf.getZkRetryBackoffStartMs(),
conf.getZkRetryBackoffMaxMs(), Integer.MAX_VALUE),
conf.getZkRetryBackoffMaxMs(), conf.getZkRetryBackoffMaxRetries()),
Optional.empty());
this.serverConf = conf;
this.statsLogger = statsLogger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public synchronized MetadataClientDriver initialize(ClientConfiguration conf,
new BoundExponentialBackoffRetryPolicy(
conf.getZkTimeout(),
conf.getZkTimeout(),
0),
conf.getZkRetryBackoffMaxRetries()),
optionalCtx);
this.statsLogger = statsLogger;
this.clientConf = conf;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ public static ServerConfiguration newServerConfiguration() {
confReturn.setAllocatorPoolingPolicy(PoolingPolicy.UnpooledHeap);
confReturn.setProperty(DbLedgerStorage.WRITE_CACHE_MAX_SIZE_MB, 4);
confReturn.setProperty(DbLedgerStorage.READ_AHEAD_CACHE_MAX_SIZE_MB, 4);
/**
* if testcase has zk error,just try 0 time for fast running
*/
confReturn.setZkRetryBackoffMaxRetries(0);
setLoopbackInterfaceAndAllowLoopback(confReturn);
return confReturn;
}
Expand Down Expand Up @@ -89,6 +93,10 @@ public static ServerConfiguration setLoopbackInterfaceAndAllowLoopback(ServerCon
public static ClientConfiguration newClientConfiguration() {
ClientConfiguration clientConfiguration = new ClientConfiguration();
clientConfiguration.setTLSEnabledProtocols("TLSv1.2,TLSv1.1");
/**
* if testcase has zk error,just try 0 time for fast running
*/
clientConfiguration.setZkRetryBackoffMaxRetries(0);
return clientConfiguration;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public RegistrationServiceProvider(ServerConfiguration bkServerConf,
this.bkZkRetryPolicy = new BoundExponentialBackoffRetryPolicy(
bkServerConf.getZkRetryBackoffStartMs(),
bkServerConf.getZkRetryBackoffMaxMs(),
Integer.MAX_VALUE);
bkServerConf.getZkRetryBackoffMaxRetries());
this.regExecutor = Executors.newSingleThreadScheduledExecutor(
new ThreadFactoryBuilder().setNameFormat("registration-service-provider-scheduler").build());
ClientConfiguration clientConfiguration = new ClientConfiguration(bkServerConf);
Expand Down

0 comments on commit 84ddc91

Please sign in to comment.