pub struct WriteBatch { /* private fields */ }Expand description
Batch of write operations applied with a shared seqno.
Duplicate keys: all entries receive the same seqno. The memtable
skiplist orders by (user_key, Reverse(seqno)) — value_type does NOT
break ties. Two entries with the same (user_key, seqno) compare equal
regardless of operation type, so one may silently overwrite the other.
- Repeated
merge()on the same key: safe. All merge operands are collected during reads regardless of skiplist position. - Mixed ops on the same key (e.g.
insert+remove): not allowed.materialize()rejects these batches withError::MixedOperationBatchin all builds. Callers must canonicalize mixed-op duplicates into a single final operation before batching.
§Examples
use lsm_tree::WriteBatch;
let mut batch = WriteBatch::new();
batch.insert("key1", "value1");
batch.insert("key2", "value2");
batch.remove("key3");
assert_eq!(batch.len(), 3);
assert!(!batch.is_empty());Implementations§
Source§impl WriteBatch
impl WriteBatch
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates an empty write batch with the given capacity.
Sourcepub fn insert<K: Into<UserKey>, V: Into<UserValue>>(&mut self, key: K, value: V)
pub fn insert<K: Into<UserKey>, V: Into<UserValue>>(&mut self, key: K, value: V)
Inserts a key-value pair into the batch.
Sourcepub fn remove_weak<K: Into<UserKey>>(&mut self, key: K)
pub fn remove_weak<K: Into<UserKey>>(&mut self, key: K)
Adds a weak delete (single-delete tombstone) for a key.
Sourcepub fn merge<K: Into<UserKey>, V: Into<UserValue>>(&mut self, key: K, value: V)
pub fn merge<K: Into<UserKey>, V: Into<UserValue>>(&mut self, key: K, value: V)
Adds a merge operand for a key.
Multiple merge() calls for the same key within one batch are supported:
they produce distinct merge operands that are resolved together during
reads (via the configured MergeOperator).
The duplicate-key warning in the struct doc applies to mixed operation
types (e.g. insert + remove on the same key), not to multiple merges.
Trait Implementations§
Source§impl Clone for WriteBatch
impl Clone for WriteBatch
Source§fn clone(&self) -> WriteBatch
fn clone(&self) -> WriteBatch
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for WriteBatch
impl Debug for WriteBatch
Source§impl Default for WriteBatch
impl Default for WriteBatch
Source§fn default() -> WriteBatch
fn default() -> WriteBatch
Auto Trait Implementations§
impl Freeze for WriteBatch
impl RefUnwindSafe for WriteBatch
impl Send for WriteBatch
impl Sync for WriteBatch
impl Unpin for WriteBatch
impl UnsafeUnpin for WriteBatch
impl UnwindSafe for WriteBatch
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more