pub struct DeltaBuffer { /* private fields */ }Expand description
Buffer for storing deltas during snapshot sync.
Implements Invariant I6: Deltas received during state-based sync MUST be preserved and applied after sync completes.
When the buffer is full, the oldest delta is evicted (FIFO eviction policy)
and the drops counter is incremented. Drops MUST be observable via metrics.
§Deduplication
The buffer tracks seen delta IDs to prevent duplicate deltas from being buffered. This protects against replay attacks where an adversary might flood the buffer with duplicate deltas to cause eviction of legitimate deltas.
Implementations§
Source§impl DeltaBuffer
impl DeltaBuffer
Sourcepub fn new(capacity: usize, sync_start_hlc: u64) -> Self
pub fn new(capacity: usize, sync_start_hlc: u64) -> Self
Create a new delta buffer with specified capacity.
§Capacity Warning
If capacity is below MIN_RECOMMENDED_CAPACITY, callers should log a
warning at startup. Zero capacity is valid but will drop ALL deltas.
Sourcepub fn is_capacity_below_recommended(&self) -> bool
pub fn is_capacity_below_recommended(&self) -> bool
Check if capacity is below recommended minimum.
Callers should log a warning at session start if this returns true.
Sourcepub fn push(&mut self, delta: BufferedDelta) -> PushResult
pub fn push(&mut self, delta: BufferedDelta) -> PushResult
Add a delta to the buffer.
Returns a PushResult indicating what happened:
Added: Delta was added successfullyDuplicate: Delta ID was already in buffer (no action taken)Evicted(id): Delta was added but oldest delta was evictedDroppedZeroCapacity(id): Delta was dropped (zero capacity buffer)
§Deduplication
If a delta with the same ID is already in the buffer, it is not added
again and PushResult::Duplicate is returned. This prevents replay attacks.
§Edge case: zero capacity
If capacity is 0, the incoming delta is immediately dropped (not added)
and PushResult::DroppedZeroCapacity is returned with the dropped delta’s ID.
Sourcepub fn drain(&mut self) -> Vec<BufferedDelta>
pub fn drain(&mut self) -> Vec<BufferedDelta>
Get all buffered deltas for replay, clearing the buffer.
Returns deltas in FIFO order (oldest first), preserving causality. Also clears the deduplication set.
Sourcepub fn contains(&self, id: &[u8; 32]) -> bool
pub fn contains(&self, id: &[u8; 32]) -> bool
Check if a delta ID is already in the buffer.
This is O(1) due to the internal HashSet tracking.
Sourcepub fn sync_start_hlc(&self) -> u64
pub fn sync_start_hlc(&self) -> u64
Get the sync start HLC.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for DeltaBuffer
impl RefUnwindSafe for DeltaBuffer
impl Send for DeltaBuffer
impl Sync for DeltaBuffer
impl Unpin for DeltaBuffer
impl UnsafeUnpin for DeltaBuffer
impl UnwindSafe for DeltaBuffer
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> 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