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); }
loadPolicy = builder.build();
m_writeLoadBalancingPolicy = new TokenAwarePolicy((m_clusterConfiguration.getLocalDCName() == null) ? new RoundRobinPolicy() : DCAwareRoundRobinPolicy.builder().withLocalDc(m_clusterConfiguration.getLocalDCName()).build(), TokenAwarePolicy.ReplicaOrdering.TOPOLOGICAL); TokenAwarePolicy readLoadBalancePolicy = new TokenAwarePolicy((m_clusterConfiguration.getLocalDCName() == null) ? new RoundRobinPolicy() : DCAwareRoundRobinPolicy.builder().withLocalDc(m_clusterConfiguration.getLocalDCName()).build(), TokenAwarePolicy.ReplicaOrdering.RANDOM);
/** * Creates a new {@code PartitionAware} policy with additional default data-center awareness. */ public PartitionAwarePolicy() { this(new DCAwareRoundRobinPolicy.Builder() .withUsedHostsPerRemoteDc(Integer.MAX_VALUE) .build()); }
getTokenAwareLoadBalancingUsedHostsPerRemoteDc()) .allowRemoteDCsForLocalConsistencyLevel() .build()
loadBalancingPolicy = policyBuilder.build(); break;
.withLocalDc(ScassandraCluster.datacenter(2)) .withUsedHostsPerRemoteDc(3) .build())) .build();
LoadBalancingPolicy loadBalancingPolicy = HostFilterPolicy.fromDCWhiteList( DCAwareRoundRobinPolicy.builder().withUsedHostsPerRemoteDc(2).build(), Lists.newArrayList(datacenter(1), datacenter(2))); Cluster cluster =
.allowRemoteDCsForLocalConsistencyLevel() .withUsedHostsPerRemoteDc(2) .build()) .build();
.withLocalDc(datacenter(1)) .withUsedHostsPerRemoteDc(2) .build()) .build();
.withPort(sCluster.getBinaryPort()) .withLoadBalancingPolicy( DCAwareRoundRobinPolicy.builder().withUsedHostsPerRemoteDc(2).build()) .build();
LoadBalancingPolicy loadBalancingPolicy = HostFilterPolicy.fromDCBlackList( DCAwareRoundRobinPolicy.builder().withUsedHostsPerRemoteDc(2).build(), Lists.newArrayList(datacenter(2))); Cluster cluster =
.withPort(sCluster.getBinaryPort()) .withLoadBalancingPolicy( DCAwareRoundRobinPolicy.builder().withUsedHostsPerRemoteDc(2).build()) .build();
DCAwareRoundRobinPolicy policy = spy(DCAwareRoundRobinPolicy.builder().build()); ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(2, 2).build(); Cluster cluster =
spy(DCAwareRoundRobinPolicy.builder().withLocalDc(datacenter(3)).build()); Cluster cluster = builder()
public void should_use_local_dc_from_contact_points_when_not_explicitly_specified() { DCAwareRoundRobinPolicy policy = spy(DCAwareRoundRobinPolicy.builder().build()); ScassandraCluster sCluster = ScassandraCluster.builder().withNodes(2, 2).build(); Cluster cluster =
.withPort(sCluster.getBinaryPort()) .withLoadBalancingPolicy( DCAwareRoundRobinPolicy.builder().withLocalDc(datacenter(1)).build()) .build(); try {
spy(DCAwareRoundRobinPolicy.builder().withLocalDc(datacenter(1)).build()); Cluster cluster = builder()
/** * The default load balancing policy. * * <p>The default load balancing policy is {@link DCAwareRoundRobinPolicy} with token awareness * (so {@code new TokenAwarePolicy(new DCAwareRoundRobinPolicy())}). * * <p>Note that this policy shuffles the replicas when token awareness is used, see {@link * TokenAwarePolicy#TokenAwarePolicy(LoadBalancingPolicy, boolean)} for an explanation of the * tradeoffs. * * @return the default load balancing policy. */ public static LoadBalancingPolicy defaultLoadBalancingPolicy() { // Note: balancing policies are stateful, so we can't store that in a static or that would screw // thing // up if multiple Cluster instance are started in the same JVM. return new TokenAwarePolicy(DCAwareRoundRobinPolicy.builder().build()); }