pub struct SledDbOverlay {
pub state: SledDbOverlayState,
/* private fields */
}Expand description
An overlay on top of an entire sled::Db which can span multiple trees
Fields§
§state: SledDbOverlayStateCurrent overlay cache state
Implementations§
Source§impl SledDbOverlay
impl SledDbOverlay
Sourcepub fn new(db: &Db, protected_tree_names: Vec<&[u8]>) -> Self
pub fn new(db: &Db, protected_tree_names: Vec<&[u8]>) -> Self
Instantiate a new SledDbOverlay on top of a given sled::Db.
Note: Provided protected trees don’t have to be opened as protected,
as they are setup as protected here.
Sourcepub fn open_tree(
&mut self,
tree_name: &[u8],
protected: bool,
) -> Result<(), Error>
pub fn open_tree( &mut self, tree_name: &[u8], protected: bool, ) -> Result<(), Error>
Create a new SledTreeOverlay on top of a given tree_name.
This function will also open a new tree inside db regardless of if it has
existed before, so for convenience, we also provide SledDbOverlay::purge_new_trees
in case we decide we don’t want to write the batches, and drop the new trees.
Additionally, a boolean flag is passed to mark the oppened tree as protected,
meanning that it can’t be removed and its references will never be dropped.
Sourcepub fn drop_tree(&mut self, tree_name: &[u8]) -> Result<(), Error>
pub fn drop_tree(&mut self, tree_name: &[u8]) -> Result<(), Error>
Drop a sled tree from the overlay.
Sourcepub fn purge_new_trees(&self) -> Result<(), Error>
pub fn purge_new_trees(&self) -> Result<(), Error>
Drop newly created trees from the sled database. This is a convenience function that should be used when we decide that we don’t want to apply any cache changes, and we want to revert back to the initial state.
Sourcepub fn get_state_trees(&self) -> BTreeMap<IVec, Tree>
pub fn get_state_trees(&self) -> BTreeMap<IVec, Tree>
Fetch all our caches current sled::Tree pointers.
Sourcepub fn contains_key(&self, tree_key: &[u8], key: &[u8]) -> Result<bool, Error>
pub fn contains_key(&self, tree_key: &[u8], key: &[u8]) -> Result<bool, Error>
Returns true if the overlay contains a value for a specified key in the specified
tree cache.
Sourcepub fn get(&self, tree_key: &[u8], key: &[u8]) -> Result<Option<IVec>, Error>
pub fn get(&self, tree_key: &[u8], key: &[u8]) -> Result<Option<IVec>, Error>
Retrieve a value from the overlay if it exists in the specified tree cache.
Sourcepub fn is_empty(&self, tree_key: &[u8]) -> Result<bool, Error>
pub fn is_empty(&self, tree_key: &[u8]) -> Result<bool, Error>
Returns true if specified tree cache is empty.
Sourcepub fn last(&self, tree_key: &[u8]) -> Result<Option<(IVec, IVec)>, Error>
pub fn last(&self, tree_key: &[u8]) -> Result<Option<(IVec, IVec)>, Error>
Returns last value from the overlay if the specified tree cache is not empty.
Sourcepub fn insert(
&mut self,
tree_key: &[u8],
key: &[u8],
value: &[u8],
) -> Result<Option<IVec>, Error>
pub fn insert( &mut self, tree_key: &[u8], key: &[u8], value: &[u8], ) -> Result<Option<IVec>, Error>
Insert a key to a new value in the specified tree cache, returning the last value if it was set.
Sourcepub fn remove(
&mut self,
tree_key: &[u8],
key: &[u8],
) -> Result<Option<IVec>, Error>
pub fn remove( &mut self, tree_key: &[u8], key: &[u8], ) -> Result<Option<IVec>, Error>
Delete a value in the specified tree cache, returning the old value if it existed.
Sourcepub fn clear(&mut self, tree_key: &[u8]) -> Result<(), Error>
pub fn clear(&mut self, tree_key: &[u8]) -> Result<(), Error>
Removes all values from the specified tree cache and marks all its tree records as removed.
Sourcepub fn apply(&mut self) -> Result<(), TransactionError<Error>>
pub fn apply(&mut self) -> Result<(), TransactionError<Error>>
Ensure all new trees that have been opened exist in sled by reopening them, atomically apply all batches on all trees as a transaction, and drop dropped trees from sled. This function does not perform a db flush. This should be done externally, since then there is a choice to perform either blocking or async IO. After execution is successful, caller should NOT use the overlay again.
Sourcepub fn checkpoint(&mut self)
pub fn checkpoint(&mut self)
Checkpoint current cache state so we can revert to it, if needed.
Sourcepub fn revert_to_checkpoint(&mut self) -> Result<(), Error>
pub fn revert_to_checkpoint(&mut self) -> Result<(), Error>
Revert to current cache state checkpoint.
Sourcepub fn diff(
&self,
sequence: &[SledDbOverlayStateDiff],
) -> Result<SledDbOverlayStateDiff, Error>
pub fn diff( &self, sequence: &[SledDbOverlayStateDiff], ) -> Result<SledDbOverlayStateDiff, Error>
Calculate differences from provided overlay state changes sequence. This can be used when we want to keep track of consecutive individual changes performed over the current overlay state. If the sequence is empty, current state is returned as the diff.
Sourcepub fn add_diff(&mut self, diff: &SledDbOverlayStateDiff) -> Result<(), Error>
pub fn add_diff(&mut self, diff: &SledDbOverlayStateDiff) -> Result<(), Error>
Add provided db overlay state changes from our own.
Sourcepub fn remove_diff(&mut self, diff: &SledDbOverlayStateDiff)
pub fn remove_diff(&mut self, diff: &SledDbOverlayStateDiff)
Remove provided db overlay state changes from our own.
Sourcepub fn apply_diff(
&mut self,
diff: &SledDbOverlayStateDiff,
) -> Result<(), TransactionError<Error>>
pub fn apply_diff( &mut self, diff: &SledDbOverlayStateDiff, ) -> Result<(), TransactionError<Error>>
For a provided SledDbOverlayStateDiff, ensure all trees exist in sled by
reopening them, atomically apply all batches on all trees as a transaction,
and drop dropped trees from sled. After that, remove the state changes from
our own. This is will also mutate the initial trees, based on what was oppened
and/or dropped. This function does not perform a db flush. This should be
done externally, since then there is a choice to perform either blocking or
async IO.
Trait Implementations§
Source§impl Clone for SledDbOverlay
impl Clone for SledDbOverlay
Source§fn clone(&self) -> SledDbOverlay
fn clone(&self) -> SledDbOverlay
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more