pub struct ReplicationSource { /* private fields */ }Expand description
Bounded backlog of recent replicated mutations.
Implementations§
Source§impl ReplicationSource
impl ReplicationSource
Sourcepub fn new(max_bytes: usize) -> Self
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.
Sourcepub fn next_offset(&self) -> u64
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.
Sourcepub fn oldest_offset(&self) -> Option<u64>
pub fn oldest_offset(&self) -> Option<u64>
Lowest offset still in the backlog, or None if empty.
Sourcepub fn newest_offset(&self) -> Option<u64>
pub fn newest_offset(&self) -> Option<u64>
Highest offset still in the backlog, or None if empty.
Sourcepub fn buffered_bytes(&self) -> usize
pub fn buffered_bytes(&self) -> usize
Total bytes occupied by frames currently in the backlog.
Sourcepub fn push_mutation<A: ArgvView + ?Sized>(&mut self, argv: &A) -> u64
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).
Sourcepub fn drop_up_to(&mut self, watermark: u64)
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.
Sourcepub fn frames_from(&self, from: u64) -> Result<FramesIter<'_>, FromOffset>
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)—fromis 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.