Search in sources :

Example 6 with PoolingOptions

use of com.datastax.driver.core.PoolingOptions in project cassandra by apache.

the class CqlConfigHelper method getCluster.

public static Cluster getCluster(String[] hosts, Configuration conf, int port) {
    Optional<AuthProvider> authProvider = getAuthProvider(conf);
    Optional<SSLOptions> sslOptions = getSSLOptions(conf);
    Optional<Integer> protocolVersion = getProtocolVersion(conf);
    LoadBalancingPolicy loadBalancingPolicy = getReadLoadBalancingPolicy(hosts);
    SocketOptions socketOptions = getReadSocketOptions(conf);
    QueryOptions queryOptions = getReadQueryOptions(conf);
    PoolingOptions poolingOptions = getReadPoolingOptions(conf);
    Cluster.Builder builder = Cluster.builder().addContactPoints(hosts).withPort(port).withCompression(ProtocolOptions.Compression.NONE);
    if (authProvider.isPresent())
        builder.withAuthProvider(authProvider.get());
    if (sslOptions.isPresent())
        builder.withSSL(sslOptions.get());
    if (protocolVersion.isPresent()) {
        builder.withProtocolVersion(ProtocolVersion.fromInt(protocolVersion.get()));
    }
    builder.withLoadBalancingPolicy(loadBalancingPolicy).withSocketOptions(socketOptions).withQueryOptions(queryOptions).withPoolingOptions(poolingOptions);
    return builder.build();
}
Also used : LoadBalancingPolicy(com.datastax.driver.core.policies.LoadBalancingPolicy) SocketOptions(com.datastax.driver.core.SocketOptions) PoolingOptions(com.datastax.driver.core.PoolingOptions) Cluster(com.datastax.driver.core.Cluster) AuthProvider(com.datastax.driver.core.AuthProvider) PlainTextAuthProvider(com.datastax.driver.core.PlainTextAuthProvider) JdkSSLOptions(com.datastax.driver.core.JdkSSLOptions) SSLOptions(com.datastax.driver.core.SSLOptions) QueryOptions(com.datastax.driver.core.QueryOptions)

Example 7 with PoolingOptions

use of com.datastax.driver.core.PoolingOptions in project storm by apache.

the class CassandraBackingMap method prepare.

public void prepare() {
    LOG.info("Preparing state for {}", options.toString());
    Preconditions.checkNotNull(options.getMapper, "CassandraBackingMap.Options should have getMapper");
    Preconditions.checkNotNull(options.putMapper, "CassandraBackingMap.Options should have putMapper");
    client = options.clientProvider.getClient(conf);
    session = client.connect();
    if (options.maxParallelism == null || options.maxParallelism <= 0) {
        PoolingOptions po = session.getCluster().getConfiguration().getPoolingOptions();
        Integer maxRequestsPerHost = Math.min(po.getMaxConnectionsPerHost(HostDistance.LOCAL) * po.getMaxRequestsPerConnection(HostDistance.LOCAL), po.getMaxConnectionsPerHost(HostDistance.REMOTE) * po.getMaxRequestsPerConnection(HostDistance.REMOTE));
        options.maxParallelism = maxRequestsPerHost / 2;
        LOG.info("Parallelism default set to {}", options.maxParallelism);
    }
    throttle = new Semaphore(options.maxParallelism, false);
    this.getResultMapper = new TridentAyncCQLResultSetValuesMapper(options.stateMapper.getStateFields(), throttle);
    this.putResultMapper = new TridentAyncCQLResultSetValuesMapper(null, throttle);
}
Also used : PoolingOptions(com.datastax.driver.core.PoolingOptions) Semaphore(java.util.concurrent.Semaphore)

Example 8 with PoolingOptions

use of com.datastax.driver.core.PoolingOptions in project spring-cloud-connectors by spring-cloud.

the class CassandraClusterCreatorTest method shouldCreateClusterWithConfig.

@Test
public void shouldCreateClusterWithConfig() throws Exception {
    CassandraServiceInfo info = new CassandraServiceInfo("local", Collections.singletonList("127.0.0.1"), 9142);
    CassandraClusterConfig config = new CassandraClusterConfig();
    config.setCompression(ProtocolOptions.Compression.NONE);
    config.setPoolingOptions(new PoolingOptions().setPoolTimeoutMillis(1234));
    config.setQueryOptions(new QueryOptions());
    config.setProtocolVersion(ProtocolVersion.NEWEST_SUPPORTED);
    config.setLoadBalancingPolicy(new RoundRobinPolicy());
    config.setReconnectionPolicy(new ConstantReconnectionPolicy(1));
    config.setRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE);
    config.setSocketOptions(new SocketOptions());
    Cluster cluster = creator.create(info, config);
    Configuration configuration = cluster.getConfiguration();
    assertThat(configuration.getProtocolOptions().getCompression(), is(config.getCompression()));
    assertThat(configuration.getQueryOptions(), is(config.getQueryOptions()));
    assertThat(configuration.getSocketOptions(), is(config.getSocketOptions()));
    Policies policies = configuration.getPolicies();
    assertThat(policies.getLoadBalancingPolicy(), is(config.getLoadBalancingPolicy()));
    assertThat(policies.getReconnectionPolicy(), is(config.getReconnectionPolicy()));
    assertThat(policies.getRetryPolicy(), is(config.getRetryPolicy()));
}
Also used : Policies(com.datastax.driver.core.policies.Policies) Configuration(com.datastax.driver.core.Configuration) CassandraServiceInfo(org.springframework.cloud.service.common.CassandraServiceInfo) SocketOptions(com.datastax.driver.core.SocketOptions) PoolingOptions(com.datastax.driver.core.PoolingOptions) Cluster(com.datastax.driver.core.Cluster) QueryOptions(com.datastax.driver.core.QueryOptions) RoundRobinPolicy(com.datastax.driver.core.policies.RoundRobinPolicy) ConstantReconnectionPolicy(com.datastax.driver.core.policies.ConstantReconnectionPolicy) Test(org.junit.Test)

Example 9 with PoolingOptions

use of com.datastax.driver.core.PoolingOptions in project zipkin by openzipkin.

the class SessionFactoryTest method maxConnections_setsMaxConnectionsPerDatacenterLocalHost.

@Test
public void maxConnections_setsMaxConnectionsPerDatacenterLocalHost() {
    PoolingOptions poolingOptions = buildCluster(CassandraStorage.builder().maxConnections(16).build()).getConfiguration().getPoolingOptions();
    assertThat(poolingOptions.getMaxConnectionsPerHost(HostDistance.LOCAL)).isEqualTo(16);
}
Also used : PoolingOptions(com.datastax.driver.core.PoolingOptions) Test(org.junit.Test)

Example 10 with PoolingOptions

use of com.datastax.driver.core.PoolingOptions in project cas by apereo.

the class DefaultCassandraSessionFactory method initializeCassandraCluster.

private static Cluster initializeCassandraCluster(final BaseCassandraProperties cassandra) {
    final Cluster cluster;
    final PoolingOptions poolingOptions = new PoolingOptions().setMaxRequestsPerConnection(HostDistance.LOCAL, cassandra.getMaxRequestsPerConnection()).setConnectionsPerHost(HostDistance.LOCAL, cassandra.getCoreConnections(), cassandra.getMaxConnections());
    final DCAwareRoundRobinPolicy.Builder dcPolicyBuilder = DCAwareRoundRobinPolicy.builder();
    if (StringUtils.isNotBlank(cassandra.getLocalDc())) {
        dcPolicyBuilder.withLocalDc(cassandra.getLocalDc());
    }
    final TokenAwarePolicy loadBalancingPolicy = new TokenAwarePolicy(dcPolicyBuilder.build(), cassandra.isShuffleReplicas());
    final SocketOptions socketOptions = new SocketOptions().setConnectTimeoutMillis(cassandra.getConnectTimeoutMillis()).setReadTimeoutMillis(cassandra.getReadTimeoutMillis());
    final QueryOptions queryOptions = new QueryOptions().setConsistencyLevel(ConsistencyLevel.valueOf(cassandra.getConsistencyLevel())).setSerialConsistencyLevel(ConsistencyLevel.valueOf(cassandra.getSerialConsistencyLevel()));
    final RetryPolicy retryPolicy = RetryPolicyType.valueOf(cassandra.getRetryPolicy()).getRetryPolicy();
    final Cluster.Builder builder = Cluster.builder().withCredentials(cassandra.getUsername(), cassandra.getPassword()).withPoolingOptions(poolingOptions).withProtocolVersion(ProtocolVersion.valueOf(cassandra.getProtocolVersion())).withLoadBalancingPolicy(loadBalancingPolicy).withSocketOptions(socketOptions).withRetryPolicy(new LoggingRetryPolicy(retryPolicy)).withCompression(ProtocolOptions.Compression.valueOf(cassandra.getCompression())).withPort(cassandra.getPort()).withQueryOptions(queryOptions);
    Arrays.stream(StringUtils.split(cassandra.getContactPoints(), ',')).forEach(contactPoint -> builder.addContactPoint(StringUtils.trim(contactPoint)));
    cluster = builder.build();
    if (LOGGER.isDebugEnabled()) {
        cluster.getMetadata().getAllHosts().forEach(clusterHost -> LOGGER.debug("Host [{}]:\n\n\tDC: [{}]\n\tRack: [{}]\n\tVersion: [{}]\n\tDistance: [{}]\n\tUp?: [{}]\n", clusterHost.getAddress(), clusterHost.getDatacenter(), clusterHost.getRack(), clusterHost.getCassandraVersion(), loadBalancingPolicy.distance(clusterHost), clusterHost.isUp()));
    }
    return cluster;
}
Also used : DCAwareRoundRobinPolicy(com.datastax.driver.core.policies.DCAwareRoundRobinPolicy) SocketOptions(com.datastax.driver.core.SocketOptions) PoolingOptions(com.datastax.driver.core.PoolingOptions) Cluster(com.datastax.driver.core.Cluster) TokenAwarePolicy(com.datastax.driver.core.policies.TokenAwarePolicy) QueryOptions(com.datastax.driver.core.QueryOptions) LoggingRetryPolicy(com.datastax.driver.core.policies.LoggingRetryPolicy) RetryPolicy(com.datastax.driver.core.policies.RetryPolicy) LoggingRetryPolicy(com.datastax.driver.core.policies.LoggingRetryPolicy)

Aggregations

PoolingOptions (com.datastax.driver.core.PoolingOptions)14 Cluster (com.datastax.driver.core.Cluster)7 QueryOptions (com.datastax.driver.core.QueryOptions)5 SocketOptions (com.datastax.driver.core.SocketOptions)4 TokenAwarePolicy (com.datastax.driver.core.policies.TokenAwarePolicy)4 Test (org.junit.Test)4 DCAwareRoundRobinPolicy (com.datastax.driver.core.policies.DCAwareRoundRobinPolicy)3 RoundRobinPolicy (com.datastax.driver.core.policies.RoundRobinPolicy)3 InetSocketAddress (java.net.InetSocketAddress)3 HostDistance (com.datastax.driver.core.HostDistance)2 JdkSSLOptions (com.datastax.driver.core.JdkSSLOptions)2 PlainTextAuthProvider (com.datastax.driver.core.PlainTextAuthProvider)2 SSLOptions (com.datastax.driver.core.SSLOptions)2 LoadBalancingPolicy (com.datastax.driver.core.policies.LoadBalancingPolicy)2 AuthProvider (com.datastax.driver.core.AuthProvider)1 BatchStatement (com.datastax.driver.core.BatchStatement)1 Type (com.datastax.driver.core.BatchStatement.Type)1 Builder (com.datastax.driver.core.Cluster.Builder)1 Configuration (com.datastax.driver.core.Configuration)1 Host (com.datastax.driver.core.Host)1