Skip to main content

HealthChecker

Struct HealthChecker 

Source
pub struct HealthChecker {
    pub failure_threshold: u32,
    pub recovery_cooldown: Duration,
    /* private fields */
}
Expand description

健康检查器:跟踪每个 slave 的健康状态,并支持故障转移

Fields§

§failure_threshold: u32

连续失败次数阈值,达到后标记为 Unhealthy

§recovery_cooldown: Duration

自动故障转移恢复时间(健康检查恢复后多久重新加入集群)

Implementations§

Source§

impl HealthChecker

Source

pub fn new(failure_threshold: u32) -> Self

Source

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

注册一个 slave,初始状态为 Healthy

Source

pub fn set_health(&self, slave: &str, health: SlaveHealth)

标记 slave 为指定健康状态

Source

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

记录一次失败,达到阈值后自动标记为 Unhealthy 返回 true 表示触发了故障转移

Source

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

记录一次成功,重置失败计数

Source

pub fn health(&self, slave: &str) -> Option<SlaveHealth>

查询 slave 健康状态,未注册返回 None

Source

pub fn list_by_health(&self, health: SlaveHealth) -> Vec<String>

列出所有处于指定状态的 slave

Source

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

返回所有健康 slave 列表

Source

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

返回所有不健康 slave 列表

Source

pub fn failure_count(&self, slave: &str) -> u32

返回当前连续失败次数

Trait Implementations§

Source§

impl Default for HealthChecker

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<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 = 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>,

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