-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat(storage): calculate crc32c by default and pass checksum in trailing and per-chunk request #13205
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
+233
−28
Merged
feat(storage): calculate crc32c by default and pass checksum in trailing and per-chunk request #13205
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0056236
feat(storage): calculate crc32c by default and pass checksum in trail…
krishnamd-jkp c5ae72b
fix(storage): lock fullObjectChecksum with mutex when accessing
krishnamd-jkp d43e043
fix(storage): resolve comments
krishnamd-jkp 052d924
fix(storage): remove unnecessary mutex lock
krishnamd-jkp 17771dd
fix(storage): clarify comments
krishnamd-jkp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
krishnamd-jkp marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| // Copyright 2025 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package storage | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "cloud.google.com/go/storage/internal/apiv2/storagepb" | ||
| "google.golang.org/protobuf/proto" | ||
| ) | ||
|
|
||
| func TestGetObjectChecksums(t *testing.T) { | ||
krishnamd-jkp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| tests := []struct { | ||
| name string | ||
| fullObjectChecksum func() uint32 | ||
| finishWrite bool | ||
| sendCRC32C bool | ||
| disableAutoChecksum bool | ||
| attrs *ObjectAttrs | ||
| want *storagepb.ObjectChecksums | ||
| }{ | ||
| { | ||
| name: "finishWrite is false", | ||
| finishWrite: false, | ||
| want: nil, | ||
| }, | ||
| { | ||
| name: "sendCRC32C is true, attrs have CRC32C", | ||
| finishWrite: true, | ||
| sendCRC32C: true, | ||
| attrs: &ObjectAttrs{CRC32C: 123}, | ||
| want: &storagepb.ObjectChecksums{ | ||
| Crc32C: proto.Uint32(123), | ||
| }, | ||
| }, | ||
| { | ||
| name: "disableCRC32C is true and sendCRC32C is true", | ||
| finishWrite: true, | ||
| sendCRC32C: true, | ||
| disableAutoChecksum: true, | ||
| attrs: &ObjectAttrs{CRC32C: 123}, | ||
| want: &storagepb.ObjectChecksums{ | ||
| Crc32C: proto.Uint32(123), | ||
| }, | ||
| }, | ||
| { | ||
| name: "disableCRC32C is true and sendCRC32C is false", | ||
| finishWrite: true, | ||
| sendCRC32C: false, | ||
| disableAutoChecksum: true, | ||
| want: nil, | ||
| }, | ||
| { | ||
| name: "CRC32C enabled, no user-provided checksum", | ||
| fullObjectChecksum: func() uint32 { return 456 }, | ||
| finishWrite: true, | ||
| sendCRC32C: false, | ||
| disableAutoChecksum: false, | ||
| attrs: &ObjectAttrs{}, | ||
| want: &storagepb.ObjectChecksums{ | ||
| Crc32C: proto.Uint32(456), | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| got := getObjectChecksums(&getObjectChecksumsParams{ | ||
| fullObjectChecksum: tt.fullObjectChecksum, | ||
| finishWrite: tt.finishWrite, | ||
| sendCRC32C: tt.sendCRC32C, | ||
| disableAutoChecksum: tt.disableAutoChecksum, | ||
| attrs: tt.attrs, | ||
| }) | ||
| if !proto.Equal(got, tt.want) { | ||
| t.Errorf("getObjectChecksums() = %v, want %v", got, tt.want) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wanted to note that you are doing the work twice here for each set of bytes between here and L945. In theory it should be possible to calculate the per-message checksum once per buffer and then use those sums to update the full object checksum as well. It doesn't look like there is an easy interface to do this with in Go, but maybe worth considering if you are trying to save CPU.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case of no retries, yes, it does seem like the same calculation is being done twice. But in case of retries, the buffer in this line and the buffer in L945 will be out of sync. And I cannot use the checksum in L945 to update the global checksum because we could be using same bytes multiple times in case of retries. So I had to separate these two computations.