Skip to content

Commit

Permalink
Introduce resources_err! error macro (#11374)
Browse files Browse the repository at this point in the history
  • Loading branch information
comphead authored Jul 10, 2024
1 parent d99002c commit b96186f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
3 changes: 3 additions & 0 deletions datafusion/common/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,9 @@ make_error!(config_err, config_datafusion_err, Configuration);
// Exposes a macro to create `DataFusionError::Substrait` with optional backtrace
make_error!(substrait_err, substrait_datafusion_err, Substrait);

// Exposes a macro to create `DataFusionError::ResourcesExhausted` with optional backtrace
make_error!(resources_err, resources_datafusion_err, ResourcesExhausted);

// Exposes a macro to create `DataFusionError::SQL` with optional backtrace
#[macro_export]
macro_rules! sql_datafusion_err {
Expand Down
6 changes: 3 additions & 3 deletions datafusion/execution/src/disk_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
//! Manages files generated during query execution, files are
//! hashed among the directories listed in RuntimeConfig::local_dirs.
use datafusion_common::{DataFusionError, Result};
use datafusion_common::{resources_datafusion_err, DataFusionError, Result};
use log::debug;
use parking_lot::Mutex;
use rand::{thread_rng, Rng};
Expand Down Expand Up @@ -119,9 +119,9 @@ impl DiskManager {
) -> Result<RefCountedTempFile> {
let mut guard = self.local_dirs.lock();
let local_dirs = guard.as_mut().ok_or_else(|| {
DataFusionError::ResourcesExhausted(format!(
resources_datafusion_err!(
"Memory Exhausted while {request_description} (DiskManager is disabled)"
))
)
})?;

// Create a temporary directory if needed
Expand Down
5 changes: 3 additions & 2 deletions datafusion/execution/src/memory_pool/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// under the License.

use crate::memory_pool::{MemoryConsumer, MemoryPool, MemoryReservation};
use datafusion_common::{DataFusionError, Result};
use datafusion_common::{resources_datafusion_err, DataFusionError, Result};
use log::debug;
use parking_lot::Mutex;
use std::sync::atomic::{AtomicUsize, Ordering};
Expand Down Expand Up @@ -231,12 +231,13 @@ impl MemoryPool for FairSpillPool {
}
}

#[inline(always)]
fn insufficient_capacity_err(
reservation: &MemoryReservation,
additional: usize,
available: usize,
) -> DataFusionError {
DataFusionError::ResourcesExhausted(format!("Failed to allocate additional {} bytes for {} with {} bytes already allocated - maximum available is {}", additional, reservation.registration.consumer.name, reservation.size, available))
resources_datafusion_err!("Failed to allocate additional {} bytes for {} with {} bytes already allocated - maximum available is {}", additional, reservation.registration.consumer.name, reservation.size, available)
}

#[cfg(test)]
Expand Down

0 comments on commit b96186f

Please sign in to comment.