Skip to content

Conversation

@skuruppu
Copy link
Contributor

@skuruppu skuruppu commented Jan 9, 2026

Snippet shows how to set the read lock mode at the client-level and how to override the option at the transaction-level.

Snippet shows how to set the read lock mode at the client-level and how
to override the option at the transaction-level.
@skuruppu skuruppu requested review from a team as code owners January 9, 2026 02:42
@generated-files-bot
Copy link

Warning: This pull request is touching the following templated files:

@snippet-bot
Copy link

snippet-bot bot commented Jan 9, 2026

Here is the summary of changes.

You are about to add 1 region tag.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@product-auto-label product-auto-label bot added size: m Pull request size is medium. api: spanner Issues related to the googleapis/nodejs-spanner API. labels Jan 9, 2026
@gemini-code-assist
Copy link

Summary of Changes

Hello @skuruppu, 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 enhances the Google Cloud Spanner documentation by adding a new sample that demonstrates the usage of read lock modes within read-write transactions. The sample illustrates how to apply an optimistic read lock mode globally at the client level and then specifically override it with a pessimistic read lock mode for individual transactions, providing clear guidance on managing transaction concurrency.

Highlights

  • New Spanner Read Lock Mode Snippet: Introduces a new code snippet demonstrating how to configure read lock modes for Spanner read-write transactions.
  • Client-Level Configuration: Shows how to set a default read lock mode (e.g., OPTIMISTIC) at the Spanner client level.
  • Transaction-Level Override: Illustrates how to override the client-level read lock mode with a transaction-specific setting (e.g., PESSIMISTIC).
  • Documentation and Testing: Includes updates to README.md files and a new system test to validate the functionality of the new sample.

🧠 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 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

@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 a new code snippet for setting the read lock mode in Spanner, along with corresponding documentation and tests. The implementation is mostly correct, but I've identified a critical issue in how the client-level options are configured in the new sample, which would prevent it from working as intended. Additionally, I've pointed out a couple of medium-severity issues related to redundant code and documentation formatting. My suggestions aim to correct these issues and improve the overall quality of the sample.

Comment on lines +31 to +43
const readLockModeOptionsForClient = {
defaultTransactionOptions: {
readLockMode:
protos.google.spanner.v1.TransactionOptions.ReadWrite.ReadLockMode
.OPTIMISTIC,
},
};

// Instantiates a client with defaultTransactionOptions
const spanner = new Spanner({
projectId: projectId,
defaultTransactionOptions: readLockModeOptionsForClient,
});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The defaultTransactionOptions object is nested incorrectly. It should be a flat object at the top level of the Spanner constructor options, not nested within another defaultTransactionOptions property. This prevents the client-level readLockMode from being applied.

  const defaultTransactionOptions = {
    readLockMode:
      protos.google.spanner.v1.TransactionOptions.ReadWrite.ReadLockMode
        .OPTIMISTIC,
  };

  // Instantiates a client with defaultTransactionOptions
  const spanner = new Spanner({
    projectId: projectId,
    defaultTransactionOptions,
  });

} catch (err) {
console.error('ERROR:', err);
} finally {
transaction.end();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The database.runTransaction() method automatically handles session management, including releasing the session when the transaction is complete. Calling transaction.end() here is redundant and should be removed for clarity and to avoid potential issues with double-releasing sessions.

Comment on lines +1917 to +1926


`node read-lock-mode.js <INSTANCE_ID> <DATABASE_ID> <PROJECT_ID>`


-----




Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There are some extra newlines here that make the formatting inconsistent with the rest of the file. Please remove the extra blank lines for consistency.

Suggested change
`node read-lock-mode.js <INSTANCE_ID> <DATABASE_ID> <PROJECT_ID>`
-----
`node read-lock-mode.js <INSTANCE_ID> <DATABASE_ID> <PROJECT_ID>`
-----

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/nodejs-spanner API. size: m Pull request size is medium.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant