-
Notifications
You must be signed in to change notification settings - Fork 499
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(services/s3): add append support #5428
Draft
Frank-III
wants to merge
3
commits into
apache:main
Choose a base branch
from
Frank-III:s3-append
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.
+135
−41
Draft
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,6 +70,8 @@ pub mod constants { | |
pub const X_AMZ_COPY_SOURCE_SERVER_SIDE_ENCRYPTION_CUSTOMER_KEY_MD5: &str = | ||
"x-amz-copy-source-server-side-encryption-customer-key-md5"; | ||
|
||
pub const X_AMZ_WRITE_OFFSET_BYTES: &str = "x-amz-write-offset-bytes"; | ||
|
||
pub const X_AMZ_META_PREFIX: &str = "x-amz-meta-"; | ||
|
||
pub const RESPONSE_CONTENT_DISPOSITION: &str = "response-content-disposition"; | ||
|
@@ -289,6 +291,54 @@ impl S3Core { | |
} | ||
req | ||
} | ||
|
||
pub fn insert_metadata_headers( | ||
&self, | ||
mut req: http::request::Builder, | ||
size: Option<u64>, | ||
args: &OpWrite, | ||
) -> http::request::Builder { | ||
if let Some(size) = size { | ||
req = req.header(CONTENT_LENGTH, size.to_string()) | ||
} | ||
|
||
if let Some(mime) = args.content_type() { | ||
req = req.header(CONTENT_TYPE, mime) | ||
} | ||
|
||
if let Some(pos) = args.content_disposition() { | ||
req = req.header(CONTENT_DISPOSITION, pos) | ||
} | ||
|
||
if let Some(encoding) = args.content_encoding() { | ||
req = req.header(CONTENT_ENCODING, encoding); | ||
} | ||
|
||
if let Some(cache_control) = args.cache_control() { | ||
req = req.header(CACHE_CONTROL, cache_control) | ||
} | ||
|
||
if let Some(if_match) = args.if_match() { | ||
req = req.header(IF_MATCH, if_match); | ||
} | ||
|
||
if args.if_not_exists() { | ||
req = req.header(IF_NONE_MATCH, "*"); | ||
} | ||
|
||
// Set storage class header | ||
if let Some(v) = &self.default_storage_class { | ||
req = req.header(HeaderName::from_static(constants::X_AMZ_STORAGE_CLASS), v); | ||
} | ||
|
||
// Set user metadata headers. | ||
if let Some(user_metadata) = args.user_metadata() { | ||
for (key, value) in user_metadata { | ||
req = req.header(format!("{X_AMZ_META_PREFIX}{key}"), value) | ||
} | ||
} | ||
req | ||
} | ||
} | ||
|
||
impl S3Core { | ||
|
@@ -441,55 +491,44 @@ impl S3Core { | |
|
||
let mut req = Request::put(&url); | ||
|
||
if let Some(size) = size { | ||
req = req.header(CONTENT_LENGTH, size.to_string()) | ||
} | ||
req = self.insert_metadata_headers(req, size, args); | ||
|
||
if let Some(mime) = args.content_type() { | ||
req = req.header(CONTENT_TYPE, mime) | ||
} | ||
// Set SSE headers. | ||
req = self.insert_sse_headers(req, true); | ||
|
||
if let Some(pos) = args.content_disposition() { | ||
req = req.header(CONTENT_DISPOSITION, pos) | ||
// Calculate Checksum. | ||
if let Some(checksum) = self.calculate_checksum(&body) { | ||
// Set Checksum header. | ||
req = self.insert_checksum_header(req, &checksum); | ||
} | ||
|
||
if let Some(encoding) = args.content_encoding() { | ||
req = req.header(CONTENT_ENCODING, encoding); | ||
} | ||
// Set body | ||
let req = req.body(body).map_err(new_request_build_error)?; | ||
|
||
if let Some(cache_control) = args.cache_control() { | ||
req = req.header(CACHE_CONTROL, cache_control) | ||
} | ||
Ok(req) | ||
} | ||
|
||
if let Some(if_match) = args.if_match() { | ||
req = req.header(IF_MATCH, if_match); | ||
} | ||
pub fn s3_append_object_request( | ||
&self, | ||
path: &str, | ||
position: u64, | ||
size: u64, | ||
args: &OpWrite, | ||
body: Buffer, | ||
) -> Result<Request<Buffer>> { | ||
let p = build_abs_path(&self.root, path); | ||
|
||
if args.if_not_exists() { | ||
req = req.header(IF_NONE_MATCH, "*"); | ||
} | ||
let url = format!("{}/{}", self.endpoint, percent_encode_path(&p)); | ||
|
||
// Set storage class header | ||
if let Some(v) = &self.default_storage_class { | ||
req = req.header(HeaderName::from_static(constants::X_AMZ_STORAGE_CLASS), v); | ||
} | ||
let mut req = Request::put(&url); | ||
|
||
// Set user metadata headers. | ||
if let Some(user_metadata) = args.user_metadata() { | ||
for (key, value) in user_metadata { | ||
req = req.header(format!("{X_AMZ_META_PREFIX}{key}"), value) | ||
} | ||
} | ||
req = self.insert_metadata_headers(req, Some(size), args); | ||
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. Hi, I assume that only the first append call supports setting up metadata. We don't need to repeat the metadata for subsequent append requests. |
||
|
||
req = req.header(constants::X_AMZ_WRITE_OFFSET_BYTES, position.to_string()); | ||
|
||
// Set SSE headers. | ||
req = self.insert_sse_headers(req, true); | ||
|
||
// Calculate Checksum. | ||
if let Some(checksum) = self.calculate_checksum(&body) { | ||
// Set Checksum header. | ||
req = self.insert_checksum_header(req, &checksum); | ||
} | ||
|
||
// Set body | ||
let req = req.body(body).map_err(new_request_build_error)?; | ||
|
||
|
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
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.
Hi, checking with
default_storage_class
doesn't seem like a good idea to me. How about adding a new flag calledenable_write_with_append
? Users who confirm that they supportappend
can enable this.