Skip to content

feat(storage): add feature header for multi stream feature#16170

Draft
v-pratap wants to merge 4 commits into
googleapis:mainfrom
v-pratap:feature-header-multistream
Draft

feat(storage): add feature header for multi stream feature#16170
v-pratap wants to merge 4 commits into
googleapis:mainfrom
v-pratap:feature-header-multistream

Conversation

@v-pratap

Copy link
Copy Markdown
Contributor

No description provided.

@product-auto-label product-auto-label Bot added the api: storage Issues related to the Cloud Storage API. label Jun 16, 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 a FeatureTracker class to track and report features adopted during storage operations, specifically tracking multi-stream usage in multi-range downloads (kMultiStreamInMRD). The tracked features are encoded as a bitmask, Base64-encoded, and sent via the x-goog-storage-cpp-features metadata header. Feedback was provided on FeatureTracker::RegisterFeature to defensively check that the feature enum value is less than 32 before shifting, preventing potential undefined behavior if more features are added in the future.

Comment on lines +48 to +51
void RegisterFeature(TrackedFeature feature) {
mask_.fetch_or(1U << static_cast<std::uint32_t>(feature),
std::memory_order_relaxed);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Shifting 1U by static_cast<std::uint32_t>(feature) can result in undefined behavior if feature has a value of 32 or greater (since mask_ is a 32-bit atomic integer). To prevent potential undefined behavior as new features are added to the TrackedFeature enum in the future, we should add a safety check to ensure the shift value is strictly less than 32.

  void RegisterFeature(TrackedFeature feature) {
    auto const shift = static_cast<std::uint32_t>(feature);
    if (shift < 32) {
      mask_.fetch_or(1U << shift, std::memory_order_relaxed);
    }
  }
References
  1. Prefer defensive code to prevent potential undefined behavior or contract changes in the future.

@codecov

codecov Bot commented Jun 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.71429% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.20%. Comparing base (cc530e2) to head (d0a921e).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...rage/internal/async/object_descriptor_impl_test.cc 93.02% 3 Missing ⚠️
google/cloud/storage/internal/async/open_object.cc 80.00% 2 Missing ⚠️
...d/storage/internal/grpc/configure_client_context.h 90.90% 1 Missing ⚠️
google/cloud/storage/internal/rest/stub.cc 88.88% 1 Missing ⚠️
...gle/cloud/storage/internal/storage_stub_factory.cc 91.66% 1 Missing ⚠️
...loud/storage/internal/storage_stub_factory_test.cc 96.15% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16170      +/-   ##
==========================================
- Coverage   92.21%   92.20%   -0.02%     
==========================================
  Files        2265     2268       +3     
  Lines      209121   209317     +196     
==========================================
+ Hits       192835   192994     +159     
- Misses      16286    16323      +37     

☔ 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.

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.

1 participant