Skip to main content

PartitionedState

Struct PartitionedState 

Source
pub struct PartitionedState<V> { /* private fields */ }
Expand description

Partitioned accumulator state for spillable aggregation.

Manages aggregate state across multiple partitions, with the ability to spill cold partitions to disk under memory pressure.

Implementations§

Source§

impl<V: Clone + Send + Sync + 'static> PartitionedState<V>

Source

pub fn new<S, D>( manager: Arc<SpillManager>, num_partitions: usize, value_serializer: S, value_deserializer: D, ) -> Self
where S: Fn(&V, &mut dyn Write) -> Result<()> + Send + Sync + 'static, D: Fn(&mut dyn Read) -> Result<V> + Send + Sync + 'static,

Creates a new partitioned state with custom serialization.

Source

pub fn partition_for(&self, key: &[Value]) -> usize

Returns the partition index for a key.

Source

pub fn is_in_memory(&self, partition_idx: usize) -> bool

Returns whether a partition is in memory.

Source

pub fn partition_size(&self, partition_idx: usize) -> usize

Returns the number of groups in a partition.

Source

pub fn total_size(&self) -> usize

Returns the total number of groups across all partitions.

Source

pub fn in_memory_count(&self) -> usize

Returns the number of in-memory partitions.

Source

pub fn spilled_count(&self) -> usize

Returns the number of spilled partitions.

Source

pub fn spill_partition(&mut self, partition_idx: usize) -> Result<usize>

Spills a specific partition to disk.

§Errors

Returns an error if writing to disk fails.

Source

pub fn spill_largest(&mut self) -> Result<usize>

Spills the largest in-memory partition.

Returns the number of bytes spilled, or 0 if no partition to spill.

§Errors

Returns an error if writing to disk fails.

Source

pub fn spill_lru(&mut self) -> Result<usize>

Spills the least recently used in-memory partition.

Returns the number of bytes spilled, or 0 if no partition to spill.

§Errors

Returns an error if writing to disk fails.

Source

pub fn insert(&mut self, key: Vec<Value>, value: V) -> Result<Option<V>>

Inserts or updates a value for a key.

§Errors

Returns an error if loading from disk fails.

Source

pub fn get(&mut self, key: &[Value]) -> Result<Option<&V>>

Gets a value for a key.

§Errors

Returns an error if loading from disk fails.

Source

pub fn get_or_insert_with<F>( &mut self, key: Vec<Value>, default: F, ) -> Result<&mut V>
where F: FnOnce() -> V,

Gets a mutable value for a key, or inserts a default.

§Errors

Returns an error if loading from disk fails.

Source

pub fn drain_all(&mut self) -> Result<Vec<(Vec<Value>, V)>>

Drains all entries from all partitions.

Loads spilled partitions as needed.

§Errors

Returns an error if loading from disk fails.

Source

pub fn iter_all(&mut self) -> Result<Vec<(Vec<Value>, V)>>

Iterates over all entries without draining.

Loads spilled partitions as needed.

§Errors

Returns an error if loading from disk fails.

Source

pub fn cleanup(&mut self)

Cleans up all spill files.

Trait Implementations§

Source§

impl<V> Drop for PartitionedState<V>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<V> Freeze for PartitionedState<V>

§

impl<V> !RefUnwindSafe for PartitionedState<V>

§

impl<V> Send for PartitionedState<V>
where V: Send,

§

impl<V> Sync for PartitionedState<V>
where V: Sync,

§

impl<V> Unpin for PartitionedState<V>
where V: Unpin,

§

impl<V> !UnwindSafe for PartitionedState<V>

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> 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, 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.