Struct fjall::PartitionHandle
source · pub struct PartitionHandle(/* private fields */);Expand description
Access to a keyspace partition
Each partition is backed by an LSM-tree to provide a disk-backed search tree, and can be configured individually.
A partition generally only takes a little bit of memory and disk space, but does not spawn its own background threads.
Implementations§
source§impl PartitionHandle
impl PartitionHandle
sourcepub fn disk_space(&self) -> u64
pub fn disk_space(&self) -> u64
sourcepub fn iter(&self) -> impl DoubleEndedIterator<Item = Result<KvPair>>
pub fn iter(&self) -> impl DoubleEndedIterator<Item = Result<KvPair>>
Returns an iterator that scans through the entire partition.
Avoid using this function, or limit it as otherwise it may scan a lot of items.
§Examples
partition.insert("a", "abc")?;
partition.insert("f", "abc")?;
partition.insert("g", "abc")?;
assert_eq!(3, partition.iter().count());sourcepub fn keys(&self) -> impl DoubleEndedIterator<Item = Result<UserKey>>
pub fn keys(&self) -> impl DoubleEndedIterator<Item = Result<UserKey>>
Returns an iterator that scans through the entire partition, returning only keys.
Avoid using this function, or limit it as otherwise it may scan a lot of items.
sourcepub fn values(
&self,
) -> impl DoubleEndedIterator<Item = Result<UserValue>> + 'static
pub fn values( &self, ) -> impl DoubleEndedIterator<Item = Result<UserValue>> + 'static
Returns an iterator that scans through the entire partition, returning only values.
Avoid using this function, or limit it as otherwise it may scan a lot of items.
sourcepub fn range<'a, K: AsRef<[u8]> + 'a, R: RangeBounds<K> + 'a>(
&'a self,
range: R,
) -> impl DoubleEndedIterator<Item = Result<KvPair>> + 'static
pub fn range<'a, K: AsRef<[u8]> + 'a, R: RangeBounds<K> + 'a>( &'a self, range: R, ) -> impl DoubleEndedIterator<Item = Result<KvPair>> + 'static
Returns an iterator over a range of items.
Avoid using full or unbounded ranges as they may scan a lot of items (unless limited).
§Examples
partition.insert("a", "abc")?;
partition.insert("f", "abc")?;
partition.insert("g", "abc")?;
assert_eq!(2, partition.range("a"..="f").count());sourcepub fn prefix<'a, K: AsRef<[u8]> + 'a>(
&'a self,
prefix: K,
) -> impl DoubleEndedIterator<Item = Result<KvPair>> + 'static
pub fn prefix<'a, K: AsRef<[u8]> + 'a>( &'a self, prefix: K, ) -> impl DoubleEndedIterator<Item = Result<KvPair>> + 'static
Returns an iterator over a prefixed set of items.
Avoid using an empty prefix as it may scan a lot of items (unless limited).
§Examples
partition.insert("a", "abc")?;
partition.insert("ab", "abc")?;
partition.insert("abc", "abc")?;
assert_eq!(2, partition.prefix("ab").count());sourcepub fn approximate_len(&self) -> usize
pub fn approximate_len(&self) -> usize
Approximates the amount of items in the partition.
For update -or delete-heavy workloads, this value will diverge from the real value, but is a O(1) operation.
For insert-only workloads (e.g. logs, time series) this value is reliable.
§Examples
assert_eq!(partition.len()?, 0);
partition.insert("1", "abc")?;
assert_eq!(partition.approximate_len(), 1);
partition.remove("1")?;
// Oops! approximate_len will not be reliable here
assert_eq!(partition.approximate_len(), 2);sourcepub fn len(&self) -> Result<usize>
pub fn len(&self) -> Result<usize>
Scans the entire partition, returning the amount of items.
§Caution
This operation scans the entire partition: O(n) complexity!
Never, under any circumstances, use .len() == 0 to check
if the partition is empty, use PartitionHandle::is_empty instead.
If you want an estimate, use PartitionHandle::approximate_len instead.
§Examples
assert_eq!(partition.len()?, 0);
partition.insert("1", "abc")?;
partition.insert("3", "abc")?;
partition.insert("5", "abc")?;
assert_eq!(partition.len()?, 3);§Errors
Will return Err if an IO error occurs.
sourcepub fn first_key_value(&self) -> Result<Option<KvPair>>
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.
§Examples
partition.insert("1", "abc")?;
partition.insert("3", "abc")?;
partition.insert("5", "abc")?;
let (key, _) = partition.first_key_value()?.expect("item should exist");
assert_eq!(&*key, "1".as_bytes());§Errors
Will return Err if an IO error occurs.
sourcepub fn last_key_value(&self) -> Result<Option<KvPair>>
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.
§Examples
partition.insert("1", "abc")?;
partition.insert("3", "abc")?;
partition.insert("5", "abc")?;
let (key, _) = partition.last_key_value()?.expect("item should exist");
assert_eq!(&*key, "5".as_bytes());§Errors
Will return Err if an IO error occurs.
sourcepub fn snapshot_at(&self, seqno: Instant) -> Snapshot
pub fn snapshot_at(&self, seqno: Instant) -> Snapshot
Opens a snapshot of this partition with a given sequence number.
sourcepub fn insert<K: AsRef<[u8]>, V: AsRef<[u8]>>(
&self,
key: K,
value: V,
) -> Result<()>
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.
§Examples
partition.insert("a", "abc")?;
assert!(!partition.is_empty()?);§Errors
Will return Err if an IO error occurs.
sourcepub fn remove<K: AsRef<[u8]>>(&self, key: K) -> Result<()>
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.
§Examples
partition.insert("a", "abc")?;
let item = partition.get("a")?.expect("should have item");
assert_eq!("abc".as_bytes(), &*item);
partition.remove("a")?;
let item = partition.get("a")?;
assert_eq!(None, item);§Errors
Will return Err if an IO error occurs.
Trait Implementations§
source§impl Clone for PartitionHandle
impl Clone for PartitionHandle
source§fn clone(&self) -> PartitionHandle
fn clone(&self) -> PartitionHandle
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl Deref for PartitionHandle
impl Deref for PartitionHandle
source§impl GarbageCollection for PartitionHandle
impl GarbageCollection for PartitionHandle
source§fn gc_scan(&self) -> Result<GcReport>
fn gc_scan(&self) -> Result<GcReport>
source§fn gc_with_space_amp_target(&self, factor: f32) -> Result<u64>
fn gc_with_space_amp_target(&self, factor: f32) -> Result<u64>
source§impl Hash for PartitionHandle
impl Hash for PartitionHandle
source§impl PartialEq for PartitionHandle
impl PartialEq for PartitionHandle
impl Eq for PartitionHandle
Auto Trait Implementations§
impl Freeze for PartitionHandle
impl !RefUnwindSafe for PartitionHandle
impl Send for PartitionHandle
impl Sync for PartitionHandle
impl Unpin for PartitionHandle
impl !UnwindSafe for PartitionHandle
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.