Struct sled_overlay::database::SledDbOverlay
source · pub struct SledDbOverlay { /* private fields */ }Expand description
An overlay on top of an entire sled::Db which can span multiple trees
Implementations§
source§impl SledDbOverlay
impl SledDbOverlay
sourcepub fn new(db: &Db) -> Self
pub fn new(db: &Db) -> Self
Instantiate a new SledDbOverlay on top of a given sled::Db.
sourcepub fn open_tree(&mut self, tree_name: &[u8]) -> Result<(), Error>
pub fn open_tree(&mut self, tree_name: &[u8]) -> 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.
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 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 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.