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 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more