Skip to main content

ReadWriteRouter

Struct ReadWriteRouter 

Source
pub struct ReadWriteRouter { /* private fields */ }
Expand description

Read-write splitting router

Master handles write requests, slave cluster handles read requests. Distributes read requests across multiple slaves according to LoadBalanceStrategy.

Implementations§

Source§

impl ReadWriteRouter

Source

pub fn new(master: &str, slaves: Vec<&str>) -> Self

Source

pub fn master(&self) -> &str

Return the master node

Source

pub fn slaves(&self) -> &[String]

Return the slave list

Source

pub fn slave(&self) -> &str

Select a slave according to the current strategy

If slaves is empty, falls back to master. If health check is enabled, skips Unhealthy/Drained slaves.

Source

pub fn set_strategy(&mut self, strategy: LoadBalanceStrategy)

Set the load balancing strategy

Source

pub fn strategy(&self) -> LoadBalanceStrategy

Get the current strategy

Source

pub fn set_weight(&self, slave: &str, weight: u32) -> Result<(), String>

Set slave weight

Source

pub fn weight(&self, slave: &str) -> Option<u32>

Get slave weight

Source

pub fn health_checker(&self) -> &HealthChecker

Health checker reference

Source

pub fn latency_stats(&self) -> &LatencyStats

Latency statistics reference

Source

pub fn record_latency(&self, slave: &str, latency: Duration)

Record the latency of a slave request

Source

pub fn measure<F, T>(&self, slave: &str, f: F) -> T
where F: FnOnce() -> T,

Measure and record the duration of a slave call

Source

pub fn set_read_rationing(&self, percent: u8)

Configure the read-write ratio

Source

pub fn read_rationing_percent(&self) -> u8

Get the current read-write ratio

Source

pub fn acquire(&self, slave: &str) -> Result<(), String>

Acquire a connection on a given slave (increment connection count, used for LeastConnections)

Source

pub fn release(&self, slave: &str) -> Result<(), String>

Release a connection on a given slave (decrement connection count)

Source

pub fn connection_count(&self, slave: &str) -> Option<usize>

Query the current connection count of a slave (for testing and monitoring)

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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