Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add env var to ignore file cache allocate error #20356

Merged
merged 6 commits into from
Dec 19, 2024
Merged
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
34 changes: 30 additions & 4 deletions crates/polars-io/src/file_cache/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::sync::atomic::AtomicU64;
use std::sync::{Arc, Mutex};

use fs4::fs_std::FileExt;
use once_cell::sync::Lazy;
use polars_core::config;
use polars_error::{polars_bail, to_compute_err, PolarsError, PolarsResult};

Expand Down Expand Up @@ -151,13 +152,38 @@ impl Inner {
.truncate(true)
.open(data_file_path)
.map_err(PolarsError::from)?;

static IGNORE_ERR: Lazy<bool> = Lazy::new(|| {
let v =
std::env::var("POLARS_IGNORE_FILE_CACHE_ALLOCATE_ERROR").as_deref() == Ok("1");
if config::verbose() {
eprintln!(
"[file_cache]: POLARS_IGNORE_FILE_CACHE_ALLOCATE_ERROR: {}",
v
);
}
v
});

// Initialize it to get the verbose print
let _ = *IGNORE_ERR;

file.lock_exclusive().unwrap();
if file.allocate(remote_metadata.size).is_err() {
polars_bail!(
ComputeError: "failed to allocate {} bytes to download uri = {}",
if let Err(e) = file.allocate(remote_metadata.size) {
let msg = format!(
"failed to reserve {} bytes on disk to download uri = {}: {:?}",
remote_metadata.size,
self.uri.as_ref()
self.uri.as_ref(),
e
);

if *IGNORE_ERR {
if config::verbose() {
eprintln!("[file_cache]: warning: {}", msg)
}
} else {
polars_bail!(ComputeError: msg);
}
}
}
self.file_fetcher.fetch(data_file_path)?;
Expand Down
Loading