-
Notifications
You must be signed in to change notification settings - Fork 599
HDDS-15179. Support Chunked Transfer without Content Length #10196
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
peterxcli
wants to merge
4
commits into
apache:master
Choose a base branch
from
peterxcli:fix/s3-chunked-transfer-without-content-length
base: master
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.
+86
−1
Open
Changes from all commits
Commits
Show all changes
4 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 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 |
|---|---|---|
|
|
@@ -41,11 +41,13 @@ | |
| import static org.apache.hadoop.ozone.s3.util.S3Consts.STORAGE_CLASS_HEADER; | ||
| import static org.apache.hadoop.ozone.s3.util.S3Consts.TAG_COUNT_HEADER; | ||
| import static org.apache.hadoop.ozone.s3.util.S3Consts.TAG_DIRECTIVE_HEADER; | ||
| import static org.apache.hadoop.ozone.s3.util.S3Utils.hasMultiChunksPayload; | ||
| import static org.apache.hadoop.ozone.s3.util.S3Utils.stripQuotes; | ||
| import static org.apache.hadoop.ozone.s3.util.S3Utils.validateSignatureHeader; | ||
| import static org.apache.hadoop.ozone.s3.util.S3Utils.wrapInQuotes; | ||
|
|
||
| import com.google.common.collect.ImmutableMap; | ||
| import com.google.common.io.FileBackedOutputStream; | ||
| import java.io.EOFException; | ||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
|
|
@@ -198,12 +200,23 @@ Response handlePutRequest(ObjectRequestContext context, String keyPath, InputStr | |
| final long startNanos = context.getStartNanos(); | ||
|
|
||
| String copyHeader = null; | ||
| FileBackedOutputStream spooledBody = null; | ||
| MultiDigestInputStream multiDigestInputStream = null; | ||
| try { | ||
| OzoneVolume volume = context.getVolume(); | ||
| OzoneBucket bucket = context.getBucket(); | ||
| final String lengthHeader = getHeaders().getHeaderString(HttpHeaders.CONTENT_LENGTH); | ||
| final String rawAmzContentSha256Header = getHeaders().getHeaderString(S3Consts.X_AMZ_CONTENT_SHA256); | ||
| final boolean hasMultiChunksUpload = | ||
| rawAmzContentSha256Header != null && hasMultiChunksPayload(rawAmzContentSha256Header); | ||
| boolean hasCalculatedLength = false; | ||
| long length = lengthHeader != null ? Long.parseLong(lengthHeader) : 0; | ||
| if (lengthHeader == null && body != null && !hasMultiChunksUpload) { | ||
| spooledBody = new FileBackedOutputStream(32); | ||
| length = IOUtils.copyLarge(body, spooledBody, new byte[getIOBufferSize(0)]); | ||
| body = spooledBody.asByteSource().openStream(); | ||
| hasCalculatedLength = true; | ||
| } | ||
|
|
||
| if (uploadID != null && !uploadID.equals("")) { | ||
| if (getHeaders().getHeaderString(COPY_SOURCE_HEADER) == null) { | ||
|
|
@@ -245,8 +258,10 @@ Response handlePutRequest(ObjectRequestContext context, String keyPath, InputStr | |
| getHeaders().getHeaderString(S3Consts.DECODED_CONTENT_LENGTH_HEADER); | ||
| boolean hasAmzDecodedLengthZero = amzDecodedLength != null && | ||
| Long.parseLong(amzDecodedLength) == 0; | ||
| boolean hasKnownZeroLength = hasAmzDecodedLengthZero || | ||
| (length == 0 && (lengthHeader != null || hasCalculatedLength || body == null)); | ||
| if (canCreateDirectory && | ||
| (length == 0 || hasAmzDecodedLengthZero) && | ||
| hasKnownZeroLength && | ||
| StringUtils.endsWith(keyPath, "/") | ||
|
Contributor
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. From what I see, the length is only need to check whether the length is 0 or not. In that case is it possible to simply check the first byte existence? |
||
| ) { | ||
| context.setAction(S3GAction.CREATE_DIRECTORY); | ||
|
|
@@ -343,6 +358,9 @@ customMetadata, tags, multiDigestInputStream, getHeaders(), | |
| if (multiDigestInputStream != null) { | ||
| multiDigestInputStream.resetDigests(); | ||
| } | ||
| if (spooledBody != null) { | ||
| spooledBody.reset(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
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
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
Is this going to copy the whole object into a temporary file on S3G machine? In other words, is S3G required to allocate some disk space for this length calculation?
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.
If so, this might be problematic since firstly currently a lot of cluster (including mine) assume that S3G does not have variable disk requirement (this then require some kind of persistent volume implementation for S3G deployed in K8s). Additionally, putting the whole object into a file and then re-reading again might incur additional disk IO.