public class RackAwareRoundRobinPolicy extends Object implements LoadBalancingPolicy
This policy provides round-robin queries over the node of the local rack. After that, the query plan includes round-robin list of nodes in the local DC (but not in local rack). It also includes in the query plans returned a configurable number of hosts in the remote data centers, but those are always tried after the local nodes. In other words, this policy guarantees that no host in a remote data center will be queried unless no host in the local data center can be reached.
| Modifier and Type | Class and Description |
|---|---|
static class |
RackAwareRoundRobinPolicy.Builder
Helper class to build the policy.
|
| Constructor and Description |
|---|
RackAwareRoundRobinPolicy(String localDc,
String localRack,
int usedHostsPerRemoteDc,
boolean allowRemoteDCsForLocalConsistencyLevel,
boolean allowEmptyLocalDc,
boolean allowEmptyLocalRack) |
| Modifier and Type | Method and Description |
|---|---|
static RackAwareRoundRobinPolicy.Builder |
builder()
Returns a builder to create a new instance.
|
void |
close()
Gets invoked at cluster shutdown.
|
HostDistance |
distance(Host host)
Return the HostDistance for the provided host.
|
void |
init(Cluster cluster,
Collection<Host> hosts)
Initialize this load balancing policy.
|
Iterator<Host> |
newQueryPlan(String loggedKeyspace,
Statement statement)
Returns the hosts to use for a new query.
|
void |
onAdd(Host host)
Called when a new node is added to the cluster.
|
void |
onDown(Host host)
Called when a node is determined to be down.
|
void |
onRemove(Host host)
Called when a node is removed from the cluster.
|
void |
onUp(Host host)
Called when a node is determined to be up.
|
public static RackAwareRoundRobinPolicy.Builder builder()
public void init(Cluster cluster, Collection<Host> hosts)
LoadBalancingPolicyNote that the driver guarantees that it will call this method exactly once per policy object and will do so before any call to another of the methods of the policy.
init in interface LoadBalancingPolicycluster - the Cluster instance for which the policy is created.hosts - the initial hosts to use.public HostDistance distance(Host host)
This policy consider nodes in the local datacenter as LOCAL. For each remote
datacenter, it considers a configurable number of hosts as REMOTE and the rest is
IGNORED.
To configure how many hosts in each remote datacenter should be considered, see RackAwareRoundRobinPolicy.Builder.withUsedHostsPerRemoteDc(int).
distance in interface LoadBalancingPolicyhost - the host of which to return the distance of.host.public Iterator<Host> newQueryPlan(String loggedKeyspace, Statement statement)
The returned plan will always try each known host in the local rack first, and then, if none of the host in local rack are reachable, will try hosts in remote racks of the local datacenter. Finally, it will try up to a configurable number of other host per remote datacenter. The order of the local node in the returned query plan will follow a Round-robin algorithm.
newQueryPlan in interface LoadBalancingPolicyloggedKeyspace - the keyspace currently logged in on for this query.statement - the query for which to build the plan.public void onUp(Host host)
LoadBalancingPolicyonUp in interface LoadBalancingPolicyhost - the host that has been detected up.public void onDown(Host host)
LoadBalancingPolicyonDown in interface LoadBalancingPolicyhost - the host that has been detected down.public void onAdd(Host host)
LoadBalancingPolicyThe newly added node should be considered up.
onAdd in interface LoadBalancingPolicyhost - the host that has been newly added.public void onRemove(Host host)
LoadBalancingPolicyonRemove in interface LoadBalancingPolicyhost - the removed host.public void close()
LoadBalancingPolicyThis gives the policy the opportunity to perform some cleanup, for instance stop threads that it might have started.
close in interface LoadBalancingPolicyCopyright © 2012–2025. All rights reserved.