SledDbOverlay

Struct SledDbOverlay 

Source
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: SledDbOverlayState

Current overlay cache state

Implementations§

Source§

impl SledDbOverlay

Source

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.

Source

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.

Source

pub fn drop_tree(&mut self, tree_name: &[u8]) -> Result<(), Error>

Drop a sled tree from the overlay.

Source

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.

Source

pub fn get_state_trees(&self) -> BTreeMap<IVec, Tree>

Fetch all our caches current sled::Tree pointers.

Source

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.

Source

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.

Source

pub fn is_empty(&self, tree_key: &[u8]) -> Result<bool, Error>

Returns true if specified tree cache is empty.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn checkpoint(&mut self)

Checkpoint current cache state so we can revert to it, if needed.

Source

pub fn revert_to_checkpoint(&mut self) -> Result<(), Error>

Revert to current cache state checkpoint.

Source

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.

Source

pub fn add_diff(&mut self, diff: &SledDbOverlayStateDiff) -> Result<(), Error>

Add provided db overlay state changes from our own.

Source

pub fn remove_diff(&mut self, diff: &SledDbOverlayStateDiff)

Remove provided db overlay state changes from our own.

Source

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.

Source

pub fn iter(&self, tree_key: &[u8]) -> Result<SledTreeOverlayIter<'_>, Error>

Retrieve an immutable itterator from the overlay if the specified tree cache exists.

Trait Implementations§

Source§

impl Clone for SledDbOverlay

Source§

fn clone(&self) -> SledDbOverlay

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.