impl(spanner): add support for Read Lock Mode in RW transactions by diegomarquezp · Pull Request #15235 · googleapis/google-cloud-cpp · GitHub | Latest TMZ Celebrity News & Gossip | Watch TMZ Live
Skip to content

impl(spanner): add support for Read Lock Mode in RW transactions #15235

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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

diegomarquezp
Copy link

@diegomarquezp diegomarquezp commented Jun 25, 2025

This change is Reviewable

This adds support for Transaction_ReadWriteOptions_ReadLockMode by adding
a constructor of ReadWriteOptions with a special enum, whose values
can be "optimistic", "pessimistic" and "unspecified".
@product-auto-label product-auto-label bot added the api: spanner Issues related to the Spanner API. label Jun 25, 2025
Copy link

codecov bot commented Jun 25, 2025

Codecov Report

Attention: Patch coverage is 60.00000% with 24 lines in your changes missing coverage. Please review.

Project coverage is 92.92%. Comparing base (05b46d0) to head (f5afe10).

Files with missing lines Patch % Lines
...anner/integration_tests/client_integration_test.cc 11.11% 24 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #15235      +/-   ##
==========================================
- Coverage   92.93%   92.92%   -0.01%     
==========================================
  Files        2394     2394              
  Lines      215352   215411      +59     
==========================================
+ Hits       200132   200167      +35     
- Misses      15220    15244      +24     

☔ 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.

@diegomarquezp
Copy link
Author

Pending: address issues pointed by checkers-pr and clang-tidy-pr

Comment on lines +777 to +779
if (UsingEmulator()) {
GTEST_SKIP() << "Optimistic locks not supported by emulator";
}
Copy link
Contributor

Choose a reason for hiding this comment

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

If you look at every other instance of UsingEmulator() in this file you'll find that it is never used to summarily skip a test. Rather, the test is run until the emulator displays different behavior, that result is expected, and then an appropriate action is taken (which might be skipping the remainder of the test). This approach should be maintained as it allows us to actively discover if/when the emulator changes.

@@ -27,12 +27,14 @@ using ::testing::IsEmpty;
TEST(TransactionOptions, Construction) {
Timestamp read_timestamp{};
std::chrono::nanoseconds staleness{};
auto read_lock_mode = Transaction::ReadLockMode::kOptimistic;
Copy link
Contributor

Choose a reason for hiding this comment

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

There's no reason to name this (particularly at this point in the code). Just pass the enumeration value directly to the ctor.

Comment on lines +88 to +92
enum class ReadLockMode {
kUnspecified,
kPessimistic,
kOptimistic,
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: Do not try to mimic the proto values. Rather, treat this enumeration as abstract, and just map its elements to proto values when filling out the protobuf. Then all the verbiage about proto classes and shorthands can disappear. See spanner::RequestPriority for a similar example.

@@ -768,6 +770,56 @@ void CheckExecuteQueryWithSingleUseOptions(
EXPECT_THAT(actual_rows, UnorderedElementsAreArray(expected_rows));
}

/// @test Verify the `ReadLockMode` option is sent in the RPC by creating a
/// situation where a transaction A perfomrs a commit while a transaction B
Copy link
Contributor

Choose a reason for hiding this comment

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

s/perfomrs/performs/

Comment on lines +791 to +792
// transaction A will do a DML after another transaction has executed DML
// If optimistic, we expect transaction A to be aborted
Copy link
Contributor

Choose a reason for hiding this comment

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

Try to use uppercase letters and periods to begin and end sentences respectively, for clarity's sake (here and below).

@@ -34,6 +34,13 @@ google::protobuf::Duration ToProto(std::chrono::nanoseconds ns) {
return proto;
}

google::spanner::v1::TransactionOptions_ReadWrite_ReadLockMode ToProto(
Transaction::ReadLockMode read_lock_mode) {
return static_cast<
Copy link
Contributor

Choose a reason for hiding this comment

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

See other comment about mapping values so as to avoid casts.

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

TMZ Celebrity News – Breaking Stories, Videos & Gossip

Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.

Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.

🎥 Watch TMZ Live

TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.