-
Notifications
You must be signed in to change notification settings - Fork 927
Fix bug in MultipartS3AsyncClient GetObject Retryable Errors #6309
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
+610
−59
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3ceee7f
Fix bug in MultipartS3AsyncClient GetObject retryable errors
davidh44 0381604
Merge branch 'master' into hdavidh/multipart-download-retryable-errors
davidh44 4cdded1
Remove retry logic from SplittingTransformer
davidh44 54457df
Update mock error test
davidh44 7f8803f
Address comments pt 1
davidh44 22b0a0b
Address comments pt2
davidh44 05ea027
Add test case and update changelog
davidh44 14cccda
Address comments
davidh44 9749657
Address comments
davidh44 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"type": "bugfix", | ||
"category": "Amazon S3", | ||
"contributor": "", | ||
"description": "Fix a bug in the Java based multipart client where retryable errors from getObject may not be retried correctly." | ||
} |
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 |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
import java.nio.ByteBuffer; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
import org.reactivestreams.Subscriber; | ||
import org.reactivestreams.Subscription; | ||
|
@@ -54,20 +55,10 @@ public class SplittingTransformer<ResponseT, ResultT> implements SdkPublisher<As | |
*/ | ||
private final AsyncResponseTransformer<ResponseT, ResultT> upstreamResponseTransformer; | ||
|
||
/** | ||
* Set to true once {@code .prepare()} is called on the upstreamResponseTransformer | ||
*/ | ||
private final AtomicBoolean preparedCalled = new AtomicBoolean(false); | ||
|
||
/** | ||
* Set to true once {@code .onResponse()} is called on the upstreamResponseTransformer | ||
*/ | ||
private final AtomicBoolean onResponseCalled = new AtomicBoolean(false); | ||
|
||
/** | ||
* Set to true once {@code .onStream()} is called on the upstreamResponseTransformer | ||
*/ | ||
private final AtomicBoolean onStreamCalled = new AtomicBoolean(false); | ||
private boolean onStreamCalled; | ||
|
||
/** | ||
* Set to true once {@code .cancel()} is called in the subscription of the downstream subscriber, or if the | ||
|
@@ -111,6 +102,17 @@ public class SplittingTransformer<ResponseT, ResultT> implements SdkPublisher<As | |
|
||
private final Object cancelLock = new Object(); | ||
|
||
/** | ||
* Keeps track of the upstream future returned by {@code upstreamResponseTransformer.prepare()}. If an error occurs, we | ||
* forward this to the {@code resultFuture}. | ||
*/ | ||
private volatile CompletableFuture<ResultT> upstreamFuture; | ||
|
||
/** | ||
* Tracks the part number. Errors will only be retried for the first part. | ||
*/ | ||
private final AtomicInteger partNumber = new AtomicInteger(0); | ||
|
||
private SplittingTransformer(AsyncResponseTransformer<ResponseT, ResultT> upstreamResponseTransformer, | ||
Long maximumBufferSizeInBytes, | ||
CompletableFuture<ResultT> resultFuture) { | ||
|
@@ -198,7 +200,7 @@ private boolean doEmit() { | |
} | ||
if (outstandingDemand.get() > 0) { | ||
demand = outstandingDemand.decrementAndGet(); | ||
downstreamSubscriber.onNext(new IndividualTransformer()); | ||
downstreamSubscriber.onNext(new IndividualTransformer(partNumber.incrementAndGet())); | ||
} | ||
} | ||
return false; | ||
|
@@ -216,7 +218,7 @@ private void handleSubscriptionCancel() { | |
log.trace(() -> "downstreamSubscriber already null, skipping downstreamSubscriber.onComplete()"); | ||
return; | ||
} | ||
if (!onStreamCalled.get()) { | ||
if (!onStreamCalled) { | ||
// we never subscribe publisherToUpstream to the upstream, it would not complete | ||
downstreamSubscriber = null; | ||
return; | ||
|
@@ -230,6 +232,7 @@ private void handleSubscriptionCancel() { | |
} else { | ||
log.trace(() -> "calling downstreamSubscriber.onComplete()"); | ||
downstreamSubscriber.onComplete(); | ||
CompletableFutureUtils.forwardResultTo(upstreamFuture, resultFuture); | ||
} | ||
downstreamSubscriber = null; | ||
}); | ||
|
@@ -259,28 +262,27 @@ private void handleFutureCancel(Throwable e) { | |
* body publisher. | ||
*/ | ||
private class IndividualTransformer implements AsyncResponseTransformer<ResponseT, ResponseT> { | ||
private final int partNumber; | ||
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. NIT: same here, avoid referring to s3 related terms |
||
private ResponseT response; | ||
private CompletableFuture<ResponseT> individualFuture; | ||
|
||
IndividualTransformer(int partNumber) { | ||
this.partNumber = partNumber; | ||
} | ||
|
||
@Override | ||
public CompletableFuture<ResponseT> prepare() { | ||
this.individualFuture = new CompletableFuture<>(); | ||
if (preparedCalled.compareAndSet(false, true)) { | ||
|
||
if (partNumber == 1) { | ||
if (isCancelled.get()) { | ||
return individualFuture; | ||
} | ||
log.trace(() -> "calling prepare on the upstream transformer"); | ||
CompletableFuture<ResultT> upstreamFuture = upstreamResponseTransformer.prepare(); | ||
if (!resultFuture.isDone()) { | ||
CompletableFutureUtils.forwardResultTo(upstreamFuture, resultFuture); | ||
} | ||
upstreamFuture = upstreamResponseTransformer.prepare(); | ||
|
||
} | ||
resultFuture.whenComplete((r, e) -> { | ||
if (e == null) { | ||
return; | ||
} | ||
individualFuture.completeExceptionally(e); | ||
}); | ||
|
||
individualFuture.whenComplete((r, e) -> { | ||
if (isCancelled.get()) { | ||
handleSubscriptionCancel(); | ||
|
@@ -291,7 +293,7 @@ public CompletableFuture<ResponseT> prepare() { | |
|
||
@Override | ||
public void onResponse(ResponseT response) { | ||
if (onResponseCalled.compareAndSet(false, true)) { | ||
if (partNumber == 1) { | ||
log.trace(() -> "calling onResponse on the upstream transformer"); | ||
upstreamResponseTransformer.onResponse(response); | ||
} | ||
|
@@ -304,7 +306,9 @@ public void onStream(SdkPublisher<ByteBuffer> publisher) { | |
return; | ||
} | ||
synchronized (cancelLock) { | ||
if (onStreamCalled.compareAndSet(false, true)) { | ||
if (partNumber == 1) { | ||
CompletableFutureUtils.forwardResultTo(upstreamFuture, resultFuture); | ||
onStreamCalled = true; | ||
log.trace(() -> "calling onStream on the upstream transformer"); | ||
upstreamResponseTransformer.onStream(upstreamSubscriber -> publisherToUpstream.subscribe( | ||
DelegatingBufferingSubscriber.builder() | ||
|
@@ -319,9 +323,19 @@ public void onStream(SdkPublisher<ByteBuffer> publisher) { | |
|
||
@Override | ||
public void exceptionOccurred(Throwable error) { | ||
publisherToUpstream.error(error); | ||
log.trace(() -> "calling exceptionOccurred on the upstream transformer"); | ||
upstreamResponseTransformer.exceptionOccurred(error); | ||
if (partNumber == 1) { | ||
log.trace(() -> "calling exceptionOccurred on the upstream transformer"); | ||
upstreamResponseTransformer.exceptionOccurred(error); | ||
} | ||
|
||
// Invoking publisherToUpstream.error() essentially fails the request immediately. We should only call this if | ||
// 1) The part number is greater than 1, since we want to retry errors on the first part OR 2) onStream() has | ||
// already been invoked and data has started to be written | ||
synchronized (cancelLock) { | ||
davidh44 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (partNumber > 1 || onStreamCalled) { | ||
publisherToUpstream.error(error); | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
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
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
Oops, something went wrong.
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.
NIT (non-blocking): I think we should avoid referring to 'parts' in the
SplittingTranformer
, that's a s3 concept, when this class is more abstract, in a core package. Maybe rename to something like 'onNextSignalsSent' oronNextNumber
which would track the total amount of 'onNext' signals sent to thedownstreamSubscriber