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
impl ReplicaStream
Sourcepub fn get_state(&self) -> ReplicaStreamState
pub fn get_state(&self) -> ReplicaStreamState
Return the current stream state.
Sourcepub fn set_state(&self, state: ReplicaStreamState)
pub fn set_state(&self, state: ReplicaStreamState)
Set the stream state.
Sourcepub fn get_applied_vlsn(&self) -> u64
pub fn get_applied_vlsn(&self) -> u64
Return the last VLSN that has been applied to the local database.
Sourcepub fn get_received_vlsn(&self) -> u64
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).
Sourcepub fn get_master_vlsn(&self) -> u64
pub fn get_master_vlsn(&self) -> u64
Return the master’s latest known VLSN (from heartbeat updates).
Sourcepub fn set_master(&self, name: &str)
pub fn set_master(&self, name: &str)
Set the master node name.
Sourcepub fn get_master(&self) -> Option<String>
pub fn get_master(&self) -> Option<String>
Return the master node name, if set.
Sourcepub fn receive_entry(&self, vlsn: u64, entry_type: u8, data: Vec<u8>)
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.
Sourcepub fn mark_applied(&self, vlsn: u64)
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).
Sourcepub fn update_master_vlsn(&self, vlsn: u64)
pub fn update_master_vlsn(&self, vlsn: u64)
Update the master’s known latest VLSN (typically from a heartbeat message).
Sourcepub fn get_lag(&self) -> u64
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.
Sourcepub fn drain_pending(&self) -> Vec<(u64, u8, Vec<u8>)>
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.
Sourcepub fn is_caught_up(&self) -> bool
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
impl Debug for ReplicaStream
Auto Trait Implementations§
impl !Freeze for ReplicaStream
impl !RefUnwindSafe for ReplicaStream
impl Send for ReplicaStream
impl Sync for ReplicaStream
impl Unpin for ReplicaStream
impl UnsafeUnpin for ReplicaStream
impl UnwindSafe for ReplicaStream
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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