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-08-22 UTC."],[[["\u003cp\u003eThis document details the \u003ccode\u003eTransaction\u003c/code\u003e class within the Cloud Spanner C++ library, offering various versions of the class, starting from version \u003ccode\u003e2.11.0\u003c/code\u003e up to the latest release candidate \u003ccode\u003e2.37.0-rc\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eA Cloud Spanner transaction, represented by the \u003ccode\u003eTransaction\u003c/code\u003e class, ensures that a group of reads and writes to a database happen together as a single, atomic operation.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eTransaction\u003c/code\u003e class offers three transaction modes: \u003ccode\u003eReadOnly\u003c/code\u003e for consistent reads without writes, \u003ccode\u003eReadWrite\u003c/code\u003e for both reading and writing, and \u003ccode\u003eSingleUse\u003c/code\u003e for read-only operations with Spanner choosing the read timestamp.\u003c/p\u003e\n"],["\u003cp\u003eCreating a \u003ccode\u003eTransaction\u003c/code\u003e object is a lazy operation, meaning no server requests are made until the first operation is performed, such as executing a query.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eTransaction\u003c/code\u003e class supports multiple constructors and operators, including those for \u003ccode\u003eReadOnlyOptions\u003c/code\u003e and \u003ccode\u003eReadWriteOptions\u003c/code\u003e, as well as move and copy operations.\u003c/p\u003e\n"]]],[],null,[]]