-
Notifications
You must be signed in to change notification settings - Fork 936
Disable MD5 checksum at S3 CRT client creation time and propagate checksum algorithm #3309
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
Closed
cenedhryn
wants to merge
1
commit into
feature/master/transfermanager-GA
from
salande/tm-disable-md5
Closed
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 |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
|
||
package software.amazon.awssdk.services.s3.internal.crt; | ||
|
||
import static software.amazon.awssdk.services.s3.internal.crt.S3InternalSdkHttpExecutionAttribute.CHECKSUM_SPECS; | ||
import static software.amazon.awssdk.services.s3.internal.crt.S3InternalSdkHttpExecutionAttribute.OPERATION_NAME; | ||
|
||
import java.net.URI; | ||
|
@@ -25,8 +26,11 @@ | |
import software.amazon.awssdk.annotations.SdkInternalApi; | ||
import software.amazon.awssdk.annotations.SdkTestInternalApi; | ||
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider; | ||
import software.amazon.awssdk.core.checksums.Algorithm; | ||
import software.amazon.awssdk.core.checksums.ChecksumSpecs; | ||
import software.amazon.awssdk.crt.http.HttpHeader; | ||
import software.amazon.awssdk.crt.http.HttpRequest; | ||
import software.amazon.awssdk.crt.s3.ChecksumAlgorithm; | ||
import software.amazon.awssdk.crt.s3.S3Client; | ||
import software.amazon.awssdk.crt.s3.S3ClientOptions; | ||
import software.amazon.awssdk.crt.s3.S3MetaRequest; | ||
|
@@ -58,6 +62,7 @@ private S3CrtAsyncHttpClient(Builder builder) { | |
.signingRegion(builder.region == null ? null : builder.region.id()) | ||
.endpointOverride(builder.endpointOverride) | ||
.credentialsProvider(builder.credentialsProvider) | ||
.contentMd5(Boolean.FALSE) | ||
.build(); | ||
|
||
S3ClientOptions s3ClientOptions = | ||
|
@@ -67,7 +72,7 @@ private S3CrtAsyncHttpClient(Builder builder) { | |
.withCredentialsProvider(s3NativeClientConfiguration.credentialsProvider()) | ||
.withClientBootstrap(s3NativeClientConfiguration.clientBootstrap()) | ||
.withPartSize(s3NativeClientConfiguration.partSizeBytes()) | ||
.withComputeContentMd5(true) | ||
.withComputeContentMd5(s3NativeClientConfiguration.isContentMd5()) | ||
.withThroughputTargetGbps(s3NativeClientConfiguration.targetThroughputInGbps()); | ||
this.crtS3Client = new S3Client(s3ClientOptions); | ||
} | ||
|
@@ -87,10 +92,12 @@ public CompletableFuture<Void> execute(AsyncExecuteRequest asyncRequest) { | |
new S3CrtResponseHandlerAdapter(executeFuture, asyncRequest.responseHandler()); | ||
|
||
S3MetaRequestOptions.MetaRequestType requestType = requestType(asyncRequest); | ||
ChecksumAlgorithm checksumAlgorithm = crtChecksumAlgorithm(asyncRequest); | ||
|
||
S3MetaRequestOptions requestOptions = new S3MetaRequestOptions() | ||
.withHttpRequest(httpRequest) | ||
.withMetaRequestType(requestType) | ||
.withChecksumAlgorithm(checksumAlgorithm) | ||
.withResponseHandler(responseHandler) | ||
.withEndpoint(s3NativeClientConfiguration.endpointOverride()); | ||
|
||
|
@@ -123,6 +130,26 @@ private static S3MetaRequestOptions.MetaRequestType requestType(AsyncExecuteRequ | |
return S3MetaRequestOptions.MetaRequestType.DEFAULT; | ||
} | ||
|
||
private static ChecksumAlgorithm crtChecksumAlgorithm(AsyncExecuteRequest asyncRequest) { | ||
ChecksumSpecs checksumSpecs = asyncRequest.httpExecutionAttributes().getAttribute(CHECKSUM_SPECS); | ||
if (checksumSpecs != null && checksumSpecs.algorithm() != null) { | ||
Algorithm checksumAlgorithm = checksumSpecs.algorithm(); | ||
switch (checksumAlgorithm) { | ||
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. Can we use Enum.fromValue(str.toUpper/LowerCase) here instead of switch case ? |
||
case CRC32: | ||
return ChecksumAlgorithm.CRC32; | ||
case CRC32C: | ||
return ChecksumAlgorithm.CRC32C; | ||
case SHA1: | ||
return ChecksumAlgorithm.SHA1; | ||
case SHA256: | ||
return ChecksumAlgorithm.SHA256; | ||
default: | ||
throw new IllegalStateException("Checksum algorithm not translatable: " + checksumAlgorithm); | ||
} | ||
} | ||
return ChecksumAlgorithm.CRC32; | ||
} | ||
|
||
private static void closeResourcesWhenComplete(CompletableFuture<Void> executeFuture, | ||
S3MetaRequest s3MetaRequest, | ||
S3CrtResponseHandlerAdapter responseHandler) { | ||
|
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
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.
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 see we do a
where is SdkExecutionAttribute.RESOLVED_CHECKSUM_SPECS updated with resolved in case of code flow for transfer manager execution ?