Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix allocation failures during sorting with spill-to-disk #12288

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion datafusion/physical-plan/src/sorts/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ impl BatchBuilder {

/// Append a new batch in `stream_idx`
pub fn push_batch(&mut self, stream_idx: usize, batch: RecordBatch) -> Result<()> {
self.reservation.try_grow(batch.get_array_memory_size())?;
// Allow memory to exceed the limit
self.reservation.grow(batch.get_array_memory_size());
let batch_idx = self.batches.len();
self.batches.push((stream_idx, batch));
self.cursors[stream_idx] = BatchCursor {
Expand Down
6 changes: 4 additions & 2 deletions datafusion/physical-plan/src/sorts/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,8 @@ impl ExternalSorter {
// Reserve headroom for next sort/merge
self.reserve_memory_for_merge()?;

self.reservation.try_resize(size)?;
// Allow memory to exceed limit temporarily before spill
self.reservation.resize(size);
self.in_mem_batches_sorted = true;
Ok(())
}
Expand Down Expand Up @@ -579,7 +580,8 @@ impl ExternalSorter {
if self.runtime.disk_manager.tmp_files_enabled() {
let size = self.sort_spill_reservation_bytes;
if self.merge_reservation.size() != size {
self.merge_reservation.try_resize(size)?;
// Allow memory to exceed the limit
self.merge_reservation.resize(size);
}
}

Expand Down
Loading