-
Notifications
You must be signed in to change notification settings - Fork 455
feat(storage): introduce core feature adoption tracking bitmask and options #16173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
v-pratap
wants to merge
1
commit into
googleapis:main
Choose a base branch
from
v-pratap:feat/storage-feature-tracker-core
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| // Copyright 2026 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // https://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #include "google/cloud/storage/internal/feature_tracker.h" | ||
| #include "google/cloud/storage/internal/base64.h" | ||
| #include "google/cloud/storage/options.h" | ||
| #include "google/cloud/options.h" | ||
| #include <memory> | ||
| #include <vector> | ||
|
|
||
| namespace google { | ||
| namespace cloud { | ||
| namespace storage { | ||
| GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN | ||
| namespace internal { | ||
|
|
||
| std::string EncodeFeatureTrackerBitmask(std::uint32_t mask) { | ||
| if (mask == 0) return {}; | ||
|
|
||
| std::vector<std::uint8_t> bytes; | ||
| for (int i = 0; i < 4; ++i) { | ||
| auto b = static_cast<std::uint8_t>((mask >> (24 - i * 8)) & 0xFF); | ||
| if (!bytes.empty() || b != 0) { | ||
| bytes.push_back(b); | ||
| } | ||
| } | ||
| return Base64Encode(bytes); | ||
| } | ||
|
|
||
| Options SetupFeatureTracker(Options opts) { | ||
| if (opts.has<EnableFeatureReportsOption>() && | ||
| !opts.get<EnableFeatureReportsOption>()) { | ||
| return std::move(opts); | ||
| } | ||
| if (opts.has<FeatureTrackerOption>()) return std::move(opts); | ||
|
|
||
| std::uint32_t mask = 0; | ||
| // Add checks for configuration-driven options here as they are introduced. | ||
| opts.set<FeatureTrackerOption>(std::make_shared<FeatureTracker>(mask)); | ||
| return std::move(opts); | ||
| } | ||
|
|
||
| } // namespace internal | ||
| GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END | ||
| } // namespace storage | ||
| } // namespace cloud | ||
| } // namespace google | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| // Copyright 2026 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // https://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_INTERNAL_FEATURE_TRACKER_H | ||
| #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_INTERNAL_FEATURE_TRACKER_H | ||
|
|
||
| #include "google/cloud/storage/version.h" | ||
| #include "google/cloud/options.h" | ||
| #include <atomic> | ||
| #include <cstdint> | ||
| #include <memory> | ||
| #include <string> | ||
|
|
||
| namespace google { | ||
| namespace cloud { | ||
| namespace storage { | ||
| GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN | ||
| namespace internal { | ||
|
|
||
| inline constexpr auto kFeatureTrackerHeaderName = "x-goog-storage-cpp-features"; | ||
|
|
||
| // Tracked features represented as bit positions in a bitmask. | ||
| enum class TrackedFeature : std::uint32_t { | ||
| // Operation-Driven Optimizations | ||
| kMultiStreamInMRD = 0, | ||
| kPCU = 1, | ||
|
|
||
| // Configuration-Driven Options | ||
| kGrpcDirectPathEnforced = 2, | ||
| kJsonReads = 3, | ||
| }; | ||
|
|
||
| // Converts a feature bitmask to a Base64-encoded string, stripping leading | ||
| // zero bytes to maintain compact representation. | ||
| std::string EncodeFeatureTrackerBitmask(std::uint32_t mask); | ||
|
|
||
| // A thread-safe state object that can be shared between operation connections | ||
| // (like ObjectDescriptorImpl) and RPC factories (like OpenStreamFactory) | ||
| // to track which features are adopted during an operation. | ||
| class FeatureTracker { | ||
| public: | ||
| FeatureTracker() = default; | ||
| explicit FeatureTracker(std::uint32_t initial) : mask_(initial) {} | ||
|
|
||
| void RegisterFeature(TrackedFeature feature) { | ||
| mask_.fetch_or(1U << static_cast<std::uint32_t>(feature), | ||
| std::memory_order_relaxed); | ||
| } | ||
|
|
||
| std::uint32_t GetMask() const { | ||
| return mask_.load(std::memory_order_relaxed); | ||
| } | ||
|
|
||
| std::string HeaderValue() const { | ||
| return EncodeFeatureTrackerBitmask(GetMask()); | ||
| } | ||
|
|
||
| private: | ||
| std::atomic<std::uint32_t> mask_{0}; | ||
| }; | ||
|
|
||
| struct FeatureTrackerOption { | ||
| using Type = std::shared_ptr<FeatureTracker>; | ||
| }; | ||
|
|
||
| // Evaluates client configuration options, creates a shared FeatureTracker | ||
| // initialized with configuration-driven feature flags (if any), and stores it | ||
| // into the Options list under FeatureTrackerOption. | ||
| Options SetupFeatureTracker(Options opts); | ||
|
|
||
| } // namespace internal | ||
| GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END | ||
| } // namespace storage | ||
| } // namespace cloud | ||
| } // namespace google | ||
|
|
||
| #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_INTERNAL_FEATURE_TRACKER_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.