zhuqi-lucas commented on code in PR #16191:
URL: https://github.com/apache/datafusion/pull/16191#discussion_r2113090658


##########
datafusion/execution/src/disk_manager.rs:
##########
@@ -32,7 +32,95 @@ 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)),

Review Comment:
   Thanks , got it!



-- 
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: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to