LeaderElectionManager

Struct LeaderElectionManager 

Source
pub struct LeaderElectionManager {
    pub state: Rc<RefCell<LeaderElectionState>>,
    pub heartbeat_interval: Option<i32>,
    /* private fields */
}
Expand description

Manager for multi-tab leader election

Fields§

§state: Rc<RefCell<LeaderElectionState>>§heartbeat_interval: Option<i32>

Implementations§

Source§

impl LeaderElectionManager

Source

pub fn new(db_name: String) -> Self

Create new leader election manager with deterministic instance ID

Source

pub async fn start_election(&mut self) -> Result<(), DatabaseError>

Start leader election process using localStorage coordination

Source

pub async fn try_become_leader_internal( &mut self, force: bool, ) -> Result<(), DatabaseError>

Try to become leader using localStorage-based atomic coordination

§Arguments
  • force - If true, ignores existing leader’s valid lease and forces takeover
Source

pub async fn try_become_leader(&mut self) -> Result<(), DatabaseError>

Try to become leader (respects existing leader’s lease)

Source

pub async fn force_become_leader(&mut self) -> Result<(), DatabaseError>

Force leadership takeover (ignores existing leader’s lease)

Source

pub fn start_heartbeat(&mut self) -> Result<(), DatabaseError>

Start sending heartbeats as leader using localStorage

Source

pub async fn stop_election(&mut self) -> Result<(), DatabaseError>

Stop leader election (e.g., when tab is closing)

Source

pub async fn is_leader(&self) -> bool

Check if this instance is the leader (with localStorage validation and re-election)

Source

pub async fn send_heartbeat(&self) -> Result<(), DatabaseError>

Send a heartbeat (for testing)

Source

pub async fn get_last_heartbeat(&self) -> u64

Get timestamp of last received leader heartbeat from localStorage

Trait Implementations§

Source§

impl Drop for LeaderElectionManager

Drop implementation to prevent “closure invoked after being dropped” errors

CRITICAL: Invalidate heartbeat_valid BEFORE clearing interval. The heartbeat closure is intentionally leaked via forget() so it’s never dropped. Any pending setInterval ticks will safely invoke the leaked closure which immediately returns due to the validity check.

Source§

fn drop(&mut self)

Executes the destructor for this 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> 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, 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.