Trait scylla::transport::load_balancing::LoadBalancingPolicy
source · pub trait LoadBalancingPolicy: Send + Sync + Debug {
// Required methods
fn pick<'a>(
&'a self,
query: &'a RoutingInfo<'_>,
cluster: &'a ClusterData,
) -> Option<(NodeRef<'a>, Option<Shard>)>;
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 and shards 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
targets (target is a node + an optional shard) to which
the driver will try to send the query. The first elements of the plan are the targets which are
the best to contact (e.g. they might have the lowest latency).
Most queries are sent on the first try, so the query execution layer rarely needs to know more
than one target from plan. To better optimize that case, LoadBalancingPolicy
has two methods:
pick
and fallback
. pick
returns the first target to contact for a given query, fallback
returns the rest of the load balancing plan.
fallback
is called not only if a send to pick
ed 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>, Option<Shard>)>
fn pick<'a>( &'a self, query: &'a RoutingInfo<'_>, cluster: &'a ClusterData, ) -> Option<(NodeRef<'a>, Option<Shard>)>
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.