Skip to content
Merged
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
28 changes: 26 additions & 2 deletions rust/lance-datafusion/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ pub type ExecutionStatsCallback = Arc<dyn Fn(&ExecutionSummaryCounts) + Send + S
pub struct LanceExecutionOptions {
pub use_spilling: bool,
pub mem_pool_size: Option<u64>,
pub max_temp_directory_size: Option<u64>,
pub batch_size: Option<usize>,
pub target_partition: Option<usize>,
pub execution_stats_callback: Option<ExecutionStatsCallback>,
Expand All @@ -300,6 +301,7 @@ impl std::fmt::Debug for LanceExecutionOptions {
f.debug_struct("LanceExecutionOptions")
.field("use_spilling", &self.use_spilling)
.field("mem_pool_size", &self.mem_pool_size)
.field("max_temp_directory_size", &self.max_temp_directory_size)
.field("batch_size", &self.batch_size)
.field("target_partition", &self.target_partition)
.field("skip_logging", &self.skip_logging)
Expand All @@ -312,6 +314,7 @@ impl std::fmt::Debug for LanceExecutionOptions {
}

const DEFAULT_LANCE_MEM_POOL_SIZE: u64 = 100 * 1024 * 1024;
const DEFAULT_LANCE_MAX_TEMP_DIRECTORY_SIZE: u64 = 100 * 1024 * 1024 * 1024; // 100GB

impl LanceExecutionOptions {
pub fn mem_pool_size(&self) -> u64 {
Expand All @@ -328,6 +331,23 @@ impl LanceExecutionOptions {
})
}

pub fn max_temp_directory_size(&self) -> u64 {
self.max_temp_directory_size.unwrap_or_else(|| {
std::env::var("LANCE_MAX_TEMP_DIRECTORY_SIZE")
.map(|s| match s.parse::<u64>() {
Ok(v) => v,
Err(e) => {
warn!(
"Failed to parse LANCE_MAX_TEMP_DIRECTORY_SIZE: {}, using default",
e
);
DEFAULT_LANCE_MAX_TEMP_DIRECTORY_SIZE
}
})
.unwrap_or(DEFAULT_LANCE_MAX_TEMP_DIRECTORY_SIZE)
})
}

pub fn use_spilling(&self) -> bool {
if !self.use_spilling {
return false;
Expand All @@ -348,8 +368,10 @@ pub fn new_session_context(options: &LanceExecutionOptions) -> SessionContext {
session_config = session_config.with_target_partitions(target_partition);
}
if options.use_spilling() {
let disk_manager_builder = DiskManagerBuilder::default()
.with_max_temp_directory_size(options.max_temp_directory_size());
runtime_env_builder = runtime_env_builder
.with_disk_manager_builder(DiskManagerBuilder::default())
.with_disk_manager_builder(disk_manager_builder)
.with_memory_pool(Arc::new(FairSpillPool::new(
options.mem_pool_size() as usize
)));
Expand All @@ -373,7 +395,9 @@ static DEFAULT_SESSION_CONTEXT_WITH_SPILLING: LazyLock<SessionContext> = LazyLoc
});

pub fn get_session_context(options: &LanceExecutionOptions) -> SessionContext {
if options.mem_pool_size() == DEFAULT_LANCE_MEM_POOL_SIZE && options.target_partition.is_none()
if options.mem_pool_size() == DEFAULT_LANCE_MEM_POOL_SIZE
&& options.max_temp_directory_size() == DEFAULT_LANCE_MAX_TEMP_DIRECTORY_SIZE
&& options.target_partition.is_none()
{
return if options.use_spilling() {
DEFAULT_SESSION_CONTEXT_WITH_SPILLING.clone()
Expand Down
Loading