View Source Xandra.Cluster.LoadBalancingPolicy.DCAwareRoundRobin (Xandra v0.19.1)
A Xandra.Cluster.LoadBalancingPolicy
that prefers hosts in a "local" data center.
This policy uses a round-robin strategy to pick hosts, giving precedence to hosts
in a "local" data center. The local data center is determined by the
:local_data_center
option (see below). "Giving precedence" means that
hosts_plan/1
and query_plan/1
will return a list of hosts where first there are all
the local hosts that are up, and then all the remote hosts that are up.
The round-robin strategy is applied to local and remote hosts separately. For example,
say the local hosts are LH1
, LH2
, LH3
, and the remote hosts are RH1
, RH2
, RH3
.
The first time, this policy will return [LH1, RH1, LH2, RH2, LH3, RH3]
. The second time,
it will return [LH2, LH3, LH1, RH2, RH3, RH1]
. And so on.
This policy is available since Xandra v0.15.0.
Options
This policy supports the following initialization options:
:local_data_center
- The local data center. If:from_first_peer
, this policy picks the local data center from the first peer that is added to the cluster. This is usually the first peer that the control connection connects to, which (if everything goes well) is the first peer listed in the:nodes
option passed toXandra.Cluster.start_link/1
. If you want to force a specific data center to be used as the local data center, you can pass a string as the value of this option (such as"datacenter1"
). The default value is:from_first_peer
.