pub trait LoadBalancingPolicy:
Send
+ Sync
+ Debug {
// Required methods
fn pick<'a>(
&'a self,
query: &'a RoutingInfo<'_>,
cluster: &'a ClusterData,
) -> Option<NodeRef<'a>>;
fn fallback<'a>(
&'a self,
query: &'a RoutingInfo<'_>,
cluster: &'a ClusterData,
) -> FallbackPlan<'a>;
fn name(&self) -> String;
// Provided methods
fn on_query_success(
&self,
_query: &RoutingInfo<'_>,
_latency: Duration,
_node: NodeRef<'_>,
) { ... }
fn on_query_failure(
&self,
_query: &RoutingInfo<'_>,
_latency: Duration,
_node: NodeRef<'_>,
_error: &QueryError,
) { ... }
}Expand description
Policy that decides which nodes to contact for each query.
When a query is prepared to be sent to ScyllaDB/Cassandra, a LoadBalancingPolicy
implementation constructs a load balancing plan. That plan is a list of nodes to which
the driver will try to send the query. The first elements of the plan are the nodes which are
the best to contact (e.g. they might have the lowest latency).
Most queries are send on the first try, so the query execution layer rarely needs to know more
than one node from plan. To better optimize that case, LoadBalancingPolicy has two methods:
pick and fallback. pick returns a first node to contact for a given query, fallback
returns the rest of the load balancing plan.
fallback is called not only if a send to picked node failed (or when executing
speculatively), but also if pick returns None.
Usually the driver needs only the first node from load balancing plan (most queries are send successfully, and there is no need to retry).
This trait is used to produce an iterator of nodes to contact for a given query.
Required Methods§
Sourcefn pick<'a>(
&'a self,
query: &'a RoutingInfo<'_>,
cluster: &'a ClusterData,
) -> Option<NodeRef<'a>>
fn pick<'a>( &'a self, query: &'a RoutingInfo<'_>, cluster: &'a ClusterData, ) -> Option<NodeRef<'a>>
Returns the first node to contact for a given query.
Sourcefn fallback<'a>(
&'a self,
query: &'a RoutingInfo<'_>,
cluster: &'a ClusterData,
) -> FallbackPlan<'a>
fn fallback<'a>( &'a self, query: &'a RoutingInfo<'_>, cluster: &'a ClusterData, ) -> FallbackPlan<'a>
Returns all contact-appropriate nodes for a given query.
Provided Methods§
Sourcefn on_query_success(
&self,
_query: &RoutingInfo<'_>,
_latency: Duration,
_node: NodeRef<'_>,
)
fn on_query_success( &self, _query: &RoutingInfo<'_>, _latency: Duration, _node: NodeRef<'_>, )
Invoked each time a query succeeds.
Sourcefn on_query_failure(
&self,
_query: &RoutingInfo<'_>,
_latency: Duration,
_node: NodeRef<'_>,
_error: &QueryError,
)
fn on_query_failure( &self, _query: &RoutingInfo<'_>, _latency: Duration, _node: NodeRef<'_>, _error: &QueryError, )
Invoked each time a query fails.