Commits a transaction. The request includes the mutations to be applied to rows in the database.
sessions.commit
might return an ABORTED
error. This can occur at any time; commonly, the cause is conflicts with concurrent transactions. However, it can also happen for a variety of other reasons. If sessions.commit
returns ABORTED
, the caller should retry the transaction from the beginning, reusing the same session.
On very rare occasions, sessions.commit
might return UNKNOWN
. This can happen, for example, if the client job experiences a 1+ hour networking failure. At that point, Cloud Spanner has lost track of the transaction outcome and we recommend that you perform another read from the database to see the state of things as they are now.
HTTP request
The URLs use gRPC Transcoding syntax.
Path parameters
session
string
Required. The session in which the transaction to be committed is running.
Authorization requires the following IAM
permission on the specified resource session
:
-
spanner.databases.write
Request body
The request body contains data with the following structure:
JSON representation |
---|
{ "mutations" : [ { object ( |
mutations[]
object (
Mutation
)
The mutations to be executed when this transaction commits. All mutations are applied atomically, in the order they appear in this list.
returnCommitStats
boolean
If true
, then statistics related to the transaction is included in the CommitResponse
. Default value is false
.
maxCommitDelay
string (
Duration
format)
Optional. The amount of latency this request is configured to incur in order to improve throughput. If this field isn't set, Spanner assumes requests are relatively latency sensitive and automatically determines an appropriate delay time. You can specify a commit delay value between 0 and 500 ms.
A duration in seconds with up to nine fractional digits, ending with ' s
'. Example: "3.5s"
.
precommitToken
object (
MultiplexedSessionPrecommitToken
)
Optional. If the read-write transaction was executed on a multiplexed session, then you must include the precommit token with the highest sequence number received in this transaction attempt. Failing to do so results in a FailedPrecondition
error.
transaction
. Required. The transaction in which to commit. transaction
can be only one of the following:transactionId
singleUseTransaction
object (
TransactionOptions
)
Execute mutations in a temporary transaction. Note that unlike commit of a previously-started transaction, commit with a temporary transaction is non-idempotent. That is, if the CommitRequest
is sent to Cloud Spanner more than once (for instance, due to retries in the application, or in the transport library), it's possible that the mutations are executed more than once. If this is undesirable, use sessions.beginTransaction
and sessions.commit
instead.
Response body
The response for sessions.commit
.
If successful, the response body contains data with the following structure:
JSON representation |
---|
{ "commitTimestamp" : string , "commitStats" : { object ( |
commitStats
object (
CommitStats
)
The statistics about this sessions.commit
. Not returned by default. For more information, see CommitRequest.return_commit_stats
.
MultiplexedSessionRetry
. You must examine and retry the commit if the following is populated. MultiplexedSessionRetry
can be only one of the following:precommitToken
object (
MultiplexedSessionPrecommitToken
)
If specified, transaction has not committed yet. You must retry the commit with the new precommit token.
Authorization scopes
Requires one of the following OAuth scopes:
-
https://www.googleapis.com/auth/spanner.data
-
https://www.googleapis.com/auth/cloud-platform
For more information, see the Authentication Overview .
CommitStats
Additional statistics about a commit.
JSON representation |
---|
{ "mutationCount" : string } |
Fields | |
---|---|
mutationCount
|
The total number of mutations for the transaction. Knowing the |