kazuyukitanimura commented on code in PR #7066: URL: https://github.com/apache/datafusion-comet/pull/7066#discussion_r4317091592
########## native/core/src/execution/spill_dirs.rs: ########## @@ -0,0 +1,133 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//! The spill directories of a native plan. +//! +//! A [`DiskManager`] in `Directories` mode creates a `datafusion-*` directory in every local +//! directory as soon as it is built, and removes it recursively when it is dropped. Each native +//! plan has its own `DiskManager`, so building one in that mode costs a `stat` and a `mkdir` per +//! local directory when the plan is created, and a recursive delete when it is released, even if +//! the plan never spills (#7060). The plan's disk manager built here creates that `Directories` +//! mode `DiskManager` on the plan's first spill instead, so a plan that never spills touches no +//! directories, and a plan that spills gets the same directories, size limit and cleanup as +//! before. + +use datafusion::common::Result; +use datafusion::execution::disk_manager::{DiskManager, DiskManagerBuilder, DiskManagerMode}; +use datafusion::execution::{SpillFile, TempFileFactory}; +use parking_lot::Mutex; +use std::path::PathBuf; +use std::sync::Arc; + +/// Returns the builder of a native plan's [`DiskManager`], which spills into a directory in each +/// of `local_dirs` and limits the plan's spill files to `max_temp_directory_size` bytes in total. +pub(crate) fn plan_disk_manager( + local_dirs: Vec<PathBuf>, + max_temp_directory_size: u64, +) -> DiskManagerBuilder { + let builder = DiskManagerBuilder::default() + .with_mode(DiskManagerMode::Directories(local_dirs)) + .with_max_temp_directory_size(max_temp_directory_size); + DiskManagerBuilder::default() + .with_temp_file_factory(Arc::new(LazyDiskManager { + builder, + disk_manager: Mutex::new(None), + })) + .with_max_temp_directory_size(max_temp_directory_size) Review Comment: Thanks for reworking this. Going through TempFileFactory keeps the limit, the accounting and the cleanup exactly as on main. I agree with viirya's comment here. I'd add two sentences to this doc comment. One should say that the outer manager only carries the factory, so its used_disk_space and spilling_progress() stay at 0 and its max_temp_directory_size is never checked. The second should say that the inner manager holds the limit and the accounting. A link to apache/datafusion#26446 would also tell the next reader when the factory can be removed. I checked 55.2 and nothing enforces on the outer manager today. The only readers I found are RuntimeEnv's reporting code at runtime_env.rs:229 and :289. A later RuntimeEnvBuilder::with_max_temp_directory_size call would silently do nothing, though. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
