Skip to content

feat(pubsub): add CancellationSharer and single-timer FIFO HedgingScheduler - #36640

Draft
feywind wants to merge 1 commit into
hedging/options-and-token-bucketfrom
hedging/coordinator-and-scheduler
Draft

feywind wants to merge 1 commit into
hedging/options-and-token-bucketfrom
hedging/coordinator-and-scheduler

Conversation

@feywind

@feywind feywind commented Oct 16, 2026 •

Copy link
Copy Markdown

Stack Structure (Stack #36644)

Layer Branch PR
1 hedging/options-and-token-bucket #36639
2 hedging/coordinator-and-scheduler #36640 (this PR)
3 hedging/queue-integration #36641
4 hedging/queue-unit-tests #36642
5 hedging/system-tests #36643

Summary

Implements Layer 2 of Cloud Pub/Sub Publish Hedging (go/sdk:pubsub-hedging) for google-cloud-pubsub:

  • AsyncPublisher::AttemptHandle & AsyncPublisher::CancellationSharer (lib/google/cloud/pubsub/async_publisher/cancellation_sharer.rb):
    • Coordinates original (attempt 0) and hedged (attempt 1..N) publish attempts per batch.
    • Enforces first-wins sibling cancellation and callback completion outside the coordinator mutex.
    • Immediately clears @batch = nil upon completion so batch message payloads can be garbage-collected while scheduled HedgedRequest entries remain queued.
    • Implements asymmetric error handling: errors from hedged attempts (attempt >= 1) are ignored while attempt 0 is in flight; terminal failure of attempt 0 immediately cancels running hedged attempts and fails the batch.
  • AsyncPublisher::HedgedRequest & AsyncPublisher::HedgingScheduler (lib/google/cloud/pubsub/async_publisher/hedging_scheduler.rb):
    • Event-driven single-timer FIFO scheduler that pops due items under @mutex and dispatches outside @mutex to prevent lock-order inversion.
    • Emits debug log messages on pubsub:publish-hedged ("Publishing hedged attempt <n>" and "Hedging rate limited due to lack of tokens.").
  • Unit tests (test/google/cloud/pubsub/async_publisher/cancellation_sharer_test.rb, test/google/cloud/pubsub/async_publisher/hedging_scheduler_test.rb).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant