Class PooledSession (3.11.0)

public sealed class PooledSession : IDisposable

A session from a SessionPool, with an associated transaction if requested. Instances must be released back to the pool via ReleaseToPool(Boolean).

Inheritance

Object > PooledSession

Implements

IDisposable

Namespace

Google.Cloud.Spanner.V1

Assembly

Google.Cloud.Spanner.V1.dll

Remarks

Each method in this class modifies requests passed as arguments to RPC methods, to populate the session and transaction properties.

This class keeps track of successful RPCs to update its internal refresh timer. This can't be applied for streaming SQL calls, as ReliableStreamReader performs the actual RPCs in that case.

Properties

ReadTimestamp

public Timestamp ReadTimestamp { get; }

The read timestamp of the transaction. (Always null if ReturnReadTimestamp = false or if TransactionMode != ReadOnly.)

Property Value
TypeDescription
Timestamp

SessionName

public SessionName SessionName { get; }

The name of the session. This is never null.

Property Value
TypeDescription
SessionName

TransactionId

public ByteString TransactionId { get; }

The ID of the transaction. May be null.

Property Value
TypeDescription
ByteString

Methods

CommitAsync(CommitRequest, CallSettings)

public Task<CommitResponse> CommitAsync(CommitRequest request, CallSettings callSettings)

Executes a Commit RPC asynchronously.

Parameters
NameDescription
requestCommitRequest

The commit request. Must not be null. The request will be modified with session and transaction details from this object.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
Task<CommitResponse>

A task representing the asynchronous operation. When the task completes, the result is the response from the RPC.

Dispose()

public void Dispose()

Releases this session back to the session pool. This method should only be called once per instance; subsequent calls are ignored. No other methods can be called after this.

Remarks

This method is equivalent to calling ReleaseToPool(Boolean) with an argument of false.

ExecuteBatchDmlAsync(ExecuteBatchDmlRequest, CallSettings)

public Task<ExecuteBatchDmlResponse> ExecuteBatchDmlAsync(ExecuteBatchDmlRequest request, CallSettings callSettings)

Executes an ExecuteBatchDml RPC asynchronously.

Parameters
NameDescription
requestExecuteBatchDmlRequest

The query request. Must not be null. The request will be modified with session and transaction details from this object. If this object's TransactionId is null, the request's transaction is not modified.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
Task<ExecuteBatchDmlResponse>

A task representing the asynchronous operation. When the task completes, the result is the response from the RPC.

ExecuteSqlAsync(ExecuteSqlRequest, CallSettings)

public Task<ResultSet> ExecuteSqlAsync(ExecuteSqlRequest request, CallSettings callSettings)

Executes an ExecuteSql RPC asynchronously.

Parameters
NameDescription
requestExecuteSqlRequest

The query request. Must not be null. The request will be modified with session and transaction details from this object. If this object's TransactionId is null, the request's transaction is not modified.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
Task<ResultSet>

A task representing the asynchronous operation. When the task completes, the result is the response from the RPC.

ExecuteSqlStreamReader(ExecuteSqlRequest, CallSettings)

public ReliableStreamReader ExecuteSqlStreamReader(ExecuteSqlRequest request, CallSettings callSettings)

Creates a ReliableStreamReader for the given request

Parameters
NameDescription
requestExecuteSqlRequest

The query request. Must not be null. The request will be modified with session and transaction details from this object. If this object's TransactionId is null, the request's transaction is not modified.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
ReliableStreamReader

A ReliableStreamReader for the streaming SQL request.

PartitionQueryAsync(PartitionQueryRequest, CallSettings)

public Task<PartitionResponse> PartitionQueryAsync(PartitionQueryRequest request, CallSettings callSettings)

Executes a PartitionQuery RPC asynchronously.

Parameters
NameDescription
requestPartitionQueryRequest

The partitioning request. Must not be null. The request will be modified with session details from this object.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
Task<PartitionResponse>

A task representing the asynchronous operation. When the task completes, the result is the response from the RPC.

ReleaseToPool(Boolean)

public void ReleaseToPool(bool forceDelete)

Returns this session to the session pool from which it was acquired, unless it has become invalid. This method should only be called once per instance; subsequent calls are ignored. No other methods can be called after this.

Parameter
NameDescription
forceDeleteBoolean

true to force the session to be deleted; false to allow the session to be reused.

RollbackAsync(RollbackRequest, CallSettings)

public Task RollbackAsync(RollbackRequest request, CallSettings callSettings)

Executes a Rollback RPC asynchronously.

Parameters
NameDescription
requestRollbackRequest

The rollback request. Must not be null. The request will be modified with session and transaction details from this object.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
Task

A task representing the asynchronous operation.

WithFreshTransactionOrNewAsync(TransactionOptions, CancellationToken)

public Task<PooledSession> WithFreshTransactionOrNewAsync(TransactionOptions transactionOptions, CancellationToken cancellationToken)

Always returns a new instance of PooledSession. The new instance can:

  1. represent the same session as this one, but will have a fresh transaction of the same type as this PooledSession did.
  2. represent an entirely different session with a fresh transaction of the same type as this PooledSession did. This method will always try to get a fresh transaction for this session. If the session has expired or it fails to get a fresh transaction, then it will acquire a session in the normal way. This PooledSession instance will be disposed of to ensure that all operations with the underlying session are done through the new instance.
Parameters
NameDescription
transactionOptionsTransactionOptions
cancellationTokenCancellationToken
Returns
TypeDescription
Task<PooledSession>

A new instance of PooledSession.

Remarks

Use this method when executing operations that are best done using the same session. For instance, when retrying aborted commits it is better if the transaction work and commit are retried with the same session, because after each abort the sessions' lock priority increments.

Exceptions
TypeDescription
InvalidOperationException

If this Google.Cloud.Spanner.V1.PooledSession.TransactionMode is None.