Skip to content

Conversation

@bhshkh
Copy link
Contributor

@bhshkh bhshkh commented Sep 27, 2025

Implements client-side logic to support the Cloud Bigtable routing cookie protocol (see go/cbt-support-routing-cookie). This feature enhances server-initiated retries and improves resilience.

Specific modifications:

  • Feature Flag: The client now signals support for this feature by setting RoutingCookie: true in the bigtable-features header.
  • Cookie Propagation: Any headers prefixed with x-goog-cbt-cookie- received in response metadata are collected and sent back on subsequent requests for the same operation.
  • Internal Tracking: The opTracer in metrics.go now stores the current cookies and the routingAttempt number.

These changes enable more sophisticated load balancing and retry strategies, by giving the service and routing layers visibility into the client's retry state and a mechanism to influence client behavior.


Conformance tests from https://github.com/googleapis/cloud-bigtable-clients-test/tree/v0.0.3 now pass:

=== RUN   TestMutateRows_Retry_WithRoutingCookie
--- PASS: TestMutateRows_Retry_WithRoutingCookie (0.04s)
=== RUN   TestReadRow_Retry_WithRoutingCookie
--- PASS: TestReadRow_Retry_WithRoutingCookie (0.05s)
=== RUN   TestReadRows_Retry_WithRoutingCookie
--- PASS: TestReadRows_Retry_WithRoutingCookie (0.06s)
=== RUN   TestReadRows_Retry_WithRoutingCookie_MultipleErrorResponses
--- PASS: TestReadRows_Retry_WithRoutingCookie_MultipleErrorResponses (0.14s)
=== RUN   TestSampleRowKeys_Retry_WithRoutingCookie
--- PASS: TestSampleRowKeys_Retry_WithRoutingCookie (0.10s)
PASS
ok  	github.com/googleapis/cloud-bigtable-clients-test/tests	0.476s

Fixes: #12658

@bhshkh bhshkh requested review from a team as code owners September 27, 2025 01:12
@bhshkh bhshkh enabled auto-merge (squash) September 27, 2025 01:13

// For routing cookie
cookiePrefix = "x-goog-cbt-cookie-"
attemptHeader = "x-goog-cbt-attempt"
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry that the design doc was unclear about this, the attempt part is not implemented on the GFE and we may not need it, so we can remove this header.

however, we do keep stats on the number of attempt of a request (regardless of routing cookie) and the header for that is bigtable-attempt. But this is a separate feature and we can do that in a different PR in the future.

// Operation has started but not the attempt.
// So, create only operation tracer and not attempt tracer
currOpTracer := opTracer{}
currOpTracer := opTracer{
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think metrics is the right place for this feature (like I mentioned in the other comment) because this is retry related and doesn't really have anything to do with metrics?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did not want to add another tracer.

I can create a follow up PR to this one. Renaming metricsTracer to Tracer and file to tracer.go

@bhshkh bhshkh requested a review from a team as a code owner October 7, 2025 04:43
@bhshkh bhshkh requested a review from mutianf October 7, 2025 04:44
@bhshkh bhshkh changed the title feat(client): Enable routing cookie and attempt headers for enhanced retries feat(client): Enable routing cookie for enhanced retries Oct 7, 2025
@bhshkh bhshkh changed the title feat(client): Enable routing cookie for enhanced retries feat(bigtable): Enable routing cookie for enhanced retries Oct 16, 2025
@bhshkh bhshkh merged commit 96cfd47 into googleapis:main Oct 16, 2025
11 checks passed
@bhshkh bhshkh deleted the feature/cbt-routing-cookie branch November 16, 2025 04:40
bhshkh added a commit that referenced this pull request Dec 15, 2025
PR created by the Librarian CLI to initialize a release. Merging this PR
will auto trigger a release.

Librarian Version: v0.7.0
Language Image:
us-central1-docker.pkg.dev/cloud-sdk-librarian-prod/images-prod/librarian-go@sha256:718167d5c23ed389b41f617b3a00ac839bdd938a6bd2d48ae0c2f1fa51ab1c3d
<details><summary>bigtable: 1.41.0</summary>

##
[1.41.0](bigtable/v1.40.1...bigtable/v1.41.0)
(2025-12-15)

### Features

* add PeerInfo proto in Bigtable API (PiperOrigin-RevId: 829585900)
([185951b](185951b3))

* precompute featureflags in client and reuse (#13297)
([3b3253a](3b3253ac))

* Add experimental Bigtable connection pool with custom load balancing
strategy. (#12882)
([7aa9612](7aa96127))

* Enable ALTS hard bound token in Bigtable w/ direct access (#13153)
([9023934](90239341))

* Enable routing cookie and attempt headers for enhanced retries
(#12964)
([96cfd47](96cfd47a))

### Bug Fixes

* fix project id sent in otel (#13286)
([4865868](4865868c))

* screaming uppercase metric status (#13484)
([b35ee8f](b35ee8fd))

### Performance Improvements

* parallelize the exportTimeSeries function (#13004)
([bafd691](bafd691d))

</details>
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.

bigtable: support routing cookie

2 participants