Skip to content

chore(spanner): wire location-aware routing into streaming read and query RPCs - #6494

Open
olavloite wants to merge 3 commits into
googleapis:mainfrom
olavloite:spanner-streaming-rpc-location-aware-routing
Open

chore(spanner): wire location-aware routing into streaming read and query RPCs#6494
olavloite wants to merge 3 commits into
googleapis:mainfrom
olavloite:spanner-streaming-rpc-location-aware-routing

Conversation

@olavloite

Copy link
Copy Markdown
Contributor
  • Add channel_id directly to Channel to avoid redundant modulo arithmetic
    when attaching Spanner request ID headers.
  • Implement protobuf-level key extraction helpers in key_extractor
    (extract_proto_read_request_routing_key, extract_key_from_proto_key_set)
    supporting point keys and key ranges (start_closed/start_open).
  • Add resolve_routing_connection to DatabaseClient and wire it into
    streaming_read and execute_query RPC dispatch.
  • Keep location-aware routing disabled by default, gating activation behind the
    GOOGLE_SPANNER_EXPERIMENTAL_LOCATION_API environment variable.

…uery RPCs

- Add `channel_id` directly to `Channel` to avoid redundant modulo arithmetic
  when attaching Spanner request ID headers.
- Implement protobuf-level key extraction helpers in `key_extractor`
  (`extract_proto_read_request_routing_key`, `extract_key_from_proto_key_set`)
  supporting point keys and key ranges (`start_closed`/`start_open`).
- Add `resolve_routing_connection` to `DatabaseClient` and wire it into
  `streaming_read` and `execute_query` RPC dispatch.
- Keep location-aware routing disabled by default, gating activation behind the
  `GOOGLE_SPANNER_EXPERIMENTAL_LOCATION_API` environment variable.
@olavloite
olavloite requested review from a team as code owners August 21, 2026 07:38
@product-auto-label product-auto-label Bot added the api: spanner Issues related to the Spanner API. label Aug 21, 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 the Spanner client to pass direct Channel references instead of channel_hint indices, simplifying request ID generation by storing a 1-based channel_id on the Channel struct. It also introduces location-aware routing for streaming reads by extracting routing keys from ReadRequest to resolve optimal server connections. Feedback on these changes includes resolving a missing import for ProtoKeyRange in tests, optimizing resolve_routing_connection to return early when no routing information is present, and removing the now-unused next_channel_hint function.

Comment thread src/spanner/src/routing/key_extractor.rs
Comment thread src/spanner/src/database_client.rs
Comment thread src/spanner/src/client.rs
@codecov

codecov Bot commented Aug 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.28910% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.41%. Comparing base (1da1b78) to head (204cf59).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/spanner/src/routing/key_extractor.rs 97.59% 4 Missing ⚠️
src/spanner/src/client.rs 96.55% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6494      +/-   ##
==========================================
+ Coverage   96.39%   96.41%   +0.02%     
==========================================
  Files         300      300              
  Lines       84585    85343     +758     
==========================================
+ Hits        81533    82283     +750     
- Misses       3052     3060       +8     

☔ 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.

@olavloite

Copy link
Copy Markdown
Contributor Author

/gemini review

@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 the Spanner client to support location-aware routing by passing Channel references directly to RPC methods instead of numeric channel hints. It introduces connection resolution logic based on transaction IDs and routing keys, and adds comprehensive tests to verify both standard round-robin channel pooling and location-aware routing. Feedback on these changes highlights two key issues: first, use_transaction_affinity is hardcoded to false in RoutingContext, which disables transaction affinity routing even when a transaction ID is present; second, errors during key extraction are silently swallowed with .ok(), violating the repository style guide's rule against swallowing errors.

Comment thread src/spanner/src/database_client.rs Outdated
Comment thread src/spanner/src/routing/key_extractor.rs Outdated
@olavloite
olavloite force-pushed the spanner-streaming-rpc-location-aware-routing branch from c2dc845 to 204cf59 Compare August 21, 2026 10:40
@olavloite

Copy link
Copy Markdown
Contributor Author

/gemini review

@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 the Spanner client's channel selection and request ID attachment by passing direct Channel references instead of numeric hints, storing a 1-based channel_id directly on the Channel struct. It also introduces location-aware routing for Spanner Omni, enabling the DatabaseClient to resolve optimal server connections using transaction affinity and routing keys extracted from read requests, while maintaining standard round-robin channel pooling as a fallback. I have reviewed the changes and have no feedback to provide as there are no review comments and the implementation is robust and well-tested.

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.

1 participant