-
Notifications
You must be signed in to change notification settings - Fork 452
feat(storage/opendal): route oss:// URLs through the S3 backend #2332
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
Open
plusplusjiajia
wants to merge
1
commit into
apache:main
Choose a base branch
from
plusplusjiajia:feat/oss-routes-through-s3
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -104,7 +104,20 @@ fn build_storage_for_scheme( | |
| config: Arc::new(config), | ||
| }) | ||
| } | ||
| #[cfg(feature = "opendal-oss")] | ||
| // OSS is S3-API-compatible; route through S3 so `s3.*` props | ||
| // work for OSS-backed tables (mirrors pyiceberg/Java S3FileIO). | ||
| #[cfg(feature = "opendal-s3")] | ||
| Scheme::Oss => { | ||
| let config = crate::s3::s3_config_parse(props.clone())?; | ||
| Ok(OpenDalStorage::S3 { | ||
| configured_scheme: scheme.to_string(), | ||
| config: Arc::new(config), | ||
| customized_credential_load: customized_credential_load.clone(), | ||
| }) | ||
| } | ||
| // Fallback: builds without `opendal-s3` but with `opendal-oss` | ||
| // still use the native OSS service (which consumes `oss.*` keys). | ||
| #[cfg(all(feature = "opendal-oss", not(feature = "opendal-s3")))] | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not very familiar with OSS storage so not sure about it: Is the fallback actually necessary? I'm thinking if using OSS exactly like S3 is the common case, maybe we can just use OpenDalS3Storage directly? |
||
| Scheme::Oss => { | ||
| let config = crate::oss::oss_config_parse(props.clone())?; | ||
| Ok(OpenDalStorage::Oss { | ||
|
|
@@ -317,3 +330,77 @@ impl Storage for OpenDalResolvingStorage { | |
| )) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[cfg(feature = "opendal-s3")] | ||
| #[test] | ||
| fn oss_scheme_routes_through_s3_backend_when_available() { | ||
| use iceberg::io::{S3_ACCESS_KEY_ID, S3_ENDPOINT}; | ||
|
|
||
| let mut props = HashMap::new(); | ||
| props.insert(S3_ACCESS_KEY_ID.to_string(), "AKIA_TEST".to_string()); | ||
| props.insert( | ||
| S3_ENDPOINT.to_string(), | ||
| "https://oss-cn-shanghai.aliyuncs.com".to_string(), | ||
| ); | ||
|
|
||
| let storage = build_storage_for_scheme(SCHEME_OSS, &props, &None).unwrap(); | ||
|
|
||
| match storage { | ||
| OpenDalStorage::S3 { | ||
| configured_scheme, .. | ||
| } => { | ||
| assert_eq!( | ||
| configured_scheme, SCHEME_OSS, | ||
| "S3 backend should advertise the `oss` scheme so `oss://` \ | ||
| URLs are accepted by OpenDalStorage::S3::create_operator" | ||
| ); | ||
| } | ||
| other => panic!( | ||
| "expected OpenDalStorage::S3 for oss://, got {other:?}; OSS is \ | ||
| S3-API-compatible and should share the S3 code path" | ||
| ), | ||
| } | ||
| } | ||
|
|
||
| #[cfg(feature = "opendal-s3")] | ||
| #[test] | ||
| fn oss_resolve_uses_s3_backend_and_caches() { | ||
| use iceberg::io::{S3_ACCESS_KEY_ID, S3_ENDPOINT}; | ||
|
|
||
| let mut props = HashMap::new(); | ||
| props.insert(S3_ACCESS_KEY_ID.to_string(), "AKIA_TEST".to_string()); | ||
| props.insert( | ||
| S3_ENDPOINT.to_string(), | ||
| "https://oss-cn-shanghai.aliyuncs.com".to_string(), | ||
| ); | ||
|
|
||
| let resolving = OpenDalResolvingStorage { | ||
| props, | ||
| storages: RwLock::new(HashMap::new()), | ||
| #[cfg(feature = "opendal-s3")] | ||
| customized_credential_load: None, | ||
| }; | ||
|
|
||
| let storage = resolving.resolve("oss://my-bucket/path/to/file").unwrap(); | ||
| assert!(matches!(storage.as_ref(), OpenDalStorage::S3 { .. })); | ||
|
|
||
| // Second call should hit the cache. | ||
| let cached = resolving.resolve("oss://my-bucket/other").unwrap(); | ||
| assert!(Arc::ptr_eq(&storage, &cached)); | ||
| } | ||
|
|
||
| #[cfg(all(feature = "opendal-oss", not(feature = "opendal-s3")))] | ||
| #[test] | ||
| fn oss_scheme_falls_back_to_native_oss_backend() { | ||
| let props = HashMap::new(); | ||
| let storage = build_storage_for_scheme(SCHEME_OSS, &props).unwrap(); | ||
| assert!( | ||
| matches!(storage, OpenDalStorage::Oss { .. }), | ||
| "Without opendal-s3, OSS should use the native OSS backend" | ||
| ); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only having s3 feature flag will introduce oss related code to non-oss users