MCPcopy Create free account
hub / github.com/apache/datafusion / create_tmp_file

Method create_tmp_file

datafusion/execution/src/disk_manager.rs:304–340  ·  view source on GitHub ↗

Return a temporary file from a randomized choice in the configured locations If the file can not be created for some reason, returns an error message referencing the request description

(
        self: &Arc<Self>,
        request_description: &str,
    )

Source from the content-addressed store, hash-verified

302 /// If the file can not be created for some reason, returns an
303 /// error message referencing the request description
304 pub fn create_tmp_file(
305 self: &Arc<Self>,
306 request_description: &str,
307 ) -> Result<RefCountedTempFile> {
308 let mut guard = self.local_dirs.lock();
309 let local_dirs = guard.as_mut().ok_or_else(|| {
310 resources_datafusion_err!(
311 "Memory Exhausted while {request_description} (DiskManager is disabled)"
312 )
313 })?;
314
315 // Create a temporary directory if needed
316 if local_dirs.is_empty() {
317 let tempdir = tempfile::tempdir().map_err(DataFusionError::IoError)?;
318
319 debug!(
320 "Created directory '{:?}' as DataFusion tempfile directory for {}",
321 tempdir.path().to_string_lossy(),
322 request_description,
323 );
324
325 local_dirs.push(Arc::new(tempdir));
326 }
327
328 let dir_index = rng().random_range(0..local_dirs.len());
329 self.active_files_count.fetch_add(1, Ordering::Relaxed);
330 Ok(RefCountedTempFile {
331 parent_temp_dir: Arc::clone(&local_dirs[dir_index]),
332 tempfile: Arc::new(
333 Builder::new()
334 .tempfile_in(local_dirs[dir_index].as_ref())
335 .map_err(DataFusionError::IoError)?,
336 ),
337 current_file_disk_usage: Arc::new(AtomicU64::new(0)),
338 disk_manager: Arc::clone(self),
339 })
340 }
341}
342
343/// A wrapper around a [`NamedTempFile`] that also contains

Calls 5

newFunction · 0.85
is_emptyMethod · 0.45
pushMethod · 0.45
lenMethod · 0.45
as_refMethod · 0.45