-
Notifications
You must be signed in to change notification settings - Fork 590
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(object store): introduce new s3 object store via OpenDAL (#14409)
Co-authored-by: William Wen <[email protected]>
- Loading branch information
Showing
6 changed files
with
115 additions
and
31 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,8 +26,8 @@ pub mod gcs; | |
|
||
pub mod obs; | ||
|
||
pub mod oss; | ||
|
||
pub mod azblob; | ||
pub mod opendal_s3; | ||
pub mod oss; | ||
|
||
pub mod fs; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright 2024 RisingWave Labs | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use std::time::Duration; | ||
|
||
use opendal::layers::{LoggingLayer, RetryLayer}; | ||
use opendal::services::S3; | ||
use opendal::Operator; | ||
use risingwave_common::config::ObjectStoreConfig; | ||
|
||
use super::{EngineType, OpendalObjectStore}; | ||
use crate::object::ObjectResult; | ||
|
||
impl OpendalObjectStore { | ||
/// create opendal s3 engine. | ||
pub fn new_s3_engine( | ||
bucket: String, | ||
object_store_config: ObjectStoreConfig, | ||
) -> ObjectResult<Self> { | ||
// Create s3 builder. | ||
let mut builder = S3::default(); | ||
builder.bucket(&bucket); | ||
|
||
// For AWS S3, there is no need to set an endpoint; for other S3 compatible object stores, it is necessary to set this field. | ||
if let Ok(endpoint_url) = std::env::var("RW_S3_ENDPOINT") { | ||
builder.endpoint(&endpoint_url); | ||
} | ||
|
||
if let Ok(region) = std::env::var("AWS_REGION") { | ||
builder.region(®ion); | ||
} else { | ||
tracing::error!("aws s3 region is not set, bucket {}", bucket); | ||
} | ||
|
||
if let Ok(access) = std::env::var("AWS_ACCESS_KEY_ID") { | ||
builder.access_key_id(&access); | ||
} else { | ||
tracing::error!("access key id of aws s3 is not set, bucket {}", bucket); | ||
} | ||
|
||
if let Ok(secret) = std::env::var("AWS_SECRET_ACCESS_KEY") { | ||
builder.secret_access_key(&secret); | ||
} else { | ||
tracing::error!("secret access key of aws s3 is not set, bucket {}", bucket); | ||
} | ||
|
||
if std::env::var("RW_IS_FORCE_PATH_STYLE").is_err() { | ||
builder.enable_virtual_host_style(); | ||
} | ||
|
||
let op: Operator = Operator::new(builder)? | ||
.layer(LoggingLayer::default()) | ||
.layer( | ||
RetryLayer::new() | ||
.with_min_delay(Duration::from_millis( | ||
object_store_config.s3.object_store_req_retry_interval_ms, | ||
)) | ||
.with_max_delay(Duration::from_millis( | ||
object_store_config.s3.object_store_req_retry_max_delay_ms, | ||
)) | ||
.with_max_times(object_store_config.s3.object_store_req_retry_max_attempts) | ||
.with_factor(1.0) | ||
.with_jitter(), | ||
) | ||
.finish(); | ||
Ok(Self { | ||
op, | ||
engine_type: EngineType::S3, | ||
}) | ||
} | ||
} |