MutableContiguous

Trait MutableContiguous 

Source
pub trait MutableContiguous: Contiguous {
    // Required methods
    fn append(
        &mut self,
        item: Self::Item,
    ) -> impl Future<Output = Result<u64, Error>>;
    fn prune(
        &mut self,
        min_position: u64,
    ) -> impl Future<Output = Result<bool, Error>>;
    fn rewind(&mut self, size: u64) -> impl Future<Output = Result<(), Error>>;

    // Provided method
    fn rewind_to<'a, P>(
        &'a mut self,
        predicate: P,
    ) -> impl Future<Output = Result<u64, Error>> + 'a
       where P: FnMut(&Self::Item) -> bool + 'a { ... }
}
Expand description

A Contiguous journal that supports appending, rewinding, and pruning.

Required Methods§

Source

fn append( &mut self, item: Self::Item, ) -> impl Future<Output = Result<u64, Error>>

Append a new item to the journal, returning its position.

Positions are consecutively increasing starting from 0. The position of each item is stable across pruning (i.e., if item X has position 5, it will always have position 5 even if earlier items are pruned).

§Errors

Returns an error if the underlying storage operation fails or if the item cannot be encoded.

Source

fn prune( &mut self, min_position: u64, ) -> impl Future<Output = Result<bool, Error>>

Prune items at positions strictly less than min_position.

Returns true if any data was pruned, false otherwise.

§Behavior
  • If min_position > size(), the prune is capped to size() (no error is returned)
  • Some items with positions less than min_position may be retained due to section/blob alignment
  • This operation is not atomic, but implementations guarantee the journal is left in a recoverable state if a crash occurs during pruning
§Errors

Returns an error if the underlying storage operation fails.

Source

fn rewind(&mut self, size: u64) -> impl Future<Output = Result<(), Error>>

Rewind the journal to the given size, discarding items from the end.

After rewinding to size N, the journal will contain exactly N items (positions 0 to N-1), and the next append will receive position N.

§Behavior
  • If size > current_size(), returns Error::InvalidRewind
  • If size == current_size(), this is a no-op
  • If size < oldest_retained_pos(), returns Error::InvalidRewind (can’t rewind to pruned data)
  • This operation is not atomic, but implementations guarantee the journal is left in a recoverable state if a crash occurs during rewinding
§Warnings
  • This operation is not guaranteed to survive restarts until commit or sync is called.
§Errors

Returns Error::InvalidRewind if size is invalid (too large or points to pruned data). Returns an error if the underlying storage operation fails.

Provided Methods§

Source

fn rewind_to<'a, P>( &'a mut self, predicate: P, ) -> impl Future<Output = Result<u64, Error>> + 'a
where P: FnMut(&Self::Item) -> bool + 'a,

Rewinds the journal to the last item matching predicate. If no item matches, the journal is rewound to the pruning boundary, discarding all unpruned items.

§Warnings
  • This operation is not guaranteed to survive restarts until commit or sync is called.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<E, C, H> MutableContiguous for commonware_storage::journal::authenticated::Journal<E, C, H, Clean<H::Digest>>
where E: Storage + Clock + Metrics, C: MutableContiguous<Item: Encode>, H: Hasher,

Source§

impl<E, C, H> MutableContiguous for commonware_storage::journal::authenticated::Journal<E, C, H, Dirty>
where E: Storage + Clock + Metrics, C: MutableContiguous<Item: Encode>, H: Hasher,

Source§

impl<E: Storage + Metrics, A: CodecFixed<Cfg = ()>> MutableContiguous for commonware_storage::journal::contiguous::fixed::Journal<E, A>

Source§

impl<E: Storage + Metrics, V: Codec> MutableContiguous for commonware_storage::journal::contiguous::variable::Journal<E, V>