-
Notifications
You must be signed in to change notification settings - Fork 14
feat: commit begins transaction if not already begun #1143
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1143 +/- ##
=========================================
+ Coverage 93.58% 93.6% +0.02%
=========================================
Files 169 170 +1
Lines 13065 13110 +45
=========================================
+ Hits 12227 12272 +45
Misses 838 838
Continue to review full report at Codecov.
|
if (s.selector_case() != spanner_proto::TransactionSelector::kId) { | ||
spanner_proto::BeginTransactionRequest begin; | ||
begin.set_session(session->session_name()); | ||
*begin.mutable_options() = s.begin(); |
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.
Even though it doesn't make sense to pass a single-use/read-only transaction to Commit()
, it also doesn't make sense to pass any read-only transaction, yet we support the latter and not the former. So, we might as well look at s.has_single_use()
and use its TransactionOptions
, rather than using the default TransactionOptions
, and let the chips fall where they may.
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.
I wouldn't say that we "support" read-only transactions. Any caller who passes in a read-only transaction to Commit()
will get an error. I believe that's true before and after this PR.
To call Commit()
correctly, callers must pass in a read-write transaction. RW transactions have all their options in the "begin" field of the selector, so that's why I think we only need to copy that field from the selector into the mutable_options
in the request.
I don't think we should write extra code to deal with things like single-use RO transactions when callers are not allowed to pass them, and if they did, it's guaranteed to fail.
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.
Discussed this offline. I changed the code to consider the case where the input selector was a single_use transaction as @devbww was suggesting. We know this will give an error, but it's what the user asked for.
Fixes #689
This change is![Reviewable](https://camo.githubusercontent.com/1541c4039185914e83657d3683ec25920c672c6c5c7ab4240ee7bff601adec0b/68747470733a2f2f72657669657761626c652e696f2f7265766965775f627574746f6e2e737667)