Skip to main content

ReplicationSource

Struct ReplicationSource 

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

Bounded backlog of recent replicated mutations.

Implementations§

Source§

impl ReplicationSource

Source

pub fn new(max_bytes: usize) -> Self

Create a new source with the given byte budget. max_bytes must be > 0; the source guarantees at most one over-budget frame at a time (the most recently pushed) so a single huge command does not silently disappear before its replicas even see it.

Source

pub fn next_offset(&self) -> u64

Next offset this source would assign. Equal to one past the last assigned offset; equals 0 for a fresh source.

Source

pub fn oldest_offset(&self) -> Option<u64>

Lowest offset still in the backlog, or None if empty.

Source

pub fn newest_offset(&self) -> Option<u64>

Highest offset still in the backlog, or None if empty.

Source

pub fn buffered_bytes(&self) -> usize

Total bytes occupied by frames currently in the backlog.

Source

pub fn len(&self) -> usize

Number of frames currently in the backlog.

Source

pub fn is_empty(&self) -> bool

Whether the backlog has no frames.

Source

pub fn push_mutation<A: ArgvView + ?Sized>(&mut self, argv: &A) -> u64

Append one applied mutation. Returns the offset assigned to it. Generic over ArgvView so the dispatcher’s borrowed argv can flow straight in — no Argv materialisation on the write path.

May evict older frames if the new frame would exceed the byte budget; the new frame is always retained (even if it is larger than max_bytes on its own — losing the most recent applied write before any replica has had a chance to ack it would be a worse failure than briefly running over budget).

Source

pub fn drop_up_to(&mut self, watermark: u64)

Drop every buffered frame whose offset is < watermark — i.e. every replica has consumed past it. Used by the per- shard tick (T1.22.5) to enforce a retention floor tighter than the raw byte budget; lets the backlog reclaim space for live frames once all consumers have advanced.

No-op when watermark <= oldest_offset() (nothing to drop) or when the buffer is empty. Updates the internal byte accounting to stay consistent with the live buffer length.

Source

pub fn frames_from(&self, from: u64) -> Result<FramesIter<'_>, FromOffset>

Borrow the slice of frames with offset ≥ from. Suitable for the streaming loop to write each frame’s bytes to a replica socket. Returns:

  • Ok(iter) — zero or more frames in offset order (empty iter means the replica is caught up).
  • Err(FromOffset::TooOld)from is older than the oldest buffered frame; the streaming loop must snapshot-ship.
  • Err(FromOffset::Future)from > next_offset(); peer is ahead of us, drop the link.

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.