public final class CosmosLoadBalancingPolicy extends Object implements com.datastax.driver.core.policies.LoadBalancingPolicy
LoadBalancingPolicy with an option to specify read datacenter and write datacenter to route read
and write requests to their corresponding data centers.
If a readDC is specified, we prioritize nodes in the read datacenter for read requests. Either one of writeDC or globalEndpoint must be specified to determine where write requests are routed. If writeDC
is specified, writes will be prioritized for that region. When globalEndpoint is specified, write requests
will be prioritized for the default write region. The globalEndpoint allows the client to gracefully fail
over by updating the default write region addresses. In this case dnsExpirationInSeconds specifies the time
to take to recover from the failover. By default, it is 60 seconds.
| Modifier and Type | Class and Description |
|---|---|
static class |
CosmosLoadBalancingPolicy.Builder
A builder for constructing
CosmosLoadBalancingPolicy objects. |
| Modifier and Type | Method and Description |
|---|---|
static CosmosLoadBalancingPolicy.Builder |
builder()
Gets a newly created
builder object for constructing a CosmosLoadBalancingPolicy. |
void |
close()
Closes the current
CosmosLoadBalancingPolicy object. |
com.datastax.driver.core.HostDistance |
distance(com.datastax.driver.core.Host host)
Return the HostDistance for the provided host.
|
void |
init(com.datastax.driver.core.Cluster cluster,
Collection<com.datastax.driver.core.Host> hosts)
Initializes the list of hosts in read, write, local, and remote categories.
|
Iterator<com.datastax.driver.core.Host> |
newQueryPlan(String loggedKeyspace,
com.datastax.driver.core.Statement statement)
Returns the hosts to use for a new query.
|
void |
onAdd(com.datastax.driver.core.Host host) |
void |
onDown(com.datastax.driver.core.Host host) |
void |
onRemove(com.datastax.driver.core.Host host) |
void |
onUp(com.datastax.driver.core.Host host) |
public static CosmosLoadBalancingPolicy.Builder builder()
builder object for constructing a CosmosLoadBalancingPolicy.CosmosLoadBalancingPolicy builder instance.public void close()
CosmosLoadBalancingPolicy object.close in interface com.datastax.driver.core.policies.LoadBalancingPolicypublic com.datastax.driver.core.HostDistance distance(com.datastax.driver.core.Host host)
This policy considers the nodes for the writeDC and the default write region at distance LOCAL.
distance in interface com.datastax.driver.core.policies.LoadBalancingPolicyhost - the host of which to return the distance of.host.public void init(com.datastax.driver.core.Cluster cluster,
Collection<com.datastax.driver.core.Host> hosts)
init in interface com.datastax.driver.core.policies.LoadBalancingPolicypublic Iterator<com.datastax.driver.core.Host> newQueryPlan(String loggedKeyspace, com.datastax.driver.core.Statement statement)
For read requests, the returned plan will always try each known host in the readDC first. if none of the host is reachable, it will try all other hosts. For writes and all other requests, the returned plan will always try each known host in the writeDC or the default write region (looked up and cached from the globalEndpoint) first. If none of the host is reachable, it will try all other hosts.
newQueryPlan in interface com.datastax.driver.core.policies.LoadBalancingPolicyloggedKeyspace - the keyspace currently logged in on for this query.statement - the query for which to build the plan.public void onAdd(com.datastax.driver.core.Host host)
onAdd in interface com.datastax.driver.core.policies.LoadBalancingPolicypublic void onDown(com.datastax.driver.core.Host host)
onDown in interface com.datastax.driver.core.policies.LoadBalancingPolicypublic void onRemove(com.datastax.driver.core.Host host)
onRemove in interface com.datastax.driver.core.policies.LoadBalancingPolicypublic void onUp(com.datastax.driver.core.Host host)
onUp in interface com.datastax.driver.core.policies.LoadBalancingPolicyCopyright © 2021. All rights reserved.