Skip to content

Commit 2137f6b

Browse files
authored
feat: Allow FileIO to reuse http client (#544)
Signed-off-by: Xuanwo <github@xuanwo.io>
1 parent cbd1844 commit 2137f6b

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

crates/iceberg/src/io/storage.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ pub(crate) enum Storage {
3838
/// s3 storage could have `s3://` and `s3a://`.
3939
/// Storing the scheme string here to return the correct path.
4040
scheme_str: String,
41+
/// uses the same client for one FileIO Storage.
42+
///
43+
/// TODO: allow users to configure this client.
44+
client: reqwest::Client,
4145
config: Arc<S3Config>,
4246
},
4347
#[cfg(feature = "storage-gcs")]
@@ -58,6 +62,7 @@ impl Storage {
5862
#[cfg(feature = "storage-s3")]
5963
Scheme::S3 => Ok(Self::S3 {
6064
scheme_str,
65+
client: reqwest::Client::new(),
6166
config: super::s3_config_parse(props)?.into(),
6267
}),
6368
#[cfg(feature = "storage-gcs")]
@@ -110,8 +115,12 @@ impl Storage {
110115
}
111116
}
112117
#[cfg(feature = "storage-s3")]
113-
Storage::S3 { scheme_str, config } => {
114-
let op = super::s3_config_build(config, path)?;
118+
Storage::S3 {
119+
scheme_str,
120+
client,
121+
config,
122+
} => {
123+
let op = super::s3_config_build(client, config, path)?;
115124
let op_info = op.info();
116125

117126
// Check prefix of s3 path.

crates/iceberg/src/io/storage_s3.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717

1818
use std::collections::HashMap;
1919

20+
use opendal::raw::HttpClient;
2021
use opendal::services::S3Config;
21-
use opendal::Operator;
22+
use opendal::{Configurator, Operator};
2223
use url::Url;
2324

2425
use crate::{Error, ErrorKind, Result};
@@ -106,7 +107,11 @@ pub(crate) fn s3_config_parse(mut m: HashMap<String, String>) -> Result<S3Config
106107
}
107108

108109
/// Build new opendal operator from give path.
109-
pub(crate) fn s3_config_build(cfg: &S3Config, path: &str) -> Result<Operator> {
110+
pub(crate) fn s3_config_build(
111+
client: &reqwest::Client,
112+
cfg: &S3Config,
113+
path: &str,
114+
) -> Result<Operator> {
110115
let url = Url::parse(path)?;
111116
let bucket = url.host_str().ok_or_else(|| {
112117
Error::new(
@@ -115,7 +120,13 @@ pub(crate) fn s3_config_build(cfg: &S3Config, path: &str) -> Result<Operator> {
115120
)
116121
})?;
117122

118-
let mut cfg = cfg.clone();
119-
cfg.bucket = bucket.to_string();
120-
Ok(Operator::from_config(cfg)?.finish())
123+
let builder = cfg
124+
.clone()
125+
.into_builder()
126+
// Set bucket name.
127+
.bucket(bucket)
128+
// Set http client we want to use.
129+
.http_client(HttpClient::with(client.clone()));
130+
131+
Ok(Operator::new(builder)?.finish())
121132
}

0 commit comments

Comments
 (0)