-
Notifications
You must be signed in to change notification settings - Fork 452
feat: Support for Spanner ReadLockMode #8419
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
Conversation
4ef3de8 to
5d0b91c
Compare
|
Opening this up for review to get early feedback. The style failures seem to be for already existing code lines in the unit test class, so not sure if I need to do anything there. Will follow up on that. |
bshaffer
left a comment
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.
This looks great!
As mentioned in the team meeting, I don't want to support the nested version of this option. We should only document and support one way to use it. If it's usable the other "nested" way, that's fine, but we don't need to test it and support it specifically.
Can you confirm that this option should NOT be supported in the other places TransactionOptions is used? This PR adds support for Database::runTransaction and Database::transaction, but #7749 shows that transaction options are used in the following methods as well:
Database::executePartitionedUpdateOperation::transaction(this is called byDatabase::transaction)Operation::executeOperation::executeUpdateDatabase::batchUpdate
| // The `readLockMode` can be set on the base options following convention or as a nested option if need be | ||
| if (isset($options['readLockMode']) || isset($options['readWrite']['readLockMode'])) { | ||
| $readLockModeOption = $options['readLockMode'] ?? $options['readWrite']['readLockMode']; | ||
| $transactionOptions['readWrite']['readLockMode'] = $readLockModeOption; | ||
| } |
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.
Let's only support it on the top level to keep it simple
| // The `readLockMode` can be set on the base options following convention or as a nested option if need be | |
| if (isset($options['readLockMode']) || isset($options['readWrite']['readLockMode'])) { | |
| $readLockModeOption = $options['readLockMode'] ?? $options['readWrite']['readLockMode']; | |
| $transactionOptions['readWrite']['readLockMode'] = $readLockModeOption; | |
| } | |
| // The `readLockMode` can be set on the base options following convention or as a nested option if need be | |
| if (isset($options['readLockMode'])) { | |
| $transactionOptions['readWrite']['readLockMode'] = $options['readLockMode'] | |
| } |
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 think we discussed keeping this officially documented as a option settable on the top level. But if someone wants to set it in the nested way they can? If we remove this condition, and someone tries to set it in the nested way it will not set the option at all as we are creating an empty readWrite array at the beginning of this function.
Let me know if that makes sense or we still want to let users only set this as a top level option (having that as the only choice might cause some confusion if folks go in and check the way the ReadLockMode is setup as a nested option in our compiled proto).
19d250d to
4d3cea5
Compare
230d1e7 to
1aae26c
Compare
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.
looks good! All small suggestions except for one regarding DX
Spanner/tests/Unit/OperationTest.php
Outdated
| $transaction = $this->prophesize(Transaction::class)->reveal(); | ||
|
|
||
| $operation->executeUpdate($this->session, $transaction, $sql, [ | ||
| 'transaction' => ['begin' => ['readWrite' => [],'readLockMode' => $expectedReadLockMode,]] |
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.
why are we supplying 'readWrite' => [] here? Is it not sufficient to supply the readLockMode option? This seems like a weird API... supplying an empty array to readWrite does not make sense to me from a DX standpoint.
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.
That sounds reasonable, agreed it is probably not the best way to go about in terms of dev experience. I have removed the 'readWrite' => []. But in order to now format the readLockMode correctly and only for readWrite transactions, I have added a condition into Grpc::formatTransactionOptions(). Lmk if that looks good.
bshaffer
left a comment
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.
great work! This is still marked as "do not merge", but it's approved on my end.
No region tags are edited in this PR.This comment is generated by snippet-bot.
|
tests: Add in unit tests for ReadLockMode option chore: Fix lint issues chore: Fix lint issues chore: Fix lint issues feat: Add ability to set this ReadLockMode through operations chore: Cleanup code and remove debug logging chore: Lint fixes chore: Fix style warnings chore: Review comment resolution
Feature to add
ReadLockModeoption forReadWritetransactions only. Two ways users can set the option -transactionOptionarray like any other txn option. This provides consistency with how our other option configurations workreadWriteoptions inside thetransactionOptionarray. This provides flexibility for the user since the readLockMode is a special nested option inside of the readWrite.Some comment changes to be in accordance with this new feature and unit tests have been added.