pub struct MemoryReservation { /* private fields */ }Expand description
A memory reservation for a single operator
Tracks memory usage for one operator (sort, aggregate, join, etc.) and automatically releases memory when dropped.
§Example
let controller = Arc::new(MemoryController::with_budget(1024 * 1024 * 1024));
let mut reservation = controller.create_reservation();
// Accumulate memory as we process data
for batch in batches {
let batch_size = batch.size_in_bytes();
if !reservation.try_grow(batch_size) {
// Memory exhausted - spill current data to disk
spill_to_disk(&accumulated_data);
reservation.shrink(accumulated_data.size_in_bytes());
}
// Process batch...
}Implementations§
Source§impl MemoryReservation
impl MemoryReservation
Sourcepub fn try_grow(&mut self, additional: usize) -> bool
pub fn try_grow(&mut self, additional: usize) -> bool
Try to grow the reservation by the specified amount
Returns true if the memory was reserved, false if there’s not enough budget available. The caller should spill to disk if this returns false.
Sourcepub fn shrink(&mut self, bytes: usize)
pub fn shrink(&mut self, bytes: usize)
Shrink the reservation by the specified amount
Call this after spilling data to disk to free up budget for new data.
Sourcepub fn release_all(&mut self)
pub fn release_all(&mut self)
Release all reserved memory
Equivalent to shrink(self.reserved())
Sourcepub fn should_spill(&self) -> bool
pub fn should_spill(&self) -> bool
Check if memory pressure is high and spilling is recommended
Sourcepub fn would_exceed_budget(&self, additional: usize) -> bool
pub fn would_exceed_budget(&self, additional: usize) -> bool
Check if trying to grow by the given amount would exceed budget
This is a non-mutating check useful for deciding whether to accumulate more data or trigger a spill first.
Sourcepub fn temp_directory(&self) -> &PathBuf
pub fn temp_directory(&self) -> &PathBuf
Get the temporary directory for spill files
Sourcepub fn target_partition_bytes(&self) -> usize
pub fn target_partition_bytes(&self) -> usize
Get the target partition size
Sourcepub fn record_spill(&self, bytes: usize)
pub fn record_spill(&self, bytes: usize)
Record that data was spilled to disk
Trait Implementations§
Auto Trait Implementations§
impl Freeze for MemoryReservation
impl RefUnwindSafe for MemoryReservation
impl Send for MemoryReservation
impl Sync for MemoryReservation
impl Unpin for MemoryReservation
impl UnwindSafe for MemoryReservation
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