Skip to content

Commit

Permalink
JCLOUDS-1606: JCLOUDS-1608: Fix MPU off-by-one
Browse files Browse the repository at this point in the history
Previously GCS could not upload large objects due to its 32 part
limit.
  • Loading branch information
verjan-isencia authored and gaul committed Feb 21, 2024
1 parent a983eac commit 47f3477
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public MultipartUploadSlicingAlgorithm(long minimumPartSize, long maximumPartSiz
this.maximumNumberOfParts = maximumNumberOfParts;
}

// TODO: This algorithm is needlessly complicated.
public long calculateChunkSize(long length) {
long unitPartSize = defaultPartSize; // first try with default part size
int parts = (int)(length / unitPartSize);
Expand Down Expand Up @@ -112,6 +113,10 @@ public long calculateChunkSize(long length) {
if (remainder == 0 && parts > 0) {
parts -= 1;
}
if (remainder > 0 && parts == maximumNumberOfParts) {
parts -= 1;
partSize = length / parts;
}
this.chunkSize = partSize;
this.parts = parts;
this.remaining = length - partSize * parts;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ public void testWhenPartsExceedsMaxNumberOfParts() {
// then the number of parts is increasing
length += 1;
chunkSize = strategy.calculateChunkSize(length);
assertEquals(chunkSize, MAX_PART_SIZE);
assertEquals(strategy.getParts(), MAX_NUMBER_OF_PARTS);
assertEquals(strategy.getRemaining(), 1);
assertEquals(chunkSize, 5369246044L);
assertEquals(strategy.getParts(), MAX_NUMBER_OF_PARTS - 1);
assertEquals(strategy.getRemaining(), 6045);
assertEquals(chunkSize * strategy.getParts() + strategy.getRemaining(), length);
}
}

0 comments on commit 47f3477

Please sign in to comment.