@Provides @LazySingleton public EnsembleProvider makeEnsembleProvider(CuratorConfig config, ExhibitorConfig exConfig) { if (exConfig.getHosts().isEmpty()) { return new FixedEnsembleProvider(config.getZkHosts()); } return new ExhibitorEnsembleProvider( new Exhibitors( exConfig.getHosts(), exConfig.getRestPort(), newBackupProvider(config.getZkHosts()) ), new DefaultExhibitorRestClient(exConfig.getUseSsl()), exConfig.getRestUriPath(), exConfig.getPollingMs(), new BoundedExponentialBackoffRetry(BASE_SLEEP_TIME_MS, MAX_SLEEP_TIME_MS, MAX_RETRIES) ) { @Override public void start() throws Exception { log.info("Poll the list of zookeeper servers for initial ensemble"); this.pollForInitialEnsemble(); super.start(); } }; }
@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)); } } }
/** * 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); }
public LeafBoundedExponentialBackoffRetry(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 not 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); }
.ensembleProvider(ensembleProvider) .sessionTimeoutMs(config.getZkSessionTimeoutMs()) .retryPolicy(new BoundedExponentialBackoffRetry(BASE_SLEEP_TIME_MS, MAX_SLEEP_TIME_MS, MAX_RETRIES)) .compressionProvider(new PotentiallyGzippedCompressionProvider(config.getEnableCompression())) .aclProvider(config.getEnableAcl() ? new SecuredACLProvider() : new DefaultACLProvider())
@Override protected int getSleepTimeMs(int retryCount, long elapsedTimeMs) { if (retryCount < expRetriesThreshold) { int exp = 1 << retryCount; int jitter = random.nextInt(exp); int sleepTimeMs = super.getBaseSleepTimeMs() + exp + jitter; return sleepTimeMs; } else { int stepJitter = random.nextInt(stepSize); return Math.min(super.getMaxSleepTimeMs(), (linearBaseSleepMs + (stepSize * (retryCount - expRetriesThreshold)) + stepJitter)); } } }
protected static CuratorFramework createNewClient() throws InterruptedException { CuratorFramework client = CuratorFrameworkFactory.newClient(testingServer.getConnectString(), new BoundedExponentialBackoffRetry(100, 1000, 3)); client.start(); return client; }
private RetryPolicy createBoundedExponentialBackoffRetry(int baseSleepTimeMs, int maxSleepTimeMs, int maxRetries) { RetryPolicy retryPolicy = new BoundedExponentialBackoffRetry(baseSleepTimeMs, maxSleepTimeMs, maxRetries); return retryPolicy; }
public RetryPolicy createBoundedExponentialBackoffRetry(int baseSleepTimeMs, int maxSleepTimeMs, int maxRetries) { RetryPolicy retryPolicy = new BoundedExponentialBackoffRetry(baseSleepTimeMs, maxSleepTimeMs, maxRetries); return retryPolicy; }
@Override RetryPolicy build(Config config) { return new BoundedExponentialBackoffRetry( getMillis(config, "baseSleepDuration"), getMillis(config, "maxSleepDuration"), config.getInt("maxRetries")); } },
public void init(Map<String, Object> conf, String participantId) { Preconditions.checkNotNull(participantId, "participantId can not be null"); Preconditions.checkNotNull(conf, "conf can not be null"); this.conf = conf; this.serverUrl = participantId; this.leaderLatchListener = createLeaderLatchListener(); LOG.info("Received configuration : [{}]", conf); CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder(); String url = (String) conf.get(CONNECT_URL); String rootPrefix = (String) conf.get("root"); builder.connectString(url); builder.connectionTimeoutMs((Integer) conf.getOrDefault(CONNECTION_TIMEOUT_MS, DEFAULT_CONN_TIMOUT)); builder.sessionTimeoutMs((Integer) conf.getOrDefault(SESSION_TIMEOUT_MS, DEFAULT_SESSION_TIMEOUT)); builder.retryPolicy( new BoundedExponentialBackoffRetry( (Integer) conf.getOrDefault(RETRY_BASE_SLEEP_TIME_MS, DEFAULT_BASE_SLEEP_TIME), (Integer) conf.getOrDefault(RETRY_MAX_SLEEP_TIME_MS, DEFAULT_MAX_SLEEP_TIME), (Integer) conf.getOrDefault(RETRY_LIMIT, DEFAULT_RETRY_LIMIT) )); curatorFramework = builder.build(); leaderLatchPath = rootPrefix + LEADER_LOCK_NODE_PATH; leaderLatchRef = new AtomicReference<>(createLeaderLatch()); curatorFramework.start(); }
public void init(Map<String, Object> conf, String participantId) { Preconditions.checkNotNull(participantId, "participantId can not be null"); Preconditions.checkNotNull(conf, "conf can not be null"); this.conf = conf; this.serverUrl = participantId; this.leaderLatchListener = createLeaderLatchListener(); LOG.info("Received configuration : [{}]", conf); CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder(); String url = (String) conf.get(CONNECT_URL); String rootPrefix = (String) conf.get("root"); builder.connectString(url); builder.connectionTimeoutMs((Integer) conf.getOrDefault(CONNECTION_TIMEOUT_MS, DEFAULT_CONN_TIMOUT)); builder.sessionTimeoutMs((Integer) conf.getOrDefault(SESSION_TIMEOUT_MS, DEFAULT_SESSION_TIMEOUT)); builder.retryPolicy( new BoundedExponentialBackoffRetry( (Integer) conf.getOrDefault(RETRY_BASE_SLEEP_TIME_MS, DEFAULT_BASE_SLEEP_TIME), (Integer) conf.getOrDefault(RETRY_MAX_SLEEP_TIME_MS, DEFAULT_MAX_SLEEP_TIME), (Integer) conf.getOrDefault(RETRY_LIMIT, DEFAULT_RETRY_LIMIT) )); curatorFramework = builder.build(); leaderLatchPath = rootPrefix + LEADER_LOCK_NODE_PATH; leaderLatchRef = new AtomicReference<>(createLeaderLatch()); curatorFramework.start(); }
public ZkRegistry(ZkConfig zkConfig) { zkClient = CuratorFrameworkFactory.builder().connectString(zkConfig.getZkAddress()) .sessionTimeoutMs(zkConfig.getZkTimeout()) .retryPolicy(new BoundedExponentialBackoffRetry(zkConfig.getBaseSleepTimeMs(), zkConfig.getMaxSleepTimeMs(), zkConfig.getMaxRetries())) .build(); zkClient.start(); }
this.maxRetries = maxRetries; curatorClient = CuratorFrameworkFactory.builder().namespace(namespace).retryPolicy(new BoundedExponentialBackoffRetry(100, 5000, 10)) .connectString(zookeeperConnectionString).build();
public LockManager(@NonNull final Configuration conf) { this.lockConf = new LockManagerConfiguration(conf); this.isEnabled = lockConf.isEnabled(); this.lockMap = new ConcurrentHashMap(); if (this.isEnabled) { final ZookeeperConfiguration zkConf = new ZookeeperConfiguration(conf); this.client = Optional.of(CuratorFrameworkFactory.builder() .connectString(zkConf.getZkQuorum()) .retryPolicy(new BoundedExponentialBackoffRetry(1000, 5000, 3)) .namespace(lockConf.getZkBasePath()) .sessionTimeoutMs(lockConf.getZkSessionTimeoutMs()) .connectionTimeoutMs(lockConf.getZkConnectionTimeoutMs()) .build()); this.client.get().start(); } else { this.client = Optional.absent(); } }
.retryPolicy(new BoundedExponentialBackoffRetry(100, 1000, 10)) .threadFactory(new ThreadFactoryBuilder().setNameFormat("emo-zookeeper-%d").build()) .namespace(namespace)
zkRootClient = CuratorFrameworkFactory.builder() .connectString(server.getConnectString()) .retryPolicy(new BoundedExponentialBackoffRetry(10, 100, 7)) .build(); zkRootClient.start();
.retryPolicy(new BoundedExponentialBackoffRetry(100, 1000, 10)) .threadFactory(new ThreadFactoryBuilder().setNameFormat("emo-zookeeper-%d").build()) .namespace(namespace)
.sessionTimeoutMs(sessionTimeout) .retryPolicy(new BoundedExponentialBackoffRetry(retryInterval, retryCeiling, retryTimes));
.sessionTimeoutMs(sessionTimeout) .retryPolicy(new BoundedExponentialBackoffRetry(retryInterval, retryCeiling, retryTimes));