Repository navigation
feat(storage): add absl::Cord accessor to ReadPayload - #16539
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces cord_contents() to ReadPayload to allow retrieving payload contents as an absl::Cord, which is useful for sharing underlying buffers without copying. It also adds corresponding unit tests and integration tests to verify this behavior. The review feedback highlights several style guide violations: std::string_view and std::optional should be preferred over their absl counterparts, and the use of auto should be avoided when it obscures StatusOr or other complex return types.
`ReadPayload` stores its data in an `absl::Cord`, but the only accessor returns a `std::vector<absl::string_view>`. Applications that need to retain the data beyond the lifetime of the payload must copy it. Add `ReadPayload::cord_contents()`, which returns the underlying `absl::Cord`. Copying the Cord is cheap (the buffers are reference counted), and an rvalue overload lets applications move the Cord out of the payload. Retaining the Cord keeps only the data buffers alive, not the RPC that received them.
0ebcefe to
246e754
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #16539 +/- ##
==========================================
- Coverage 92.40% 92.39% -0.01%
==========================================
Files 2265 2265
Lines 219433 219470 +37
==========================================
+ Hits 202760 202781 +21
- Misses 16673 16689 +16 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Please update the note in the PR description about regional buckets: |
There was a problem hiding this comment.
clang-tidy fails on this PR because of one of the new test cases. Please address those failures.
There was a problem hiding this comment.
Done. Added // NOLINTNEXTLINE(performance-unnecessary-copy-initialization) where absl::Cord is intentionally copy-constructed in the tests, and verified clang-tidy passes cleanly.
|
Updated the PR description and addressed all review comments. Thanks for the review! |
ReadPayloadstores its data in anabsl::Cord, but the only accessor (contents()) returns astd::vector. Applications that need to retain the data beyond the lifetime of the payload must copy it.This PR adds
ReadPayload::cord_contents(), which exposes the underlyingabsl::Cord:Copying an
absl::Cordis cheap (the buffers are reference counted), and the rvalue overload lets applications move the Cord out of the payload. Retaining the Cord keeps only the data buffers alive, not the RPC that received them (the content is stolen from the response proto before the payload is created).Testing
read_payload_impl_test.cc: contents, multi-chunk payloads, empty payloads, and that copies / moves share the underlying buffer (no data copy) and moving transfers ownership.async_client_integration_test.cc, for bothAsyncClient::ReadObject()andAsyncClient::Open()+ObjectDescriptor::Read():cord_contents()refers to the same buffers ascontents(), and copies share them.StreamingReadCordContentsusesInsertObject(works with standard test buckets and the testbench emulator), andOpenReadCordContentsusesStartAppendableObjectUpload(supported on zonal buckets in production and the testbench emulator).b/533700890