feat(storage): add full object checksum validation for grpc flow#13265
feat(storage): add full object checksum validation for grpc flow#13265Dhriti07 wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces cumulative checksum validation for full object reads in the GapicUnbufferedReadableByteChannel. It wraps the existing hasher in a CumulativeHasher when a read starts at offset 0 and triggers validation once the end of the stream is reached. The update includes several new test cases to verify validation behavior across different scenarios, such as multi-chunk reads and ranged reads. Review feedback suggests optimizing the implementation by only instantiating the CumulativeHasher when no read limit is specified, thereby avoiding unnecessary overhead for ranged reads where validation is skipped.
| this.hasher = (req.getReadOffset() == 0) | ||
| ? new CumulativeHasher(hasher, 0, req.getReadLimit() <= 0 ? OptionalLong.empty() : OptionalLong.of(req.getReadLimit())) | ||
| : hasher; |
There was a problem hiding this comment.
The CumulativeHasher is currently instantiated for any read starting at offset 0, even if a readLimit is provided. However, the test case validateCumulativeChecksum_skippedForRangedRead demonstrates that validation is skipped when a limit is present. To avoid unnecessary object allocation and wrapping overhead for ranged reads, the CumulativeHasher should only be instantiated when both the offset is 0 and no limit is specified (i.e., a full object read).
| this.hasher = (req.getReadOffset() == 0) | |
| ? new CumulativeHasher(hasher, 0, req.getReadLimit() <= 0 ? OptionalLong.empty() : OptionalLong.of(req.getReadLimit())) | |
| : hasher; | |
| this.hasher = (req.getReadOffset() == 0 && req.getReadLimit() <= 0) | |
| ? new CumulativeHasher(hasher, 0, OptionalLong.empty()) | |
| : hasher; |
Adding full object checksum for grpc flow
Refer to: go/full_checksum_java