From ed308e855f8093c5e369720510c51d68ce6b1f8f Mon Sep 17 00:00:00 2001 From: Harald Musum Date: Mon, 2 Dec 2019 13:40:30 +0100 Subject: Use regular ZooKeeper factory --- .../main/java/com/yahoo/vespa/curator/Curator.java | 4 +- .../curator/DNSResolvingFixerZooKeeperFactory.java | 45 ---------------------- .../yahoo/vespa/curator/VespaZooKeeperFactory.java | 22 +++++++++++ 3 files changed, 23 insertions(+), 48 deletions(-) delete mode 100644 zkfacade/src/main/java/com/yahoo/vespa/curator/DNSResolvingFixerZooKeeperFactory.java create mode 100644 zkfacade/src/main/java/com/yahoo/vespa/curator/VespaZooKeeperFactory.java (limited to 'zkfacade/src') 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 c8aea1f3d21..0e20710298f 100644 --- a/zkfacade/src/main/java/com/yahoo/vespa/curator/Curator.java +++ b/zkfacade/src/main/java/com/yahoo/vespa/curator/Curator.java @@ -29,7 +29,6 @@ import java.util.Arrays; import java.util.List; import java.util.Optional; import java.util.concurrent.ExecutorService; -import java.util.concurrent.TimeUnit; import java.util.function.Function; /** @@ -44,7 +43,6 @@ import java.util.function.Function; */ public class Curator implements AutoCloseable { - private static final long UNKNOWN_HOST_TIMEOUT_MILLIS = TimeUnit.MINUTES.toMillis(30); private static final int ZK_SESSION_TIMEOUT = 30000; private static final int ZK_CONNECTION_TIMEOUT = 30000; @@ -91,7 +89,7 @@ public class Curator implements AutoCloseable { .sessionTimeoutMs(ZK_SESSION_TIMEOUT) .connectionTimeoutMs(ZK_CONNECTION_TIMEOUT) .connectString(connectionSpec) - .zookeeperFactory(new DNSResolvingFixerZooKeeperFactory(UNKNOWN_HOST_TIMEOUT_MILLIS)) + .zookeeperFactory(new VespaZooKeeperFactory()) .dontUseContainerParents() // TODO: Remove when we know ZooKeeper 3.5 works fine, consider waiting until Vespa 8 .build()); } diff --git a/zkfacade/src/main/java/com/yahoo/vespa/curator/DNSResolvingFixerZooKeeperFactory.java b/zkfacade/src/main/java/com/yahoo/vespa/curator/DNSResolvingFixerZooKeeperFactory.java deleted file mode 100644 index ba045fd8acb..00000000000 --- a/zkfacade/src/main/java/com/yahoo/vespa/curator/DNSResolvingFixerZooKeeperFactory.java +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.curator; - -import com.yahoo.log.LogLevel; -import org.apache.curator.utils.DefaultZookeeperFactory; -import org.apache.curator.utils.ZookeeperFactory; -import org.apache.zookeeper.Watcher; -import org.apache.zookeeper.ZooKeeper; - -import java.net.UnknownHostException; -import java.util.concurrent.TimeUnit; -import java.util.logging.Logger; - -/** - * A ZooKeeper handle factory that handles unknown host exceptions. - * - * @author Ulf Lilleengen - * @since 5.9 - */ -class DNSResolvingFixerZooKeeperFactory implements ZookeeperFactory { - - public static final long UNKNOWN_HOST_WAIT_TIME_MILLIS = TimeUnit.SECONDS.toMillis(10); - - private static final Logger log = Logger.getLogger(DNSResolvingFixerZooKeeperFactory.class.getName()); - private final DefaultZookeeperFactory zookeeperFactory; - private final long maxTimeout; - public DNSResolvingFixerZooKeeperFactory(long maxTimeout) { - this.maxTimeout = maxTimeout; - this.zookeeperFactory = new DefaultZookeeperFactory(); - } - @Override - public ZooKeeper newZooKeeper(String connectString, int sessionTimeout, Watcher watcher, boolean canBeReadOnly) throws Exception { - long endTime = System.currentTimeMillis() + maxTimeout; - do { - try { - return zookeeperFactory.newZooKeeper(connectString, sessionTimeout, watcher, canBeReadOnly); - } catch (UnknownHostException e) { - log.log(LogLevel.WARNING, "Error creating ZooKeeper handle", e); - Thread.sleep(UNKNOWN_HOST_WAIT_TIME_MILLIS); - } - } while (System.currentTimeMillis() < endTime); - throw new RuntimeException("Error creating zookeeper handle within timeout"); - } - -} diff --git a/zkfacade/src/main/java/com/yahoo/vespa/curator/VespaZooKeeperFactory.java b/zkfacade/src/main/java/com/yahoo/vespa/curator/VespaZooKeeperFactory.java new file mode 100644 index 00000000000..7c08168c536 --- /dev/null +++ b/zkfacade/src/main/java/com/yahoo/vespa/curator/VespaZooKeeperFactory.java @@ -0,0 +1,22 @@ +// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.curator; + +import org.apache.curator.utils.ZookeeperFactory; +import org.apache.zookeeper.Watcher; +import org.apache.zookeeper.ZooKeeper; + +/** + * A ZooKeeper factory for creating a ZooKeeper client + * + * @author hmusum + */ +// TODO: add constructor that takes feature flag so that we can write ZooKeeper client config and start +// ZooKeeper client with that config +class VespaZooKeeperFactory implements ZookeeperFactory { + + @Override + public ZooKeeper newZooKeeper(String connectString, int sessionTimeout, Watcher watcher, boolean canBeReadOnly) throws Exception { + return new ZooKeeper(connectString, sessionTimeout, watcher); + } + +} -- cgit v1.2.3