feat(storage): Make PrecomputedChecksumsOption compatible with Options - #16295
Conversation
By simply adding `using Type = std::string;` to the legacy ComplexOption
structs `MD5HashValue` and `Crc32cChecksumValue`, we instantly make them
compatible with the modern `google::cloud::Options` API.
This enables the exact same type to be used as both a variadic option
for the synchronous client (e.g. `InsertObject(..., MD5HashValue("hash"))`)
and as a modern option for the asynchronous client (e.g.
`options.set<MD5HashValue>("hash")`).
This avoids needing any deprecations, any new types, or any duplicate
upload/download namespace variants. It is perfectly backward-compatible.
There was a problem hiding this comment.
Code Review
This pull request updates the Google Cloud Storage C++ client to fall back to the current context options for Crc32cChecksumValue and MD5HashValue when they are not explicitly provided in the request options. This change affects object writing, hashing functions, REST stub operations, and parallel uploads. The review feedback suggests optimizing the parallel upload implementation by using an immediately-invoked lambda expression (IIFE) to retrieve the current options once instead of calling google::cloud::internal::CurrentOptions() multiple times in the initializer list.
Introduces a map-based option that allows users to provide both CRC32C and MD5 hashes simultaneously for an upload or download.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #16295 +/- ##
==========================================
- Coverage 92.31% 92.30% -0.01%
==========================================
Files 2223 2223
Lines 208086 208141 +55
==========================================
+ Hits 192086 192123 +37
- Misses 16000 16018 +18 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…t for performance Refactored PrecomputedChecksumsOption to use a flat PrecomputedChecksums struct containing crc32c and md5 fields rather than allocating a std::map dynamically on the hot path for every object insertion. Added unit tests to internal/hash_function_impl_test.cc to verify its behavior and precedence against explicitly provided variadic checksum options.
- Removed unused <map> include from options.h - Extracted PrecomputedChecksumsOption lookups into local variables to avoid redundant get() calls in parallel_upload.cc, client.cc, hash_function.cc, and rest/stub.cc.
This pull request updates the Google Cloud Storage C++ client to fall back to the current context options for
Crc32cChecksumValueandMD5HashValuewhen they are not explicitly provided in the request options. It also introduces a flatPrecomputedChecksumsstruct andPrecomputedChecksumsOptionto cleanly pass multiple precomputed hashes within the unifiedOptionsframework.This enables the same exact conceptual options to be used as both a variadic argument for the synchronous client (e.g.
InsertObject(..., MD5HashValue("hash"))) and as a modern option for the asynchronous client (e.g.options.set<PrecomputedChecksumsOption>({..., "hash"})), while avoiding heap allocations and lookups during hash execution.This avoids needing any deprecations, any new types leaking into public method signatures, or any duplicate upload/download namespace variants. It is perfectly backward-compatible.