Skip to main content

Mutable

Trait Mutable 

Source
pub trait Mutable:
    Contiguous
    + Send
    + Sync {
    // Required methods
    fn append(
        &mut self,
        item: &Self::Item,
    ) -> impl Future<Output = Result<u64, Error>> + Send;
    fn append_many<'a>(
        &'a mut self,
        items: Many<'a, Self::Item>,
    ) -> impl Future<Output = Result<u64, Error>> + Send + 'a
       where Self::Item: Sync;
    fn prune(
        &mut self,
        min_position: u64,
    ) -> impl Future<Output = Result<bool, Error>> + Send;
    fn rewind(
        &mut self,
        size: u64,
    ) -> impl Future<Output = Result<(), Error>> + Send;
    fn commit(&mut self) -> impl Future<Output = Result<(), Error>> + Send;
    fn sync(&mut self) -> impl Future<Output = Result<(), Error>> + Send;
    fn destroy(self) -> impl Future<Output = Result<(), Error>> + Send
       where Self: Sized;

    // Provided method
    fn rewind_to<'a, P>(
        &'a mut self,
        predicate: P,
    ) -> impl Future<Output = Result<u64, Error>> + Send + 'a
       where P: FnMut(&Self::Item) -> bool + Send + '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>> + Send

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 append_many<'a>( &'a mut self, items: Many<'a, Self::Item>, ) -> impl Future<Output = Result<u64, Error>> + Send + 'a
where Self::Item: Sync,

Append items to the journal, returning the position of the last item appended.

Returns Error::EmptyAppend if items is empty.

Source

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

Prune items at positions strictly less than min_position.

Returns true if any data was pruned, false otherwise.

§Behavior
  • If min_position > bounds.end, the prune is capped to bounds.end (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>> + Send

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 > bounds.end, returns Error::InvalidRewind
  • If size == bounds.end, this is a no-op
  • If size < bounds.start, returns Error::ItemPruned (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 beyond the current size, or Error::ItemPruned if it precedes the pruning boundary. Returns an error if the underlying storage operation fails.

Source

fn commit(&mut self) -> impl Future<Output = Result<(), Error>> + Send

Durably persist the journal, guaranteeing the current state will survive a crash.

For a stronger guarantee that eliminates potential recovery, use Self::sync instead.

Source

fn sync(&mut self) -> impl Future<Output = Result<(), Error>> + Send

Durably persist the journal, guaranteeing the current state will survive a crash, and that no recovery will be needed on startup.

This provides a stronger guarantee than Self::commit but may be slower.

Source

fn destroy(self) -> impl Future<Output = Result<(), Error>> + Send
where Self: Sized,

Destroy the journal, removing all associated storage.

This method consumes the journal and deletes all persisted data, leaving behind no storage artifacts. This can be used to clean up disk resources in tests.

§Crash Safety

This operation is intended for final teardown and is not crash-safe. If interrupted, reopening the same storage may observe partially removed state. Use a reset operation provided by the concrete type when the journal must remain recoverable.

Provided Methods§

Source

fn rewind_to<'a, P>( &'a mut self, predicate: P, ) -> impl Future<Output = Result<u64, Error>> + Send + 'a
where P: FnMut(&Self::Item) -> bool + Send + '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".

Implementors§

Source§

impl<E: Context, A: CodecFixedShared> Mutable for commonware_storage::journal::contiguous::fixed::Journal<E, A>

Source§

impl<E: Context, V: CodecShared> Mutable for commonware_storage::journal::contiguous::variable::Journal<E, V>

Source§

impl<F, E, C, H, S> Mutable for commonware_storage::journal::authenticated::Journal<F, E, C, H, S>
where F: Family, E: Context, C: Mutable<Item: EncodeShared>, H: Hasher, S: Strategy,