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

refactor(rust): Don't pickle entire python function for object store keying #19340

Merged
Merged
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
8 changes: 8 additions & 0 deletions crates/polars-io/src/cloud/credential_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ impl PlCredentialProvider {
PythonFunction(func),
)))
}

pub(super) fn func_addr(&self) -> usize {
match self {
Self::Function(CredentialProviderFunction(v)) => Arc::as_ptr(v) as *const () as usize,
#[cfg(feature = "python")]
Self::Python(PythonCredentialProvider(v)) => Arc::as_ptr(v) as *const () as usize,
}
}
}

pub enum ObjectStoreCredential {
Expand Down
35 changes: 33 additions & 2 deletions crates/polars-io/src/cloud/object_store_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use tokio::sync::RwLock;
use url::Url;

use super::{parse_url, CloudLocation, CloudOptions, CloudType};
use crate::cloud::CloudConfig;

/// Object stores must be cached. Every object-store will do DNS lookups and
/// get rate limited when querying the DNS (can take up to 5s).
Expand All @@ -29,10 +30,40 @@ fn err_missing_feature(feature: &str, scheme: &str) -> BuildResult {
}

/// Get the key of a url for object store registration.
/// The credential info will be removed
fn url_and_creds_to_key(url: &Url, options: Option<&CloudOptions>) -> String {
#[derive(Clone, Debug, PartialEq, Hash, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
struct S {
max_retries: usize,
#[cfg(feature = "file_cache")]
file_cache_ttl: u64,
config: Option<CloudConfig>,
#[cfg(feature = "cloud")]
credential_provider: usize,
}

// We include credentials as they can expire, so users will send new credentials for the same url.
let creds = serde_json::to_string(&options).unwrap_or_else(|_| "".into());
let creds = serde_json::to_string(&options.map(
|CloudOptions {
// Destructure to ensure this breaks if anything changes.
max_retries,
#[cfg(feature = "file_cache")]
file_cache_ttl,
config,
#[cfg(feature = "cloud")]
credential_provider,
}| {
S {
max_retries: *max_retries,
#[cfg(feature = "file_cache")]
file_cache_ttl: *file_cache_ttl,
config: config.clone(),
#[cfg(feature = "cloud")]
credential_provider: credential_provider.as_ref().map_or(0, |x| x.func_addr()),
}
},
))
.unwrap();
format!(
"{}://{}<\\creds\\>{}",
url.scheme(),
Expand Down
Loading