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

fix: Ignore file cache allocation error if fallocate() is not permitted #20796

Merged
merged 3 commits into from
Jan 20, 2025
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
35 changes: 21 additions & 14 deletions crates/polars-io/src/file_cache/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,20 +153,27 @@ impl Inner {
.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: {}",
// * Some(true) => always raise
// * Some(false) => never raise
// * None => do not raise if fallocate() is not permitted, otherwise raise.
static RAISE_ALLOC_ERROR: Lazy<Option<bool>> = Lazy::new(|| {
let v = match std::env::var("POLARS_IGNORE_FILE_CACHE_ALLOCATE_ERROR").as_deref() {
Ok("1") => Some(false),
Ok("0") => Some(true),
Err(_) => None,
Ok(v) => panic!(
"invalid value {} for POLARS_IGNORE_FILE_CACHE_ALLOCATE_ERROR",
v
);
),
};
if config::verbose() {
eprintln!("[file_cache]: RAISE_ALLOC_ERROR: {:?}", v);
}
v
});

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

file.lock_exclusive().unwrap();
if let Err(e) = file.allocate(remote_metadata.size) {
Expand All @@ -177,12 +184,12 @@ impl Inner {
e
);

if *IGNORE_ERR {
if config::verbose() {
eprintln!("[file_cache]: warning: {}", msg)
}
} else {
polars_bail!(ComputeError: msg);
if raise_alloc_err == Some(true)
|| (raise_alloc_err.is_none() && file.allocate(1).is_ok())
{
polars_bail!(ComputeError: msg)
} else if config::verbose() {
eprintln!("[file_cache]: warning: {}", msg)
}
}
}
Expand Down
Loading