private static CuratorFramework newCurator(Configuration config) throws Exception { return CuratorFrameworkFactory.newClient(config.zkHosts, config.zkSessionTimeoutMs, config.zkConnectionTimeoutMs, new RetryNTimes(config.zkRetryTimes, config.zkRetryIntervalMs)); }
protected CuratorFramework createClient() { return CuratorFrameworkFactory.newClient(zkConnString, new ExponentialBackoffRetry(1000, 1)); }
@Override public int getSleepTimeMs(int retryCount, long elapsedTimeMs) { if (retryCount < expRetriesThreshold) { int exp = 1 << retryCount; int jitter = random.nextInt(exp); return super.getBaseSleepTimeMs() + exp + jitter; } else { int stepJitter = random.nextInt(stepSize); return Math.min(super.getMaxSleepTimeMs(), (linearBaseSleepMs + (stepSize * (retryCount - expRetriesThreshold)) + stepJitter)); } } }
TestingServer zkTestServer; @Before public void startZookeeper() throws Exception { zkTestServer = new TestingServer(2181); cli = CuratorFrameworkFactory.newClient(zkTestServer.getConnectString(), new RetryOneTime(2000)); } @After public void stopZookeeper() throws IOException { cli.close(); zkTestServer.stop(); }
private void create() throws Exception { client = CuratorFrameworkFactory.builder().connectString(ensemble).sessionTimeoutMs(sessionTimeout) .retryPolicy(new RetryForever(1000)).canBeReadOnly(true).build(); client.start(); cache = new NodeCache(client, NODE); cache.start(true); }
/** * The class provides generic exponential-linear backoff retry strategy for storm. It calculates threshold for exponentially increasing sleeptime for * retries. Beyond this threshold, the sleeptime increase is linear. Also adds jitter for exponential/linear retry. It guarantees currSleepTimeMs >= * prevSleepTimeMs and baseSleepTimeMs <= currSleepTimeMs <= maxSleepTimeMs */ public StormBoundedExponentialBackoffRetry(int baseSleepTimeMs, int maxSleepTimeMs, int maxRetries) { super(baseSleepTimeMs, maxSleepTimeMs, maxRetries); expRetriesThreshold = 1; while ((1 << (expRetriesThreshold + 1)) < ((maxSleepTimeMs - baseSleepTimeMs) / 2)) expRetriesThreshold++; LOG.info("The baseSleepTimeMs [" + baseSleepTimeMs + "] the maxSleepTimeMs [" + maxSleepTimeMs + "] " + "the maxRetries [" + maxRetries + "]"); if (baseSleepTimeMs > maxSleepTimeMs) { LOG.warn("Misconfiguration: the baseSleepTimeMs [" + baseSleepTimeMs + "] can't be greater than " + "the maxSleepTimeMs [" + maxSleepTimeMs + "]."); } if (maxRetries > 0 && maxRetries > expRetriesThreshold) { this.stepSize = Math.max(1, (maxSleepTimeMs - (1 << expRetriesThreshold)) / (maxRetries - expRetriesThreshold)); } else { this.stepSize = 1; } this.linearBaseSleepMs = super.getBaseSleepTimeMs() + (1 << expRetriesThreshold); }
CuratorFramework getCurator(String zkConnectString) { return CuratorFrameworkFactory .builder() .connectString(zkConnectString) .retryPolicy(new ExponentialBackoffRetry(zkBaseSleepMillis, zkMaxRetries, zkSleepMillis)) .build(); }
public ZookeeperStateStore(String connectionString, int retries, int retryInterval) { if (connectionString == null) { zookeeperConnectionString = "localhost:2181"; } else { zookeeperConnectionString = connectionString; } RetryPolicy retryPolicy = new RetryNTimes(retries, retryInterval); curatorFramework = CuratorFrameworkFactory.newClient(zookeeperConnectionString, retryPolicy); }
protected void setupServerAndCurator() throws Exception { server = new TestingServer(); timing = new Timing(); curator = CuratorFrameworkFactory .builder() .connectString(server.getConnectString()) .sessionTimeoutMs(timing.session()) .connectionTimeoutMs(timing.connection()) .retryPolicy(new RetryOneTime(1)) .compressionProvider(new PotentiallyGzippedCompressionProvider(true)) .build(); }
/** * Open a ZooKeeper connection for the JobState. */ public static CuratorFramework zkOpen(String zkHosts, int zkSessionTimeoutMs) throws IOException { //do we need to add a connection status listener? What will that do? ExponentialBackoffRetry retryPolicy = new ExponentialBackoffRetry(1000, 3); CuratorFramework zk = CuratorFrameworkFactory.newClient(zkHosts, zkSessionTimeoutMs, CuratorFrameworkFactory.builder().getConnectionTimeoutMs(), retryPolicy); zk.start(); return zk; }
private static CuratorFramework newCurator(Configuration config) throws Exception { return CuratorFrameworkFactory.newClient(config.zkHosts, config.zkSessionTimeoutMs, config.zkConnectionTimeoutMs, new RetryNTimes(config.zkRetryTimes, config.zkRetryIntervalMs)); }
private void setupServerAndCurator() throws Exception { server = new TestingServer(); timing = new Timing(); curator = CuratorFrameworkFactory .builder() .connectString(server.getConnectString()) .sessionTimeoutMs(timing.session()) .connectionTimeoutMs(timing.connection()) .retryPolicy(new RetryOneTime(1)) .compressionProvider(new PotentiallyGzippedCompressionProvider(true)) .build(); }
/** * Constructor for {@link ZkMasterInquireClient}. * * @param connectDetails connect details * @param electionPath the path of the master election */ private ZkMasterInquireClient(ZkMasterConnectDetails connectDetails, String electionPath, int inquireRetryCount) { mConnectDetails = connectDetails; mElectionPath = electionPath; LOG.info("Creating new zookeeper client for {}", connectDetails); // Start the client lazily. mClient = CuratorFrameworkFactory.newClient(connectDetails.getZkAddress(), new ExponentialBackoffRetry(Constants.SECOND_MS, 3)); mInquireRetryCount = inquireRetryCount; }
void initialize () { curatorFramework = CuratorFrameworkFactory.newClient(zkInfo.getZkUrl(), zkInfo.getSessionTimeoutMs(), zkInfo.getConnectionTimeoutMs(), new RetryNTimes(zkInfo.getRetryAttempts(), zkInfo.getRetryIntervalMs())); curatorFramework.start(); }
private static CuratorFramework getZkClient(JdbcConnectionParams connParams) throws Exception { String zooKeeperEnsemble = connParams.getZooKeeperEnsemble(); CuratorFramework zooKeeperClient = CuratorFrameworkFactory.builder().connectString(zooKeeperEnsemble) .retryPolicy(new ExponentialBackoffRetry(1000, 3)).build(); zooKeeperClient.start(); return zooKeeperClient; }
private CuratorFramework newCurator(Map conf, KafkaSpoutConfig config) throws Exception { String serverPorts = ""; List<Host> zkServers = config.zkServers; for (Host server : zkServers) { serverPorts = serverPorts + server.getHost() + ":" + server.getPort() + ","; } return CuratorFrameworkFactory.newClient(serverPorts, Utils.getInt(conf.get(Config.STORM_ZOOKEEPER_SESSION_TIMEOUT)), 15000, new RetryNTimes( Utils.getInt(conf.get(Config.STORM_ZOOKEEPER_RETRY_TIMES)), Utils.getInt(conf.get(Config.STORM_ZOOKEEPER_RETRY_INTERVAL)))); }
private CuratorFramework createCurator(final String connectString) { final ExponentialBackoffRetry retryPolicy = new ExponentialBackoffRetry(1000, 3); final CuratorFramework curator = CuratorFrameworkFactory.builder() .connectString(connectString) .retryPolicy(retryPolicy) .authorization("digest", (SUPER_USER + ":" + SUPER_PASSWORD).getBytes()) .build(); curator.start(); return curator; }
@PostConstruct public void init() { if (adapterCanalConfig.getZookeeperHosts() != null) { curator = CuratorFrameworkFactory.builder() .connectString(adapterCanalConfig.getZookeeperHosts()) .retryPolicy(new ExponentialBackoffRetry(1000, 3)) .sessionTimeoutMs(6000) .connectionTimeoutMs(3000) .namespace("canal-adapter") .build(); curator.start(); } }
private CuratorFramework getSession() { if (zkSession == null || zkSession.getState() == CuratorFrameworkState.STOPPED) { synchronized (this) { if (zkSession == null || zkSession.getState() == CuratorFrameworkState.STOPPED) { zkSession = CuratorFrameworkFactory.builder().connectString(zkConnectString) .connectionTimeoutMs(connectTimeoutMillis).aclProvider(aclDefaultProvider) .retryPolicy(new ExponentialBackoffRetry(1000, 3)).build(); zkSession.start(); } } } return zkSession; }
private ExponentialBackoffRetry makeRetryPolicy(Map<String, String> configValues) { return new ExponentialBackoffRetry(asInt(configValues.get(CONFIG_RETRY_SLEEP_MS.getKey())), asInt(configValues.get(CONFIG_MAX_RETRIES.getKey()))); }