Skip to content

fix(spanner): improve grpc-gcp affinity cleanup and location-aware retries#12682

Merged
rahul2393 merged 4 commits intomainfrom
location-aware-resource-exhausted
Apr 7, 2026
Merged

fix(spanner): improve grpc-gcp affinity cleanup and location-aware retries#12682
rahul2393 merged 4 commits intomainfrom
location-aware-resource-exhausted

Conversation

@rahul2393
Copy link
Copy Markdown
Contributor

@rahul2393 rahul2393 commented Apr 6, 2026

Summary

This change updates grpc-gcp channel-affinity behavior and location-aware retry behavior in the Java Spanner client.

It does three things:

  1. Uses random channel hints for grpc-gcp-backed single-use operations and multi-use transactions instead of reusing the session-affined hint.
  2. Adds explicit affinity unbind handling for single-use read/query RPCs and terminal commit/rollback RPCs, including the retry-to-different-channel path.
  3. 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

@rahul2393 rahul2393 requested review from a team as code owners April 6, 2026 08:08
@rahul2393 rahul2393 requested a review from sakthivelmanii April 6, 2026 08:09
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a 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.

@rahul2393 rahul2393 force-pushed the location-aware-resource-exhausted branch from 6f4791b to 69fc961 Compare April 6, 2026 18:18
@rahul2393 rahul2393 merged commit aca0428 into main Apr 7, 2026
130 of 131 checks passed
@rahul2393 rahul2393 deleted the location-aware-resource-exhausted branch April 7, 2026 09:15
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.

2 participants