public sealed class SessionPool
A pool of sessions associated with a SpannerClient. Sessions can be acquired by specifying the desired transaction options, if any. A session/transaction pair is then returned, which should be returned to the pool when it is no longer required. Sessions are kept alive automatically, and retired if they are expired by the server.
Namespace
Google.Cloud.Spanner.V1Assembly
Google.Cloud.Spanner.V1.dll
Constructors
SessionPool(SpannerClient, SessionPoolOptions)
public SessionPool(SpannerClient client, SessionPoolOptions options)
Creates a session pool for the given client.
Parameters | |
---|---|
Name | Description |
client | SpannerClient The client to use for this session pool. Must not be null. |
options | SessionPoolOptions The options for this session pool. Must not be null. |
Properties
Options
public SessionPoolOptions Options { get; }
The options governing this session pool.
Property Value | |
---|---|
Type | Description |
SessionPoolOptions |
Methods
AcquireSessionAsync(DatabaseName, TransactionOptions, CancellationToken)
public Task<PooledSession> AcquireSessionAsync(DatabaseName databaseName, TransactionOptions transactionOptions, CancellationToken cancellationToken)
Asynchronously acquires a session, potentially associated with a transaction.
Parameters | |
---|---|
Name | Description |
databaseName | Google.Cloud.Spanner.Common.V1.DatabaseName The name of the database to acquire the session for. |
transactionOptions | TransactionOptions The transaction options required for the session. After the operation completes, this value is no longer used, so modifications to the object will not affect the transaction. May be null. |
cancellationToken | CancellationToken An optional token for canceling the call. |
Returns | |
---|---|
Type | Description |
Task<PooledSession> | The PooledSession representing the client, session and transaction. |
CreateDetachedSession(SessionName, ByteString, TransactionOptions.ModeOneofCase)
public PooledSession CreateDetachedSession(SessionName sessionName, ByteString transactionId, TransactionOptions.ModeOneofCase transactionMode)
Creates a PooledSession with a known name and transaction ID/mode, with the client associated with this pool, but is otherwise not part of this pool. This method does not query the server for the session state. When the returned PooledSession is released, it will not become part of this pool, and the transaction will not be rolled back.
Parameters | |
---|---|
Name | Description |
sessionName | SessionName The name of the transaction. Must not be null. |
transactionId | ByteString The ID of the transaction. Must not be null. |
transactionMode | TransactionOptions.ModeOneofCase The mode of the transaction. |
Returns | |
---|---|
Type | Description |
PooledSession | A PooledSession for the given session and transaction. |
This is typically used for partitioned queries, where the same session is used across multiple machines, so should not be reused by the pool.
CreateDetachedSession(SessionName, ByteString, TransactionOptions.ModeOneofCase, Timestamp)
public PooledSession CreateDetachedSession(SessionName sessionName, ByteString transactionId, TransactionOptions.ModeOneofCase transactionMode, Timestamp readTimestamp)
Creates a PooledSession with a known name and transaction ID/mode, with the client associated with this pool, but is otherwise not part of this pool. This method does not query the server for the session state. When the returned PooledSession is released, it will not become part of this pool, and the transaction will not be rolled back.
Parameters | |
---|---|
Name | Description |
sessionName | SessionName The name of the transaction. Must not be null. |
transactionId | ByteString The ID of the transaction. Must not be null. |
transactionMode | TransactionOptions.ModeOneofCase The mode of the transaction. |
readTimestamp | Timestamp The read timestamp of the transaction. |
Returns | |
---|---|
Type | Description |
PooledSession | A PooledSession for the given session and transaction. |
This is typically used for partitioned queries, where the same session is used across multiple machines, so should not be reused by the pool.
GetStatisticsSnapshot()
public SessionPool.Statistics GetStatisticsSnapshot()
Provides a snapshot of statistics for this pool.
Returns | |
---|---|
Type | Description |
SessionPool.Statistics | A snapshot of statistics for this pool. |
GetStatisticsSnapshot(DatabaseName)
public SessionPool.DatabaseStatistics GetStatisticsSnapshot(DatabaseName databaseName)
Provides a snapshot of statistics for a database-specific pool.
Parameter | |
---|---|
Name | Description |
databaseName | Google.Cloud.Spanner.Common.V1.DatabaseName |
Returns | |
---|---|
Type | Description |
SessionPool.DatabaseStatistics | A snapshot of statistics for this pool. |
ShutdownPoolAsync(DatabaseName, CancellationToken)
public Task ShutdownPoolAsync(DatabaseName databaseName, CancellationToken cancellationToken)
Shuts down the session pool associated with the given database name. Further attempts to acquire sessions will fail immediately.
Parameters | |
---|---|
Name | Description |
databaseName | Google.Cloud.Spanner.Common.V1.DatabaseName The database whose session pool should be shut down. Must not be null. |
cancellationToken | CancellationToken An optional token for canceling the returned task. This does not cancel the shutdown itself. |
Returns | |
---|---|
Type | Description |
Task | A task which will complete when the session pool has finished shutting down. |
This call will delete all pooled sessions, and wait for all active sessions to be released back to the pool and also deleted.
WhenPoolReady(DatabaseName, CancellationToken)
public Task WhenPoolReady(DatabaseName databaseName, CancellationToken cancellationToken = default(CancellationToken))
Returns a task indicating when the session pool associated with the given database name is populated up to its minimum size.
Parameters | |
---|---|
Name | Description |
databaseName | Google.Cloud.Spanner.Common.V1.DatabaseName The database whose session pool should be populated. Must not be null. |
cancellationToken | CancellationToken An optional token for canceling the call. |
Returns | |
---|---|
Type | Description |
Task | A task which will complete when the session pool has reached its minimum size. |
If the pool is unhealthy or becomes unhealthy before it reaches its minimum size, the returned task will be faulted with an RpcException.