Skip to main content

ReplicationLagMonitor

Struct ReplicationLagMonitor 

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

复制延迟监控器

维护每个 slave 的最新延迟快照,提供基于延迟的路由决策。

Implementations§

Source§

impl ReplicationLagMonitor

Source

pub fn new(threshold_secs: u64) -> Self

创建监控器

Source

pub fn with_max_history(self, max: usize) -> Self

设置最大历史保留条数

Source

pub fn report(&self, slave: &str, lag_seconds: u64)

上报一次延迟采样

Source

pub fn latest_lag(&self, slave: &str) -> Option<u64>

获取 slave 的最新延迟

Source

pub fn is_lagging(&self, slave: &str) -> bool

判断 slave 是否延迟过大

Source

pub fn is_safe_to_read(&self, slave: &str) -> bool

判断 slave 是否可以安全读取

Source

pub fn lagging_slaves(&self) -> Vec<String>

返回所有延迟过大的 slave

Source

pub fn safe_slaves(&self) -> Vec<String>

返回所有安全可读的 slave

Source

pub fn history(&self, slave: &str) -> Vec<ReplicationLagSnapshot>

获取 slave 的延迟历史

Source

pub fn avg_lag(&self, slave: &str) -> Option<u64>

计算 slave 的平均延迟(基于历史)

Source

pub fn max_lag(&self, slave: &str) -> Option<u64>

计算 slave 的最大延迟(基于历史)

Source

pub fn threshold(&self) -> u64

获取延迟阈值

Source

pub fn reset(&self, slave: &str)

重置 slave 的历史

Source

pub fn reset_all(&self)

重置所有 slave 的历史

Source

pub fn select_least_lag<'a>(&self, candidates: &'a [String]) -> Option<&'a str>

从候选列表中选择延迟最小的 slave

返回 None 表示候选列表为空或无延迟数据。

Source

pub fn min_lag(&self, slave: &str) -> Option<u64>

计算 slave 的最小延迟(基于历史)

Source

pub fn all_slaves(&self) -> Vec<String>

返回所有已知 slave 列表

Source

pub fn slave_count(&self) -> usize

已知 slave 数量

Source

pub fn lag_trend(&self, slave: &str) -> i64

延迟趋势:比较最近两次采样

返回正数表示延迟上升,负数表示下降,0 表示稳定或数据不足。

Source

pub fn summary(&self) -> String

生成汇总报告字符串

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