Batch

Struct Batch 

Source
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:

  1. The starting sequence number as a 64-bit fixed-length integer
  2. The number operations in the batch as a 32-bit fixed-length integer
  3. Serialized BatchElement’s. See the BatchElement docs 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

Source

pub fn new() -> Self

Create an empty Batch.

Source

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

Source

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

Source

pub fn clear(&mut self) -> &mut Self

Clear the operations added to the batch.

Source

pub fn iter(&self) -> Iter<'_, BatchElement>

Get an iterator over references to operations added to the batch.

Source

pub fn len(&self) -> usize

Get the number of entries within the batch.

Source

pub fn is_empty(&self) -> bool

Returns true if the batch does not have any operations. Otherwise, returns false.

Source§

impl Batch

Crate-only methods

Source

pub(crate) fn get_approximate_size(&self) -> usize

Get the approximate size of the database changes that would be caused by this batch.

Source

pub(crate) fn set_starting_seq_number(&mut self, seq_number: u64)

The the starting sequence number of the batch.

Source

pub(crate) fn get_starting_seq_number(&self) -> Option<u64>

Get the starting sequence number of the batch.

Source

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.

Source

pub(crate) fn add_operation(&mut self, batch_element: BatchElement)

Append an operation.

Trait Implementations§

Source§

impl Default for Batch

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<&Batch> for Vec<u8>

Source§

fn from(batch: &Batch) -> Vec<u8>

Serialize a Batch to bytes.

Source§

impl PartialEq for Batch

Source§

fn eq(&self, other: &Batch) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<&[u8]> for Batch

Source§

type Error = RainDBError

The type returned in the event of a conversion error.
Source§

fn try_from(buf: &[u8]) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Eq for Batch

Source§

impl StructuralPartialEq for Batch

Auto Trait Implementations§

§

impl Freeze for Batch

§

impl RefUnwindSafe for Batch

§

impl Send for Batch

§

impl Sync for Batch

§

impl Unpin for Batch

§

impl UnwindSafe for Batch

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V