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>
impl<V: Clone + Send + Sync + 'static> PartitionedState<V>
Sourcepub fn new<S, D>(
manager: Arc<SpillManager>,
num_partitions: usize,
value_serializer: S,
value_deserializer: D,
) -> Self
pub fn new<S, D>( manager: Arc<SpillManager>, num_partitions: usize, value_serializer: S, value_deserializer: D, ) -> Self
Creates a new partitioned state with custom serialization.
Sourcepub fn partition_for(&self, key: &[Value]) -> usize
pub fn partition_for(&self, key: &[Value]) -> usize
Returns the partition index for a key.
Sourcepub fn is_in_memory(&self, partition_idx: usize) -> bool
pub fn is_in_memory(&self, partition_idx: usize) -> bool
Returns whether a partition is in memory.
Sourcepub fn partition_size(&self, partition_idx: usize) -> usize
pub fn partition_size(&self, partition_idx: usize) -> usize
Returns the number of groups in a partition.
Sourcepub fn total_size(&self) -> usize
pub fn total_size(&self) -> usize
Returns the total number of groups across all partitions.
Sourcepub fn in_memory_count(&self) -> usize
pub fn in_memory_count(&self) -> usize
Returns the number of in-memory partitions.
Sourcepub fn spilled_count(&self) -> usize
pub fn spilled_count(&self) -> usize
Returns the number of spilled partitions.
Sourcepub fn spill_partition(&mut self, partition_idx: usize) -> Result<usize>
pub fn spill_partition(&mut self, partition_idx: usize) -> Result<usize>
Sourcepub fn spill_largest(&mut self) -> Result<usize>
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.
Sourcepub fn spill_lru(&mut self) -> Result<usize>
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.
Sourcepub fn get_or_insert_with<F>(
&mut self,
key: Vec<Value>,
default: F,
) -> Result<&mut V>where
F: FnOnce() -> V,
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.
Sourcepub fn drain_all(&mut self) -> Result<Vec<(Vec<Value>, V)>>
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.
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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