Skip to content

refactor(spanner): add centralized unary RPC retry helpers - #19176

Open
olavloite wants to merge 1 commit into
mainfrom
spanner-centralize-unary-rpc-retry-helpers
Open

olavloite wants to merge 1 commit into
mainfrom
spanner-centralize-unary-rpc-retry-helpers

Conversation

@olavloite

Copy link
Copy Markdown
Contributor

Introduce a shared unary RPC retry helper for both the synchronous and asynchronous Spanner clients.

Previously, unary RPCs relied on ad-hoc retry loops and inconsistent handling of transient errors, which prevented per-attempt request ID tracking from advancing across retries. This change lays the groundwork for unifying unary retries across the client in follow-up changes by:

  • Resolving method-specific retry policies from the underlying transport configuration while extending them to retry transient Spanner internal errors alongside unavailable and resource-exhausted responses.
  • Executing unary requests through a shared retry wrapper that allocates a single logical request ID per operation and increments the attempt counter on each retry.
  • Adding unit tests covering both synchronous and asynchronous retry resolution, backoff execution, error classification, and timeout behavior.

No existing client operations are modified in this change.

@olavloite
olavloite requested a review from a team as a code owner November 22, 2026 14:33

@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 introduces centralized unary RPC retry helpers for Cloud Spanner, adding both asynchronous and synchronous implementations along with comprehensive unit tests. The feedback highlights an issue where re-instantiating the retry policy using type(retry_policy)(...) could raise a TypeError if a custom subclass has a different constructor signature. It is recommended to directly pass the on_error handler when calling the retry policy instead.

Introduce a shared unary RPC retry helper for both the synchronous and
asynchronous Spanner clients.

Previously, unary RPCs relied on ad-hoc retry loops and inconsistent
handling of transient errors, which prevented per-attempt request ID
tracking from advancing across retries. This change lays the groundwork
for unifying unary retries across the client in follow-up changes by:

- Resolving method-specific retry policies from the underlying transport
  configuration while extending them to retry transient Spanner internal
  errors alongside unavailable and resource-exhausted responses.
- Executing unary requests through a shared retry wrapper that allocates
  a single logical request ID per operation and increments the attempt
  counter on each retry.
- Adding unit tests covering both synchronous and asynchronous retry
  resolution, backoff execution, error classification, and timeout
  behavior.

No existing client operations are modified in this change.
@olavloite
olavloite force-pushed the spanner-centralize-unary-rpc-retry-helpers branch from 904dd8a to e8ea6bb Compare November 23, 2026 07:34
@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 introduces centralized unary RPC retry helpers for Cloud Spanner, providing both asynchronous and synchronous implementations (_async/_retry.py and _retry.py) along with comprehensive unit tests. These helpers handle transient Spanner errors, resolve effective retry policies, and execute unary RPCs with per-attempt request IDs. I have no feedback to provide as the implementation is clean and well-tested.

This branch has not been deployed

No deployments
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.

1 participant