Skip to content

chore(spanner): add stream lifetime guards and error tracking to server streaming - #6735

Open
olavloite wants to merge 2 commits into
googleapis:mainfrom
olavloite:spanner-server-streaming-guards
Open

chore(spanner): add stream lifetime guards and error tracking to server streaming#6735
olavloite wants to merge 2 commits into
googleapis:mainfrom
olavloite:spanner-server-streaming-guards

Conversation

@olavloite

Copy link
Copy Markdown
Contributor

Adds RAII lifetime guards and error reporting to Spanner server-streaming RPCs.

This allows streaming operations (such as ExecuteStreamingSql and StreamingRead) to hold an opaque guard that tracks in-flight RPC state on the underlying channel lease for the full lifetime of the stream. If a stream fails during the initial handshake or mid-stream, the error status code is recorded on the guard so the channel pool can update channel health metrics and error penalties.

@olavloite
olavloite requested review from a team as code owners September 8, 2026 14:47
@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 refactors the stream lifetime management by introducing a StreamGuard trait and updating StreamLifetimeGuard to be an Arc<dyn StreamGuard>. This enables recording RPC error codes during stream failures or initial handshakes across various Spanner operations. The review feedback suggests two minor code simplifications: directly pattern matching on self.lifetime_guard.take() in next_message to avoid a temporary variable, and directly assigning lifetime_guard to the stream in make_server_streaming_request instead of using an if let block.

Comment thread src/spanner/src/server_streaming/stream.rs
Comment thread src/spanner/src/server_streaming/builder.rs Outdated
@olavloite
olavloite force-pushed the spanner-server-streaming-guards branch from 0c9131e to 0f156fb Compare September 8, 2026 14:59
@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 stream lifetime management by introducing a StreamGuard trait and updating StreamLifetimeGuard to be an Arc<dyn StreamGuard>. This allows recording RPC error codes during stream lifetime events (initial handshake failures and stream errors) to support dynamic channel pooling. The builder classes and streaming requests are updated to propagate this guard, and comprehensive tests are added. The review feedback recommends refactoring the tuple pattern matching in SpannerServerStream::next_message and make_server_streaming_request into nested if let statements to avoid implicit side-effects and improve code readability in alignment with the 'Reject Code Poetry' style guide principle.

Comment thread src/spanner/src/server_streaming/stream.rs
Comment thread src/spanner/src/server_streaming/builder.rs
@olavloite
olavloite force-pushed the spanner-server-streaming-guards branch from 0f156fb to aadff1a Compare September 8, 2026 15:09
@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 server streaming lifetime management in the Spanner client. It replaces the opaque Box<dyn Any + Send + Sync> lifetime guard with a structured StreamLifetimeGuard (an Arc) capable of recording RPC error codes. This enables tracking connection issues for dynamic channel pooling. The streaming builders (ExecuteStreamingSql, StreamingRead, BatchWrite, and FetchCacheUpdate) now support attaching this guard, and both initial handshake failures and stream errors are updated to record their status codes. I have no feedback to provide as there are no review comments.

@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.97%. Comparing base (ecfc7c2) to head (841266b).

Additional details and impacted files
@@           Coverage Diff            @@
##             main    #6735    +/-   ##
========================================
  Coverage   96.96%   96.97%            
========================================
  Files         319      319            
  Lines      105574   105844   +270     
========================================
+ Hits       102365   102637   +272     
+ Misses       3209     3207     -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.

@olavloite
olavloite force-pushed the spanner-server-streaming-guards branch from aadff1a to 05e4899 Compare September 8, 2026 17:58
@olavloite
olavloite requested a review from rahul2393 September 8, 2026 17:59
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