From 84ddc9116b36221c92df89bc2f55eeff5c0442c5 Mon Sep 17 00:00:00 2001 From: StevenLuMT <42990025+StevenLuMT@users.noreply.github.com> Date: Mon, 10 Jan 2022 09:37:52 +0800 Subject: [PATCH] zk client config update and bugfix for ZKMetadataClientDriver (#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: #2760 --- .../conf/AbstractConfiguration.java | 22 +++++++++++++++++++ .../meta/zk/ZKMetadataBookieDriver.java | 2 +- .../meta/zk/ZKMetadataClientDriver.java | 2 +- .../bookkeeper/conf/TestBKConfiguration.java | 8 +++++++ .../service/RegistrationServiceProvider.java | 2 +- 5 files changed, 33 insertions(+), 3 deletions(-) diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/conf/AbstractConfiguration.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/conf/AbstractConfiguration.java index f4b378bae3b..414ac991068 100644 --- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/conf/AbstractConfiguration.java +++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/conf/AbstractConfiguration.java @@ -75,6 +75,7 @@ public abstract class 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"; @@ -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. * diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/zk/ZKMetadataBookieDriver.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/zk/ZKMetadataBookieDriver.java index 9eb853bff6b..d66ef338c68 100644 --- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/zk/ZKMetadataBookieDriver.java +++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/zk/ZKMetadataBookieDriver.java @@ -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; diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/zk/ZKMetadataClientDriver.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/zk/ZKMetadataClientDriver.java index 638f39066f8..c1c8514d18d 100644 --- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/zk/ZKMetadataClientDriver.java +++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/zk/ZKMetadataClientDriver.java @@ -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; diff --git a/bookkeeper-server/src/test/java/org/apache/bookkeeper/conf/TestBKConfiguration.java b/bookkeeper-server/src/test/java/org/apache/bookkeeper/conf/TestBKConfiguration.java index 5ceee0bf007..7617911e1d7 100644 --- a/bookkeeper-server/src/test/java/org/apache/bookkeeper/conf/TestBKConfiguration.java +++ b/bookkeeper-server/src/test/java/org/apache/bookkeeper/conf/TestBKConfiguration.java @@ -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; } @@ -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; } } diff --git a/stream/server/src/main/java/org/apache/bookkeeper/stream/server/service/RegistrationServiceProvider.java b/stream/server/src/main/java/org/apache/bookkeeper/stream/server/service/RegistrationServiceProvider.java index 03bf23d1a53..ed31c90caf9 100644 --- a/stream/server/src/main/java/org/apache/bookkeeper/stream/server/service/RegistrationServiceProvider.java +++ b/stream/server/src/main/java/org/apache/bookkeeper/stream/server/service/RegistrationServiceProvider.java @@ -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);