Skip to content

chore(spanner): record transaction affinity for streaming RPCs with inline begin - #6731

Open
olavloite wants to merge 1 commit into
googleapis:mainfrom
olavloite:spanner-streaming-rpc-transaction-affinity
Open

chore(spanner): record transaction affinity for streaming RPCs with inline begin#6731
olavloite wants to merge 1 commit into
googleapis:mainfrom
olavloite:spanner-streaming-rpc-transaction-affinity

Conversation

@olavloite

Copy link
Copy Markdown
Contributor

When executing a streaming query (execute_streaming_sql) or streaming read (streaming_read) with an inline-begin read-write transaction in Spanner Omni, the returned transaction ID was not being captured to establish location-aware routing affinity.

This change:

  • Captures the transaction ID from the first stream response chunk and registers node affinity with the location router.
  • Introduces a single-use TransactionIdCallback (Box) attached during stream construction.
  • Adds helper logic on DatabaseClient to determine whether affinity recording is required based on the transaction selector and routing mode.
  • Expands mock tests covering inline-begin streaming queries, streaming reads, stream errors, and aborted transaction retries.

@olavloite
olavloite requested review from a team as code owners September 8, 2026 11:00
@product-auto-label product-auto-label Bot added the api: spanner Issues related to the Spanner API. label Sep 8, 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 implements transaction affinity routing for Spanner server-streaming RPCs (ExecuteStreamingSql and StreamingRead) by introducing a callback mechanism to capture the first transaction ID returned in a stream. It also adds comprehensive integration and unit tests to verify affinity recording, error handling, aborted retries, and tablet routing. The review feedback suggests refactoring several conditional builder configurations to use idiomatic Rust expressions instead of mutable variables.

Comment thread src/spanner/src/database_client.rs Outdated
Comment thread src/spanner/src/server_streaming/builder.rs Outdated
Comment thread src/spanner/src/server_streaming/builder.rs Outdated
@codecov

codecov Bot commented Sep 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.81%. Comparing base (bd3124b) to head (ffc8d98).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff            @@
##             main    #6731    +/-   ##
========================================
  Coverage   96.80%   96.81%            
========================================
  Files         313      313            
  Lines      104285   104513   +228     
========================================
+ Hits       100958   101188   +230     
+ Misses       3327     3325     -2     

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

…nline begin

When executing a streaming query (execute_streaming_sql) or streaming read
(streaming_read) with an inline-begin read-write transaction in Spanner Omni,
the returned transaction ID was not being captured to establish location-aware
routing affinity.

This change:
- Captures the transaction ID from the first stream response chunk and
  registers node affinity with the location router.
- Introduces a single-use TransactionIdCallback (Box<dyn FnOnce>) attached
  during stream construction.
- Adds helper logic on DatabaseClient to determine whether affinity
  recording is required based on the transaction selector and routing mode.
- Expands mock tests covering inline-begin streaming queries, streaming reads,
  stream errors, and aborted transaction retries.
@olavloite
olavloite force-pushed the spanner-streaming-rpc-transaction-affinity branch from 44e237f to ffc8d98 Compare September 8, 2026 12:08
@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 implements transaction affinity recording for streaming RPCs (such as streaming SQL and streaming reads) that initiate inline read-write transactions. It introduces a TransactionIdCallback mechanism to extract the transaction ID from the first PartialResultSet in the stream and record affinity to the target server address. Additionally, comprehensive unit and mock integration tests have been added to verify this behavior across various scenarios, including multi-chunk streams, aborted transaction retries, and tablet routing. I have no feedback to provide as there are no review comments to evaluate.

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