Google.Cloud.Spanner.Data - Class SpannerTransaction (5.0.0-beta03)

public sealed class SpannerTransaction : SpannerTransactionBase, IDbTransaction, IDisposable, IAsyncDisposable

Reference documentation and code samples for the Google.Cloud.Spanner.Data class SpannerTransaction.

Represents a SQL transaction to be made in a Spanner database. A transaction in Cloud Spanner is a set of reads and writes that execute atomically at a single logical point in time across columns, rows, and tables in a database.

Inheritance

object > MarshalByRefObject > DbTransaction > SpannerTransactionBase > SpannerTransaction

Namespace

Google.Cloud.Spanner.Data

Assembly

Google.Cloud.Spanner.Data.dll

Properties

CommitPriority

public Priority CommitPriority { get; set; }

The RPC priority to use for the commit RPC of this transaction. This can only be set for read/write transactions. This priority is not used for commands that are executed on this transaction. Use Priority to set the priority of commands. The default priority is Unspecified.

Property Value
Type Description
Priority

CommitTimeout

public int CommitTimeout { get; set; }

Gets or sets the wait time before terminating the attempt to Commit() or Rollback() and generating an error. Defaults to the timeout from the connection string. A value of '0' normally indicates that no timeout should be used (it waits an infinite amount of time). However, if you specify AllowImmediateTimeouts=true in the connection string, '0' will cause a timeout that expires immediately. This is normally used only for testing purposes.

Property Value
Type Description
int

DbConnection

protected override DbConnection DbConnection { get; }

Specifies the DbConnection object associated with the transaction.

Property Value
Type Description
DbConnection

The DbConnection object associated with the transaction.

Overrides

DisposeBehavior

public DisposeBehavior DisposeBehavior { get; set; }

Specifies how resources are treated when Dispose(bool) is called. The default behavior of ReleaseToPool will cause transactional resources to be sent back into a shared pool for re-use. Shared transactions may only set this value to either CloseResources to close resources or Detach to detach from the resources. A shared transaction must have one process choose CloseResources to avoid leaks of transactional resources.

Property Value
Type Description
DisposeBehavior

IsolationLevel

public override IsolationLevel IsolationLevel { get; }

Specifies the IsolationLevel for this transaction.

Property Value
Type Description
IsolationLevel

The IsolationLevel for this transaction.

Overrides

LogCommitStats

public bool LogCommitStats { get; set; }

Specifies whether this transaction should request commit statistics from the backend and log these. This property is by default equal to the value set on the SpannerConnection of this transaction, but can be overridden for a specific transaction.

Property Value
Type Description
bool

MaxCommitDelay

public TimeSpan? MaxCommitDelay { get; set; }

The maximum amount of time the commit may be delayed server side for batching with other commits. The bigger the delay, the better the throughput (QPS), but at the expense of commit latency. If set to Zero, commit batching is disabled. May be null, in which case commits will continue to be batched as they had been before this configuration option was made available to Spanner API consumers. May be set to any value between Zero and 500ms.

Property Value
Type Description
TimeSpan

Mode

public TransactionMode Mode { get; }

Indicates the TransactionMode for the transaction.

Property Value
Type Description
TransactionMode
Remarks

Cloud Spanner supports two transaction modes:

  • Locking read-write transactions are the only transaction type that support writing data into Cloud Spanner. These transactions rely on pessimistic locking and, if necessary, two-phase commit. Locking read-write transactions may abort, requiring the application to retry.
  • Read-only transactions provide guaranteed consistency across several reads, but do not allow writes. Read-only transactions can be configured to read at timestamps in the past. Read-only transactions do not need to be committed and do not take locks.

ReadTimestamp

public Timestamp ReadTimestamp { get; }

The read timestamp of the read-only transaction if ReturnReadTimestamp is true, else null.

Property Value
Type Description
Timestamp

Shared

public bool Shared { get; }

Returns true if this transaction is being used by multiple SpannerConnection objects. GetReaderPartitionsAsync(PartitionOptions, CancellationToken) will automatically mark the transaction as shared because it is expected that you will be distributing the read among several tasks or processes.

Property Value
Type Description
bool

Tag

public string Tag { get; set; }

The transaction tag to use for this transaction. This can only be set for read/write transactions, and must be set before any statements are executed on the transaction.

Property Value
Type Description
string

TimestampBound

public TimestampBound TimestampBound { get; }

Tells Cloud Spanner how to choose a timestamp at which to read the data for read-only transactions.

Property Value
Type Description
TimestampBound
Remarks

The types of timestamp bounds are:

  • Strong (the default): read the latest data.
  • Bounded staleness: read a version of the data that's no staler than a bound.
  • Exact staleness: read the version of the data at an exact timestamp.

TransactionId

public TransactionId TransactionId { get; }

Identifying information about this transaction.

Property Value
Type Description
TransactionId

Methods

Commit()

public override void Commit()

Commits the database transaction.

Overrides

Commit(out DateTime)

public void Commit(out DateTime timestamp)

Commits the database transaction synchronously, returning the database timestamp for the commit via timestamp.

Parameter
Name Description
timestamp DateTime

Returns the UTC timestamp when the data was written to the database.

CommitAsync(CancellationToken)

public Task<DateTime> CommitAsync(CancellationToken cancellationToken = default)

Commits the database transaction asynchronously, returning the commit timestamp.

Parameter
Name Description
cancellationToken CancellationToken

A cancellation token used for this task.

Returns
Type Description
TaskDateTime

Returns the UTC timestamp when the data was written to the database.

CreateBatchDmlCommand()

public SpannerBatchCommand CreateBatchDmlCommand()

Creates a new SpannerBatchCommand to execute batched DML statements within this transaction. You can add commands to the batch by using Add(SpannerCommand), Add(SpannerCommandTextBuilder, SpannerParameterCollection) and Add(string, SpannerParameterCollection).

Returns
Type Description
SpannerBatchCommand

Dispose(bool)

protected override void Dispose(bool disposing)

Releases the unmanaged resources used by the DbTransaction and optionally releases the managed resources.

Parameter
Name Description
disposing bool

If true, this method releases all resources held by any managed objects that this DbTransaction references.

Overrides

Rollback()

public override void Rollback()

Rolls back a transaction from a pending state.

Overrides

RollbackAsync(CancellationToken)

public override Task RollbackAsync(CancellationToken cancellationToken = default)

Rolls back a transaction asynchronously.

Parameter
Name Description
cancellationToken CancellationToken

A cancellation token used for this task.

Returns
Type Description
Task
Overrides