Skip to content

feat(storage): add absl::Cord accessor to ReadPayload - #16539

Merged
v-pratap merged 4 commits into
googleapis:mainfrom
v-pratap:feat-storage-read-payload-cord
Oct 14, 2026
Merged

v-pratap merged 4 commits into
googleapis:mainfrom
v-pratap:feat-storage-read-payload-cord

Conversation

@v-pratap

@v-pratap v-pratap commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

ReadPayload stores its data in an absl::Cord, but the only accessor (contents()) returns a std::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 underlying absl::Cord:

absl::Cord const& cord_contents() const&;
absl::Cord cord_contents() &&;

Copying an absl::Cord is 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

  • Unit tests in 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.
  • Integration tests in async_client_integration_test.cc, for both AsyncClient::ReadObject() and AsyncClient::Open() + ObjectDescriptor::Read():
    • cord_contents() refers to the same buffers as contents(), and copies share them.
    • Cords retained from each payload remain valid and contain the full object after the payloads, reader, and client are destroyed.
    • StreamingReadCordContents uses InsertObject (works with standard test buckets and the testbench emulator), and OpenReadCordContents uses StartAppendableObjectUpload (supported on zonal buckets in production and the testbench emulator).

b/533700890

@v-pratap
v-pratap requested review from a team as code owners October 6, 2026 10:25
@product-auto-label product-auto-label Bot added the api: storage Issues related to the Cloud Storage API. label Oct 6, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread google/cloud/storage/internal/async/read_payload_impl_test.cc Outdated
Comment thread google/cloud/storage/internal/async/read_payload_impl_test.cc Outdated
Comment thread google/cloud/storage/tests/async_client_integration_test.cc Outdated
Comment thread google/cloud/storage/tests/async_client_integration_test.cc Outdated
Comment thread google/cloud/storage/tests/async_client_integration_test.cc Outdated
Comment thread google/cloud/storage/tests/async_client_integration_test.cc Outdated
Comment thread google/cloud/storage/tests/async_client_integration_test.cc Outdated
Comment thread google/cloud/storage/tests/async_client_integration_test.cc Outdated
`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.
@v-pratap
v-pratap force-pushed the feat-storage-read-payload-cord branch from 0ebcefe to 246e754 Compare October 6, 2026 10:29
@codecov

codecov Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.39%. Comparing base (61709d3) to head (db53a9f).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kalragauri

Copy link
Copy Markdown
Contributor

Please update the note in the PR description about regional buckets: StartAppendableObjectUpload (appendable: true) is only supported on zonal buckets in production (and the testbench emulator).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy fails on this PR because of one of the new test cases. Please address those failures.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Added // NOLINTNEXTLINE(performance-unnecessary-copy-initialization) where absl::Cord is intentionally copy-constructed in the tests, and verified clang-tidy passes cleanly.

Comment thread google/cloud/storage/tests/async_client_integration_test.cc
Comment thread google/cloud/storage/internal/async/read_payload_impl_test.cc
Comment thread google/cloud/storage/tests/async_client_integration_test.cc Outdated
@v-pratap

Copy link
Copy Markdown
Contributor Author

Updated the PR description and addressed all review comments. Thanks for the review!

@v-pratap
v-pratap merged commit 982a01f into googleapis:main Oct 14, 2026
71 checks passed

This branch was successfully deployed

1 active deployment
false — db53a9f2 Deployed Oct 13, 2026 by v-pratap via Save PR ref #12422
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: storage Issues related to the Cloud Storage API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants