Skip to main content

BatchWriter

Struct BatchWriter 

Source
pub struct BatchWriter { /* private fields */ }
Expand description

Batch writer with configurable settings.

BatchWriter provides a configurable interface for applying batch mutations to Prolly trees. It wraps the batch operation logic and applies the configured optimizations.

§Example

use prolly::{BatchWriter, BatchWriterConfig, Prolly, MemStore, Config, Mutation};

let store = MemStore::new();
let prolly = Prolly::new(store, Config::default());
let tree = prolly.create();

// Create a batch writer with custom configuration
let config = BatchWriterConfig::new()
    .with_optimized_merge(true);

let writer = BatchWriter::with_config(config);

// Apply mutations using the configured writer
let mutations = vec![
    Mutation::Upsert { key: b"a".to_vec(), val: b"1".to_vec() },
    Mutation::Upsert { key: b"b".to_vec(), val: b"2".to_vec() },
];

let new_tree = writer.apply_batch(&prolly, &tree, mutations).unwrap();

Implementations§

Source§

impl BatchWriter

Source

pub fn new() -> Self

Create a new batch writer with default configuration.

§Returns

A new BatchWriter with default settings.

§Example
use prolly::BatchWriter;

let writer = BatchWriter::new();
Source

pub fn with_config(config: BatchWriterConfig) -> Self

Create a new batch writer with custom configuration.

§Arguments
  • config - The configuration to use
§Returns

A new BatchWriter with the specified configuration.

§Example
use prolly::{BatchWriter, BatchWriterConfig};

let config = BatchWriterConfig::new()
    .with_prefetch_parallelism(32);

let writer = BatchWriter::with_config(config);
Source

pub fn config(&self) -> &BatchWriterConfig

Get a reference to the current configuration.

§Returns

A reference to the BatchWriterConfig.

§Example
use prolly::{BatchWriter, BatchWriterConfig};

let writer = BatchWriter::new();
let config = writer.config();
assert_eq!(config.prefetch_parallelism, 16);
Source

pub fn apply_batch<S: Store>( &self, prolly: &Prolly<S>, tree: &Tree, mutations: Vec<Mutation>, ) -> Result<Tree, Error>

Apply batch mutations using the configured settings.

This method applies mutations to a tree using the optimizations specified in the configuration:

  • Stores that prefer batched reads hydrate mutation paths in ordered batches
  • If use_optimized_merge is true, uses O(n+m) two-pointer merge
  • Otherwise, uses O(m log n) binary search approach
  • If use_bottom_up_rebuild is true, uses bottom-up rebuild strategy for parent reconstruction (ensures each node is written exactly once)
§Arguments
  • prolly - Reference to the Prolly tree manager
  • tree - The tree to modify
  • mutations - Vector of mutations to apply
§Returns
  • Ok(Tree) - New tree with all mutations applied
  • Err(Error) - On storage or processing errors
§Example
use prolly::{BatchWriter, Prolly, MemStore, Config, Mutation};

let store = MemStore::new();
let prolly = Prolly::new(store, Config::default());
let tree = prolly.create();

let writer = BatchWriter::new();
let mutations = vec![
    Mutation::Upsert { key: b"key".to_vec(), val: b"value".to_vec() },
];

let new_tree = writer.apply_batch(&prolly, &tree, mutations).unwrap();
Source

pub fn apply_batch_with_stats<S: Store>( &self, prolly: &Prolly<S>, tree: &Tree, mutations: Vec<Mutation>, ) -> Result<BatchApplyResult, Error>

Apply batch mutations and return store-neutral execution stats.

This is useful for tuning workload shape across storage backends. The returned stats report tree-level work such as affected leaves and unique prolly nodes/bytes written, independent of backend compaction or object layout.

Trait Implementations§

Source§

impl Default for BatchWriter

Source§

fn default() -> Self

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

Auto Trait Implementations§

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.