pub struct DefaultPolicyBuilder { /* private fields */ }
Expand description

The intended way to instantiate the DefaultPolicy.

§Example

use scylla::load_balancing::DefaultPolicy;

let default_policy = DefaultPolicy::builder()
    .prefer_datacenter("dc1".to_string())
    .token_aware(true)
    .permit_dc_failover(true)
    .build();

Implementations§

source§

impl DefaultPolicyBuilder

source

pub fn new() -> Self

Creates a builder used to customise configuration of a new DefaultPolicy.

source

pub fn build(self) -> Arc<dyn LoadBalancingPolicy>

Builds a new DefaultPolicy with the previously set configuration.

source

pub fn prefer_datacenter(self, datacenter_name: String) -> Self

Sets the datacenter to be preferred by this policy.

Allows the load balancing policy to prioritize nodes based on their location. When a preferred datacenter is set, the policy will treat nodes in that datacenter as “local” nodes, and nodes in other datacenters as “remote” nodes. This affects the order in which nodes are returned by the policy when selecting replicas for read or write operations. If no preferred datacenter is specified, the policy will treat all nodes as local nodes.

When datacenter failover is disabled (permit_dc_failover is set to false), the default policy will only include local nodes in load balancing plans. Remote nodes will be excluded, even if they are alive and available to serve requests.

source

pub fn prefer_datacenter_and_rack( self, datacenter_name: String, rack_name: String, ) -> Self

Sets the datacenter and rack to be preferred by this policy.

Allows the load balancing policy to prioritize nodes based on their location as well as their availability zones in the preferred datacenter. When a preferred datacenter is set, the policy will treat nodes in that datacenter as “local” nodes, and nodes in other datacenters as “remote” nodes. This affects the order in which nodes are returned by the policy when selecting replicas for read or write operations. If no preferred datacenter is specified, the policy will treat all nodes as local nodes.

When datacenter failover is disabled (permit_dc_failover is set to false), the default policy will only include local nodes in load balancing plans. Remote nodes will be excluded, even if they are alive and available to serve requests.

When a preferred rack is set, the policy will first return replicas in the local rack in the preferred datacenter, and then the other replicas in the datacenter.

source

pub fn token_aware(self, is_token_aware: bool) -> Self

Sets whether this policy is token-aware (balances load more consciously) or not.

Token awareness refers to a mechanism by which the driver is aware of the token range assigned to each node in the cluster. Tokens are assigned to nodes to partition the data and distribute it across the cluster.

When a user wants to read or write data, the driver can use token awareness to route the request to the correct node based on the token range of the data being accessed. This can help to minimize network traffic and improve performance by ensuring that the data is accessed locally as much as possible.

In the case of DefaultPolicy, token awareness is enabled by default, meaning that the policy will prefer to return alive local replicas if the token is available. This means that if the client is requesting data that falls within the token range of a particular node, the policy will try to route the request to that node first, assuming it is alive and responsive.

Token awareness can significantly improve the performance and scalability of applications built on Scylla. By using token awareness, users can ensure that data is accessed locally as much as possible, reducing network overhead and improving throughput.

source

pub fn permit_dc_failover(self, permit: bool) -> Self

Sets whether this policy permits datacenter failover, i.e. ever attempts to send requests to nodes from a non-preferred datacenter.

In the event of a datacenter outage or network failure, the nodes in that datacenter may become unavailable, and clients may no longer be able to access data stored on those nodes. To address this, the DefaultPolicy supports datacenter failover, which allows routing requests to nodes in other datacenters if the local nodes are unavailable.

Datacenter failover can be enabled in DefaultPolicy setting this flag. When it is set, the policy will prefer to return alive remote replicas if datacenter failover is permitted and possible due to consistency constraints.

source

pub fn latency_awareness( self, latency_awareness_builder: LatencyAwarenessBuilder, ) -> Self

Latency awareness is a mechanism that penalises nodes whose measured recent average latency classifies it as falling behind the others.

Every update_rate the global minimum average latency is computed, and all nodes whose average latency is worse than exclusion_threshold times the global minimum average latency become penalised for retry_period. Penalisation involves putting those nodes at the very end of the query plan. As it is often not truly beneficial to prefer faster non-replica than replicas lagging behind the non-replicas, this mechanism may as well worsen latencies and/or throughput.

ATTENTION: using latency awareness is NOT recommended, unless prior benchmarks prove its beneficial impact on the specific workload’s performance. Use with caution.

source

pub fn enable_shuffling_replicas(self, enable: bool) -> Self

Sets whether this policy should shuffle replicas when token-awareness is enabled. Shuffling can help distribute the load over replicas, but can reduce the effectiveness of caching on the database side (e.g. for reads).

This option is enabled by default. If disabled, replicas will be chosen in some random order that is chosen when the load balancing policy is created and will not change over its lifetime.

Trait Implementations§

source§

impl Clone for DefaultPolicyBuilder

source§

fn clone(&self) -> DefaultPolicyBuilder

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for DefaultPolicyBuilder

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for DefaultPolicyBuilder

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> ErasedDestructor for T
where T: 'static,