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.