Repository navigation
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the hedging logic by extracting the rate, concurrency, and lifetime limiting responsibilities from HedgingThreadPool into a new, dedicated HedgeLimiter class, simplifying the thread pool implementation and adding targeted unit tests. The review feedback recommends templating HedgeLimiter on a Clock type to allow injecting a mock clock, which avoids flaky sleep-based unit tests. Additionally, it suggests explicitly including <mutex> in hedging_thread_pool.h to comply with the "Include What You Use" style guide rule.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #16715 +/- ##
=======================================
Coverage 92.78% 92.79%
=======================================
Files 2277 2279 +2
Lines 228147 228185 +38
=======================================
+ Hits 211696 211740 +44
+ Misses 16451 16445 -6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
bfee084 to
6d8a063
Compare
Note
Part 1 of 3 splitting #16612: Independent root on
main(zero overlap with #16613; both can merge in parallel).{#16613, #16715 (this PR)}→ impl(storage): add HedgedOpenStream coordinator for async Open #16716 (after refactor(storage): extract HedgeLimiter from HedgingThreadPool #16715) → feat(storage): add speculative open hedging to AsyncClient::Open #16612 (after fix(storage): make OpenStream and OpenObject cancellation-safe #16613 + impl(storage): add HedgedOpenStream coordinator for async Open #16716).Summary
Extracts the thread-safe three-gate hedge budget limiter (
MaxConcurrentHedgesOption,ReadHedgeRateLimitOption, andMaxTotalHedgesOption) fromHedgingThreadPoolinto a standalonestorage::internal::HedgeLimiterheader (google/cloud/storage/internal/hedge_limiter.h).Motivation
Currently, hedge rate, concurrency, and lifetime budget enforcement is embedded inside
HedgingThreadPool, which spawns dedicated worker threads for synchronousstorage::Client::ReadObject()hedging. ExtractingHedgeLimiteras a pure, thread-pool-free component allows asynchronousCompletionQueue-driven hedging (storage::AsyncClient::Open(), #16716 and #16612) to reuse the exact same three-gate limiter without allocating unused background thread pools.Changes
google/cloud/storage/internal/hedge_limiter.h:HedgeLimiter(TryAcquireHedgeToken(),ReleaseHedgeSlot(),IsTotalBudgetSpent()) with identical gate ordering and rollback semantics.google/cloud/storage/internal/hedging_thread_pool.h:HedgeLimiter limiter_insideHedgingThreadPooland delegatesTryAcquireHedgeToken(),ReleaseHedgeSlot(), andIsTotalBudgetSpent().hedge_limiter_test.cc,hedging_thread_pool_test.cc,google_cloud_cpp_storage.{cmake,bzl},storage_client_unit_tests.bzl):hedge_limiter_test.cc(testingHedgeLimiterdirectly without spawning worker threads per test) and retains a delegation test (DelegatesToHedgeLimiter) onHedgingThreadPool.