Struct TransactionalPartitionHandle

Source
pub struct TransactionalPartitionHandle { /* private fields */ }
Expand description

Access to a partition of a transactional keyspace

Implementations§

Source§

impl TransactionalPartitionHandle

Source

pub fn path(&self) -> PathBuf

Returns the underlying LSM-tree’s path

Source

pub fn take<K: Into<UserKey>>(&self, key: K) -> Result<Option<UserValue>>

Removes an item and returns its value if it existed.

The operation will run wrapped in a transaction.

partition.insert("a", "abc")?;

let taken = partition.take("a")?.unwrap();
assert_eq!(b"abc", &*taken);

let item = partition.get("a")?;
assert!(item.is_none());
§Errors

Will return Err if an IO error occurs.

Source

pub fn fetch_update<K: Into<UserKey>, F: FnMut(Option<&UserValue>) -> Option<UserValue>>( &self, key: K, f: F, ) -> Result<Option<UserValue>>

Atomically updates an item and returns the previous value.

Returning None removes the item if it existed before.

The operation will run wrapped in a transaction.

§Note

The provided closure can be called multiple times as this function automatically retries on conflict. Since this is an FnMut, make sure it is idempotent and will not cause side-effects.

§Examples
partition.insert("a", "abc")?;

let prev = partition.fetch_update("a", |_| Some(Slice::from(*b"def")))?.unwrap();
assert_eq!(b"abc", &*prev);

let item = partition.get("a")?;
assert_eq!(Some("def".as_bytes().into()), item);
partition.insert("a", "abc")?;

let prev = partition.fetch_update("a", |_| None)?.unwrap();
assert_eq!(b"abc", &*prev);

let item = partition.get("a")?;
assert!(item.is_none());
§Errors

Will return Err if an IO error occurs.

Source

pub fn update_fetch<K: Into<UserKey>, F: FnMut(Option<&UserValue>) -> Option<UserValue>>( &self, key: K, f: F, ) -> Result<Option<UserValue>>

Atomically updates an item and returns the new value.

Returning None removes the item if it existed before.

The operation will run wrapped in a transaction.

§Note

The provided closure can be called multiple times as this function automatically retries on conflict. Since this is an FnMut, make sure it is idempotent and will not cause side-effects.

§Examples
partition.insert("a", "abc")?;

let updated = partition.update_fetch("a", |_| Some(Slice::from(*b"def")))?.unwrap();
assert_eq!(b"def", &*updated);

let item = partition.get("a")?;
assert_eq!(Some("def".as_bytes().into()), item);
partition.insert("a", "abc")?;

let updated = partition.update_fetch("a", |_| None)?;
assert!(updated.is_none());

let item = partition.get("a")?;
assert!(item.is_none());
§Errors

Will return Err if an IO error occurs.

Source

pub fn insert<K: Into<UserKey>, V: Into<UserValue>>( &self, key: K, value: V, ) -> Result<()>

Inserts a key-value pair into the partition.

Keys may be up to 65536 bytes long, values up to 2^32 bytes. Shorter keys and values result in better performance.

If the key already exists, the item will be overwritten.

The operation will run wrapped in a transaction.

§Examples
partition.insert("a", "abc")?;

assert!(!keyspace.read_tx().is_empty(&partition)?);
§Errors

Will return Err if an IO error occurs.

Source

pub fn remove<K: Into<UserKey>>(&self, key: K) -> Result<()>

Removes an item from the partition.

The key may be up to 65536 bytes long. Shorter keys result in better performance.

The operation will run wrapped in a transaction.

§Examples
partition.insert("a", "abc")?;
assert!(!keyspace.read_tx().is_empty(&partition)?);

partition.remove("a")?;
assert!(keyspace.read_tx().is_empty(&partition)?);
§Errors

Will return Err if an IO error occurs.

Source

pub fn get<K: AsRef<[u8]>>(&self, key: K) -> Result<Option<UserValue>>

Retrieves an item from the partition.

The operation will run wrapped in a read snapshot.

§Examples
partition.insert("a", "my_value")?;

let item = partition.get("a")?;
assert_eq!(Some("my_value".as_bytes().into()), item);
§Errors

Will return Err if an IO error occurs.

Source

pub fn size_of<K: AsRef<[u8]>>(&self, key: K) -> Result<Option<u32>>

Retrieves the size of an item from the partition.

The operation will run wrapped in a read snapshot.

§Examples
partition.insert("a", "my_value")?;

let len = partition.size_of("a")?.unwrap_or_default();
assert_eq!("my_value".len() as u32, len);
§Errors

Will return Err if an IO error occurs.

Source

pub fn first_key_value(&self) -> Result<Option<KvPair>>

Returns the first key-value pair in the partition. The key in this pair is the minimum key in the partition.

The operation will run wrapped in a read snapshot.

§Examples
partition.insert("a", "my_value")?;
partition.insert("b", "my_value")?;

assert_eq!(b"a", &*partition.first_key_value()?.unwrap().0);
§Errors

Will return Err if an IO error occurs.

Source

pub fn last_key_value(&self) -> Result<Option<KvPair>>

Returns the last key-value pair in the partition. The key in this pair is the maximum key in the partition.

The operation will run wrapped in a read snapshot.

§Examples
partition.insert("a", "my_value")?;
partition.insert("b", "my_value")?;

assert_eq!(b"b", &*partition.last_key_value()?.unwrap().0);
§Errors

Will return Err if an IO error occurs.

Source

pub fn contains_key<K: AsRef<[u8]>>(&self, key: K) -> Result<bool>

Returns true if the partition contains the specified key.

The operation will run wrapped in a read snapshot.

§Examples
partition.insert("a", "my_value")?;

assert!(partition.contains_key("a")?);
assert!(!partition.contains_key("b")?);
§Errors

Will return Err if an IO error occurs.

Trait Implementations§

Source§

impl Clone for TransactionalPartitionHandle

Source§

fn clone(&self) -> TransactionalPartitionHandle

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

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

Performs copy-assignment from source. Read more
Source§

impl GarbageCollection for TransactionalPartitionHandle

Source§

fn gc_scan(&self) -> Result<GcReport>

Collects statistics about blob fragmentation inside the partition. Read more
Source§

fn gc_with_space_amp_target(&self, factor: f32) -> Result<u64>

Rewrites blobs in order to achieve the given space amplification factor. Read more
Source§

fn gc_with_staleness_threshold(&self, threshold: f32) -> Result<u64>

Rewrites blobs that have reached a given staleness threshold. Read more
Source§

fn gc_drop_stale_segments(&self) -> Result<u64>

Drops fully stale segments. 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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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.