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§
Sourcetype CheckpointId
type CheckpointId
The type used to identify checkpointed positions in the tree.
Required Methods§
Sourcefn get_shard(
&self,
shard_root: Address,
) -> Result<Option<LocatedPrunableTree<Self::H>>, Self::Error>
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.
Sourcefn last_shard(
&self,
) -> Result<Option<LocatedPrunableTree<Self::H>>, Self::Error>
fn last_shard( &self, ) -> Result<Option<LocatedPrunableTree<Self::H>>, Self::Error>
Returns the subtree containing the maximum inserted leaf position.
Sourcefn put_shard(
&mut self,
subtree: LocatedPrunableTree<Self::H>,
) -> Result<(), Self::Error>
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
.
Sourcefn get_shard_roots(&self) -> Result<Vec<Address>, Self::Error>
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.
Sourcefn truncate_shards(&mut self, shard_index: u64) -> Result<(), Self::Error>
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.
Sourcefn get_cap(&self) -> Result<PrunableTree<Self::H>, Self::Error>
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.
Sourcefn put_cap(&mut self, cap: PrunableTree<Self::H>) -> Result<(), Self::Error>
fn put_cap(&mut self, cap: PrunableTree<Self::H>) -> Result<(), Self::Error>
Persists the provided cap to the data store.
Sourcefn min_checkpoint_id(&self) -> Result<Option<Self::CheckpointId>, Self::Error>
fn min_checkpoint_id(&self) -> Result<Option<Self::CheckpointId>, Self::Error>
Returns the identifier for the checkpoint with the lowest associated position value.
Sourcefn max_checkpoint_id(&self) -> Result<Option<Self::CheckpointId>, Self::Error>
fn max_checkpoint_id(&self) -> Result<Option<Self::CheckpointId>, Self::Error>
Returns the identifier for the checkpoint with the highest associated position value.
Sourcefn add_checkpoint(
&mut self,
checkpoint_id: Self::CheckpointId,
checkpoint: Checkpoint,
) -> Result<(), Self::Error>
fn add_checkpoint( &mut self, checkpoint_id: Self::CheckpointId, checkpoint: Checkpoint, ) -> Result<(), Self::Error>
Adds a checkpoint to the data store.
Sourcefn checkpoint_count(&self) -> Result<usize, Self::Error>
fn checkpoint_count(&self) -> Result<usize, Self::Error>
Returns the number of checkpoints maintained by the data store
Sourcefn get_checkpoint_at_depth(
&self,
checkpoint_depth: usize,
) -> Result<Option<(Self::CheckpointId, Checkpoint)>, Self::Error>
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.
Sourcefn get_checkpoint(
&self,
checkpoint_id: &Self::CheckpointId,
) -> Result<Option<Checkpoint>, Self::Error>
fn get_checkpoint( &self, checkpoint_id: &Self::CheckpointId, ) -> Result<Option<Checkpoint>, Self::Error>
Returns the checkpoint corresponding to the specified checkpoint identifier.
Sourcefn with_checkpoints<F>(
&mut self,
limit: usize,
callback: F,
) -> Result<(), Self::Error>
fn with_checkpoints<F>( &mut self, limit: usize, callback: F, ) -> Result<(), Self::Error>
Iterates in checkpoint ID order over the first limit
checkpoints, applying the
given callback to each.
Sourcefn for_each_checkpoint<F>(
&self,
limit: usize,
callback: F,
) -> Result<(), Self::Error>
fn for_each_checkpoint<F>( &self, limit: usize, callback: F, ) -> Result<(), Self::Error>
Calls the given callback for each checkpoint in CheckpointId
order. This is
essentially the immutable version of with_checkpoints
.
Sourcefn update_checkpoint_with<F>(
&mut self,
checkpoint_id: &Self::CheckpointId,
update: F,
) -> Result<bool, Self::Error>
fn update_checkpoint_with<F>( &mut self, checkpoint_id: &Self::CheckpointId, update: F, ) -> Result<bool, 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.
Sourcefn remove_checkpoint(
&mut self,
checkpoint_id: &Self::CheckpointId,
) -> Result<(), Self::Error>
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.
Sourcefn truncate_checkpoints_retaining(
&mut self,
checkpoint_id: &Self::CheckpointId,
) -> Result<(), Self::Error>
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.