Skip to content

Commit

Permalink
Fix allocation failures during sorting with spill-to-disk
Browse files Browse the repository at this point in the history
This change replaces `try_resize` with `resize` in three sites, allowing memory
to overshoot the configured pool size. These are sites where we don't fall back
to spilling to disk when the allocation fails.

Fixes: apache#12136
  • Loading branch information
cjolowicz committed Sep 2, 2024
1 parent 8fd129f commit b0a921d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
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
3 changes: 2 additions & 1 deletion datafusion/physical-plan/src/sorts/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,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

0 comments on commit b0a921d

Please sign in to comment.