Skip to content

Conversation

@prathmeshcc
Copy link
Collaborator

This PR introduces the IsolationLevel enum class in google/cloud/spanner/isolation_level.h.

This enum maps to the google.spanner.v1.TransactionOptions.IsolationLevel protobuf and defines the supported isolation levels for Cloud Spanner read-write transactions:

  • kUnspecified
  • kSerializable
  • kRepeatableRead

This addition is a prerequisite for allowing users to configure the isolation level (specifically Repeatable Read) in transaction options.

@product-auto-label product-auto-label bot added the api: spanner Issues related to the Spanner API. label Jan 5, 2026
@gemini-code-assist
Copy link

Summary of Changes

Hello @prathmeshcc, 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 C++ client library by introducing explicit support for transaction isolation levels. It defines a new IsolationLevel enum and integrates it into the transaction options, allowing users to configure the desired isolation behavior, such as Repeatable Read, for their read-write transactions. This change lays the groundwork for more granular control over transaction semantics.

Highlights

  • New IsolationLevel Enum: Introduced google::cloud::spanner::IsolationLevel enum class, mirroring google.spanner.v1.TransactionOptions.IsolationLevel with kUnspecified, kSerializable, and kRepeatableRead.
  • Configurable Transaction Isolation: Added the ability to specify the isolation level for read-write transactions through Transaction::ReadWriteOptions and TransactionIsolationLevelOption.
  • Integration and Unit Tests: Included new integration tests in client_integration_test.cc and unit tests in transaction_test.cc to validate the correct application and precedence of isolation levels.

🧠 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 an IsolationLevel enum and the corresponding TransactionIsolationLevelOption to allow users to configure the isolation level for read-write transactions. The changes are well-structured and follow existing patterns in the codebase. The new functionality is well-tested with new unit and integration tests that verify the option handling and precedence. The implementation appears correct and complete. I have one minor suggestion to remove some debugging output from the unit tests.

Comment on lines +174 to +225
TEST(Transaction, IsolationLevel) {
auto opts = Transaction::ReadWriteOptions().WithIsolationLevel(
IsolationLevel::kRepeatableRead);
Transaction txn = MakeReadWriteTransaction(opts);
spanner_internal::Visit(
txn, [](spanner_internal::SessionHolder&,
StatusOr<google::spanner::v1::TransactionSelector>& s,
spanner_internal::TransactionContext const&) {
EXPECT_TRUE(s->has_begin());
EXPECT_TRUE(s->begin().has_read_write());
EXPECT_EQ(s->begin().isolation_level(),
google::spanner::v1::TransactionOptions::REPEATABLE_READ);

std::cout << "Isolation Level: "
<< s->begin().isolation_level() << std::endl;
return 0;
});
}

TEST(Transaction, IsolationLevelPrecedence) {
internal::OptionsSpan span(Options{}.set<TransactionIsolationLevelOption>(
IsolationLevel::kSerializable));

// Case 1: Per-call overrides client default
auto opts = Transaction::ReadWriteOptions().WithIsolationLevel(
IsolationLevel::kRepeatableRead);
Transaction txn = MakeReadWriteTransaction(opts);
spanner_internal::Visit(
txn, [](spanner_internal::SessionHolder&,
StatusOr<google::spanner::v1::TransactionSelector>& s,
spanner_internal::TransactionContext const&) {
EXPECT_EQ(s->begin().isolation_level(),
google::spanner::v1::TransactionOptions::REPEATABLE_READ);
std::cout << "Isolation Level: "
<< s->begin().isolation_level() << std::endl;
return 0;
});

// Case 2: Fallback to client default
auto opts_default = Transaction::ReadWriteOptions();
Transaction txn_default = MakeReadWriteTransaction(opts_default);
spanner_internal::Visit(
txn_default, [](spanner_internal::SessionHolder&,
StatusOr<google::spanner::v1::TransactionSelector>& s,
spanner_internal::TransactionContext const&) {
EXPECT_EQ(s->begin().isolation_level(),
google::spanner::v1::TransactionOptions::SERIALIZABLE);
std::cout << "Isolation Level: "
<< s->begin().isolation_level() << std::endl;
return 0;
});
}

Choose a reason for hiding this comment

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

medium

The new tests TEST(Transaction, IsolationLevel) and TEST(Transaction, IsolationLevelPrecedence) contain std::cout statements (lines 187-188, 207-208, and 221-222) that seem to be for debugging. Please remove them to keep the test output clean.

@codecov
Copy link

codecov bot commented Jan 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.94%. Comparing base (d6aff23) to head (c6e6066).
⚠️ Report is 13 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #15853      +/-   ##
==========================================
- Coverage   92.95%   92.94%   -0.01%     
==========================================
  Files        2458     2458              
  Lines      227589   227661      +72     
==========================================
+ Hits       211553   211605      +52     
- Misses      16036    16056      +20     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment on lines +77 to +79
opts.set_isolation_level(
static_cast<google::spanner::v1::TransactionOptions::IsolationLevel>(
isolation_level));
Copy link
Contributor

Choose a reason for hiding this comment

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

We strive to not tie the C++ enum values to the protobuf enum values. See, for example, LockHint, OrderBy, ReadLockMode, ReplicaType, RequestPriority, etc. Please continue that by introducing an explicit mapping here (removing the static_cast and specific enum class values).

for (auto const& row : rows) {
if (!row) return row.status();
}
// std::cout << "Transaction is active." << std::endl;
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Acknowledged. Will remove this in the next push.

// std::cout << "Transaction is active." << std::endl;
return Mutations{};
},
Options{}.set<TransactionIsolationLevelOption>(
Copy link
Contributor

Choose a reason for hiding this comment

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

Would this test behave any differently if this was ignored? That is, what are we testing?

}
return Mutations{};
},
Options{}.set<TransactionIsolationLevelOption>(
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto.

Comment on lines +141 to +142
*selector.mutable_begin() =
MakeOpts(std::move(opts.rw_opts_), opts.isolation_level_);
Copy link
Contributor

Choose a reason for hiding this comment

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

[GitHub seems to have dropped a comment here. Apologies if you see this twice.]

It seems weird that the isolation level appears to only be useful in read-write mode yet it wasn't made part of message ReadWrite. Is that appearance true (and the protos should probably be fixed, in which case we would not need any special treatment here), or are we being too specific in making the isolation mode a member of ReadWriteOptions?

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 Spanner API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants