Skip to content

Commit a7720e4

Browse files
authored
chore(storage): fix checksums for gRPC uploads (#7193)
There was an API change so that checksums can now only be provided by the StartResumableUpload request rather than while uploading. Send the checksum at this stage instead. Fixes #7033
1 parent 94723a2 commit a7720e4

2 files changed

Lines changed: 22 additions & 24 deletions

File tree

storage/grpc_client.go

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,11 +1496,29 @@ func (w *gRPCWriter) startResumableUpload() error {
14961496
if err != nil {
14971497
return err
14981498
}
1499+
req := &storagepb.StartResumableWriteRequest{
1500+
WriteObjectSpec: spec,
1501+
CommonObjectRequestParams: toProtoCommonObjectRequestParams(w.encryptionKey),
1502+
}
1503+
// TODO: Currently the checksums are only sent on the first message
1504+
// of the stream, but in the future, we must also support sending it
1505+
// on the *last* message of the stream (instead of the first).
1506+
if w.sendCRC32C {
1507+
req.ObjectChecksums = &storagepb.ObjectChecksums{
1508+
Crc32C: proto.Uint32(w.attrs.CRC32C),
1509+
}
1510+
}
1511+
if len(w.attrs.MD5) != 0 {
1512+
if cs := req.GetObjectChecksums(); cs == nil {
1513+
req.ObjectChecksums = &storagepb.ObjectChecksums{
1514+
Md5Hash: w.attrs.MD5,
1515+
}
1516+
} else {
1517+
cs.Md5Hash = w.attrs.MD5
1518+
}
1519+
}
14991520
return run(w.ctx, func() error {
1500-
upres, err := w.c.raw.StartResumableWrite(w.ctx, &storagepb.StartResumableWriteRequest{
1501-
WriteObjectSpec: spec,
1502-
CommonObjectRequestParams: toProtoCommonObjectRequestParams(w.encryptionKey),
1503-
})
1521+
upres, err := w.c.raw.StartResumableWrite(w.ctx, req)
15041522
w.upid = upres.GetUploadId()
15051523
return err
15061524
}, w.settings.retry, w.settings.idempotent, setRetryHeaderGRPC(w.ctx))
@@ -1587,23 +1605,6 @@ func (w *gRPCWriter) uploadBuffer(recvd int, start int64, doneReading bool) (*st
15871605
req.CommonObjectRequestParams = toProtoCommonObjectRequestParams(w.encryptionKey)
15881606
}
15891607

1590-
// TODO: Currently the checksums are only sent on the first message
1591-
// of the stream, but in the future, we must also support sending it
1592-
// on the *last* message of the stream (instead of the first).
1593-
if w.sendCRC32C {
1594-
req.ObjectChecksums = &storagepb.ObjectChecksums{
1595-
Crc32C: proto.Uint32(w.attrs.CRC32C),
1596-
}
1597-
}
1598-
if len(w.attrs.MD5) != 0 {
1599-
if cs := req.GetObjectChecksums(); cs == nil {
1600-
req.ObjectChecksums = &storagepb.ObjectChecksums{
1601-
Md5Hash: w.attrs.MD5,
1602-
}
1603-
} else {
1604-
cs.Md5Hash = w.attrs.MD5
1605-
}
1606-
}
16071608
}
16081609

16091610
err = w.stream.Send(req)

storage/integration_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,9 +1082,6 @@ func TestIntegration_MultiMessageWriteGRPC(t *testing.T) {
10821082

10831083
func TestIntegration_MultiChunkWrite(t *testing.T) {
10841084
multiTransportTest(context.Background(), t, func(t *testing.T, ctx context.Context, bucket string, _ string, client *Client) {
1085-
if bucket == grpcBucketName {
1086-
t.Skip("https://github.com/googleapis/google-cloud-go/issues/7033")
1087-
}
10881085
h := testHelper{t}
10891086
obj := client.Bucket(bucket).Object(uidSpace.New()).Retryer(WithPolicy(RetryAlways))
10901087
defer h.mustDeleteObject(obj)

0 commit comments

Comments
 (0)