Skip to content
Draft
Show file tree
Hide file tree
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
13 changes: 12 additions & 1 deletion datafusion/execution/src/disk_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use rand::{rng, Rng};
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::Arc;
use tempfile::{Builder, NamedTempFile, TempDir};
use tempfile::{Builder, NamedTempFile, TempDir, TempPath};

use crate::memory_pool::human_readable_size;

Expand Down Expand Up @@ -370,6 +370,17 @@ impl RefCountedTempFile {
pub fn current_disk_usage(&self) -> u64 {
self.current_file_disk_usage
}

pub fn clone_refcounted(&self) -> Result<Self> {
let reopened = std::fs::File::open(self.path())?;
let temp_path = TempPath::from_path(self.path());
Ok(Self {
_parent_temp_dir: Arc::clone(&self._parent_temp_dir),
tempfile: NamedTempFile::from_parts(reopened, temp_path),
current_file_disk_usage: self.current_file_disk_usage,
disk_manager: Arc::clone(&self.disk_manager),
})
}
}

/// When the temporary file is dropped, subtract its disk usage from the disk manager's total
Expand Down
Loading
Loading