Skip to content

Commit 5e9641c

Browse files
committed
refactor(storage-opendal): rename the client field to client_config
`client` reads like an HTTP client handle. Rename the field on every `OpenDalStorage` variant, and the `OpenDalStorage::client()` accessor, to `client_config` to match `OpenDalClientConfig`. `opendal_config` would be ambiguous next to the backend `config` field, which holds an OpenDAL config too. `test_default_io_timeout_matches_opendal` compares `Debug` output. Both sides go through the same derived impl, so a format change cannot make them differ. A `Debug` that stopped printing `io_timeout` would make the check pass vacuously, so also assert that a different `io_timeout` produces a different string.
1 parent 3a3df73 commit 5e9641c

3 files changed

Lines changed: 66 additions & 60 deletions

File tree

‎crates/storage/opendal/public-api.txt‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,28 @@ pub use iceberg_storage_opendal::AwsCredential
33
pub use iceberg_storage_opendal::ProvideCredential
44
pub enum iceberg_storage_opendal::OpenDalStorage
55
pub iceberg_storage_opendal::OpenDalStorage::Azdls
6-
pub iceberg_storage_opendal::OpenDalStorage::Azdls::client: iceberg_storage_opendal::OpenDalClientConfig
6+
pub iceberg_storage_opendal::OpenDalStorage::Azdls::client_config: iceberg_storage_opendal::OpenDalClientConfig
77
pub iceberg_storage_opendal::OpenDalStorage::Azdls::config: alloc::sync::Arc<opendal_service_azdls::config::AzdlsConfig>
88
pub iceberg_storage_opendal::OpenDalStorage::Gcs
9-
pub iceberg_storage_opendal::OpenDalStorage::Gcs::client: iceberg_storage_opendal::OpenDalClientConfig
9+
pub iceberg_storage_opendal::OpenDalStorage::Gcs::client_config: iceberg_storage_opendal::OpenDalClientConfig
1010
pub iceberg_storage_opendal::OpenDalStorage::Gcs::config: alloc::sync::Arc<opendal_service_gcs::config::GcsConfig>
1111
pub iceberg_storage_opendal::OpenDalStorage::Hf
12-
pub iceberg_storage_opendal::OpenDalStorage::Hf::client: iceberg_storage_opendal::OpenDalClientConfig
12+
pub iceberg_storage_opendal::OpenDalStorage::Hf::client_config: iceberg_storage_opendal::OpenDalClientConfig
1313
pub iceberg_storage_opendal::OpenDalStorage::Hf::config: alloc::sync::Arc<opendal_service_hf::config::HfConfig>
1414
pub iceberg_storage_opendal::OpenDalStorage::LocalFs
15-
pub iceberg_storage_opendal::OpenDalStorage::LocalFs::client: iceberg_storage_opendal::OpenDalClientConfig
15+
pub iceberg_storage_opendal::OpenDalStorage::LocalFs::client_config: iceberg_storage_opendal::OpenDalClientConfig
1616
pub iceberg_storage_opendal::OpenDalStorage::Memory
17-
pub iceberg_storage_opendal::OpenDalStorage::Memory::client: iceberg_storage_opendal::OpenDalClientConfig
17+
pub iceberg_storage_opendal::OpenDalStorage::Memory::client_config: iceberg_storage_opendal::OpenDalClientConfig
1818
pub iceberg_storage_opendal::OpenDalStorage::Memory::operator: opendal_core::types::operator::operator::Operator
1919
pub iceberg_storage_opendal::OpenDalStorage::Oss
20-
pub iceberg_storage_opendal::OpenDalStorage::Oss::client: iceberg_storage_opendal::OpenDalClientConfig
20+
pub iceberg_storage_opendal::OpenDalStorage::Oss::client_config: iceberg_storage_opendal::OpenDalClientConfig
2121
pub iceberg_storage_opendal::OpenDalStorage::Oss::config: alloc::sync::Arc<opendal_service_oss::config::OssConfig>
2222
pub iceberg_storage_opendal::OpenDalStorage::S3
23-
pub iceberg_storage_opendal::OpenDalStorage::S3::client: iceberg_storage_opendal::OpenDalClientConfig
23+
pub iceberg_storage_opendal::OpenDalStorage::S3::client_config: iceberg_storage_opendal::OpenDalClientConfig
2424
pub iceberg_storage_opendal::OpenDalStorage::S3::config: alloc::sync::Arc<opendal_service_s3::config::S3Config>
2525
pub iceberg_storage_opendal::OpenDalStorage::S3::customized_credential_load: core::option::Option<iceberg_storage_opendal::CustomAwsCredentialLoader>
2626
impl iceberg_storage_opendal::OpenDalStorage
27-
pub fn iceberg_storage_opendal::OpenDalStorage::client(&self) -> &iceberg_storage_opendal::OpenDalClientConfig
27+
pub fn iceberg_storage_opendal::OpenDalStorage::client_config(&self) -> &iceberg_storage_opendal::OpenDalClientConfig
2828
impl core::clone::Clone for iceberg_storage_opendal::OpenDalStorage
2929
pub fn iceberg_storage_opendal::OpenDalStorage::clone(&self) -> iceberg_storage_opendal::OpenDalStorage
3030
impl core::fmt::Debug for iceberg_storage_opendal::OpenDalStorage

‎crates/storage/opendal/src/lib.rs‎

Lines changed: 49 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -214,42 +214,42 @@ where
214214
impl StorageFactory for OpenDalStorageFactory {
215215
#[allow(unused_variables)]
216216
fn build(&self, config: &StorageConfig) -> Result<Arc<dyn Storage>> {
217-
let client = OpenDalClientConfig::from_properties(config.props())?;
217+
let client_config = OpenDalClientConfig::from_properties(config.props())?;
218218
match self {
219219
#[cfg(feature = "opendal-memory")]
220220
OpenDalStorageFactory::Memory => Ok(Arc::new(OpenDalStorage::Memory {
221221
operator: memory_config_build()?,
222-
client,
222+
client_config,
223223
})),
224224
#[cfg(feature = "opendal-fs")]
225-
OpenDalStorageFactory::Fs => Ok(Arc::new(OpenDalStorage::LocalFs { client })),
225+
OpenDalStorageFactory::Fs => Ok(Arc::new(OpenDalStorage::LocalFs { client_config })),
226226
#[cfg(feature = "opendal-s3")]
227227
OpenDalStorageFactory::S3 {
228228
customized_credential_load,
229229
} => Ok(Arc::new(OpenDalStorage::S3 {
230230
config: s3_config_parse(config.props().clone())?.into(),
231231
customized_credential_load: customized_credential_load.clone(),
232-
client,
232+
client_config,
233233
})),
234234
#[cfg(feature = "opendal-gcs")]
235235
OpenDalStorageFactory::Gcs => Ok(Arc::new(OpenDalStorage::Gcs {
236236
config: gcs_config_parse(config.props().clone())?.into(),
237-
client,
237+
client_config,
238238
})),
239239
#[cfg(feature = "opendal-oss")]
240240
OpenDalStorageFactory::Oss => Ok(Arc::new(OpenDalStorage::Oss {
241241
config: oss_config_parse(config.props().clone())?.into(),
242-
client,
242+
client_config,
243243
})),
244244
#[cfg(feature = "opendal-azdls")]
245245
OpenDalStorageFactory::Azdls => Ok(Arc::new(OpenDalStorage::Azdls {
246246
config: azdls_config_parse(config.props().clone())?.into(),
247-
client,
247+
client_config,
248248
})),
249249
#[cfg(feature = "opendal-hf")]
250250
OpenDalStorageFactory::Hf => Ok(Arc::new(OpenDalStorage::Hf {
251251
config: hf_config_parse(config.props().clone())?.into(),
252-
client,
252+
client_config,
253253
})),
254254
#[cfg(all(
255255
not(feature = "opendal-memory"),
@@ -285,14 +285,14 @@ pub enum OpenDalStorage {
285285
operator: Operator,
286286
/// Backend-independent client settings.
287287
#[serde(default)]
288-
client: OpenDalClientConfig,
288+
client_config: OpenDalClientConfig,
289289
},
290290
/// Local filesystem storage variant.
291291
#[cfg(feature = "opendal-fs")]
292292
LocalFs {
293293
/// Backend-independent client settings.
294294
#[serde(default)]
295-
client: OpenDalClientConfig,
295+
client_config: OpenDalClientConfig,
296296
},
297297
/// S3 storage variant.
298298
///
@@ -307,7 +307,7 @@ pub enum OpenDalStorage {
307307
customized_credential_load: Option<CustomAwsCredentialLoader>,
308308
/// Backend-independent client settings.
309309
#[serde(default)]
310-
client: OpenDalClientConfig,
310+
client_config: OpenDalClientConfig,
311311
},
312312
/// GCS storage variant.
313313
#[cfg(feature = "opendal-gcs")]
@@ -316,7 +316,7 @@ pub enum OpenDalStorage {
316316
config: Arc<GcsConfig>,
317317
/// Backend-independent client settings.
318318
#[serde(default)]
319-
client: OpenDalClientConfig,
319+
client_config: OpenDalClientConfig,
320320
},
321321
/// OSS storage variant.
322322
#[cfg(feature = "opendal-oss")]
@@ -325,7 +325,7 @@ pub enum OpenDalStorage {
325325
config: Arc<OssConfig>,
326326
/// Backend-independent client settings.
327327
#[serde(default)]
328-
client: OpenDalClientConfig,
328+
client_config: OpenDalClientConfig,
329329
},
330330
/// Azure Data Lake Storage variant.
331331
///
@@ -339,7 +339,7 @@ pub enum OpenDalStorage {
339339
config: Arc<AzdlsConfig>,
340340
/// Backend-independent client settings.
341341
#[serde(default)]
342-
client: OpenDalClientConfig,
342+
client_config: OpenDalClientConfig,
343343
},
344344
/// HuggingFace Hub storage variant.
345345
///
@@ -352,7 +352,7 @@ pub enum OpenDalStorage {
352352
config: Arc<HfConfig>,
353353
/// Backend-independent client settings.
354354
#[serde(default)]
355-
client: OpenDalClientConfig,
355+
client_config: OpenDalClientConfig,
356356
},
357357
}
358358

@@ -479,29 +479,29 @@ impl OpenDalStorage {
479479
let operator = operator
480480
.layer(
481481
TimeoutLayer::new()
482-
.with_io_timeout(Duration::from_millis(self.client().io_timeout_ms())),
482+
.with_io_timeout(Duration::from_millis(self.client_config().io_timeout_ms())),
483483
)
484484
.layer(RetryLayer::new());
485485
Ok((operator, relative_path))
486486
}
487487

488488
/// Client settings for this backend.
489-
pub fn client(&self) -> &OpenDalClientConfig {
489+
pub fn client_config(&self) -> &OpenDalClientConfig {
490490
match self {
491491
#[cfg(feature = "opendal-memory")]
492-
OpenDalStorage::Memory { client, .. } => client,
492+
OpenDalStorage::Memory { client_config, .. } => client_config,
493493
#[cfg(feature = "opendal-fs")]
494-
OpenDalStorage::LocalFs { client } => client,
494+
OpenDalStorage::LocalFs { client_config } => client_config,
495495
#[cfg(feature = "opendal-s3")]
496-
OpenDalStorage::S3 { client, .. } => client,
496+
OpenDalStorage::S3 { client_config, .. } => client_config,
497497
#[cfg(feature = "opendal-gcs")]
498-
OpenDalStorage::Gcs { client, .. } => client,
498+
OpenDalStorage::Gcs { client_config, .. } => client_config,
499499
#[cfg(feature = "opendal-oss")]
500-
OpenDalStorage::Oss { client, .. } => client,
500+
OpenDalStorage::Oss { client_config, .. } => client_config,
501501
#[cfg(feature = "opendal-azdls")]
502-
OpenDalStorage::Azdls { client, .. } => client,
502+
OpenDalStorage::Azdls { client_config, .. } => client_config,
503503
#[cfg(feature = "opendal-hf")]
504-
OpenDalStorage::Hf { client, .. } => client,
504+
OpenDalStorage::Hf { client_config, .. } => client_config,
505505
// Only compiled when every backend feature is off and the enum has no variants.
506506
// Gating it this way makes a new variant without an arm a compile error.
507507
#[cfg(all(
@@ -835,13 +835,16 @@ mod tests {
835835
fn test_default_io_timeout_matches_opendal() {
836836
// `TimeoutLayer` has no getters, so compare through `Debug`. An OpenDAL upgrade that
837837
// changes its default fails here instead of silently diverging from it.
838-
assert_eq!(
839-
format!("{:?}", TimeoutLayer::new()),
838+
let opendal_default = format!("{:?}", TimeoutLayer::new());
839+
let with_io_timeout = |ms| {
840840
format!(
841841
"{:?}",
842-
TimeoutLayer::new().with_io_timeout(Duration::from_millis(DEFAULT_IO_TIMEOUT_MS))
843-
),
844-
);
842+
TimeoutLayer::new().with_io_timeout(Duration::from_millis(ms))
843+
)
844+
};
845+
assert_eq!(opendal_default, with_io_timeout(DEFAULT_IO_TIMEOUT_MS));
846+
// If `Debug` stopped printing `io_timeout`, the check above would pass vacuously.
847+
assert_ne!(opendal_default, with_io_timeout(DEFAULT_IO_TIMEOUT_MS + 1));
845848
}
846849

847850
#[cfg(feature = "opendal-s3")]
@@ -850,17 +853,20 @@ mod tests {
850853
let storage = OpenDalStorage::S3 {
851854
config: Arc::new(S3Config::default()),
852855
customized_credential_load: None,
853-
client: client_config("45000").unwrap(),
856+
client_config: client_config("45000").unwrap(),
854857
};
855858

856859
let mut value = serde_json::to_value(&storage).unwrap();
857860
let restored: OpenDalStorage = serde_json::from_value(value.clone()).unwrap();
858-
assert_eq!(restored.client().io_timeout_ms(), 45_000);
861+
assert_eq!(restored.client_config().io_timeout_ms(), 45_000);
859862

860-
// A payload without `client` falls back to the default.
861-
value["S3"].as_object_mut().unwrap().remove("client");
863+
// A payload without `client_config` falls back to the default.
864+
value["S3"].as_object_mut().unwrap().remove("client_config");
862865
let restored: OpenDalStorage = serde_json::from_value(value).unwrap();
863-
assert_eq!(restored.client().io_timeout_ms(), DEFAULT_IO_TIMEOUT_MS);
866+
assert_eq!(
867+
restored.client_config().io_timeout_ms(),
868+
DEFAULT_IO_TIMEOUT_MS
869+
);
864870
}
865871

866872
#[cfg(feature = "opendal-memory")]
@@ -919,7 +925,7 @@ mod tests {
919925
// path. The counter in `OpenDalWriter` is what covers services that don't, such as S3.
920926
let storage = Arc::new(OpenDalStorage::Memory {
921927
operator: default_memory_operator(),
922-
client: OpenDalClientConfig::default(),
928+
client_config: OpenDalClientConfig::default(),
923929
});
924930
let path = "memory:///stored-size";
925931
for plaintext in [
@@ -950,7 +956,7 @@ mod tests {
950956
fn test_relativize_path_memory() {
951957
let storage = OpenDalStorage::Memory {
952958
operator: default_memory_operator(),
953-
client: OpenDalClientConfig::default(),
959+
client_config: OpenDalClientConfig::default(),
954960
};
955961

956962
assert_eq!(
@@ -968,7 +974,7 @@ mod tests {
968974
#[test]
969975
fn test_relativize_path_fs() {
970976
let storage = OpenDalStorage::LocalFs {
971-
client: OpenDalClientConfig::default(),
977+
client_config: OpenDalClientConfig::default(),
972978
};
973979

974980
assert_eq!(
@@ -989,7 +995,7 @@ mod tests {
989995
let storage = OpenDalStorage::S3 {
990996
config: Arc::new(S3Config::default()),
991997
customized_credential_load: None,
992-
client: OpenDalClientConfig::default(),
998+
client_config: OpenDalClientConfig::default(),
993999
};
9941000

9951001
// All S3-family schemes are accepted by the same storage instance.
@@ -1010,7 +1016,7 @@ mod tests {
10101016
fn test_relativize_path_gcs() {
10111017
let storage = OpenDalStorage::Gcs {
10121018
config: Arc::new(GcsConfig::default()),
1013-
client: OpenDalClientConfig::default(),
1019+
client_config: OpenDalClientConfig::default(),
10141020
};
10151021

10161022
assert_eq!(
@@ -1026,7 +1032,7 @@ mod tests {
10261032
fn test_relativize_path_gcs_invalid_scheme() {
10271033
let storage = OpenDalStorage::Gcs {
10281034
config: Arc::new(GcsConfig::default()),
1029-
client: OpenDalClientConfig::default(),
1035+
client_config: OpenDalClientConfig::default(),
10301036
};
10311037

10321038
assert!(
@@ -1041,7 +1047,7 @@ mod tests {
10411047
fn test_relativize_path_oss() {
10421048
let storage = OpenDalStorage::Oss {
10431049
config: Arc::new(OssConfig::default()),
1044-
client: OpenDalClientConfig::default(),
1050+
client_config: OpenDalClientConfig::default(),
10451051
};
10461052

10471053
assert_eq!(
@@ -1057,7 +1063,7 @@ mod tests {
10571063
fn test_relativize_path_oss_invalid_scheme() {
10581064
let storage = OpenDalStorage::Oss {
10591065
config: Arc::new(OssConfig::default()),
1060-
client: OpenDalClientConfig::default(),
1066+
client_config: OpenDalClientConfig::default(),
10611067
};
10621068

10631069
assert!(
@@ -1076,7 +1082,7 @@ mod tests {
10761082
endpoint: Some("https://myaccount.dfs.core.windows.net".to_string()),
10771083
..Default::default()
10781084
}),
1079-
client: OpenDalClientConfig::default(),
1085+
client_config: OpenDalClientConfig::default(),
10801086
};
10811087

10821088
assert_eq!(

‎crates/storage/opendal/src/resolving.rs‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,54 +86,54 @@ fn build_storage_for_scheme(
8686
props: &HashMap<String, String>,
8787
#[cfg(feature = "opendal-s3")] customized_credential_load: &Option<CustomAwsCredentialLoader>,
8888
) -> Result<OpenDalStorage> {
89-
let client = OpenDalClientConfig::from_properties(props)?;
89+
let client_config = OpenDalClientConfig::from_properties(props)?;
9090
match scheme {
9191
#[cfg(feature = "opendal-s3")]
9292
"s3" => {
9393
let config = crate::s3::s3_config_parse(props.clone())?;
9494
Ok(OpenDalStorage::S3 {
9595
config: Arc::new(config),
9696
customized_credential_load: customized_credential_load.clone(),
97-
client,
97+
client_config,
9898
})
9999
}
100100
#[cfg(feature = "opendal-gcs")]
101101
"gcs" => {
102102
let config = crate::gcs::gcs_config_parse(props.clone())?;
103103
Ok(OpenDalStorage::Gcs {
104104
config: Arc::new(config),
105-
client,
105+
client_config,
106106
})
107107
}
108108
#[cfg(feature = "opendal-oss")]
109109
"oss" => {
110110
let config = crate::oss::oss_config_parse(props.clone())?;
111111
Ok(OpenDalStorage::Oss {
112112
config: Arc::new(config),
113-
client,
113+
client_config,
114114
})
115115
}
116116
#[cfg(feature = "opendal-azdls")]
117117
"azdls" => {
118118
let config = crate::azdls::azdls_config_parse(props.clone())?;
119119
Ok(OpenDalStorage::Azdls {
120120
config: Arc::new(config),
121-
client,
121+
client_config,
122122
})
123123
}
124124
#[cfg(feature = "opendal-fs")]
125-
"file" => Ok(OpenDalStorage::LocalFs { client }),
125+
"file" => Ok(OpenDalStorage::LocalFs { client_config }),
126126
#[cfg(feature = "opendal-memory")]
127127
"memory" => Ok(OpenDalStorage::Memory {
128128
operator: crate::memory::memory_config_build()?,
129-
client,
129+
client_config,
130130
}),
131131
#[cfg(feature = "opendal-hf")]
132132
"hf" => {
133133
let config = crate::hf::hf_config_parse(props.clone())?;
134134
Ok(OpenDalStorage::Hf {
135135
config: Arc::new(config),
136-
client,
136+
client_config,
137137
})
138138
}
139139
unsupported => Err(Error::new(
@@ -397,7 +397,7 @@ mod tests {
397397
.insert(OPENDAL_IO_TIMEOUT_MS.to_string(), "45000".to_string());
398398

399399
let resolved = storage.resolve("s3://bucket/key").unwrap();
400-
assert_eq!(resolved.client().io_timeout_ms(), 45_000);
400+
assert_eq!(resolved.client_config().io_timeout_ms(), 45_000);
401401
}
402402

403403
#[cfg(feature = "opendal-s3")]

0 commit comments

Comments
 (0)