Skip to content

chore: sample for snapshot isolation #2265

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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

alkatrivedi
Copy link
Contributor

@alkatrivedi alkatrivedi commented Mar 25, 2025

This PR contains sample for the Snapshot Isolation level support. Isolation level is being set to SERIALIZABLE at the client level which is getting overwritten by the isolation level REPEATABLE_READ set at the transaction level.

@alkatrivedi alkatrivedi requested review from a team as code owners March 25, 2025 07:05
Copy link

snippet-bot bot commented Mar 25, 2025

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. samples Issues that are directly related to samples. labels Mar 25, 2025
// Gets a reference to a Cloud Spanner instance and database
const instance = spanner.instance(instanceId);
const database = instance.database(databaseId);
const snapshotIsolationOptionsForRequest = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const snapshotIsolationOptionsForRequest = {
// The isolation level specified at the request level takes precedence over the isolation level configured at the client level.
const snapshotIsolationOptionsForRequest = {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@surbhigarg92 surbhigarg92 added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Mar 25, 2025
Copy link

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

// [START spanner_isolation_level]
// Imports the Google Cloud Spanner client library
const {Spanner, protos} = require('@google-cloud/spanner');
const snapshotIsolationOptionsForClient = {
Copy link
Contributor

Choose a reason for hiding this comment

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

probably calls this isolationOptionsForClient.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

defaultTransactionOptions: snapshotIsolationOptionsForClient,
});

function spannerSnapshotIsolation() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would call this runTransactionWithIsolationLevel().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

const instance = spanner.instance(instanceId);
const database = instance.database(databaseId);
// The isolation level specified at the request level takes precedence over the isolation level configured at the client level.
const snapshotIsolationOptionsForRequest = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here with naming, something like isolationOptionsForTransaction.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@alkatrivedi alkatrivedi added kokoro:force-run Add this label to force Kokoro to re-run the tests. owlbot:run Add this label to trigger the Owlbot post processor. labels Apr 1, 2025
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Apr 1, 2025
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 1, 2025
@alkatrivedi alkatrivedi force-pushed the sample-snapshot-isolation branch from c292e3c to 2ee6b33 Compare April 1, 2025 05:21
@alkatrivedi alkatrivedi force-pushed the sample-snapshot-isolation branch from 2ee6b33 to 82eb764 Compare April 2, 2025 04:28
@alkatrivedi alkatrivedi added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 2, 2025
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 2, 2025
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's rename this to repeatable-read.js.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

__Usage:__


`node snapshot-isolation.js <INSTANCE_ID> <DATABASE_ID> <PROJECT_ID>`
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here with naming: repeatable-read.js

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

// isolation_level_option
it('should run read-write transaction with isolation level option set', () => {
const output = execSync(
`node snapshot-isolation.js ${INSTANCE_ID} ${DATABASE_ID} ${PROJECT_ID}`
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here with naming.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@alkatrivedi alkatrivedi added the owlbot:run Add this label to trigger the Owlbot post processor. label Apr 7, 2025
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Apr 7, 2025
@alkatrivedi alkatrivedi force-pushed the sample-snapshot-isolation branch from 43c3f23 to 0da8b77 Compare April 7, 2025 11:49
@alkatrivedi alkatrivedi added kokoro:force-run Add this label to force Kokoro to re-run the tests. owlbot:run Add this label to trigger the Owlbot post processor. labels Apr 7, 2025
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Apr 7, 2025
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 7, 2025
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. do not merge Indicates a pull request not ready for merge, due to either quality or timing. samples Issues that are directly related to samples. size: m Pull request size is medium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants