Skip to content

Fix bug about wrong part size number in CopyObjectHelper #4049

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 2 commits into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/next-release/bugfix-AWSSDKforJavav2-5d8e168.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "bugfix",
"category": "AWS SDK for Java v2",
"contributor": "",
"description": "Fix an issue where the optimal number of parts calculated could be higher than 10,000"
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private void doCopyInParts(CopyObjectRequest copyObjectRequest,
Long contentLength,
CompletableFuture<CopyObjectResponse> returnFuture,
String uploadId) {
long optimalPartSize = calculateOptimalPartSizeForCopy(partSizeInBytes);
long optimalPartSize = calculateOptimalPartSizeForCopy(contentLength);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦🏼‍♀️


int partCount = determinePartCount(contentLength, optimalPartSize);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,41 @@ void multiPartCopy_completeMultipartFailed_shouldFailAndAbort() {
assertThat(actualRequest.uploadId()).isEqualTo(MULTIPART_ID);
}

@Test
void multiPartCopy_contentSizeExceeds10000Parts_shouldAdjustPartSize() {
long contentLength = 1024L * 10_000 * 2; // twice too many parts with configures part size

stubSuccessfulHeadObjectCall(contentLength);
stubSuccessfulCreateMulipartCall();
stubSuccessfulUploadPartCopyCalls();
stubSuccessfulCompleteMultipartCall();

CopyObjectRequest copyObjectRequest = copyObjectRequest();

CompletableFuture<CopyObjectResponse> future = copyHelper.copyObject(copyObjectRequest);

CopyObjectResponse actualResponse = future.join();
assertThat(actualResponse.copyObjectResult()).isNotNull();

ArgumentCaptor<UploadPartCopyRequest> argumentCaptor = ArgumentCaptor.forClass(UploadPartCopyRequest.class);
verify(s3AsyncClient, times(10_000)).uploadPartCopy(argumentCaptor.capture());
List<UploadPartCopyRequest> actualUploadPartCopyRequests = argumentCaptor.getAllValues();
assertThat(actualUploadPartCopyRequests).allSatisfy(d -> {
assertThat(d.sourceBucket()).isEqualTo(SOURCE_BUCKET);
assertThat(d.sourceKey()).isEqualTo(SOURCE_KEY);
assertThat(d.destinationBucket()).isEqualTo(DESTINATION_BUCKET);
assertThat(d.destinationKey()).isEqualTo(DESTINATION_KEY);
});

long expectedPartSize = 2048L;
for (int i = 0; i < actualUploadPartCopyRequests.size(); i++) {
int rangeStart = (int) expectedPartSize * i;
int rangeEnd = (int) (rangeStart + (expectedPartSize - 1));
assertThat(actualUploadPartCopyRequests.get(i).copySourceRange()).isEqualTo(
String.format("bytes=%d-%d", rangeStart, rangeEnd));
}
}

@Test
void copy_cancelResponseFuture_shouldPropagate() {
CopyObjectRequest copyObjectRequest = copyObjectRequest();
Expand Down