Refine search
requireNonNull(extraColumnMetadataCodec, "extraColumnMetadataCodec is null"); Cluster.Builder clusterBuilder = Cluster.builder() .withProtocolVersion(config.getProtocolVersion()); clusterBuilder.withPort(config.getNativeProtocolPort()); clusterBuilder.withReconnectionPolicy(new ExponentialReconnectionPolicy(500, 10000)); clusterBuilder.withRetryPolicy(config.getRetryPolicy().getPolicy()); DCAwareRoundRobinPolicy.Builder builder = DCAwareRoundRobinPolicy.builder() .withLocalDc(config.getDcAwareLocalDC()); if (config.getDcAwareUsedHostsPerRemoteDc() > 0) { builder.withUsedHostsPerRemoteDc(config.getDcAwareUsedHostsPerRemoteDc()); if (config.isDcAwareAllowRemoteDCsForLocal()) { builder.allowRemoteDCsForLocalConsistencyLevel(); loadPolicy = builder.build();
if( !cassandraConfig.getLocalDataCenter().isEmpty() ){ loadBalancingPolicy = new DCAwareRoundRobinPolicy.Builder() .withLocalDc( cassandraConfig.getLocalDataCenter() ).build(); }else{ loadBalancingPolicy = new DCAwareRoundRobinPolicy.Builder().build(); .setMetadataEnabled(true); // choose whether to have the driver store metadata such as schema info Cluster.Builder datastaxCluster = Cluster.builder() .withClusterName(cassandraConfig.getClusterName()) .addContactPoints(cassandraConfig.getHosts().split(",")) .withMaxSchemaAgreementWaitSeconds(45) .withCompression(ProtocolOptions.Compression.LZ4) .withLoadBalancingPolicy(loadBalancingPolicy)
Cluster cluster = builder() .addContactPoints(sCluster.address(1, 1).getAddress()) .withPort(sCluster.getBinaryPort()) .withLoadBalancingPolicy( DCAwareRoundRobinPolicy.builder().withUsedHostsPerRemoteDc(2).build()) .build(); sCluster.init(); Session session = cluster.connect(); cluster.close(); sCluster.stop();
@Override public synchronized void startup() { if (cassandraCluster != null) return; Builder b = Cluster.builder(); b.withLoadBalancingPolicy(new TokenAwarePolicy(DCAwareRoundRobinPolicy.builder().build())); for (String host : hosts) { b.addContactPoint(host); } if (port != null) { b.withPort(port); } cassandraCluster = b.build(); cassandraCluster.getConfiguration().getSocketOptions().setReadTimeoutMillis(60000); logger.info("Connected to cluster: {}", cassandraCluster.getMetadata().getClusterName()); for (Host host : cassandraCluster.getMetadata().getAllHosts()) { logger.info("Datatacenter: {} Host: {} Rack: {}", host.getDatacenter(), host.getAddress(), host.getRack()); } session = cassandraCluster.connect(keyspace); }
private void initialize() throws IOException { if (cluster == null) { synchronized (DefaultCassandraDriver.class) { Cluster.Builder builder = Cluster.builder(); List<String> nodes = getConfiguration().getNodeHosts(); builder.addContactPoints(nodes.toArray(new String[nodes.size()])) .withRetryPolicy(DefaultRetryPolicy.INSTANCE); builder.withPort(getConfiguration().getPort()); builder.withCredentials( getConfiguration().getUsername(), builder.withLoadBalancingPolicy( new TokenAwarePolicy( new DCAwareRoundRobinPolicy.Builder() .withLocalDc(getConfiguration() .getTokenAwareLoadBalancingLocalDC().get()) .withUsedHostsPerRemoteDc(getConfiguration(). getTokenAwareLoadBalancingUsedHostsPerRemoteDc()) .allowRemoteDCsForLocalConsistencyLevel() .build() session = cluster.connect(getConfiguration().getKeyspaceName()); } catch (InvalidQueryException ex) { //This exception occurs when namesapce does not exists session = cluster.connect(); // have to attach to the root keyspace first initializeKeyspace(); } catch (Exception e) {
.build(); Cluster cluster = Cluster.builder() .addContactPoints(sCluster.address(1).getAddress()) .withPort(sCluster.getBinaryPort()) .withNettyOptions(nonQuietClusterCloseOptions) .withLoadBalancingPolicy( new TokenAwarePolicy( DCAwareRoundRobinPolicy.builder() .withLocalDc(ScassandraCluster.datacenter(2)) .withUsedHostsPerRemoteDc(3) .build())) .build(); sCluster.init(); Session session = cluster.connect(); queryTracker.assertQueried(sCluster, 1, 1, 0); } finally { cluster.close(); sCluster.stop();
DCAwareRoundRobinPolicy policy = spy(DCAwareRoundRobinPolicy.builder().build()); ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(2, 2).build(); Cluster cluster = builder() .addContactPoints( sCluster.address(1, 1).getAddress(), sCluster.address(2, 1).getAddress()) .withPort(sCluster.getBinaryPort()) .withLoadBalancingPolicy(policy) .build(); cluster.init(); Mockito.verify(policy).init(any(Cluster.class), initHostsCaptor.capture()); assertThat(initHostsCaptor.getValue()).containsOnly(host1, host3); cluster.close(); sCluster.stop();
DCAwareRoundRobinPolicy dcAwareRoundRobinPolicy = DCAwareRoundRobinPolicy.builder().withUsedHostsPerRemoteDc(1).build(); Cluster.Builder builder = Cluster.builder() .withLoadBalancingPolicy(new TokenAwarePolicy(dcAwareRoundRobinPolicy)) .withNettyOptions(new RatpackCassandraNettyOptions()) .withSpeculativeExecutionPolicy(new PercentileSpeculativeExecutionPolicy(tracker, 0.99, 3)); session = cluster.connect(cassandraConfig.keyspace); } else { session = cluster.connect();
.setConnectionsPerHost(HostDistance.LOCAL, cassandra.getCoreConnections(), cassandra.getMaxConnections()); val dcPolicyBuilder = DCAwareRoundRobinPolicy.builder(); if (StringUtils.isNotBlank(cassandra.getLocalDc())) { dcPolicyBuilder.withLocalDc(cassandra.getLocalDc()); val loadBalancingPolicy = new TokenAwarePolicy(dcPolicyBuilder.build(), replica); Cluster.builder() .withCredentials(cassandra.getUsername(), cassandra.getPassword()) .withPoolingOptions(poolingOptions) .withProtocolVersion(ProtocolVersion.valueOf(cassandra.getProtocolVersion())) .withLoadBalancingPolicy(loadBalancingPolicy) .withSocketOptions(socketOptions) 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(),
public LoadBalancingPolicy getLoadBalancingPolicy() { if (this.loadBalancingPolicyName.equals(TokenAwarePolicy.class.getSimpleName())) { return new TokenAwarePolicy(new RoundRobinPolicy()); } if (this.loadBalancingPolicyName.equals(DCAwareRoundRobinPolicy.class.getSimpleName())) { Builder builder = DCAwareRoundRobinPolicy.builder(); if (StringUtils.isNotBlank(datacenterName)) { builder = builder.withLocalDc(this.datacenterName); } return new TokenAwarePolicy(builder.build()); } throw new IllegalArgumentException("Unknown cassandra load balancing policy " + this.loadBalancingPolicyName); }
/** * Returns a builder to create a new instance. * * @return the builder. */ public static Builder builder() { return new Builder(); }
/** * Returns a builder to create a new instance. * * @return the builder. */ public static Builder builder() { return new Builder(); }
/** * Creates a new {@code PartitionAware} policy with additional default data-center awareness. */ public PartitionAwarePolicy() { this(new DCAwareRoundRobinPolicy.Builder() .withUsedHostsPerRemoteDc(Integer.MAX_VALUE) .build()); }
/** * Returns a builder to create a new instance. * * @return the builder. */ public static Builder builder() { return new Builder(); }
public DCAwareRoundRobinPolicy(String localDc, int usedHostsPerRemoteDc, boolean allowRemoteDCsForLocalConsistencyLevel) { builder.withLocalDc(localDc) .withUsedHostsPerRemoteDc(usedHostsPerRemoteDc); if(allowRemoteDCsForLocalConsistencyLevel){ builder.allowRemoteDCsForLocalConsistencyLevel(); } }
/** * Returns a builder to create a new instance. * * @return the builder. */ public static Builder builder() { return new Builder(); }
cluster = Cluster .builder() .addContactPoints("192.1.1.1","192.1.1.2") .withRetryPolicy(DefaultRetryPolicy.INSTANCE) .withLoadBalancingPolicy( new TokenAwarePolicy(new DCAwareRoundRobinPolicy.Builder().build())) .build();
public DCAwareRoundRobinPolicy(String localDc, int usedHostsPerRemoteDc) { builder.withLocalDc(localDc) .withUsedHostsPerRemoteDc(usedHostsPerRemoteDc); }
public DCAwareRoundRobinPolicy(String localDc) { builder.withLocalDc(localDc); }
public com.datastax.driver.core.policies.DCAwareRoundRobinPolicy build(){ return builder.build(); }