Skip to content

Commit 4da9f31

Browse files
authored
fix: update PCU request building logic to properly clear crc32c and md5 (#3323)
1 parent 3d4eb9f commit 4da9f31

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

google-cloud-storage/src/main/java/com/google/cloud/storage/ParallelCompositeUploadBlobWriteSessionConfig.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,9 @@ private ParallelCompositeUploadWriterFactory(
10251025
@Override
10261026
public WritableByteChannelSession<?, BlobInfo> writeSession(
10271027
StorageInternal s, BlobInfo info, Opts<ObjectTargetOpt> opts) {
1028-
return new PCUSession(s, info, opts);
1028+
// if crc32cMatch or md5Match were specified, they will already be in opts
1029+
BlobInfo trimmed = info.toBuilder().clearCrc32c().clearMd5().build();
1030+
return new PCUSession(s, trimmed, opts);
10291031
}
10301032

10311033
private final class PCUSession

google-cloud-storage/src/main/java/com/google/cloud/storage/ParallelCompositeUploadWritableByteChannel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ private ApiFuture<BlobInfo> cleanupParts(BlobInfo finalInfo) {
425425

426426
private BlobInfo definePart(BlobInfo ultimateObject, PartRange partRange, long offset) {
427427
BlobId id = ultimateObject.getBlobId();
428-
BlobInfo.Builder b = ultimateObject.toBuilder();
428+
BlobInfo.Builder b = ultimateObject.toBuilder().clearCrc32c().clearMd5();
429429
String partName = partNamingStrategy.fmtName(id.getName(), partRange);
430430
b.setBlobId(BlobId.of(id.getBucket(), partName));
431431
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();

google-cloud-storage/src/test/java/com/google/cloud/storage/ParallelCompositeUploadWritableByteChannelTest.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import com.google.cloud.storage.UnifiedOpts.ObjectSourceOpt;
4040
import com.google.cloud.storage.UnifiedOpts.ObjectTargetOpt;
4141
import com.google.cloud.storage.UnifiedOpts.Opts;
42+
import com.google.cloud.storage.it.ChecksummedTestContent;
4243
import com.google.cloud.storage.spi.v1.StorageRpc;
4344
import com.google.common.base.MoreObjects;
4445
import com.google.common.base.Preconditions;
@@ -810,6 +811,41 @@ public BlobInfo internalDirectUpload(
810811
pcu.close();
811812
}
812813

814+
@Test
815+
public void partDoesNotSpecifyAnyChecksum() throws IOException {
816+
FakeStorageInternal storageInternal =
817+
new FakeStorageInternal() {
818+
@Override
819+
public BlobInfo compose(ComposeRequest composeRequest) {
820+
BlobInfo target = composeRequest.getTarget();
821+
if (target.getBlobId().getName().startsWith(partNamingStrategy.prefix)) {
822+
assertThat(target.getCrc32c()).isNull();
823+
assertThat(target.getMd5()).isNull();
824+
}
825+
return super.compose(composeRequest);
826+
}
827+
};
828+
ChecksummedTestContent content = ChecksummedTestContent.gen(bufferCapacity * 3 - 1);
829+
ParallelCompositeUploadWritableByteChannel pcu =
830+
new ParallelCompositeUploadWritableByteChannel(
831+
bufferHandlePool,
832+
MoreExecutors.directExecutor(),
833+
partNamingStrategy,
834+
PartCleanupStrategy.always(),
835+
2,
836+
b -> b,
837+
finalObject,
838+
storageInternal,
839+
info.toBuilder()
840+
.setCrc32c(content.getCrc32cBase64())
841+
.setMd5(content.getMd5Base64())
842+
.build(),
843+
opts);
844+
pcu.write(content.asByteBuffer());
845+
846+
pcu.close();
847+
}
848+
813849
@NonNull
814850
private ParallelCompositeUploadWritableByteChannel defaultPcu(int maxElementsPerCompact) {
815851
return new ParallelCompositeUploadWritableByteChannel(

0 commit comments

Comments
 (0)