Skip to content

chore(spanner): wire location-aware routing into begin_transaction and commit - #6671

Open
olavloite wants to merge 2 commits into
googleapis:mainfrom
olavloite:spanner-location-aware-routing-begin-commit
Open

chore(spanner): wire location-aware routing into begin_transaction and commit#6671
olavloite wants to merge 2 commits into
googleapis:mainfrom
olavloite:spanner-location-aware-routing-begin-commit

Conversation

@olavloite

Copy link
Copy Markdown
Contributor

Connect unary BeginTransaction and Commit RPCs to location-aware routing in DatabaseClient:

  • pre_route_begin_transaction / post_route_begin_transaction: Resolve route and attach covering RoutingHint when mutation_key is present. Bind transaction affinity to the resolved connection (or fallback default gateway for unkeyed begins) upon successful transaction creation.
  • pre_route_commit / post_route_commit: Prioritize registered transaction affinity while deriving mutation RoutingHint from request.mutations. Fall back to round-robin channel pooling when neither affinity nor a routing key exists. Clear affinity upon commit completion.
  • Mutation::select_mutation_key_ref: Add an O(1) fast path for single-mutation slices, operate on borrowed references, exclude unroutable Delete mutations (full-table deletes, empty key sets, or missing key sets), and extract is_routable_non_insert to keep selection logic flat and idiomatic.

…d commit

Connect unary `BeginTransaction` and `Commit` RPCs to location-aware
routing in `DatabaseClient`:
- `pre_route_begin_transaction` / `post_route_begin_transaction`:
  Resolve route and attach covering `RoutingHint` when `mutation_key`
  is present. Bind transaction affinity to the resolved connection (or
  fallback default gateway for unkeyed begins) upon successful transaction
  creation.
- `pre_route_commit` / `post_route_commit`:
  Prioritize registered transaction affinity while deriving mutation
  `RoutingHint` from `request.mutations`. Fall back to round-robin channel
  pooling when neither affinity nor a routing key exists. Clear affinity
  upon commit completion.
- `Mutation::select_mutation_key_ref`:
  Add an O(1) fast path for single-mutation slices, operate on borrowed
  references, exclude unroutable `Delete` mutations (full-table deletes,
  empty key sets, or missing key sets), and extract `is_routable_non_insert`
  to keep selection logic flat and idiomatic.
@olavloite
olavloite requested review from a team as code owners September 7, 2026 07:38
@product-auto-label product-auto-label Bot added the api: spanner Issues related to the Spanner API. label Sep 7, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

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 refactors location-aware routing in the Spanner client to intercept unary BeginTransactionRequest and CommitRequest calls, resolving leader or affinity routing and attaching a RoutingHint when active. It introduces Mutation::select_mutation_key_ref to select routing keys by reference, avoiding unnecessary clones, and adds comprehensive unit tests covering various routing, affinity, and mutation selection scenarios. No review comments were provided, so there is no feedback to address.

@codecov

codecov Bot commented Sep 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.75%. Comparing base (f02b42c) to head (caa859c).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6671      +/-   ##
==========================================
+ Coverage   96.72%   96.75%   +0.03%     
==========================================
  Files         313      313              
  Lines      101266   102368    +1102     
==========================================
+ Hits        97948    99049    +1101     
- Misses       3318     3319       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Labels

api: spanner Issues related to the Spanner API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants