docs(spanner): snippets to set transaction options#2194
docs(spanner): snippets to set transaction options#2194skuruppu wants to merge 1 commit intoGoogleCloudPlatform:mainfrom
Conversation
|
Here is the summary of changes. You are about to add 2 region tags.
This comment is generated by snippet-bot.
|
There was a problem hiding this comment.
Code Review
This pull request introduces new PHP code samples and integration tests for Google Cloud Spanner, demonstrating transaction isolation levels and read lock modes. Several technical issues were identified in the implementation: the defaultTransactionOptions configuration key is not supported by the SpannerClient constructor, the readLockMode option is incorrectly nested and will be ignored by the library, and the use of REPEATABLE_READ isolation is invalid for the read-write transaction context provided in the sample.
| printf('%d record(s) updated.' . PHP_EOL, $rowCount); | ||
| }, [ | ||
| 'transactionOptions' => [ | ||
| 'isolationLevel' => IsolationLevel::REPEATABLE_READ |
There was a problem hiding this comment.
Cloud Spanner only supports SERIALIZABLE isolation for read-write transactions in the GoogleSQL dialect. REPEATABLE_READ is only supported for read-only transactions. Since runTransaction creates a read-write transaction and this snippet performs an UPDATE, using REPEATABLE_READ here will likely result in an error from the Spanner API. Consider using SERIALIZABLE or demonstrating this option in a read-only transaction context.
There was a problem hiding this comment.
This is not true. Cloud Spanner supports setting the isolation level to SERIALIZABLE or REPEATABLE_READ in both GSQL and PG dialects. It also supports setting the isolation level in both ReadWrite and ReadOnly transactions. It's a no-op to set it in ReadOnly transactions.
| 'transactionOptions' => [ | ||
| 'readLockMode' => ReadLockMode::PESSIMISTIC | ||
| ] |
There was a problem hiding this comment.
The readLockMode option must be nested under the readWrite key within transactionOptions to correctly map to the underlying Protobuf structure (transaction_options.read_write.read_lock_mode). Without this nesting, the option will be ignored by the library.
'transactionOptions' => [
'readWrite' => [
'readLockMode' => ReadLockMode::PESSIMISTIC
]
]There was a problem hiding this comment.
This is necessary when setting it in the grpc API but not at the client-library level. See the unit tests for an example of setting readLockMode in this way.
Adds a snippet for setting the isolation level and another for setting the read lock mode. Both samples shows how to set the isolation level and read lock mode at the client level, and how to set it at a transaction level.
02f8a23 to
a2d07ca
Compare
Adds a snippet for setting the isolation level and another for setting the read lock mode.
Both samples show how to set the isolation level and read lock mode at the client level, and how to set it at a transaction level.