pub struct Batch {
starting_seq_number: Option<u64>,
operations: Vec<BatchElement>,
}Expand description
A set of operations to perform atomically.
The updates are applied in the order in which they are added to the batch.
§Examples
use raindb::Batch;
let mut batch = Batch::new();
batch
.add_put("key".into(), "v1".into())
.add_delete("key".into())
.add_put("key".into(), "v2".into())
.add_put("key".into(), "v3".into());
// The value of "key" will be "v3" when the batch is applied to the database.§Serialization
A batch has the following layout when serialized:
- The starting sequence number as a 64-bit fixed-length integer
- The number operations in the batch as a 32-bit fixed-length integer
- Serialized
BatchElement’s. See theBatchElementdocs their serialization format.
Fields§
§starting_seq_number: Option<u64>The starting sequence number for this batch of operations.
This is set internally when a write is actually executed.
operations: Vec<BatchElement>A list of operations to perform in a batch.
Implementations§
Source§impl Batch
Public methods
impl Batch
Public methods
Sourcepub fn add_put(&mut self, key: Vec<u8>, value: Vec<u8>) -> &mut Self
pub fn add_put(&mut self, key: Vec<u8>, value: Vec<u8>) -> &mut Self
Add a Put operation to the batch.
key - the user provided key to associate with the value to be stored
value - the value to be stored in the database
Sourcepub fn add_delete(&mut self, key: Vec<u8>) -> &mut Self
pub fn add_delete(&mut self, key: Vec<u8>) -> &mut Self
Add a Delete operation to the batch.
key - the user provided key to associate with the value to be stored
Sourcepub fn iter(&self) -> Iter<'_, BatchElement>
pub fn iter(&self) -> Iter<'_, BatchElement>
Get an iterator over references to operations added to the batch.
Source§impl Batch
Crate-only methods
impl Batch
Crate-only methods
Sourcepub(crate) fn get_approximate_size(&self) -> usize
pub(crate) fn get_approximate_size(&self) -> usize
Get the approximate size of the database changes that would be caused by this batch.
Sourcepub(crate) fn set_starting_seq_number(&mut self, seq_number: u64)
pub(crate) fn set_starting_seq_number(&mut self, seq_number: u64)
The the starting sequence number of the batch.
Sourcepub(crate) fn get_starting_seq_number(&self) -> Option<u64>
pub(crate) fn get_starting_seq_number(&self) -> Option<u64>
Get the starting sequence number of the batch.
Sourcepub(crate) fn append_batch(&mut self, batch_to_append: &Batch)
pub(crate) fn append_batch(&mut self, batch_to_append: &Batch)
Append the operations from another batch to the operations of the current batch.
This is usually done to create a group commit and reduce write latency.
Sourcepub(crate) fn add_operation(&mut self, batch_element: BatchElement)
pub(crate) fn add_operation(&mut self, batch_element: BatchElement)
Append an operation.