Class DCAwareRoundRobinPolicy
A data-center aware Round-robin load balancing policy.
This policy provides round-robin queries over the node of the local datacenter. Currently, it also includes in the query plans returned a configurable number of hosts in the remote datacenters (which are always tried after the local nodes) but this functionality will be removed in the next major version of the driver. See the comments on DCAwareRoundRobinPolicy(string, int) for more information.
Implements
Inherited Members
Namespace: Cassandra
Assembly: Cassandra.dll
Syntax
public class DCAwareRoundRobinPolicy : ILoadBalancingPolicy
Constructors
DCAwareRoundRobinPolicy()
Creates a new datacenter aware round robin policy that auto-discover the local data-center.
If this constructor is used, the data-center used as local will the data-center of the first Cassandra node the driver connects to. This will always be ok if all the contact points use at Cluster creation are in the local data-center. If it's not the case, you should provide the local data-center name yourself by using one of the other constructor of this class.
Declaration
public DCAwareRoundRobinPolicy()
DCAwareRoundRobinPolicy(string)
Creates a new datacenter aware round robin policy given the name of the local datacenter.
The name of the local datacenter provided must be the local datacenter name as known by Cassandra.
The policy created will ignore all
remote hosts. In other words, this is equivalent to
new DCAwareRoundRobinPolicy(localDc, 0).
Declaration
public DCAwareRoundRobinPolicy(string localDc)
Parameters
| Type | Name | Description |
|---|---|---|
| string | localDc | the name of the local datacenter (as known by Cassandra). |
DCAwareRoundRobinPolicy(string, int)
Creates a new DCAwareRoundRobin policy given the name of the local datacenter and that uses the provided number of host per remote datacenter as failover for the local hosts.
The name of the local datacenter provided must be the local datacenter name as known by Cassandra.
Declaration
[Obsolete("The usedHostsPerRemoteDc parameter will be removed in the next major release of the driver. DC failover should not be done in the driver, which does not have the necessary context to know what makes sense considering application semantics. See https://datastax-oss.atlassian.net/browse/CSHARP-722")]
public DCAwareRoundRobinPolicy(string localDc, int usedHostsPerRemoteDc)
Parameters
| Type | Name | Description |
|---|---|---|
| string | localDc | The name of the local datacenter (as known by Cassandra). |
| int | usedHostsPerRemoteDc | The number of host per remote
datacenter that policies created by the returned factory should
consider. Created policies Note that this parameter will be removed in the next major release of the driver. |
Properties
LocalDc
Gets the Local Datacenter. This value is provided in the constructor.
Declaration
public string LocalDc { get; }
Property Value
| Type | Description |
|---|---|
| string |
UsedHostsPerRemoteDc
Gets the number of hosts per remote datacenter that should be considered. This value is provided in the constructor.
Declaration
[Obsolete("The usedHostsPerRemoteDc parameter will be removed in the next major release of the driver. DC failover should not be done in the driver, which does not have the necessary context to know what makes sense considering application semantics. See https://datastax-oss.atlassian.net/browse/CSHARP-722")]
public int UsedHostsPerRemoteDc { get; }
Property Value
| Type | Description |
|---|---|
| int |
Methods
Distance(Host)
Return the HostDistance for the provided 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 host in each remote
datacenter is considered Remote.
Declaration
public HostDistance Distance(Host host)
Parameters
| Type | Name | Description |
|---|---|---|
| Host | host | the host of which to return the distance of. |
Returns
| Type | Description |
|---|---|
| HostDistance | the HostDistance to |
Initialize(ICluster)
Initialize this load balancing policy.
Note 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.
Declaration
public void Initialize(ICluster cluster)
Parameters
| Type | Name | Description |
|---|---|---|
| ICluster | cluster | The information about the session instance for which the policy is created. |
NewQueryPlan(string, IStatement)
Returns the hosts to use for a new query.
The returned plan will always try each known host in the local datacenter first, and then, if none of the local host is reachable, 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.
Declaration
public IEnumerable<Host> NewQueryPlan(string keyspace, IStatement query)
Parameters
| Type | Name | Description |
|---|---|---|
| string | keyspace | Keyspace on which the query is going to be executed |
| IStatement | query | the query for which to build the plan. |
Returns
| Type | Description |
|---|---|
| IEnumerable<Host> | a new query plan, i.e. an iterator indicating which host to try first for querying, which one to use as failover, etc... |