Skip to content

Comments

fix: retry CreateSession also when waitForMinSessions is zero#4360

Open
olavloite wants to merge 2 commits intomainfrom
retry-create-session
Open

fix: retry CreateSession also when waitForMinSessions is zero#4360
olavloite wants to merge 2 commits intomainfrom
retry-create-session

Conversation

@olavloite
Copy link
Collaborator

The creation of a session at startup would only be retried if waitForMinSessions was set. This changed introduces retries for CreateSession at startup if the error code is potentially transient. The number of retries is set to maximum 10.

The creation of a session at startup would only be retried if waitForMinSessions was set.
This changed introduces retries for CreateSession at startup if the error code is
potentially transient. The number of retries is set to maximum 10.
@olavloite olavloite requested review from a team as code owners February 20, 2026 12:32
@product-auto-label product-auto-label bot added size: l Pull request size is large. api: spanner Issues related to the googleapis/java-spanner API. labels Feb 20, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @olavloite, 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 improves the robustness of the Spanner client library by implementing more comprehensive retry mechanisms for session creation during application startup. It ensures that transient issues during initial session establishment are handled gracefully, preventing immediate failures. Additionally, the changes include new test coverage for transaction options and error handling during session creation, contributing to overall stability and reliability.

Highlights

  • Enhanced Session Creation Retries: The CreateSession operation now includes retry logic for transient errors during startup, even when waitForMinSessions is not explicitly configured.
  • Increased Initial Retry Attempts: When waitForMinSessions is zero or null, the initial CreateSession call will now attempt up to 10 retries for transient errors.
  • New Test for ExcludeFromChangeStream: A new test file was added to validate the functionality of excluding transactions from change streams under various conditions, including transaction aborts and unavailable reads.
  • New Test for CreateSession Deadline Exceeded: A test case was introduced to specifically verify the client's behavior when CreateSession encounters a DEADLINE_EXCEEDED error.
Changelog
  • google-cloud-spanner/src/main/java/com/google/cloud/spanner/MultiplexedSessionDatabaseClient.java
    • Modified asyncCreateMultiplexedSession method signature to accept a remainingAttempts parameter.
    • Implemented retry logic within onSessionCreateFailure for transient SpannerException error codes, using the remainingAttempts count.
    • Adjusted the initial call to asyncCreateMultiplexedSession to use 10 attempts if waitForMinSessions is zero or null, otherwise 1 attempt.
    • Updated maybeWaitForSessionCreation to pass 1 as the remainingAttempts when retrying session creation.
  • google-cloud-spanner/src/test/java/com/google/cloud/spanner/ExcludeFromChangeStreamTest.java
    • Added a new test file ExcludeFromChangeStreamTest.java.
    • Included tests for testStandardTransaction, testTransactionAbortedDuringRead, testTransactionAbortedDuringCommit, testReadReturnsUnavailable, and testReadReturnsUnavailableHalfway.
  • google-cloud-spanner/src/test/java/com/google/cloud/spanner/MultiplexedSessionDatabaseClientMockServerTest.java
    • Added testCreateSessionDeadlineExceeded to verify handling of DEADLINE_EXCEEDED errors during CreateSession.
Activity
  • The pull request was created by olavloite to address a fix for retrying CreateSession calls, specifically when waitForMinSessions is zero, to handle transient errors more effectively.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 introduces retry logic for CreateSession at startup, which is a valuable improvement for handling transient network issues. The implementation in MultiplexedSessionDatabaseClient.java is sound. I've added one suggestion to replace a magic number with a named constant to improve code maintainability. Additionally, please note that the new test file google-cloud-spanner/src/test/java/com/google/cloud/spanner/ExcludeFromChangeStreamTest.java appears to be unrelated to the scope of this pull request and may have been included unintentionally.

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 googleapis/java-spanner API. size: l Pull request size is large.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant