GeezerVison is showing github.com — fix(spanner): improve grpc-gcp affinity cleanup and location-aware retries by rahul2393 · Pull Request #12682 · googleapis/google-cloud-java
Conversation
rahul2393
commented
Apr 6, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Summary
This change updates grpc-gcp channel-affinity behavior and location-aware retry behavior in the Java Spanner client.
It does three things:
- Uses random channel hints for grpc-gcp-backed single-use operations and multi-use transactions instead of reusing the session-affined hint.
- Adds explicit affinity unbind handling for single-use read/query RPCs and terminal commit/rollback RPCs, including the retry-to-different-channel path.
- Updates location-aware routing so retries for
RESOURCE_EXHAUSTED do not go back to the same routed endpoint for the same logical request.
What Changed
grpc-gcp channel hints
When grpc-gcp is enabled:
- single-use read/query now uses a random channel hint
- single-use write (
writeAtLeastOnce) now uses a random channel hint
- multi-use read-only transactions now get a random hint reused within that transaction
- multi-use read-write transactions now get a random hint reused within that transaction
- multiplexed single-use operations no longer use the bitset-based reserved single-use channel path
explicit affinity unbind
Added UNBIND_CHANNEL_HINT support and wired it through grpc-gcp call options.
This now:
- marks single-use read/query calls for unbind after completion
- preserves unbind when a streaming read/query is retried on a different grpc channel
- unbinds grpc-gcp affinity keys on commit
- unbinds grpc-gcp affinity keys on rollback
location-aware retry behavior
For location-aware routing:
- route selection now records tracing attributes/events
- if a routed endpoint returns
RESOURCE_EXHAUSTED, the next retry attempt for that same logical request avoids that endpoint
- the skip is scoped by
X-Goog-Spanner-Request-Id logical request identity, so unrelated transactions/requests do not nherit the exclusion
- if no alternate healthy replica is available, routing falls back to the default host
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
gemini-code-assist[bot] reacted with eyes emoji
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a mechanism to unbind gRPC-GCP affinity keys after terminal RPCs (like Commit and Rollback) or when a specific channel hint is provided. It also adds logic to exclude endpoints that return RESOURCE_EXHAUSTED for the duration of a logical request's retry attempts. I have identified a discrepancy in the code comments within AbstractReadContext.java, where the comment claims the unbind flag is not carried on retries, despite the implementation explicitly adding it.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Apr 10, 2026
Reviewers
+1 more reviewer
Reviewers whose approvals may not affect merge requirements
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.