Trait ShardStore

Source
pub trait ShardStore {
    type H;
    type CheckpointId;
    type Error: Error;

Show 18 methods // Required methods fn get_shard( &self, shard_root: Address, ) -> Result<Option<LocatedPrunableTree<Self::H>>, Self::Error>; fn last_shard( &self, ) -> Result<Option<LocatedPrunableTree<Self::H>>, Self::Error>; fn put_shard( &mut self, subtree: LocatedPrunableTree<Self::H>, ) -> Result<(), Self::Error>; fn get_shard_roots(&self) -> Result<Vec<Address>, Self::Error>; fn truncate_shards(&mut self, shard_index: u64) -> Result<(), Self::Error>; fn get_cap(&self) -> Result<PrunableTree<Self::H>, Self::Error>; fn put_cap(&mut self, cap: PrunableTree<Self::H>) -> Result<(), Self::Error>; fn min_checkpoint_id( &self, ) -> Result<Option<Self::CheckpointId>, Self::Error>; fn max_checkpoint_id( &self, ) -> Result<Option<Self::CheckpointId>, Self::Error>; fn add_checkpoint( &mut self, checkpoint_id: Self::CheckpointId, checkpoint: Checkpoint, ) -> Result<(), Self::Error>; fn checkpoint_count(&self) -> Result<usize, Self::Error>; fn get_checkpoint_at_depth( &self, checkpoint_depth: usize, ) -> Result<Option<(Self::CheckpointId, Checkpoint)>, Self::Error>; fn get_checkpoint( &self, checkpoint_id: &Self::CheckpointId, ) -> Result<Option<Checkpoint>, Self::Error>; fn with_checkpoints<F>( &mut self, limit: usize, callback: F, ) -> Result<(), Self::Error> where F: FnMut(&Self::CheckpointId, &Checkpoint) -> Result<(), Self::Error>; fn for_each_checkpoint<F>( &self, limit: usize, callback: F, ) -> Result<(), Self::Error> where F: FnMut(&Self::CheckpointId, &Checkpoint) -> Result<(), Self::Error>; fn update_checkpoint_with<F>( &mut self, checkpoint_id: &Self::CheckpointId, update: F, ) -> Result<bool, Self::Error> where F: Fn(&mut Checkpoint) -> Result<(), Self::Error>; fn remove_checkpoint( &mut self, checkpoint_id: &Self::CheckpointId, ) -> Result<(), Self::Error>; fn truncate_checkpoints_retaining( &mut self, checkpoint_id: &Self::CheckpointId, ) -> Result<(), Self::Error>;
}
Expand description

A capability for storage of fragment subtrees of the ShardTree type.

All fragment subtrees must have roots at level SHARD_HEIGHT.

Required Associated Types§

Source

type H

The type used for leaves and nodes in the tree.

Source

type CheckpointId

The type used to identify checkpointed positions in the tree.

Source

type Error: Error

The error type for operations on this store.

Required Methods§

Source

fn get_shard( &self, shard_root: Address, ) -> Result<Option<LocatedPrunableTree<Self::H>>, Self::Error>

Returns the subtree at the given root address, if any such subtree exists.

Source

fn last_shard( &self, ) -> Result<Option<LocatedPrunableTree<Self::H>>, Self::Error>

Returns the subtree containing the maximum inserted leaf position.

Source

fn put_shard( &mut self, subtree: LocatedPrunableTree<Self::H>, ) -> Result<(), Self::Error>

Inserts or replaces the subtree having the same root address as the provided tree.

Implementations of this method MUST enforce the constraint that the root address of the provided subtree has level SHARD_HEIGHT.

Source

fn get_shard_roots(&self) -> Result<Vec<Address>, Self::Error>

Returns the vector of addresses corresponding to the roots of subtrees stored in this store.

Source

fn truncate_shards(&mut self, shard_index: u64) -> Result<(), Self::Error>

Removes subtrees from the underlying store having root addresses at indices greater than or equal to that of the specified index.

Source

fn get_cap(&self) -> Result<PrunableTree<Self::H>, Self::Error>

A tree that is used to cache the known roots of subtrees in the “cap” - the top part of the tree, which contains parent nodes produced by hashing the roots of the individual shards. Nodes in the cap have levels in the range SHARD_HEIGHT..DEPTH. Note that the cap may be sparse, in the same way that individual shards may be sparse.

Source

fn put_cap(&mut self, cap: PrunableTree<Self::H>) -> Result<(), Self::Error>

Persists the provided cap to the data store.

Source

fn min_checkpoint_id(&self) -> Result<Option<Self::CheckpointId>, Self::Error>

Returns the identifier for the checkpoint with the lowest associated position value.

Source

fn max_checkpoint_id(&self) -> Result<Option<Self::CheckpointId>, Self::Error>

Returns the identifier for the checkpoint with the highest associated position value.

Source

fn add_checkpoint( &mut self, checkpoint_id: Self::CheckpointId, checkpoint: Checkpoint, ) -> Result<(), Self::Error>

Adds a checkpoint to the data store.

Source

fn checkpoint_count(&self) -> Result<usize, Self::Error>

Returns the number of checkpoints maintained by the data store

Source

fn get_checkpoint_at_depth( &self, checkpoint_depth: usize, ) -> Result<Option<(Self::CheckpointId, Checkpoint)>, Self::Error>

Returns the id and position of the checkpoint at the specified depth, if it exists.

Returns None if if insufficient checkpoints exist to seek back to the requested depth. Depth 0 refers to the most recent checkpoint in the tree; depth 1 refers to the previous checkpoint, and so forth.

Source

fn get_checkpoint( &self, checkpoint_id: &Self::CheckpointId, ) -> Result<Option<Checkpoint>, Self::Error>

Returns the checkpoint corresponding to the specified checkpoint identifier.

Source

fn with_checkpoints<F>( &mut self, limit: usize, callback: F, ) -> Result<(), Self::Error>
where F: FnMut(&Self::CheckpointId, &Checkpoint) -> Result<(), Self::Error>,

Iterates in checkpoint ID order over the first limit checkpoints, applying the given callback to each.

Source

fn for_each_checkpoint<F>( &self, limit: usize, callback: F, ) -> Result<(), Self::Error>
where F: FnMut(&Self::CheckpointId, &Checkpoint) -> Result<(), Self::Error>,

Calls the given callback for each checkpoint in CheckpointId order. This is essentially the immutable version of with_checkpoints.

Source

fn update_checkpoint_with<F>( &mut self, checkpoint_id: &Self::CheckpointId, update: F, ) -> Result<bool, Self::Error>
where F: Fn(&mut Checkpoint) -> Result<(), Self::Error>,

Update the checkpoint having the given identifier by mutating it with the provided function, and persist the updated checkpoint to the data store.

Returns Ok(true) if the checkpoint was found, Ok(false) if no checkpoint with the provided identifier exists in the data store, or an error if a storage error occurred.

Source

fn remove_checkpoint( &mut self, checkpoint_id: &Self::CheckpointId, ) -> Result<(), Self::Error>

Removes a checkpoint from the data store.

If no checkpoint exists with the given ID, this does nothing.

Source

fn truncate_checkpoints_retaining( &mut self, checkpoint_id: &Self::CheckpointId, ) -> Result<(), Self::Error>

Removes checkpoints with identifiers greater than to the given identifier, and removes mark removal metadata from the specified checkpoint.

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.

Implementations on Foreign Types§

Source§

impl<S: ShardStore> ShardStore for &mut S

Source§

type H = <S as ShardStore>::H

Source§

type CheckpointId = <S as ShardStore>::CheckpointId

Source§

type Error = <S as ShardStore>::Error

Source§

fn get_shard( &self, shard_root: Address, ) -> Result<Option<LocatedPrunableTree<Self::H>>, Self::Error>

Source§

fn last_shard( &self, ) -> Result<Option<LocatedPrunableTree<Self::H>>, Self::Error>

Source§

fn put_shard( &mut self, subtree: LocatedPrunableTree<Self::H>, ) -> Result<(), Self::Error>

Source§

fn get_shard_roots(&self) -> Result<Vec<Address>, Self::Error>

Source§

fn get_cap(&self) -> Result<PrunableTree<Self::H>, Self::Error>

Source§

fn put_cap(&mut self, cap: PrunableTree<Self::H>) -> Result<(), Self::Error>

Source§

fn truncate_shards(&mut self, shard_index: u64) -> Result<(), Self::Error>

Source§

fn min_checkpoint_id(&self) -> Result<Option<Self::CheckpointId>, Self::Error>

Source§

fn max_checkpoint_id(&self) -> Result<Option<Self::CheckpointId>, Self::Error>

Source§

fn add_checkpoint( &mut self, checkpoint_id: Self::CheckpointId, checkpoint: Checkpoint, ) -> Result<(), Self::Error>

Source§

fn checkpoint_count(&self) -> Result<usize, Self::Error>

Source§

fn get_checkpoint_at_depth( &self, checkpoint_depth: usize, ) -> Result<Option<(Self::CheckpointId, Checkpoint)>, Self::Error>

Source§

fn get_checkpoint( &self, checkpoint_id: &Self::CheckpointId, ) -> Result<Option<Checkpoint>, Self::Error>

Source§

fn with_checkpoints<F>( &mut self, limit: usize, callback: F, ) -> Result<(), Self::Error>
where F: FnMut(&Self::CheckpointId, &Checkpoint) -> Result<(), Self::Error>,

Source§

fn for_each_checkpoint<F>( &self, limit: usize, callback: F, ) -> Result<(), Self::Error>
where F: FnMut(&Self::CheckpointId, &Checkpoint) -> Result<(), Self::Error>,

Source§

fn update_checkpoint_with<F>( &mut self, checkpoint_id: &Self::CheckpointId, update: F, ) -> Result<bool, Self::Error>
where F: Fn(&mut Checkpoint) -> Result<(), Self::Error>,

Source§

fn remove_checkpoint( &mut self, checkpoint_id: &Self::CheckpointId, ) -> Result<(), Self::Error>

Source§

fn truncate_checkpoints_retaining( &mut self, checkpoint_id: &Self::CheckpointId, ) -> Result<(), Self::Error>

Implementors§