This page describes how to use repeatable read isolation in Spanner.
Repeatable read is an isolation level that ensures that all read operations within a transaction see a consistent snapshot of the database as it existed at the start of the transaction. In Spanner, this isolation level is implemented using a technique that is also commonly called snapshot isolation. This approach is beneficial in high read-write concurrency scenarios where numerous transactions read data that other transactions might be modifying. By using a fixed snapshot, repeatable read avoids the performance impacts of the more rigorous serializable isolation level. Reads can execute without acquiring locks and without blocking concurrent writes, which results in potentially fewer aborted transactions that might need to be retried due to serialization conflicts. For more information, see Isolation level overview.
Set the isolation level
You can set the isolation level on read-write transactions at the transaction-level using the following methods:
Client libraries
Go
Java
Node.js
Python
REST
You can use the TransactionOptions.isolation_level
REST API to set the isolation level on read-write transactions at the
transaction-level. The valid options are TransactionOptions.SERIALIZABLE
and
TransactionOptions.REPEATABLE_READ
. By default, Spanner sets
the isolation level to serializable isolation.
RPC
Unsupported use cases
- You can only use repeatable read isolation in read-write transactions. Spanner returns an error if you set this isolation level on a read-only transaction. All read-only transactions operate at a fixed snapshot and don't require locks.
- You can't use repeatable read isolation to modify tables that has full-text search indexes defined on its columns.
What's next
Learn more about isolation levels.
Learn how to use SELECT FOR UPDATE in repeatable read isolation.
Learn more about Spanner serializability and external consistency, see TrueTime and external consistency.