Search in sources :

Example 56 with ExponentialBackoffRetry

use of org.apache.flink.shaded.curator5.org.apache.curator.retry.ExponentialBackoffRetry in project VX-API-Gateway by EliMirren.

the class VxApiClusterZookeeperImpl method getConfig.

@Override
public void getConfig(Handler<AsyncResult<JsonObject>> event) {
    vertx.<JsonObject>executeBlocking(get -> {
        JsonObject retry = zkConf.getJsonObject("retry", new JsonObject());
        String hosts = zkConf.getString("zookeeperHosts", "127.0.0.1");
        int baseSleepTimeMs = retry.getInteger("initialSleepTime", 1000);
        int maxRetries = retry.getInteger("maxTimes", 5);
        int maxSleepMs = retry.getInteger("intervalTimes", 10000);
        int sessionTimeoutMs = zkConf.getInteger("sessionTimeout", 20000);
        int connectionTimeoutMs = zkConf.getInteger("connectTimeout", 3000);
        ExponentialBackoffRetry retryPolicy = new ExponentialBackoffRetry(baseSleepTimeMs, maxRetries, maxSleepMs);
        String vxApiConfPath = zkConf.getString("vxApiConfPath", "/io.vertx/vx.api.gateway/conf");
        CuratorFramework client = CuratorFrameworkFactory.newClient(hosts, sessionTimeoutMs, connectionTimeoutMs, retryPolicy);
        try {
            client.start();
            byte[] data = client.getData().forPath(vxApiConfPath);
            String jsons = new String(data);
            get.complete(new JsonObject(jsons));
        } catch (Exception e) {
            get.fail(e);
        } finally {
            client.close();
        }
    }, event);
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) JsonObject(io.vertx.core.json.JsonObject)

Example 57 with ExponentialBackoffRetry

use of org.apache.flink.shaded.curator5.org.apache.curator.retry.ExponentialBackoffRetry in project dble by actiontech.

the class DistributedSequenceHandler method initializeZK.

public void initializeZK(String zkAddress) {
    if (zkAddress == null) {
        throw new RuntimeException("please check zkURL is correct in config file \"myid.prperties\" .");
    }
    if (this.client != null) {
        this.client.close();
    }
    this.client = CuratorFrameworkFactory.newClient(zkAddress, new ExponentialBackoffRetry(1000, 3));
    this.client.start();
    try {
        if (client.checkExists().forPath(INSTANCE_PATH) == null) {
            client.create().creatingParentContainersIfNeeded().forPath(INSTANCE_PATH);
        }
    } catch (Exception e) {
        throw new RuntimeException("create instance path " + INSTANCE_PATH + "error", e);
    }
    this.leaderSelector = new LeaderSelector(client, KVPathUtil.getSequencesLeaderPath(), this);
    this.leaderSelector.autoRequeue();
    this.leaderSelector.start();
    Runnable runnable = new Runnable() {

        @Override
        public void run() {
            try {
                while (leaderSelector.getLeader() == null) {
                    Thread.currentThread().yield();
                }
                if (!leaderSelector.hasLeadership()) {
                    isLeader = false;
                    if (slavePath != null && client.checkExists().forPath(slavePath) != null) {
                        return;
                    }
                    slavePath = client.create().creatingParentsIfNeeded().withMode(CreateMode.EPHEMERAL_SEQUENTIAL).forPath(PATH.concat("/instance/node"), "ready".getBytes());
                    while ("ready".equals(new String(client.getData().forPath(slavePath)))) {
                        Thread.currentThread().yield();
                    }
                    instanceId = Long.parseLong(new String(client.getData().forPath(slavePath)));
                    ready = true;
                }
            } catch (Exception e) {
                LOGGER.info("Caught exception while handling zk!", e);
            }
        }
    };
    long selfCheckPeriod = 10L;
    timerExecutor.scheduleAtFixedRate(runnable, 1L, selfCheckPeriod, TimeUnit.SECONDS);
}
Also used : ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) LeaderSelector(org.apache.curator.framework.recipes.leader.LeaderSelector) IOException(java.io.IOException) CancelLeadershipException(org.apache.curator.framework.recipes.leader.CancelLeadershipException)

Example 58 with ExponentialBackoffRetry

use of org.apache.flink.shaded.curator5.org.apache.curator.retry.ExponentialBackoffRetry in project SpinalTap by airbnb.

the class SpinalTapStandaloneApp method main.

public static void main(String[] args) throws Exception {
    if (args.length != 1) {
        log.error("Usage: SpinalTapStandaloneApp <config.yaml>");
        System.exit(1);
    }
    ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory());
    SpinalTapStandaloneConfiguration config = objectMapper.readValue(new File(args[0]), SpinalTapStandaloneConfiguration.class);
    MySQLPipeFactory mySQLPipeFactory = new MySQLPipeFactory(config.getMysqlUser(), config.getMysqlPassword(), config.getMysqlServerId(), () -> new KafkaDestinationBuilder<>(config.getKafkaProducerConfig()), config.getMysqlSchemaStoreConfig(), new TaggedMetricRegistry());
    CuratorFramework zkClient = CuratorFrameworkFactory.builder().namespace(config.getZkNamespace()).connectString(config.getZkConnectionString()).retryPolicy(new ExponentialBackoffRetry(100, 3)).build();
    ZookeeperRepositoryFactory zkRepositoryFactory = new ZookeeperRepositoryFactory(zkClient);
    zkClient.start();
    PipeManager pipeManager = new PipeManager();
    for (MysqlConfiguration mysqlSourceConfig : config.getMysqlSources()) {
        String sourceName = mysqlSourceConfig.getName();
        String partitionName = String.format("%s_0", sourceName);
        pipeManager.addPipes(sourceName, partitionName, mySQLPipeFactory.createPipes(mysqlSourceConfig, partitionName, zkRepositoryFactory, 0));
    }
    Runtime.getRuntime().addShutdownHook(new Thread(() -> pipeManager.stop()));
}
Also used : ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) CuratorFramework(org.apache.curator.framework.CuratorFramework) YAMLFactory(com.fasterxml.jackson.dataformat.yaml.YAMLFactory) TaggedMetricRegistry(com.airbnb.common.metrics.TaggedMetricRegistry) MysqlConfiguration(com.airbnb.spinaltap.mysql.config.MysqlConfiguration) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) PipeManager(com.airbnb.spinaltap.common.pipe.PipeManager)

Example 59 with ExponentialBackoffRetry

use of org.apache.flink.shaded.curator5.org.apache.curator.retry.ExponentialBackoffRetry in project iris by chicc999.

the class ZookeeperService method beforeStart.

@Override
public void beforeStart() throws Exception {
    ExponentialBackoffRetry retryPolicy = new ExponentialBackoffRetry(1000, 3);
    zk = CuratorFrameworkFactory.builder().connectString(connectionString).retryPolicy(retryPolicy).connectionTimeoutMs(connectionTimeout).sessionTimeoutMs(sessionTimeout).namespace(NAME_SPACE).build();
}
Also used : ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry)

Example 60 with ExponentialBackoffRetry

use of org.apache.flink.shaded.curator5.org.apache.curator.retry.ExponentialBackoffRetry in project iris by chicc999.

the class MetaManager method beforeStart.

@Override
public void beforeStart() throws Exception {
    if (zkClient == null) {
        ExponentialBackoffRetry retryPolicy = new ExponentialBackoffRetry(metaConfig.getZookeeperBaseSleepTimeMs(), metaConfig.getZookeeperMaxRetries());
        zkClient = CuratorFrameworkFactory.builder().connectString(metaConfig.getConnectionString()).retryPolicy(retryPolicy).connectionTimeoutMs(metaConfig.getConnectionTimeout()).sessionTimeoutMs(metaConfig.getSessionTimeout()).namespace(metaConfig.getNameSpace()).build();
    }
    // 初始化本地broker
    if (this.broker == null) {
        this.broker = new Broker(System.getProperty(ServerType.Broker.nameKey()));
    }
    // 初始化本地所在brokerGroup
    if (this.brokerGroup == null) {
        this.brokerGroup = new BrokerGroup();
    }
    this.brokerGroup.addBroker(this.broker);
}
Also used : Broker(pers.cy.iris.commons.cluster.Broker) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) BrokerGroup(pers.cy.iris.commons.cluster.BrokerGroup)

Aggregations

ExponentialBackoffRetry (org.apache.curator.retry.ExponentialBackoffRetry)189 CuratorFramework (org.apache.curator.framework.CuratorFramework)113 RetryPolicy (org.apache.curator.RetryPolicy)46 Before (org.junit.Before)31 TestingCluster (org.apache.curator.test.TestingCluster)28 Test (org.testng.annotations.Test)23 TestingServer (org.apache.curator.test.TestingServer)19 IOException (java.io.IOException)18 Timing (org.apache.curator.test.Timing)16 CountDownLatch (java.util.concurrent.CountDownLatch)15 ArrayList (java.util.ArrayList)14 CuratorFrameworkFactory (org.apache.curator.framework.CuratorFrameworkFactory)12 ACLProvider (org.apache.curator.framework.api.ACLProvider)12 Test (org.junit.Test)12 ConnectionState (org.apache.curator.framework.state.ConnectionState)11 ExecutorService (java.util.concurrent.ExecutorService)10 ConnectionStateListener (org.apache.curator.framework.state.ConnectionStateListener)10 TestingServerStarter (io.pravega.test.common.TestingServerStarter)9 HashMap (java.util.HashMap)8 KeeperException (org.apache.zookeeper.KeeperException)8