Skip to main content

ReplicaStream

Struct ReplicaStream 

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

Tracks the state of receiving replication data from the master.

The replica stream receives log entries from the master, buffers them in a pending queue, and tracks which VLSNs have been received vs. applied to the local database.

Implementations§

Source§

impl ReplicaStream

Source

pub fn new() -> Self

Create a new replica stream in the idle state.

Source

pub fn get_state(&self) -> ReplicaStreamState

Return the current stream state.

Source

pub fn set_state(&self, state: ReplicaStreamState)

Set the stream state.

Source

pub fn get_applied_vlsn(&self) -> u64

Return the last VLSN that has been applied to the local database.

Source

pub fn get_received_vlsn(&self) -> u64

Return the last VLSN received from the master (may be ahead of applied_vlsn if entries are buffered).

Source

pub fn get_master_vlsn(&self) -> u64

Return the master’s latest known VLSN (from heartbeat updates).

Source

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

Set the master node name.

Source

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

Return the master node name, if set.

Source

pub fn receive_entry(&self, vlsn: u64, entry_type: u8, data: Vec<u8>)

Receive a log entry from the master.

The entry is added to the pending queue and received_vlsn is updated if the new VLSN is greater than the current value.

Source

pub fn mark_applied(&self, vlsn: u64)

Mark a VLSN as applied to the local database.

The applied_vlsn is updated if the new VLSN is greater than the current value (applied VLSNs should advance monotonically).

Source

pub fn update_master_vlsn(&self, vlsn: u64)

Update the master’s known latest VLSN (typically from a heartbeat message).

Source

pub fn get_lag(&self) -> u64

Return the replication lag: the difference between the master’s latest VLSN and the last applied VLSN.

A lag of 0 means the replica is fully caught up with the master.

Source

pub fn drain_pending(&self) -> Vec<(u64, u8, Vec<u8>)>

Drain all pending entries for processing.

Returns the entries in the order they were received and leaves the pending queue empty.

Source

pub fn is_caught_up(&self) -> bool

Check if the replica is caught up with the master.

Returns true if all of the following are true:

  • the master VLSN is non-zero (i.e. at least one master VLSN has been observed; a stream that has never received a master VLSN reports false),
  • the applied VLSN equals or exceeds the master’s latest known VLSN, and
  • there are no pending entries.

Trait Implementations§

Source§

impl Debug for ReplicaStream

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ReplicaStream

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