pub struct StorageWriteAheadBuffer {
pub entries: Vec<BufferedEntry>,
pub config: BufferConfig,
pub next_seq: u64,
pub total_buffered_bytes: u64,
}Expand description
In-memory write-ahead buffer with sequence-numbered entries.
Incoming WriteOps are appended with monotonically increasing sequence
numbers. The buffer tracks total payload bytes and the age of the oldest
unflushed entry so that callers can decide when to flush.
After a flush the entries remain in entries (marked flushed = true)
until trim_flushed is called, enabling crash-recovery
replay via replay_from.
Fields§
§entries: Vec<BufferedEntry>All entries in arrival order.
config: BufferConfigConfiguration controlling flush thresholds.
next_seq: u64Next sequence number to assign.
total_buffered_bytes: u64Running total of size_bytes for unflushed Put ops.
Implementations§
Source§impl StorageWriteAheadBuffer
impl StorageWriteAheadBuffer
Sourcepub fn new(config: BufferConfig) -> Self
pub fn new(config: BufferConfig) -> Self
Create a new, empty buffer with the supplied configuration.
Sourcepub fn write(&mut self, op: WriteOp, now_secs: u64) -> u64
pub fn write(&mut self, op: WriteOp, now_secs: u64) -> u64
Stage op in the buffer and return the assigned sequence number.
Putops incrementtotal_buffered_bytesby theirsize_bytes.DeleteandUpdateops do not affect the byte counter.
Sourcepub fn should_flush(&self, now_secs: u64) -> bool
pub fn should_flush(&self, now_secs: u64) -> bool
Returns true if any flush threshold has been reached.
Triggers when:
- the number of unflushed entries ≥
max_buffered_entries, or total_buffered_bytes≥max_buffered_bytes, or- the oldest unflushed entry’s age ≥
flush_interval_secs.
Sourcepub fn flush(&mut self, _now_secs: u64) -> FlushResult
pub fn flush(&mut self, _now_secs: u64) -> FlushResult
Mark every unflushed entry as flushed and return a FlushResult.
After this call total_buffered_bytes is
reset to 0. Flushed entries are retained in entries
until trim_flushed is called.
Sourcepub fn pending_entries(&self) -> Vec<&BufferedEntry>
pub fn pending_entries(&self) -> Vec<&BufferedEntry>
Returns references to all entries that have not yet been flushed, in arrival order.
Sourcepub fn replay_from(&self, seq: u64) -> Vec<&BufferedEntry>
pub fn replay_from(&self, seq: u64) -> Vec<&BufferedEntry>
Returns references to all entries whose sequence number is ≥ seq,
regardless of flushed state. Useful for crash-recovery replay.
Sourcepub fn trim_flushed(&mut self)
pub fn trim_flushed(&mut self)
Remove all entries that have been flushed, freeing memory.
After this call, replay_from will only see
entries that have not yet been flushed.
Auto Trait Implementations§
impl Freeze for StorageWriteAheadBuffer
impl RefUnwindSafe for StorageWriteAheadBuffer
impl Send for StorageWriteAheadBuffer
impl Sync for StorageWriteAheadBuffer
impl Unpin for StorageWriteAheadBuffer
impl UnsafeUnpin for StorageWriteAheadBuffer
impl UnwindSafe for StorageWriteAheadBuffer
Blanket Implementations§
impl<T> Allocation for T
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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