@@ -361,19 +361,31 @@ message TransactionOptions {
361
361
enum ReadLockMode {
362
362
// Default value.
363
363
//
364
- // If the value is not specified, the pessimistic read lock is used.
364
+ // * If isolation level is `REPEATABLE_READ`, then it is an error to
365
+ // specify `read_lock_mode`. Locking semantics default to `OPTIMISTIC`.
366
+ // No validation checks are done for reads, except for:
367
+ // 1. reads done as part of queries that use `SELECT FOR UPDATE`
368
+ // 2. reads done as part of statements with a `LOCK_SCANNED_RANGES`
369
+ // hint
370
+ // 3. reads done as part of DML statements
371
+ // to validate that the data that was served at the snapshot time is
372
+ // unchanged at commit time.
373
+ // * At all other isolation levels, if `read_lock_mode` is the default
374
+ // value, then pessimistic read lock is used.
365
375
READ_LOCK_MODE_UNSPECIFIED = 0 ;
366
376
367
377
// Pessimistic lock mode.
368
378
//
369
379
// Read locks are acquired immediately on read.
380
+ // Semantics described only applies to `SERIALIZABLE` isolation.
370
381
PESSIMISTIC = 1 ;
371
382
372
383
// Optimistic lock mode.
373
384
//
374
385
// Locks for reads within the transaction are not acquired on read.
375
386
// Instead the locks are acquired on a commit to validate that
376
387
// read/queried data has not changed since the transaction started.
388
+ // Semantics described only applies to `SERIALIZABLE` isolation.
377
389
OPTIMISTIC = 2 ;
378
390
}
379
391
@@ -461,6 +473,38 @@ message TransactionOptions {
461
473
bool return_read_timestamp = 6 ;
462
474
}
463
475
476
+ // `IsolationLevel` is used when setting `isolation_level` for a transaction.
477
+ enum IsolationLevel {
478
+ // Default value.
479
+ //
480
+ // If the value is not specified, the `SERIALIZABLE` isolation level is
481
+ // used.
482
+ ISOLATION_LEVEL_UNSPECIFIED = 0 ;
483
+
484
+ // All transactions appear as if they executed in a serial order, even if
485
+ // some of the reads, writes, and other operations of distinct transactions
486
+ // actually occurred in parallel. Spanner assigns commit timestamps that
487
+ // reflect the order of committed transactions to implement this property.
488
+ // Spanner offers a stronger guarantee than serializability called external
489
+ // consistency. For further details, please refer to
490
+ // https://cloud.google.com/spanner/docs/true-time-external-consistency#serializability.
491
+ SERIALIZABLE = 1 ;
492
+
493
+ // All reads performed during the transaction observe a consistent snapshot
494
+ // of the database, and the transaction will only successfully commit in the
495
+ // absence of conflicts between its updates and any concurrent updates that
496
+ // have occurred since that snapshot. Consequently, in contrast to
497
+ // `SERIALIZABLE` transactions, only write-write conflicts are detected in
498
+ // snapshot transactions.
499
+ //
500
+ // This isolation level does not support Read-only and Partitioned DML
501
+ // transactions.
502
+ //
503
+ // When `REPEATABLE_READ` is specified on a read-write transaction, the
504
+ // locking semantics default to `OPTIMISTIC`.
505
+ REPEATABLE_READ = 2 ;
506
+ }
507
+
464
508
// Required. The type of transaction.
465
509
oneof mode {
466
510
// Transaction may write.
@@ -500,6 +544,9 @@ message TransactionOptions {
500
544
// partitioned-dml transactions, otherwise the API will return an
501
545
// `INVALID_ARGUMENT` error.
502
546
bool exclude_txn_from_change_streams = 5 ;
547
+
548
+ // Isolation level for the transaction.
549
+ IsolationLevel isolation_level = 6 ;
503
550
}
504
551
505
552
// A transaction.
0 commit comments