pub struct TransactionalPartitionHandle { /* private fields */ }Expand description
Access to a partition of a transactional keyspace
Implementations§
Source§impl TransactionalPartitionHandle
impl TransactionalPartitionHandle
Sourcepub fn take<K: Into<UserKey>>(&self, key: K) -> Result<Option<UserValue>>
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.
Sourcepub fn fetch_update<K: Into<UserKey>, F: FnMut(Option<&UserValue>) -> Option<UserValue>>(
&self,
key: K,
f: F,
) -> Result<Option<UserValue>>
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.
Sourcepub fn update_fetch<K: Into<UserKey>, F: FnMut(Option<&UserValue>) -> Option<UserValue>>(
&self,
key: K,
f: F,
) -> Result<Option<UserValue>>
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.
Sourcepub fn insert<K: Into<UserKey>, V: Into<UserValue>>(
&self,
key: K,
value: V,
) -> Result<()>
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.
Sourcepub fn remove<K: Into<UserKey>>(&self, key: K) -> Result<()>
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.
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.
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.
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.
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.
Trait Implementations§
Source§impl Clone for TransactionalPartitionHandle
impl Clone for TransactionalPartitionHandle
Source§fn clone(&self) -> TransactionalPartitionHandle
fn clone(&self) -> TransactionalPartitionHandle
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more