summaryrefslogtreecommitdiffstats
path: root/zkfacade
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2020-04-14 13:13:48 +0200
committerMartin Polden <mpolden@mpolden.no>2020-04-14 14:39:02 +0200
commit984f9204bfbe098d591d55d1ff86fbcc6027c9eb (patch)
tree0e1756e155d958e01af960d070e3b747a64b78b8 /zkfacade
parentdd7c3720dc10e6bc4c9b82f43c9e7b7418fa66a0 (diff)
Use Duration for timeouts
Diffstat (limited to 'zkfacade')
-rw-r--r--zkfacade/src/main/java/com/yahoo/vespa/curator/Curator.java32
1 files changed, 14 insertions, 18 deletions
diff --git a/zkfacade/src/main/java/com/yahoo/vespa/curator/Curator.java b/zkfacade/src/main/java/com/yahoo/vespa/curator/Curator.java
index 7c5b1ae319a..989584c43e4 100644
--- a/zkfacade/src/main/java/com/yahoo/vespa/curator/Curator.java
+++ b/zkfacade/src/main/java/com/yahoo/vespa/curator/Curator.java
@@ -48,27 +48,23 @@ import java.util.logging.Logger;
*/
public class Curator implements AutoCloseable {
- private static final Logger logger = Logger.getLogger(Curator.class.getName());
-
- private static final int ZK_SESSION_TIMEOUT = 30000;
- private static final int ZK_CONNECTION_TIMEOUT = 30000;
-
- private static final int BASE_SLEEP_TIME = 1000; //ms
+ private static final Logger LOG = Logger.getLogger(Curator.class.getName());
+ private static final File ZK_CLIENT_CONFIG_FILE = new File(Defaults.getDefaults().underVespaHome("conf/zookeeper/zookeeper-client.cfg"));
+ private static final Duration ZK_SESSION_TIMEOUT = Duration.ofSeconds(30);
+ private static final Duration ZK_CONNECTION_TIMEOUT = Duration.ofSeconds(30);
+ private static final Duration BASE_SLEEP_TIME = Duration.ofSeconds(1);
private static final int MAX_RETRIES = 10;
- private static final File zkClientConfigFile = new File(Defaults.getDefaults().underVespaHome("conf/zookeeper/zookeeper-client.cfg"));
-
protected final RetryPolicy retryPolicy;
private final CuratorFramework curatorFramework;
private final String connectionSpec; // May be a subset of the servers in the ensemble
-
private final String zooKeeperEnsembleConnectionSpec;
private final int zooKeeperEnsembleCount;
/** Creates a curator instance from a comma-separated string of ZooKeeper host:port strings */
public static Curator create(String connectionSpec) {
- return new Curator(connectionSpec, connectionSpec, Optional.of(zkClientConfigFile));
+ return new Curator(connectionSpec, connectionSpec, Optional.of(ZK_CLIENT_CONFIG_FILE));
}
// For testing only, use Optional.empty for clientConfigFile parameter to create default zookeeper client config
@@ -80,7 +76,7 @@ public class Curator implements AutoCloseable {
// TODO: Move zookeeperserver config out of configserverconfig (requires update of controller services.xml as well)
@Inject
public Curator(ConfigserverConfig configserverConfig, VespaZooKeeperServer server) {
- this(configserverConfig, Optional.of(zkClientConfigFile));
+ this(configserverConfig, Optional.of(ZK_CLIENT_CONFIG_FILE));
}
Curator(ConfigserverConfig configserverConfig, Optional<File> clientConfigFile) {
@@ -93,8 +89,8 @@ public class Curator implements AutoCloseable {
(retryPolicy) -> CuratorFrameworkFactory
.builder()
.retryPolicy(retryPolicy)
- .sessionTimeoutMs(ZK_SESSION_TIMEOUT)
- .connectionTimeoutMs(ZK_CONNECTION_TIMEOUT)
+ .sessionTimeoutMs((int) ZK_SESSION_TIMEOUT.toMillis())
+ .connectionTimeoutMs((int) ZK_CONNECTION_TIMEOUT.toMillis())
.connectString(connectionSpec)
.zookeeperFactory(new VespaZooKeeperFactory(createClientConfig(clientConfigFile)))
.dontUseContainerParents() // TODO: Remove when we know ZooKeeper 3.5 works fine, consider waiting until Vespa 8
@@ -105,7 +101,7 @@ public class Curator implements AutoCloseable {
String zooKeeperEnsembleConnectionSpec,
Function<RetryPolicy, CuratorFramework> curatorFactory) {
this(connectionSpec, zooKeeperEnsembleConnectionSpec, curatorFactory,
- new ExponentialBackoffRetry(BASE_SLEEP_TIME, MAX_RETRIES));
+ new ExponentialBackoffRetry((int) BASE_SLEEP_TIME.toMillis(), MAX_RETRIES));
}
private Curator(String connectionSpec,
@@ -193,7 +189,7 @@ public class Curator implements AutoCloseable {
/** For internal use; prefer creating a {@link CuratorCounter} */
public DistributedAtomicLong createAtomicCounter(String path) {
- return new DistributedAtomicLong(curatorFramework, path, new ExponentialBackoffRetry(BASE_SLEEP_TIME, MAX_RETRIES));
+ return new DistributedAtomicLong(curatorFramework, path, new ExponentialBackoffRetry((int) BASE_SLEEP_TIME.toMillis(), MAX_RETRIES));
}
/** For internal use; prefer creating a {@link com.yahoo.vespa.curator.Lock} */
@@ -204,9 +200,9 @@ public class Curator implements AutoCloseable {
private void addLoggingListener() {
curatorFramework.getConnectionStateListenable().addListener((curatorFramework, connectionState) -> {
switch (connectionState) {
- case SUSPENDED: logger.info("ZK connection state change: SUSPENDED"); break;
- case RECONNECTED: logger.info("ZK connection state change: RECONNECTED"); break;
- case LOST: logger.warning("ZK connection state change: LOST"); break;
+ case SUSPENDED: LOG.info("ZK connection state change: SUSPENDED"); break;
+ case RECONNECTED: LOG.info("ZK connection state change: RECONNECTED"); break;
+ case LOST: LOG.warning("ZK connection state change: LOST"); break;
}
});
}