Class Transaction (2.27.0)

The representation of a Cloud Spanner transaction.

A transaction is a set of reads and writes that execute atomically at a single logical point in time across the columns/rows/tables in a database. Those reads and writes are grouped by passing them the same Transaction.

All reads/writes in the transaction must be executed within the same session, and that session may have only one transaction active at a time.

Spanner supports these transaction modes:

  • ReadOnly. Provides guaranteed consistency across several reads, but does not allow writes. Can be configured to read at timestamps in the past. Does not need to be committed and does not take locks.
  • ReadWrite. Supports reading and writing data at a single point in time. Uses pessimistic locking and, if necessary, two-phase commit. May abort, requiring the application to rerun.
  • SingleUse. A restricted form of a ReadOnly transaction where Spanner chooses the read timestamp.

Constructors

Transaction(ReadOnlyOptions)

Construction of read-only and read-write transactions.

Parameter
Name Description
opts ReadOnlyOptions

Transaction(ReadWriteOptions)

Construction of read-only and read-write transactions.

Parameter
Name Description
opts ReadWriteOptions

Transaction(Transaction const &, ReadWriteOptions)

Construction of read-only and read-write transactions.

Parameters
Name Description
txn Transaction const &
opts ReadWriteOptions

Transaction(Transaction &&)

Regular value type, supporting copy, assign, move.

Parameter
Name Description
Transaction &&

Transaction(Transaction const &)

Regular value type, supporting copy, assign, move.

Parameter
Name Description
Transaction const &

Operators

operator=(Transaction &&)

Regular value type, supporting copy, assign, move.

Parameter
Name Description
Transaction &&
Returns
Type Description
Transaction &

operator=(Transaction const &)

Regular value type, supporting copy, assign, move.

Parameter
Name Description
Transaction const &
Returns
Type Description
Transaction &