jdrouet commented on code in PR #16191:
URL: https://github.com/apache/datafusion/pull/16191#discussion_r2111306335
##########
datafusion/execution/src/disk_manager.rs:
##########
@@ -32,6 +32,92 @@ use crate::memory_pool::human_readable_size;
const DEFAULT_MAX_TEMP_DIRECTORY_SIZE: u64 = 100 * 1024 * 1024 * 1024; // 100GB
+/// Builder pattern for the [DiskManager] structure
+#[derive(Clone, Debug)]
+pub struct DiskManagerBuilder {
+ /// The storage mode of the disk manager
+ mode: DiskManagerMode,
+ /// The maximum amount of data (in bytes) stored inside the temporary
directories.
+ /// Default to 100GB
+ max_temp_directory_size: u64,
+}
+
+impl Default for DiskManagerBuilder {
+ fn default() -> Self {
+ Self {
+ mode: DiskManagerMode::OsTmpDirectory,
+ max_temp_directory_size: DEFAULT_MAX_TEMP_DIRECTORY_SIZE,
+ }
+ }
+}
+
+impl DiskManagerBuilder {
+ pub fn set_mode(&mut self, mode: DiskManagerMode) {
+ self.mode = mode;
+ }
+
+ pub fn with_mode(mut self, mode: DiskManagerMode) -> Self {
+ self.set_mode(mode);
+ self
+ }
+
+ pub fn set_max_temp_directory_size(&mut self, value: u64) {
+ self.max_temp_directory_size = value;
+ }
+
+ pub fn with_max_temp_directory_size(mut self, value: u64) -> Self {
+ self.set_max_temp_directory_size(value);
+ self
+ }
+
+ /// Create a DiskManager given the builder
+ pub fn build(self) -> Result<DiskManager> {
+ match self.mode {
+ DiskManagerMode::OsTmpDirectory => Ok(DiskManager {
+ local_dirs: Mutex::new(Some(vec![])),
+ max_temp_directory_size: self.max_temp_directory_size,
+ used_disk_space: Arc::new(AtomicU64::new(0)),
+ }),
+ DiskManagerMode::Directories(conf_dirs) => {
+ let local_dirs = create_local_dirs(conf_dirs)?;
+ debug!(
+ "Created local dirs {local_dirs:?} as DataFusion working
directory"
+ );
+ Ok(DiskManager {
+ local_dirs: Mutex::new(Some(local_dirs)),
+ max_temp_directory_size: self.max_temp_directory_size,
+ used_disk_space: Arc::new(AtomicU64::new(0)),
+ })
+ }
+ DiskManagerMode::Disabled => Ok(DiskManager {
+ local_dirs: Mutex::new(None),
+ max_temp_directory_size: self.max_temp_directory_size,
+ used_disk_space: Arc::new(AtomicU64::new(0)),
+ }),
+ }
+ }
+}
+
+#[derive(Clone, Debug)]
+pub enum DiskManagerMode {
+ /// Create a new [DiskManager] that creates temporary files within
+ /// a temporary directory chosen by the OS
+ OsTmpDirectory,
+
+ /// Create a new [DiskManager] that creates temporary files within
+ /// the specified directories
Review Comment:
addressed in
https://github.com/apache/datafusion/pull/16191/commits/fa4552a010c71526115e5e08dd1165da3d400351
--
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]