-
Notifications
You must be signed in to change notification settings - Fork 1k
Fix multipart download response metadata for presigned URL and normal paths #7077
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
base: feature/master/pre-signed-url-getobject
Are you sure you want to change the base?
Changes from 6 commits
c3252d8
2397de3
c24d9db
587e5c6
d9bc3d6
9cf092f
e628e58
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ | |
| import java.util.concurrent.atomic.AtomicInteger; | ||
| import java.util.concurrent.atomic.AtomicLong; | ||
| import java.util.concurrent.atomic.AtomicReference; | ||
| import java.util.function.UnaryOperator; | ||
| import org.reactivestreams.Subscriber; | ||
| import org.reactivestreams.Subscription; | ||
| import software.amazon.awssdk.annotations.SdkInternalApi; | ||
|
|
@@ -84,12 +85,22 @@ public class ByteArraySplittingTransformer<ResponseT> implements SdkPublisher<As | |
|
|
||
| private final Map<Integer, ByteBuffer> buffers; | ||
|
|
||
| private final UnaryOperator<ResponseT> responseMapper; | ||
|
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. Question: don't we need to update FileAsyncResponseTransfomer as well?
Contributor
Author
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. No, file's existing split(config) now reads the mapper from the config like every other transformer, so it's handled automatically |
||
|
|
||
| public ByteArraySplittingTransformer(AsyncResponseTransformer<ResponseT, ResponseBytes<ResponseT>> | ||
| upstreamResponseTransformer, | ||
| CompletableFuture<ResponseBytes<ResponseT>> resultFuture) { | ||
| this(upstreamResponseTransformer, resultFuture, UnaryOperator.identity()); | ||
| } | ||
|
|
||
| public ByteArraySplittingTransformer(AsyncResponseTransformer<ResponseT, ResponseBytes<ResponseT>> | ||
|
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. Why do we need to new ctor? can we just add a new parameter?
Contributor
Author
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. Cleaned up, the mapper now comes from the config rather than a separate split(config, mapper), |
||
| upstreamResponseTransformer, | ||
| CompletableFuture<ResponseBytes<ResponseT>> resultFuture, | ||
| UnaryOperator<ResponseT> responseMapper) { | ||
| this.upstreamResponseTransformer = upstreamResponseTransformer; | ||
| this.resultFuture = resultFuture; | ||
| this.buffers = new ConcurrentHashMap<>(); | ||
| this.responseMapper = responseMapper; | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -181,7 +192,7 @@ private void handleSubscriptionCancel() { | |
| CompletableFuture<ResponseBytes<ResponseT>> upstreamPrepareFuture = upstreamResponseTransformer.prepare(); | ||
| CompletableFutureUtils.forwardResultTo(upstreamPrepareFuture, resultFuture); | ||
|
|
||
| upstreamResponseTransformer.onResponse(responseT.get()); | ||
| upstreamResponseTransformer.onResponse(responseMapper.apply(responseT.get())); | ||
|
|
||
| int totalPartCount = nextPartNumber.get() - 1; | ||
| if (buffers.size() != totalPartCount) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -334,7 +334,7 @@ private CopyObjectRequest attachSdkAttribute(CopyObjectRequest copyObjectRequest | |
| } | ||
|
|
||
| private GetObjectRequest attachSdkAttribute(GetObjectRequest request, | ||
| Consumer<AwsRequestOverrideConfiguration.Builder> builderMutation) { | ||
| Consumer<AwsRequestOverrideConfiguration.Builder> builderMutation) { | ||
| AwsRequestOverrideConfiguration modifiedRequestOverrideConfig = | ||
| request.overrideConfiguration() | ||
| .map(o -> o.toBuilder().applyMutation(builderMutation).build()) | ||
|
|
@@ -650,11 +650,18 @@ public final <ResultT> Download<ResultT> downloadWithPresignedUrl( | |
| TransferProgressUpdater progressUpdater = new TransferProgressUpdater(presignedDownloadRequest, null); | ||
| progressUpdater.transferInitiated(); | ||
|
|
||
| responseTransformer = isS3ClientMultipartEnabled() | ||
| && presignedDownloadRequest.presignedUrlDownloadRequest().range() == null | ||
| ? progressUpdater.wrapForNonSerialFileDownload( | ||
| responseTransformer, GetObjectRequest.builder().build()) | ||
| : progressUpdater.wrapResponseTransformer(responseTransformer); | ||
| if (isS3ClientMultipartEnabled() | ||
|
Contributor
Author
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. Fixes test failure for bytesTransferred not firing for presigned toBytes multipart downloads. |
||
| && presignedDownloadRequest.presignedUrlDownloadRequest().range() == null) { | ||
| if (responseTransformer.split(b -> b.bufferSizeInBytes(1L)).parallelSplitSupported()) { | ||
|
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. I'm a bit concerned that invoking Is there another way?
Contributor
Author
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. good point, removed. With the mapper on the config, the wrapper's own split() handles both the rewrite and byte counting. |
||
| responseTransformer = progressUpdater.wrapForNonSerialFileDownload( | ||
| responseTransformer, GetObjectRequest.builder().build()); | ||
| } else { | ||
| responseTransformer = progressUpdater.wrapResponseTransformerForMultipartDownload( | ||
| responseTransformer, GetObjectRequest.builder().build()); | ||
| } | ||
| } else { | ||
| responseTransformer = progressUpdater.wrapResponseTransformer(responseTransformer); | ||
| } | ||
| progressUpdater.registerCompletion(returnFuture); | ||
|
|
||
| try { | ||
|
|
||
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.
IMO all public methods in a public API class are inherently public APIs, so we can't really add SdkInternalApi. Should we consider folding responseMapper into SplittingTransformerConfiguration. That way, we don't have to introduce another method
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.
moved responseMapper onto SplittingTransformerConfiguration and removed the extra split method