Skip to main content

MasterTracker

Struct MasterTracker 

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

Tracks the current known master of the replication group.

All methods are safe to call concurrently from multiple threads. Reads use a shared lock; writes use an exclusive lock.

When a PhiAccrualDetector is attached (via MasterTracker::with_phi), is_master_alive uses the continuous φ suspicion level instead of the binary heartbeat timeout. This adapts automatically to network jitter.

Implementations§

Source§

impl MasterTracker

Source

pub fn new(heartbeat_timeout: Duration) -> Self

Create a new tracker with the given heartbeat timeout.

Uses binary heartbeat timeout for liveness detection. Call with_phi to switch to phi accrual detection.

Source

pub fn with_phi(self, detector: PhiAccrualDetector) -> Self

Attach a phi accrual failure detector.

When attached, is_master_alive returns phi_detector.is_available() instead of the binary timeout check.

Source

pub fn set_master(&self, name: &str, term: u64)

Set the current master and its term unconditionally.

Also records a heartbeat at the current time.

Source

pub fn clear_master(&self)

Clear the current master.

After this call, get_master returns None.

Source

pub fn get_master(&self) -> Option<String>

Returns the name of the current master, if known.

Source

pub fn get_term(&self) -> u64

Returns the term of the current master.

Source

pub fn record_heartbeat(&self)

Record a heartbeat from the master at the current time.

Source

pub fn is_master_alive(&self) -> bool

Returns true if a master is set and it is still considered alive.

When a phi detector is configured, uses the continuous suspicion level (phi.is_available()). Otherwise falls back to binary heartbeat timeout (elapsed < heartbeat_timeout).

Source

pub fn phi(&self) -> Option<f64>

Returns the current phi suspicion value, or None if no phi detector is configured.

Source

pub fn time_since_heartbeat(&self) -> Option<Duration>

Returns the duration since the last heartbeat, or None if no heartbeat has been recorded.

Source

pub fn update_master(&self, name: &str, term: u64) -> bool

Update the master only if term is greater than or equal to the current term.

This ensures that stale election results (from older terms) cannot overwrite a more recent master.

Returns true if the master was updated, false if the update was rejected due to a stale term.

Source

pub fn heartbeat_timeout(&self) -> Duration

Returns the configured heartbeat timeout.

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