-
Notifications
You must be signed in to change notification settings - Fork 915
Fixed the issue in S3 multipart client where the list of parts could … #4998
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 all commits
Commits
Show all changes
2 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"type": "bugfix", | ||
"category": "AWS S3", | ||
"contributor": "", | ||
"description": "Fixed the issue in S3 multipart client where the list of parts could be out of order in CompleteMultipartRequest, causing `The list of parts was not in ascending order` error to be thrown." | ||
} |
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,13 +18,15 @@ | |
import static software.amazon.awssdk.services.s3.multipart.S3MultipartExecutionAttribute.JAVA_PROGRESS_LISTENER; | ||
|
||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.ConcurrentLinkedQueue; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import java.util.concurrent.atomic.AtomicReferenceArray; | ||
import java.util.function.Consumer; | ||
import java.util.stream.IntStream; | ||
import org.reactivestreams.Subscriber; | ||
import org.reactivestreams.Subscription; | ||
import software.amazon.awssdk.annotations.SdkInternalApi; | ||
|
@@ -59,12 +61,16 @@ public class KnownContentLengthAsyncRequestBodySubscriber implements Subscriber< | |
private final Collection<CompletableFuture<CompletedPart>> futures = new ConcurrentLinkedQueue<>(); | ||
private final PutObjectRequest putObjectRequest; | ||
private final CompletableFuture<PutObjectResponse> returnFuture; | ||
private final Map<Integer, CompletedPart> completedParts; | ||
private final AtomicReferenceArray<CompletedPart> completedParts; | ||
private final Map<Integer, CompletedPart> existingParts; | ||
private final PublisherListener<Long> progressListener; | ||
private Subscription subscription; | ||
private volatile boolean isDone; | ||
private volatile boolean isPaused; | ||
/** | ||
* Indicates whether CompleteMultipart has been initiated or not. | ||
*/ | ||
private final AtomicBoolean completedMultipartInitiated = new AtomicBoolean(false); | ||
private volatile CompletableFuture<CompleteMultipartUploadResponse> completeMpuFuture; | ||
|
||
KnownContentLengthAsyncRequestBodySubscriber(MpuRequestContext mpuRequestContext, | ||
|
@@ -75,9 +81,9 @@ public class KnownContentLengthAsyncRequestBodySubscriber implements Subscriber< | |
this.putObjectRequest = mpuRequestContext.request().left(); | ||
this.returnFuture = returnFuture; | ||
this.uploadId = mpuRequestContext.uploadId(); | ||
this.existingParts = mpuRequestContext.existingParts(); | ||
this.existingParts = mpuRequestContext.existingParts() == null ? new HashMap<>() : mpuRequestContext.existingParts(); | ||
this.numExistingParts = NumericUtils.saturatedCast(mpuRequestContext.numPartsCompleted()); | ||
this.completedParts = new ConcurrentHashMap<>(); | ||
this.completedParts = new AtomicReferenceArray<>(partCount); | ||
this.multipartUploadHelper = multipartUploadHelper; | ||
this.progressListener = putObjectRequest.overrideConfiguration().map(c -> c.executionAttributes() | ||
.getAttribute(JAVA_PROGRESS_LISTENER)) | ||
|
@@ -154,8 +160,8 @@ public void onNext(AsyncRequestBody asyncRequestBody) { | |
partNumber.getAndIncrement(), | ||
uploadId); | ||
|
||
Consumer<CompletedPart> completedPartConsumer = | ||
completedPart -> completedParts.put(completedPart.partNumber(), completedPart); | ||
Consumer<CompletedPart> completedPartConsumer = completedPart -> completedParts.set(completedPart.partNumber() - 1, | ||
completedPart); | ||
multipartUploadHelper.sendIndividualUploadPartRequest(uploadId, completedPartConsumer, futures, | ||
Pair.of(uploadRequest, asyncRequestBody), progressListener) | ||
.whenComplete((r, t) -> { | ||
|
@@ -193,15 +199,16 @@ public void onComplete() { | |
} | ||
|
||
private void completeMultipartUploadIfFinished(int requestsInFlight) { | ||
if (isDone && requestsInFlight == 0) { | ||
if (isDone && requestsInFlight == 0 && completedMultipartInitiated.compareAndSet(false, true)) { | ||
CompletedPart[] parts; | ||
if (existingParts.isEmpty()) { | ||
parts = completedParts.values().toArray(new CompletedPart[0]); | ||
} else if (!completedParts.isEmpty()) { | ||
parts = | ||
IntStream.range(0, completedParts.length()) | ||
.mapToObj(completedParts::get) | ||
.toArray(CompletedPart[]::new); | ||
} else { | ||
// List of CompletedParts needs to be in ascending order | ||
parts = mergeCompletedParts(); | ||
} else { | ||
parts = existingParts.values().toArray(new CompletedPart[0]); | ||
Comment on lines
-203
to
-204
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. This else block is not needed since mergeCompletedParts should handle it |
||
} | ||
completeMpuFuture = multipartUploadHelper.completeMultipartUpload(returnFuture, uploadId, parts, putObjectRequest); | ||
} | ||
|
@@ -212,7 +219,7 @@ private CompletedPart[] mergeCompletedParts() { | |
int currPart = 1; | ||
while (currPart < partCount + 1) { | ||
CompletedPart completedPart = existingParts.containsKey(currPart) ? existingParts.get(currPart) : | ||
completedParts.get(currPart); | ||
completedParts.get(currPart - 1); | ||
merged[currPart - 1] = completedPart; | ||
currPart++; | ||
} | ||
|
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,7 +15,6 @@ | |
|
||
package software.amazon.awssdk.services.s3.internal.multipart; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import software.amazon.awssdk.annotations.SdkInternalApi; | ||
|
@@ -94,7 +93,7 @@ public String uploadId() { | |
} | ||
|
||
public Map<Integer, CompletedPart> existingParts() { | ||
return existingParts != null ? Collections.unmodifiableMap(existingParts) : null; | ||
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 removed this since this seems a bit overkill for an internal API. |
||
return existingParts; | ||
} | ||
|
||
public static final class Builder { | ||
|
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.
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.
Added back this check. It was removed as part of the refactoring for some reason.