Skip to main content

ReplicaNode

Struct ReplicaNode 

pub struct ReplicaNode { /* private fields */ }
Expand description

One replica of a shard group.

Implementations§

§

impl ReplicaNode

pub async fn start(cfg: ReplicaConfig) -> Result<Self>

Starts the replica: recovers its protocol log, re-applies committed batches to its engine directory, and joins the group.

pub fn observer(&self) -> ReplicaObserver

pub fn status(&self) -> NodeStatus

pub async fn wait_ready(&mut self)

Resolves once this replica is primary with everything committed and applied, so an engine opened now sees the whole committed log.

pub async fn wait_lost(&mut self)

Resolves once this replica is no longer a ready primary.

pub fn standby_config(&self) -> Config

The engine configuration for this replica while it is primary. Call it after wait_ready: its storage refuses writes once this replica stops being the ready primary.

The engine has the group’s shard count: the one its log was written with, or for a new group one per core up to eight. Keep it: records of a shard the engine does not open would never be replayed. A hot-standby engine configuration: an engine opened with it on a backup (or at any time) opens at once with every shard standing by (threads, runtimes, open run stores, registered workflows), and its shards start the moment this replica becomes the ready primary: each recovers from the committed log batches the I/O thread holds in memory and the files it already has open, with no engine to open. Calls wait meanwhile. Like an engine from engine_config it stops when this replica loses the primary role: shut it down and open another standby engine. Log groups only (a segment group’s shard refuses to stand by).

loop {
    let engine = Engine::open(node.standby_config()).await?; // at once
    register_workflows(&engine);
    node.wait_ready().await;   // promoted: the shards are running
    node.wait_lost().await;
    let _ = engine.shutdown().await;
}

pub fn engine_config(&self) -> Config

pub fn lease_valid(&self) -> bool

Whether this replica is the ready primary and holds a read lease now: a quorum answered its ping recently enough that no other member can lead a newer view yet, so reads of its engine (queries, results, inspect, list) see every write the group acknowledged. The lease is renewed with every heartbeat and lapses about Timing::lease_ms after the last quorum of answers.

pub async fn confirm_reads(&self) -> Result<()>

For a read that must not be stale: returns at once under a lease, else once a no-op commits through a quorum (one round trip). Fails if this replica is not the ready primary or no quorum answers; the read must then not be served from this replica.

pub fn membership(&self) -> (u64, Vec<(ReplicaId, String)>)

The membership epoch this replica is in, and its members with their addresses, in order (the first leads the epoch’s first view).

pub async fn change_members( &self, members: Vec<(ReplicaId, String)>, timeout: Duration, ) -> Result<u64>

Changes the group’s membership to members (each ID with its address), from any member: the primary proposes it as the last entry of the current epoch; once it commits, the new members that hold the log change to the next epoch with a view change, members left out retire, and new members (started with ReplicaConfig::join) fetch the log. A quorum of the new members must be members now, so one change adds or removes members, or replaces a minority: replace a dead member by adding its successor in its place. Returns the new epoch once this replica has entered it (a removed replica enters it to retire). Like a failover, the change stops the primary’s engine: it reopens on the first member of the new list (the current primary when it stays).

pub fn reads(&self) -> ReadGuard

A handle that answers Self::lease_valid and Self::confirm_reads from other tasks.

pub fn kill(self)

Stops the replica at once, as a crash would (in-flight work is lost unless a quorum already holds it).

Trait Implementations§

§

impl Drop for ReplicaNode

§

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> Same for T

Source§

type Output = T

Should always be Self
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.