#include <userver/storages/postgres/cluster.hpp>
Interface for executing queries on a cluster of PostgreSQL servers.
See Typed PostgreSQL results for usage examples of the storages::postgres::ResultSet.
Usually retrieved from components::Postgres component.
Definition at line 87 of file cluster.hpp.
Public Member Functions | |
Cluster (DsnList dsns, clients::dns::Resolver *resolver, engine::TaskProcessor &bg_task_processor, const ClusterSettings &cluster_settings, DefaultCommandControls &&default_cmd_ctls, const testsuite::PostgresControl &testsuite_pg_ctl, const error_injection::Settings &ei_settings, testsuite::TestsuiteTasks &testsuite_tasks, dynamic_config::Source config_source, int shard_number) | |
ClusterStatisticsPtr | GetStatistics () const |
QueryQueue | CreateQueryQueue (ClusterHostTypeFlags flags) |
QueryQueue | CreateQueryQueue (ClusterHostTypeFlags flags, TimeoutDuration acquire_timeout) |
NotifyScope | Listen (std::string_view channel, OptionalCommandControl={}) |
Listen for notifications on channel. | |
void | SetDefaultCommandControl (CommandControl) |
Replaces globally updated command control with a static user-provided one. | |
CommandControl | GetDefaultCommandControl () const |
Returns current default command control. | |
void | SetHandlersCommandControl (CommandControlByHandlerMap handlers_command_control) |
void | SetQueriesCommandControl (CommandControlByQueryMap queries_command_control) |
void | SetConnectionSettings (const ConnectionSettings &settings) |
void | SetPoolSettings (const PoolSettings &settings) |
void | SetTopologySettings (const TopologySettings &settings) |
void | SetStatementMetricsSettings (const StatementMetricsSettings &settings) |
Transaction start | |
Transaction | Begin (const TransactionOptions &, OptionalCommandControl={}) |
Transaction | Begin (ClusterHostTypeFlags, const TransactionOptions &, OptionalCommandControl={}) |
Transaction | Begin (std::string name, const TransactionOptions &) |
Transaction | Begin (std::string name, ClusterHostTypeFlags, const TransactionOptions &) |
Single-statement query in an auto-commit transaction | |
template<typename... Args> | |
ResultSet | Execute (ClusterHostTypeFlags, const Query &query, const Args &... args) |
Execute a statement at host of specified type. | |
template<typename... Args> | |
ResultSet | Execute (ClusterHostTypeFlags, OptionalCommandControl, const Query &query, const Args &... args) |
Execute a statement with specified host selection rules and command control settings. | |
ResultSet | Execute (ClusterHostTypeFlags flags, const Query &query, const ParameterStore &store) |
Execute a statement with stored arguments and specified host selection rules. | |
ResultSet | Execute (ClusterHostTypeFlags flags, OptionalCommandControl statement_cmd_ctl, const Query &query, const ParameterStore &store) |
Execute a statement with stored arguments, specified host selection rules and command control settings. | |
storages::postgres::Cluster::Cluster | ( | DsnList | dsns, |
clients::dns::Resolver * | resolver, | ||
engine::TaskProcessor & | bg_task_processor, | ||
const ClusterSettings & | cluster_settings, | ||
DefaultCommandControls && | default_cmd_ctls, | ||
const testsuite::PostgresControl & | testsuite_pg_ctl, | ||
const error_injection::Settings & | ei_settings, | ||
testsuite::TestsuiteTasks & | testsuite_tasks, | ||
dynamic_config::Source | config_source, | ||
int | shard_number ) |
Cluster constructor
dsns | List of DSNs to connect to |
resolver | asynchronous DNS resolver |
bg_task_processor | task processor for blocking connection operations |
cluster_settings | struct with settings fields: task_data_keys_settings - settings for per-handler command controls topology_settings - settings for host discovery pool_settings - settings for connection pools conn_settings - settings for individual connections |
default_cmd_ctls | default command execution options |
testsuite_pg_ctl | command execution options customizer for testsuite |
ei_settings | error injection settings |
max_connection_pool_size
is reached, and no idle connections available, PoolError
is thrown for every new connection request Transaction storages::postgres::Cluster::Begin | ( | ClusterHostTypeFlags | , |
const TransactionOptions & | , | ||
OptionalCommandControl | = {} ) |
Start a transaction in a connection with specified host selection rules.
If the requested host role is not available, may fall back to another host role, see ClusterHostType. If the transaction is RW, only master connection can be used.
ClusterUnavailable | if no hosts are available |
Transaction storages::postgres::Cluster::Begin | ( | const TransactionOptions & | , |
OptionalCommandControl | = {} ) |
Start a transaction in any available connection depending on transaction options.
If the transaction is RW, will start transaction in a connection to master. If the transaction is RO, will start trying connections starting with slaves.
ClusterUnavailable | if no hosts are available |
Transaction storages::postgres::Cluster::Begin | ( | std::string | name, |
ClusterHostTypeFlags | , | ||
const TransactionOptions & | ) |
Start a named transaction in a connection with specified host selection rules.
If the requested host role is not available, may fall back to another host role, see ClusterHostType. If the transaction is RW, only master connection can be used. name
is used to set command control in config at runtime.
ClusterUnavailable | if no hosts are available |
Transaction storages::postgres::Cluster::Begin | ( | std::string | name, |
const TransactionOptions & | ) |
Start a named transaction in any available connection depending on transaction options.
If the transaction is RW, will start transaction in a connection to master. If the transaction is RO, will start trying connections starting with slaves. name
is used to set command control in config at runtime.
ClusterUnavailable | if no hosts are available |
QueryQueue storages::postgres::Cluster::CreateQueryQueue | ( | ClusterHostTypeFlags | flags | ) |
Start a query queue with specified host selection rules and timeout for acquiring a connection.
QueryQueue storages::postgres::Cluster::CreateQueryQueue | ( | ClusterHostTypeFlags | flags, |
TimeoutDuration | acquire_timeout ) |
Start a query queue with specified host selection rules and timeout for acquiring a connection.
ResultSet storages::postgres::Cluster::Execute | ( | ClusterHostTypeFlags | flags, |
const Query & | query, | ||
const Args &... | args ) |
Execute a statement at host of specified type.
Definition at line 253 of file cluster.hpp.
ResultSet storages::postgres::Cluster::Execute | ( | ClusterHostTypeFlags | flags, |
OptionalCommandControl | statement_cmd_ctl, | ||
const Query & | query, | ||
const Args &... | args ) |
Execute a statement with specified host selection rules and command control settings.
Definition at line 259 of file cluster.hpp.
ClusterStatisticsPtr storages::postgres::Cluster::GetStatistics | ( | ) | const |
Get cluster statistics
The statistics object is too big to fit on stack
NotifyScope storages::postgres::Cluster::Listen | ( | std::string_view | channel, |
OptionalCommandControl | = {} ) |
Listen for notifications on channel.
void storages::postgres::Cluster::SetConnectionSettings | ( | const ConnectionSettings & | settings | ) |
Replaces cluster connection settings.
Connections with an old settings will be dropped and reestablished.