Struct fjall::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: AsRef<[u8]>>(&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: AsRef<[u8]>, F: Fn(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.

§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: AsRef<[u8]>, F: Fn(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.

§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: AsRef<[u8]>, V: AsRef<[u8]>>( &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: AsRef<[u8]>>(&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 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 T)

🔬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.