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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-07-26 UTC."],[[["This document outlines the `Transaction` class in Google Cloud Spanner's C++ client library, focusing on version 2.34.0 and including links to various other versions from 2.11.0 through 2.37.0-rc."],["A Spanner transaction is defined as an atomic unit of reads and writes, all occurring at a consistent point in time within a database, and each transaction is bound to a single session, which can only contain one active transaction."],["Spanner transactions can operate in three different modes: `ReadOnly` for consistent reads without writes, `ReadWrite` for both reading and writing with potential for aborts, and `SingleUse` which allows only reading with an automatically selected timestamp."],["The `Transaction` object creation is a lazy operation, meaning no RPCs are executed during instantiation; instead, the first server request, such as an `ExecuteQuery()`, triggers the transaction's creation."],["The `Transaction` class supports various constructors, including those for `ReadOnlyOptions` and `ReadWriteOptions`, along with move and copy constructors."]]],[]]