-
Notifications
You must be signed in to change notification settings - Fork 619
HDDS-5869. Added support for stream on S3Gateway write path #4970
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
55c2f68
HDDS-5869. Added support for stream on S3Gateway write path
guohao-rosicky 9c77db8
Merge branch 'apache:master' into guohao-HDDS-5869-dev
guohao-rosicky 9bc0073
checkstyle
guohao-rosicky 2ff6418
checkstyle
guohao-rosicky d55fe40
metadata
guohao-rosicky 6cc693d
Merge branch 'apache:master' into guohao-HDDS-5869-dev
guohao-rosicky 56083c7
code review
guohao-rosicky 99c0857
code review
guohao-rosicky ab12739
Merge branch 'apache:master' into guohao-HDDS-5869-dev
guohao-rosicky b811e3c
Merge branch 'guohao-HDDS-5869-dev' of github.com:guohao-rosicky/ozon…
guohao-rosicky 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
122 changes: 122 additions & 0 deletions
122
.../s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/ObjectEndpointStreaming.java
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 |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| /* | ||
| * 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 | ||
| * <p> | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * <p> | ||
| * 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. | ||
| */ | ||
| package org.apache.hadoop.ozone.s3.endpoint; | ||
|
|
||
| import org.apache.hadoop.hdds.client.ReplicationConfig; | ||
| import org.apache.hadoop.ozone.client.OzoneBucket; | ||
| import org.apache.hadoop.ozone.client.io.OzoneDataStreamOutput; | ||
| import org.apache.hadoop.ozone.om.exceptions.OMException; | ||
| import org.apache.hadoop.ozone.s3.exception.OS3Exception; | ||
| import org.apache.hadoop.ozone.s3.exception.S3ErrorTable; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.nio.ByteBuffer; | ||
| import java.util.Map; | ||
|
|
||
| import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_ENABLE_FILESYSTEM_PATHS; | ||
| import static org.apache.hadoop.ozone.s3.exception.S3ErrorTable.INVALID_REQUEST; | ||
|
|
||
| /** | ||
| * Key level rest endpoints for Streaming. | ||
| */ | ||
| final class ObjectEndpointStreaming { | ||
|
|
||
| private static final Logger LOG = | ||
| LoggerFactory.getLogger(ObjectEndpointStreaming.class); | ||
|
|
||
| private ObjectEndpointStreaming() { | ||
| } | ||
|
|
||
| public static long put(OzoneBucket bucket, String keyPath, | ||
| long length, ReplicationConfig replicationConfig, | ||
| int chunkSize, Map<String, String> keyMetadata, | ||
| InputStream body) | ||
| throws IOException, OS3Exception { | ||
|
|
||
| try { | ||
| return putKeyWithStream(bucket, keyPath, | ||
| length, chunkSize, replicationConfig, keyMetadata, body); | ||
| } catch (IOException ex) { | ||
| LOG.error("Exception occurred in PutObject", ex); | ||
| if (ex instanceof OMException) { | ||
| if (((OMException) ex).getResult() == | ||
| OMException.ResultCodes.NOT_A_FILE) { | ||
| OS3Exception os3Exception = S3ErrorTable.newError(INVALID_REQUEST, | ||
| keyPath); | ||
| os3Exception.setErrorMessage("An error occurred (InvalidRequest) " + | ||
| "when calling the PutObject/MPU PartUpload operation: " + | ||
| OZONE_OM_ENABLE_FILESYSTEM_PATHS + " is enabled Keys are" + | ||
| " considered as Unix Paths. Path has Violated FS Semantics " + | ||
| "which caused put operation to fail."); | ||
| throw os3Exception; | ||
| } else if ((((OMException) ex).getResult() == | ||
| OMException.ResultCodes.PERMISSION_DENIED)) { | ||
| throw S3ErrorTable.newError(S3ErrorTable.ACCESS_DENIED, keyPath); | ||
| } | ||
| } | ||
| throw ex; | ||
| } | ||
| } | ||
|
|
||
| public static long putKeyWithStream(OzoneBucket bucket, | ||
| String keyPath, | ||
| long length, | ||
| int bufferSize, | ||
| ReplicationConfig replicationConfig, | ||
| Map<String, String> keyMetadata, | ||
| InputStream body) | ||
| throws IOException { | ||
| long writeLen = 0; | ||
| try (OzoneDataStreamOutput streamOutput = bucket.createStreamKey(keyPath, | ||
| length, replicationConfig, keyMetadata)) { | ||
| writeLen = writeToStreamOutput(streamOutput, body, bufferSize, length); | ||
| } | ||
| return writeLen; | ||
| } | ||
|
|
||
| private static long writeToStreamOutput(OzoneDataStreamOutput streamOutput, | ||
| InputStream body, int bufferSize, | ||
| long length) | ||
| throws IOException { | ||
| byte[] buffer = new byte[bufferSize]; | ||
| ByteBuffer writeByteBuffer; | ||
| long total = 0; | ||
| do { | ||
| int realBufferSize = (int) (length - total); | ||
| if (realBufferSize > 0 && realBufferSize < bufferSize) { | ||
| buffer = new byte[realBufferSize]; | ||
| } | ||
| int nn = body.read(buffer); | ||
| if (nn == -1) { | ||
| break; | ||
| } else if (nn != bufferSize) { | ||
| byte[] subBuffer = new byte[nn]; | ||
| System.arraycopy(buffer, 0, subBuffer, 0, nn); | ||
| writeByteBuffer = ByteBuffer.wrap(subBuffer, 0, nn); | ||
| } else { | ||
| writeByteBuffer = ByteBuffer.wrap(buffer, 0, nn); | ||
| } | ||
| streamOutput.write(writeByteBuffer, 0, nn); | ||
| total += nn; | ||
| } while (total != length); | ||
| return total; | ||
|
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. The method can be simplified to final byte[] buffer = new byte[bufferSize];
long n = 0;
while (n < length) {
final int toRead = Math.toIntExact(Math.min(bufferSize, length - n));
final int readLength = body.read(buffer, 0, toRead);
if (readLength == -1) {
break;
}
streamOutput.write(ByteBuffer.wrap(buffer, 0, readLength));
n += readLength;
}
return n; |
||
| } | ||
| } | ||
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.
How about we use Streaming only if it has more than one chunk?
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.
Thanks @szetszwo review this.
I think it is ok, whether this is better to have a display configuration, and then this configuration can be decided by the user, if you think it is possible, I can add this configuration
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.
@guohao-rosicky , yes, it is a good idea. How about we reuse the OZONE_FS_DATASTREAM_AUTO_THRESHOLD conf?
ozone/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/OzoneConfigKeys.java
Lines 117 to 118 in 01007af
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.
sure.