Google Cloud Spanner C++ Client  1.32.0
A C++ Client Library for Google Cloud Spanner
Public Member Functions | List of all members
google::cloud::spanner::v1::SessionPoolOptions Class Reference

Controls the session pool maintained by a spanner::Client. More...

#include <google/cloud/spanner/session_pool_options.h>

Public Member Functions

 SessionPoolOptions ()
 
SessionPoolOptionsEnforceConstraints (int num_channels)
 Enforce the stated constraints on the option values, altering them if necessary. More...
 
SessionPoolOptionsset_min_sessions (int count)
 Set the minimum number of sessions to keep in the pool. More...
 
int min_sessions () const
 Return the minimum number of sessions to keep in the pool. More...
 
SessionPoolOptionsset_max_sessions_per_channel (int count)
 Set the maximum number of sessions to create on each channel. More...
 
int max_sessions_per_channel () const
 Return the minimum number of sessions to keep in the pool. More...
 
SessionPoolOptionsset_max_idle_sessions (int count)
 Set the maximum number of sessions to keep in the pool in an idle state. More...
 
int max_idle_sessions () const
 Return the maximum number of idle sessions to keep in the pool. More...
 
SessionPoolOptionsset_action_on_exhaustion (ActionOnExhaustion action)
 Set whether to block or fail on pool exhaustion. More...
 
ActionOnExhaustion action_on_exhaustion () const
 Return the action to take (kBlock or kFail) when attempting to allocate a session when the pool is exhausted. More...
 
SessionPoolOptionsset_keep_alive_interval (std::chrono::seconds interval)
 Set the interval at which we refresh sessions so they don't get collected by the backend GC. More...
 
std::chrono::seconds keep_alive_interval () const
 Return the interval at which we refresh sessions to prevent GC. More...
 
SessionPoolOptionsset_labels (std::map< std::string, std::string > labels)
 Set the labels used when creating sessions within the pool. More...
 
std::map< std::string, std::string > const & labels () const
 Return the labels used when creating sessions within the pool. More...
 

Detailed Description

Controls the session pool maintained by a spanner::Client.

Creating Cloud Spanner sessions is an expensive operation. The recommended practice is to maintain a cache (or pool) of sessions in the client side. This class controls the initial size of this pool, and how the pool grows (or shrinks) as needed.

Note
If no sessions are available to perform an operation the client library blocks until new sessions are available (either released by other threads or allocated on-demand, depending on the active constraints). It is also possible to configure the client to fail a request when the session pool is exhausted.

Definition at line 60 of file session_pool_options.h.

Constructor & Destructor Documentation

◆ SessionPoolOptions()

google::cloud::spanner::v1::SessionPoolOptions::SessionPoolOptions ( )
inline

Definition at line 62 of file session_pool_options.h.

Member Function Documentation

◆ action_on_exhaustion()

ActionOnExhaustion google::cloud::spanner::v1::SessionPoolOptions::action_on_exhaustion ( ) const
inline

Return the action to take (kBlock or kFail) when attempting to allocate a session when the pool is exhausted.

Definition at line 130 of file session_pool_options.h.

◆ EnforceConstraints()

SessionPoolOptions& google::cloud::spanner::v1::SessionPoolOptions::EnforceConstraints ( int  num_channels)
inline

Enforce the stated constraints on the option values, altering them if necessary.

This can't be done in the setters, since we don't yet know the number of channels, and it would also constrain the order in which the fields must be set.

num_channels the number of RPC channels in use by the pool.

Definition at line 72 of file session_pool_options.h.

◆ keep_alive_interval()

std::chrono::seconds google::cloud::spanner::v1::SessionPoolOptions::keep_alive_interval ( ) const
inline

Return the interval at which we refresh sessions to prevent GC.

Definition at line 146 of file session_pool_options.h.

◆ labels()

std::map<std::string, std::string> const& google::cloud::spanner::v1::SessionPoolOptions::labels ( ) const
inline

Return the labels used when creating sessions within the pool.

Definition at line 162 of file session_pool_options.h.

◆ max_idle_sessions()

int google::cloud::spanner::v1::SessionPoolOptions::max_idle_sessions ( ) const
inline

Return the maximum number of idle sessions to keep in the pool.

Definition at line 116 of file session_pool_options.h.

◆ max_sessions_per_channel()

int google::cloud::spanner::v1::SessionPoolOptions::max_sessions_per_channel ( ) const
inline

Return the minimum number of sessions to keep in the pool.

Definition at line 102 of file session_pool_options.h.

◆ min_sessions()

int google::cloud::spanner::v1::SessionPoolOptions::min_sessions ( ) const
inline

Return the minimum number of sessions to keep in the pool.

Definition at line 90 of file session_pool_options.h.

◆ set_action_on_exhaustion()

SessionPoolOptions& google::cloud::spanner::v1::SessionPoolOptions::set_action_on_exhaustion ( ActionOnExhaustion  action)
inline

Set whether to block or fail on pool exhaustion.

Definition at line 121 of file session_pool_options.h.

◆ set_keep_alive_interval()

SessionPoolOptions& google::cloud::spanner::v1::SessionPoolOptions::set_keep_alive_interval ( std::chrono::seconds  interval)
inline

Set the interval at which we refresh sessions so they don't get collected by the backend GC.

The GC collects objects older than 60 minutes, so any duration below that (less some slack to allow the calls to be made to refresh the sessions) should suffice.

Definition at line 140 of file session_pool_options.h.

◆ set_labels()

SessionPoolOptions& google::cloud::spanner::v1::SessionPoolOptions::set_labels ( std::map< std::string, std::string >  labels)
inline

Set the labels used when creating sessions within the pool.

  • Label keys must match [a-z]([-a-z0-9]{0,61}[a-z0-9])?.
  • Label values must match ([a-z]([-a-z0-9]{0,61}[a-z0-9])?)?.
  • The maximum number of labels is 64.

Definition at line 156 of file session_pool_options.h.

◆ set_max_idle_sessions()

SessionPoolOptions& google::cloud::spanner::v1::SessionPoolOptions::set_max_idle_sessions ( int  count)
inline

Set the maximum number of sessions to keep in the pool in an idle state.

Values <= 0 are treated as 0.

Definition at line 110 of file session_pool_options.h.

◆ set_max_sessions_per_channel()

SessionPoolOptions& google::cloud::spanner::v1::SessionPoolOptions::set_max_sessions_per_channel ( int  count)
inline

Set the maximum number of sessions to create on each channel.

Values <= 1 are treated as 1.

Definition at line 96 of file session_pool_options.h.

◆ set_min_sessions()

SessionPoolOptions& google::cloud::spanner::v1::SessionPoolOptions::set_min_sessions ( int  count)
inline

Set the minimum number of sessions to keep in the pool.

Values <= 0 are treated as 0. This value will effectively be reduced if it exceeds the overall limit on the number of sessions (max_sessions_per_channel * number of channels).

Definition at line 84 of file session_pool_options.h.