-
Notifications
You must be signed in to change notification settings - Fork 159
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
feat: support for gcs storage #520
Merged
liurenjie1024
merged 19 commits into
apache:main
from
jdockerty:feat/storage-backend-gcs
Aug 14, 2024
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
6abab33
chore: include opendal/services-gcs
jdockerty 4b86f54
feat: basic gcs scaffolding
jdockerty 10a124d
feat: populate config parse with basic details
jdockerty d5a009e
feat: include docker-compose integration tests
jdockerty ab2eb6f
feat: add extra iceberg properties
jdockerty 6a595c9
feat: add tests for gcs read/write
jdockerty 3a2f166
chore: minor cleanup for compose todo
jdockerty 0900c15
fix: do not introduce new properties
jdockerty 5e171cc
feat: infer bucket from path
jdockerty f741055
chore: add user-project const
jdockerty 30f90d1
feat: add allow_anonymous for test
jdockerty 6fa4b77
chore: remove test-with dep
jdockerty c9f7c64
feat: update with allow_anonymous functionality
jdockerty e4e7dad
ci: use cargo sort
jdockerty 5284405
chore: undo storage-gcs default feature
jdockerty 7f2e8d8
feat: include disable_ params for GCS_NO_AUTH
jdockerty f44cc97
ci: use storage-all for async-std tests
jdockerty 9cbcb8e
chore: merge branch 'main' into feat/storage-backend-gcs
jdockerty 3ab0a37
revert: use opendal from workspace
jdockerty 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 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
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,68 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you 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. | ||
//! Google Cloud Storage properties | ||
|
||
use std::collections::HashMap; | ||
|
||
use opendal::services::GcsConfig; | ||
use opendal::Operator; | ||
use url::Url; | ||
|
||
use crate::{Error, ErrorKind, Result}; | ||
|
||
// Reference: https://github.com/apache/iceberg/blob/main/gcp/src/main/java/org/apache/iceberg/gcp/GCPProperties.java | ||
|
||
/// Google Cloud Project ID | ||
pub const GCS_PROJECT_ID: &str = "gcs.project-id"; | ||
/// Google Cloud Storage endpoint | ||
pub const GCS_SERVICE_PATH: &str = "gcs.service.path"; | ||
/// Google Cloud user project | ||
pub const GCS_USER_PROJECT: &str = "gcs.user-project"; | ||
/// Allow unauthenticated requests | ||
pub const GCS_NO_AUTH: &str = "gcs.no-auth"; | ||
|
||
/// Parse iceberg properties to [`GcsConfig`]. | ||
pub(crate) fn gcs_config_parse(mut m: HashMap<String, String>) -> Result<GcsConfig> { | ||
let mut cfg = GcsConfig::default(); | ||
|
||
if let Some(endpoint) = m.remove(GCS_SERVICE_PATH) { | ||
cfg.endpoint = Some(endpoint); | ||
} | ||
|
||
if m.remove(GCS_NO_AUTH).is_some() { | ||
cfg.allow_anonymous = true; | ||
cfg.disable_vm_metadata = true; | ||
cfg.disable_config_load = true; | ||
} | ||
|
||
Ok(cfg) | ||
} | ||
|
||
/// Build a new OpenDAL [`Operator`] based on a provided [`GcsConfig`]. | ||
pub(crate) fn gcs_config_build(cfg: &GcsConfig, path: &str) -> Result<Operator> { | ||
let url = Url::parse(path)?; | ||
let bucket = url.host_str().ok_or_else(|| { | ||
Error::new( | ||
ErrorKind::DataInvalid, | ||
format!("Invalid gcs url: {}, bucket is required", path), | ||
) | ||
})?; | ||
|
||
let mut cfg = cfg.clone(); | ||
cfg.bucket = bucket.to_string(); | ||
Ok(Operator::from_config(cfg)?.finish()) | ||
} |
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,23 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you 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. | ||
|
||
services: | ||
gcs-server: | ||
image: fsouza/fake-gcs-server@sha256:36b0116fae5236e8def76ccb07761a9ca323e476f366a5f4bf449cac19deaf2d | ||
expose: | ||
- 4443 | ||
command: --scheme http |
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,125 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you 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. | ||
|
||
//! Integration tests for FileIO Google Cloud Storage (GCS). | ||
|
||
use std::collections::HashMap; | ||
use std::net::SocketAddr; | ||
use std::sync::RwLock; | ||
|
||
use bytes::Bytes; | ||
use ctor::{ctor, dtor}; | ||
use iceberg::io::{FileIO, FileIOBuilder, GCS_NO_AUTH, GCS_SERVICE_PATH}; | ||
use iceberg_test_utils::docker::DockerCompose; | ||
use iceberg_test_utils::{normalize_test_name, set_up}; | ||
|
||
static DOCKER_COMPOSE_ENV: RwLock<Option<DockerCompose>> = RwLock::new(None); | ||
static FAKE_GCS_PORT: u16 = 4443; | ||
static FAKE_GCS_BUCKET: &str = "test-bucket"; | ||
|
||
#[ctor] | ||
fn before_all() { | ||
let mut guard = DOCKER_COMPOSE_ENV.write().unwrap(); | ||
let docker_compose = DockerCompose::new( | ||
normalize_test_name(module_path!()), | ||
format!("{}/testdata/file_io_gcs", env!("CARGO_MANIFEST_DIR")), | ||
); | ||
docker_compose.run(); | ||
guard.replace(docker_compose); | ||
} | ||
|
||
#[dtor] | ||
fn after_all() { | ||
let mut guard = DOCKER_COMPOSE_ENV.write().unwrap(); | ||
guard.take(); | ||
} | ||
|
||
async fn get_file_io_gcs() -> FileIO { | ||
set_up(); | ||
|
||
let ip = DOCKER_COMPOSE_ENV | ||
.read() | ||
.unwrap() | ||
.as_ref() | ||
.unwrap() | ||
.get_container_ip("gcs-server"); | ||
let addr = SocketAddr::new(ip, FAKE_GCS_PORT); | ||
|
||
// A bucket must exist for FileIO | ||
create_bucket(FAKE_GCS_BUCKET, addr.to_string()) | ||
.await | ||
.unwrap(); | ||
|
||
FileIOBuilder::new("gcs") | ||
.with_props(vec![ | ||
(GCS_SERVICE_PATH, format!("http://{}", addr)), | ||
(GCS_NO_AUTH, "true".to_string()), | ||
]) | ||
.build() | ||
.unwrap() | ||
} | ||
|
||
// Create a bucket against the emulated GCS storage server. | ||
async fn create_bucket(name: &str, server_addr: String) -> anyhow::Result<()> { | ||
let mut bucket_data = HashMap::new(); | ||
bucket_data.insert("name", name); | ||
|
||
let client = reqwest::Client::new(); | ||
let endpoint = format!("http://{}/storage/v1/b", server_addr); | ||
client.post(endpoint).json(&bucket_data).send().await?; | ||
Ok(()) | ||
} | ||
|
||
fn get_gs_path() -> String { | ||
format!("gs://{}", FAKE_GCS_BUCKET) | ||
} | ||
|
||
#[tokio::test] | ||
async fn gcs_exists() { | ||
let file_io = get_file_io_gcs().await; | ||
assert!(file_io | ||
.is_exist(format!("{}/", get_gs_path())) | ||
.await | ||
.unwrap()); | ||
} | ||
|
||
#[tokio::test] | ||
async fn gcs_write() { | ||
let gs_file = format!("{}/write-file", get_gs_path()); | ||
let file_io = get_file_io_gcs().await; | ||
let output = file_io.new_output(&gs_file).unwrap(); | ||
output | ||
.write(bytes::Bytes::from_static(b"iceberg-gcs!")) | ||
.await | ||
.expect("Write to test output file"); | ||
assert!(file_io.is_exist(gs_file).await.unwrap()) | ||
} | ||
|
||
#[tokio::test] | ||
async fn gcs_read() { | ||
let gs_file = format!("{}/read-gcs", get_gs_path()); | ||
let file_io = get_file_io_gcs().await; | ||
let output = file_io.new_output(&gs_file).unwrap(); | ||
output | ||
.write(bytes::Bytes::from_static(b"iceberg!")) | ||
.await | ||
.expect("Write to test output file"); | ||
assert!(file_io.is_exist(&gs_file).await.unwrap()); | ||
|
||
let input = file_io.new_input(gs_file).unwrap(); | ||
assert_eq!(input.read().await.unwrap(), Bytes::from_static(b"iceberg!")); | ||
} |
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.
I'm not 100% certain this is the right approach, but I figured rather than adding on another item for
storage-gcs
, simply usingstorage-all
here covers it for future contributors too.Granted, I'm not quite sure whether this is what we want. Happy to alter/take suggestions 👍
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.
I'm ok with this in CI.