Repository navigation
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a new HedgeLimiter class to centralize connection-wide rate, concurrency, and lifetime limits on speculative hedged requests, refactoring HedgingThreadPool to delegate to it. It also implements HedgedOpenStream to race a primary open stream attempt against speculative delayed attempts. Feedback on the changes identifies a potential data race in HedgedOpenStreamConcurrencyTest where workers.emplace_back is called concurrently without synchronization inside the mock factory lambda.
2922104 to
929672c
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #16716 +/- ##
==========================================
+ Coverage 92.78% 92.80% +0.01%
==========================================
Files 2277 2281 +4
Lines 228147 228697 +550
==========================================
+ Hits 211696 212239 +543
- Misses 16451 16458 +7 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
929672c to
957c80c
Compare
Note
Stacked PR (Part 2 of 3 splitting #16612): Stacked on #16715 (
refactor(storage): extract HedgeLimiter from HedgingThreadPool).6 files, +960 / -0, inline-commentable): Commit929672ca7ain #16716{#16613, #16715}(independent roots in parallel) → impl(storage): add HedgedOpenStream coordinator for async Open #16716 (this PR, after refactor(storage): extract HedgeLimiter from HedgingThreadPool #16715) → feat(storage): add speculative open hedging to AsyncClient::Open #16612 (after both fix(storage): make OpenStream and OpenObject cancellation-safe #16613 and impl(storage): add HedgedOpenStream coordinator for async Open #16716).main, its commit drops out of this PR automatically.Summary
Adds the standalone
CompletionQueue-drivenstorage_internal::HedgedOpenStreamcoordinator (google/cloud/storage/internal/async/hedged_open_stream.{h,cc}) and its unit/concurrency test suite (hedged_open_stream_test.cc), ahead of wiringAsyncConnectionImpl::Open()in #16612.Design & Concurrency Invariants
hedged_open_stream.h):HedgedOpenParams{delay, max_hedges}andHedgedOpenStream(...), keepingHedgedOpenOperationprivate insidehedged_open_stream.cc.hedged_open_stream.cc):OpenStreamFactoryattempt against up tomax_hedgesdelayed speculative attempts scheduled viaCompletionQueue::MakeRelativeTimer(with zero dedicated worker threads).mu_and cancelled outsidemu_(preventing re-entrant deadlocks), and any late-completing loser'sOpenStreamis immediately closed viaOpenStream::Cancel().std::vector<std::optional<future<void>>>(FinishAttemptLocked) so winner self-extraction avoids self-cancellation while preventing post-completion slot overwrites beforefuture::thenmarks its output state ready.kCancelledpermanent failure (retry_policy->IsPermanentFailure(status)), while allowing in-flight hedges to rescue primaries cancelled by per-stream stall timeouts (kCancelled).HedgeLimiter(re-arming atmax(delay, 10ms)on temporary concurrency/rate denial and stopping onceIsTotalBudgetSpent()), releasing concurrency slots via move-only RAIIHedgeSlotprior to completion resolution.hedged_open_stream_test.cc):HedgedOpenStreamdirectly against anAsyncSequencer-drivenOpenStreamFactoryandMockCompletionQueueImplacross fast-primary timer cancellation, slow-primary hedge win + late-streamCancel(), primary win after hedge dispatch, parameterized transient/stall-timeout rescues, parameterized symmetric permanent-error aborts, all-attempts-fail primary error precedence, caller.cancel()(both async and inline inside the cancel callback),10mslimiter-denial retry + lifetime budget exhaustion, negative parameter clamping, and 25-iteration multi-threaded barrier races.