-
Notifications
You must be signed in to change notification settings - Fork 135
fix: Implement retry-on-access for multiplexed session creation failures #4279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Summary of ChangesHello @rahul2393, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the robustness of multiplexed session creation in the Spanner client library. It introduces a sophisticated retry-on-access mechanism, allowing the client to gracefully recover from transient session creation failures by automatically retrying. Concurrency primitives ensure that session creation attempts are synchronized, and improved error handling ensures that only non-recoverable errors (like Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
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 a retry-on-access mechanism for multiplexed session creation, which is a valuable improvement for resilience against transient failures. The new concurrency logic using ReentrantLock and CountDownLatch is a good approach. However, I've identified a critical race condition in the implementation that could lead to deadlocks. My review includes a suggested refactoring to resolve this issue, ensuring the concurrent code is safe. The accompanying tests for the new functionality are well-written and cover the intended behavior.
...e-cloud-spanner/src/main/java/com/google/cloud/spanner/MultiplexedSessionDatabaseClient.java
Show resolved
Hide resolved
7b5db3d to
de2a5f7
Compare
de2a5f7 to
81b39cd
Compare
81b39cd to
3235d25
Compare
This PR changes the Java Spanner client's multiplexed session creation behavior to retry on transient errors. Previously, if the initial
CreateSessionRPC failed, the error was cached permanently and returned to all subsequent requests without any retry attempt.Problem
The current implementation fetches a multiplexed session once during client initialization:
This behavior causes client breakage on transient failures (e.g.,
DEADLINE_EXCEEDED,UNAVAILABLE) even after the server recovers.Solution
Implement retry-on-access semantics:
UNIMPLEMENTEDDatabaseNotFoundExceptionInstanceNotFoundExceptionDEADLINE_EXCEEDEDUNAVAILABLEImplementation Details
State Management: Changed from
SettableApiFutureto explicit state tracking:AtomicReference<ApiFuture<SessionReference>>for the sessionAtomicReference<Throwable>for the last creation errorReentrantLock+CountDownLatch+AtomicBooleanfor coordinating concurrent creation attemptsThread Safety: Used blocking lock pattern to avoid race conditions where a waiting thread could read an old latch that has already been counted down and replaced.
Maintainer Behavior: The maintainer now starts even on failure (for transient errors) to enable background retries.
Behavior Diagram
flowchart TD subgraph "Session Creation Flow" A[Client Initialization] --> B[Trigger CreateSession RPC] B --> C{Creation Result?} C -->|Success| D[Store Session Reference] D --> E[Start Maintainer] E --> F[Session Ready for Use] C -->|UNIMPLEMENTED| G[Mark as Unimplemented] G --> H[Fall Back to Regular Sessions] C -->|DatabaseNotFoundException<br/>InstanceNotFoundException| I[Cache Error as Permanent] I --> J[Do NOT Start Maintainer] J --> K[Return Error on All RPCs - No Retry] C -->|Transient Error<br/>DEADLINE_EXCEEDED, UNAVAILABLE, etc.| L[Cache Error Temporarily] L --> M[Start Maintainer] M --> N[Allow Retry on Next RPC Access] end subgraph "Retry on Access Flow" O[RPC Request] --> P{Session Exists?} P -->|Yes| Q[Use Existing Session] P -->|No| R{Check Error Type} R -->|UNIMPLEMENTED| S[Throw UNIMPLEMENTED Error] R -->|ResourceNotFoundException| T[Throw ResourceNotFoundException] R -->|No Permanent Error| U{Creation In Progress?} U -->|Yes| V[Wait for Creation to Complete] U -->|No| W[Trigger New CreateSession RPC] W --> V V --> X{Creation Result?} X -->|Success| Q X -->|Failure| Y[Throw Error to Caller] end subgraph "Maintainer Flow" Z[Maintainer Running] --> AA{Session Expired or Null?} AA -->|No| AB[Sleep and Check Again] AB --> AA AA -->|Yes| AC{Permanent Error?} AC -->|UNIMPLEMENTED or ResourceNotFound| AD[Stop - No Retry] AC -->|No| AE[Trigger CreateSession RPC] AE --> AF{Creation Result?} AF -->|Success| AG[Update Session Reference] AG --> AB AF -->|Failure| AH[Log Error, Continue Loop] AH --> AB endConcurrent Request Handling
When multiple RPCs arrive during a failed/pending session creation: