pub struct SortSession<K, V> { /* private fields */ }Expand description
An in-progress sort. Generic over the ordering key K and payload V.
Implementations§
Source§impl<K, V> SortSession<K, V>where
K: Ord + Clone + Serialize + DeserializeOwned + Send + 'static,
V: Serialize + DeserializeOwned + Send + 'static,
impl<K, V> SortSession<K, V>where
K: Ord + Clone + Serialize + DeserializeOwned + Send + 'static,
V: Serialize + DeserializeOwned + Send + 'static,
Sourcepub fn new(plan: SortPlan, dir: PathBuf, dedup: bool) -> Self
pub fn new(plan: SortPlan, dir: PathBuf, dedup: bool) -> Self
Open a session for plan, spilling (if it spills at all) under the
unique scratch directory dir. The directory is created lazily on
the first spill, so a purely in-memory sort never touches disk.
Sourcepub fn with_temp_dir(plan: SortPlan, temp_root: &Path, dedup: bool) -> Self
pub fn with_temp_dir(plan: SortPlan, temp_root: &Path, dedup: bool) -> Self
Open an ungoverned session under a freshly-minted unique directory
beneath temp_root. For tests and callers that run without a
governor; the engine stays bounded and async regardless.
Sourcepub fn hold_resource(self, resource: Box<dyn Send>) -> Self
pub fn hold_resource(self, resource: Box<dyn Send>) -> Self
Attach an opaque resource (typically the admission lease) to be held alive for as long as this sort’s output stream — so the fd permits backing the sort are released only once its results are consumed.
Sourcepub fn scratch_dir(&self) -> &Path
pub fn scratch_dir(&self) -> &Path
The unique scratch directory this sort spills into (created lazily on the first spill, removed when the output stream is dropped).
Sourcepub async fn push_with_size(
&mut self,
key: K,
value: V,
estimated_bytes: usize,
) -> Result<(), SorterError>
pub async fn push_with_size( &mut self, key: K, value: V, estimated_bytes: usize, ) -> Result<(), SorterError>
Push one row, sized with a caller estimate. Spills the current run first when adding this row would overflow the plan’s run buffer.
§Errors
Returns SorterError if spilling the current run fails. A failed
or cancelled spill invalidates the session; subsequent pushes and
Self::finish fail instead of yielding incomplete results.
Sourcepub async fn push(&mut self, key: K, value: V) -> Result<(), SorterError>
pub async fn push(&mut self, key: K, value: V) -> Result<(), SorterError>
Push one row using a conservative fixed size estimate.
§Errors
Returns SorterError if spilling the current run fails.
Sourcepub async fn finish(
self,
) -> Result<Pin<Box<dyn Stream<Item = Result<V, SorterError>> + Send>>, SorterError>
pub async fn finish( self, ) -> Result<Pin<Box<dyn Stream<Item = Result<V, SorterError>> + Send>>, SorterError>
Finish the sort, returning a stream of values in key order.
§Errors
Returns SorterError if a final spill or the merge setup fails.