Search in sources :

Example 51 with ExponentialBackoffRetry

use of org.apache.curator.retry.ExponentialBackoffRetry in project phoenix by apache.

the class ZookeeperRegistry method registerServer.

@Override
public void registerServer(LoadBalanceZookeeperConf configuration, int pqsPort, String zookeeperConnectString, String pqsHost) throws Exception {
    this.client = CuratorFrameworkFactory.newClient(zookeeperConnectString, new ExponentialBackoffRetry(1000, 10));
    this.client.start();
    HostAndPort hostAndPort = HostAndPort.fromParts(pqsHost, pqsPort);
    String path = configuration.getFullPathToNode(hostAndPort);
    String node = hostAndPort.toString();
    this.client.create().creatingParentsIfNeeded().withMode(CreateMode.EPHEMERAL).forPath(path, node.getBytes(StandardCharsets.UTF_8));
    Stat stat = this.client.setACL().withACL(configuration.getAcls()).forPath(path);
    if (stat != null) {
        LOG.info(" node created with right ACL");
    } else {
        LOG.error("could not create node with right ACL. So, system would exit now.");
        throw new RuntimeException(" Unable to connect to Zookeeper");
    }
}
Also used : HostAndPort(com.google.common.net.HostAndPort) Stat(org.apache.zookeeper.data.Stat) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry)

Example 52 with ExponentialBackoffRetry

use of 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 53 with ExponentialBackoffRetry

use of 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 54 with ExponentialBackoffRetry

use of 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)

Example 55 with ExponentialBackoffRetry

use of org.apache.curator.retry.ExponentialBackoffRetry in project flink by apache.

the class ZooKeeperUtils method startCuratorFramework.

/**
 * Starts a {@link CuratorFramework} instance and connects it to the given ZooKeeper quorum.
 *
 * @param configuration {@link Configuration} object containing the configuration values
 * @param fatalErrorHandler {@link FatalErrorHandler} fatalErrorHandler to handle unexpected
 *     errors of {@link CuratorFramework}
 * @return {@link CuratorFrameworkWithUnhandledErrorListener} instance
 */
public static CuratorFrameworkWithUnhandledErrorListener startCuratorFramework(Configuration configuration, FatalErrorHandler fatalErrorHandler) {
    checkNotNull(configuration, "configuration");
    String zkQuorum = configuration.getValue(HighAvailabilityOptions.HA_ZOOKEEPER_QUORUM);
    if (zkQuorum == null || StringUtils.isBlank(zkQuorum)) {
        throw new RuntimeException("No valid ZooKeeper quorum has been specified. " + "You can specify the quorum via the configuration key '" + HighAvailabilityOptions.HA_ZOOKEEPER_QUORUM.key() + "'.");
    }
    int sessionTimeout = configuration.getInteger(HighAvailabilityOptions.ZOOKEEPER_SESSION_TIMEOUT);
    int connectionTimeout = configuration.getInteger(HighAvailabilityOptions.ZOOKEEPER_CONNECTION_TIMEOUT);
    int retryWait = configuration.getInteger(HighAvailabilityOptions.ZOOKEEPER_RETRY_WAIT);
    int maxRetryAttempts = configuration.getInteger(HighAvailabilityOptions.ZOOKEEPER_MAX_RETRY_ATTEMPTS);
    String root = configuration.getValue(HighAvailabilityOptions.HA_ZOOKEEPER_ROOT);
    String namespace = configuration.getValue(HighAvailabilityOptions.HA_CLUSTER_ID);
    boolean disableSaslClient = configuration.getBoolean(SecurityOptions.ZOOKEEPER_SASL_DISABLE);
    ACLProvider aclProvider;
    ZkClientACLMode aclMode = ZkClientACLMode.fromConfig(configuration);
    if (disableSaslClient && aclMode == ZkClientACLMode.CREATOR) {
        String errorMessage = "Cannot set ACL role to " + ZkClientACLMode.CREATOR + "  since SASL authentication is " + "disabled through the " + SecurityOptions.ZOOKEEPER_SASL_DISABLE.key() + " property";
        LOG.warn(errorMessage);
        throw new IllegalConfigurationException(errorMessage);
    }
    if (aclMode == ZkClientACLMode.CREATOR) {
        LOG.info("Enforcing creator for ZK connections");
        aclProvider = new SecureAclProvider();
    } else {
        LOG.info("Enforcing default ACL for ZK connections");
        aclProvider = new DefaultACLProvider();
    }
    String rootWithNamespace = generateZookeeperPath(root, namespace);
    LOG.info("Using '{}' as Zookeeper namespace.", rootWithNamespace);
    final CuratorFrameworkFactory.Builder curatorFrameworkBuilder = CuratorFrameworkFactory.builder().connectString(zkQuorum).sessionTimeoutMs(sessionTimeout).connectionTimeoutMs(connectionTimeout).retryPolicy(new ExponentialBackoffRetry(retryWait, maxRetryAttempts)).namespace(trimStartingSlash(rootWithNamespace)).aclProvider(aclProvider);
    if (configuration.get(HighAvailabilityOptions.ZOOKEEPER_TOLERATE_SUSPENDED_CONNECTIONS)) {
        curatorFrameworkBuilder.connectionStateErrorPolicy(new SessionConnectionStateErrorPolicy());
    }
    return startCuratorFramework(curatorFrameworkBuilder, fatalErrorHandler);
}
Also used : ACLProvider(org.apache.flink.shaded.curator5.org.apache.curator.framework.api.ACLProvider) DefaultACLProvider(org.apache.flink.shaded.curator5.org.apache.curator.framework.imps.DefaultACLProvider) CuratorFrameworkFactory(org.apache.flink.shaded.curator5.org.apache.curator.framework.CuratorFrameworkFactory) ExponentialBackoffRetry(org.apache.flink.shaded.curator5.org.apache.curator.retry.ExponentialBackoffRetry) IllegalConfigurationException(org.apache.flink.configuration.IllegalConfigurationException) CompletedCheckpoint(org.apache.flink.runtime.checkpoint.CompletedCheckpoint) SessionConnectionStateErrorPolicy(org.apache.flink.shaded.curator5.org.apache.curator.framework.state.SessionConnectionStateErrorPolicy) DefaultACLProvider(org.apache.flink.shaded.curator5.org.apache.curator.framework.imps.DefaultACLProvider)

Aggregations

ExponentialBackoffRetry (org.apache.curator.retry.ExponentialBackoffRetry)181 CuratorFramework (org.apache.curator.framework.CuratorFramework)107 RetryPolicy (org.apache.curator.RetryPolicy)46 Before (org.junit.Before)26 TestingCluster (org.apache.curator.test.TestingCluster)23 Test (org.testng.annotations.Test)23 IOException (java.io.IOException)18 TestingServer (org.apache.curator.test.TestingServer)18 Timing (org.apache.curator.test.Timing)16 CountDownLatch (java.util.concurrent.CountDownLatch)15 CuratorFrameworkFactory (org.apache.curator.framework.CuratorFrameworkFactory)12 ACLProvider (org.apache.curator.framework.api.ACLProvider)12 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)11 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 KeeperException (org.apache.zookeeper.KeeperException)8 HashMap (java.util.HashMap)7