Skip to content

Commit 47f3477

Browse files
verjan-isenciagaul
authored andcommitted
JCLOUDS-1606: JCLOUDS-1608: Fix MPU off-by-one
Previously GCS could not upload large objects due to its 32 part limit.
1 parent a983eac commit 47f3477

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

blobstore/src/main/java/org/jclouds/blobstore/strategy/internal/MultipartUploadSlicingAlgorithm.java

+5
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public MultipartUploadSlicingAlgorithm(long minimumPartSize, long maximumPartSiz
7272
this.maximumNumberOfParts = maximumNumberOfParts;
7373
}
7474

75+
// TODO: This algorithm is needlessly complicated.
7576
public long calculateChunkSize(long length) {
7677
long unitPartSize = defaultPartSize; // first try with default part size
7778
int parts = (int)(length / unitPartSize);
@@ -112,6 +113,10 @@ public long calculateChunkSize(long length) {
112113
if (remainder == 0 && parts > 0) {
113114
parts -= 1;
114115
}
116+
if (remainder > 0 && parts == maximumNumberOfParts) {
117+
parts -= 1;
118+
partSize = length / parts;
119+
}
115120
this.chunkSize = partSize;
116121
this.parts = parts;
117122
this.remaining = length - partSize * parts;

blobstore/src/test/java/org/jclouds/blobstore/strategy/internal/MpuPartitioningAlgorithmTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ public void testWhenPartsExceedsMaxNumberOfParts() {
137137
// then the number of parts is increasing
138138
length += 1;
139139
chunkSize = strategy.calculateChunkSize(length);
140-
assertEquals(chunkSize, MAX_PART_SIZE);
141-
assertEquals(strategy.getParts(), MAX_NUMBER_OF_PARTS);
142-
assertEquals(strategy.getRemaining(), 1);
140+
assertEquals(chunkSize, 5369246044L);
141+
assertEquals(strategy.getParts(), MAX_NUMBER_OF_PARTS - 1);
142+
assertEquals(strategy.getRemaining(), 6045);
143143
assertEquals(chunkSize * strategy.getParts() + strategy.getRemaining(), length);
144144
}
145145
}

0 commit comments

Comments
 (0)