Skip to content

Commit 2ca1557

Browse files
author
Devdutt Shenoi
committed
refactor: construct once
1 parent 6372269 commit 2ca1557

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

src/storage/azure_blob.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ impl ObjectStorageProvider for AzureBlobConfig {
163163
RuntimeConfig::new().with_object_store_registry(Arc::new(object_store_registry))
164164
}
165165

166-
fn get_object_store(&self) -> Arc<dyn super::ObjectStorage> {
166+
fn construct_client(&self) -> Arc<dyn super::ObjectStorage> {
167167
let azure = self.get_default_builder().build().unwrap();
168168
// limit objectstore to a concurrent request limit
169169
let azure = LimitStore::new(azure, super::MAX_OBJECT_STORE_REQUESTS);

src/storage/localfs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl ObjectStorageProvider for FSConfig {
6767
RuntimeConfig::new()
6868
}
6969

70-
fn get_object_store(&self) -> Arc<dyn ObjectStorage> {
70+
fn construct_client(&self) -> Arc<dyn ObjectStorage> {
7171
Arc::new(LocalFS::new(self.root.clone()))
7272
}
7373

src/storage/object_storage.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ use bytes::Bytes;
4646
use chrono::Local;
4747
use datafusion::{datasource::listing::ListingTableUrl, execution::runtime_env::RuntimeConfig};
4848
use itertools::Itertools;
49+
use once_cell::sync::OnceCell;
4950
use relative_path::RelativePath;
5051
use relative_path::RelativePathBuf;
5152

@@ -60,7 +61,12 @@ use std::{
6061

6162
pub trait ObjectStorageProvider: StorageMetrics + std::fmt::Debug + Send + Sync {
6263
fn get_datafusion_runtime(&self) -> RuntimeConfig;
63-
fn get_object_store(&self) -> Arc<dyn ObjectStorage>;
64+
fn construct_client(&self) -> Arc<dyn ObjectStorage>;
65+
fn get_object_store(&self) -> Arc<dyn ObjectStorage> {
66+
static STORE: OnceCell<Arc<dyn ObjectStorage>> = OnceCell::new();
67+
68+
STORE.get_or_init(|| self.construct_client()).clone()
69+
}
6470
fn get_endpoint(&self) -> String;
6571
fn register_store_metrics(&self, handler: &PrometheusMetrics);
6672
}

src/storage/s3.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ impl ObjectStorageProvider for S3Config {
298298
RuntimeConfig::new().with_object_store_registry(Arc::new(object_store_registry))
299299
}
300300

301-
fn get_object_store(&self) -> Arc<dyn ObjectStorage> {
301+
fn construct_client(&self) -> Arc<dyn ObjectStorage> {
302302
let s3 = self.get_default_builder().build().unwrap();
303303

304304
// limit objectstore to a concurrent request limit

0 commit comments

Comments
 (0)