-
Notifications
You must be signed in to change notification settings - Fork 112
docs(spanner): snippet for setting read lock mode #2495
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
base: main
Are you sure you want to change the base?
Conversation
Snippet shows how to set the read lock mode at the client-level and how to override the option at the transaction-level.
|
Warning: This pull request is touching the following templated files:
|
|
Here is the summary of changes. You are about to add 1 region tag.
This comment is generated by snippet-bot.
|
Summary of ChangesHello @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 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 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.
| 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, | ||
| }); |
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.
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(); |
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.
|
|
||
|
|
||
| `node read-lock-mode.js <INSTANCE_ID> <DATABASE_ID> <PROJECT_ID>` | ||
|
|
||
|
|
||
| ----- | ||
|
|
||
|
|
||
|
|
||
|
|
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.
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.
| `node read-lock-mode.js <INSTANCE_ID> <DATABASE_ID> <PROJECT_ID>` | |
| ----- | |
| `node read-lock-mode.js <INSTANCE_ID> <DATABASE_ID> <PROJECT_ID>` | |
| ----- | |
Snippet shows how to set the read lock mode at the client-level and how to override the option at the transaction-level.