Github   Telegram
Loading...
Searching...
No Matches
cluster.hpp
Go to the documentation of this file.
1#pragma once
2
5
6#include <memory>
7
8#include <userver/clients/dns/resolver_fwd.hpp>
11#include <userver/error_injection/settings_fwd.hpp>
12#include <userver/testsuite/postgres_control.hpp>
13
16#include <userver/storages/postgres/detail/non_transaction.hpp>
21
57
58USERVER_NAMESPACE_BEGIN
59
60namespace components {
61class Postgres;
62} // namespace components
63
65
66namespace detail {
67
68class ClusterImpl;
69using ClusterImplPtr = std::unique_ptr<ClusterImpl>;
70
71} // namespace detail
72
83class Cluster {
84 public:
100 Cluster(DsnList dsns, clients::dns::Resolver* resolver,
101 engine::TaskProcessor& bg_task_processor,
102 const ClusterSettings& cluster_settings,
103 DefaultCommandControls&& default_cmd_ctls,
104 const testsuite::PostgresControl& testsuite_pg_ctl,
105 const error_injection::Settings& ei_settings);
106 ~Cluster();
107
111 ClusterStatisticsPtr GetStatistics() const;
112
115
124
133
142 Transaction Begin(const std::string& name, const TransactionOptions&);
143
152 Transaction Begin(const std::string& name, ClusterHostTypeFlags,
153 const TransactionOptions&);
155
158
167 template <typename... Args>
169 const Args&... args);
170
178 template <typename... Args>
180 const Query& query, const Args&... args);
181
185 const ParameterStore& store);
186
190 OptionalCommandControl statement_cmd_ctl,
191 const Query& query, const ParameterStore& store);
193
196
199
200 void SetHandlersCommandControl(
201 const CommandControlByHandlerMap& handlers_command_control);
202
203 void SetQueriesCommandControl(
204 const CommandControlByQueryMap& queries_command_control);
205
208 void ApplyGlobalCommandControlUpdate(CommandControl);
210
215
216 void SetPoolSettings(const PoolSettings& settings);
217
218 void SetStatementMetricsSettings(const StatementMetricsSettings& settings);
219
220 private:
221 detail::NonTransaction Start(ClusterHostTypeFlags, OptionalCommandControl);
222
223 OptionalCommandControl GetQueryCmdCtl(const std::string& query_name) const;
224 OptionalCommandControl GetHandlersCmdCtl(
225 OptionalCommandControl cmd_ctl) const;
226
227 detail::ClusterImplPtr pimpl_;
228};
229
230template <typename... Args>
232 const Args&... args) {
233 return Execute(flags, OptionalCommandControl{}, query, args...);
234}
235
236template <typename... Args>
238 OptionalCommandControl statement_cmd_ctl,
239 const Query& query, const Args&... args) {
240 if (!statement_cmd_ctl && query.GetName()) {
241 statement_cmd_ctl = GetQueryCmdCtl(query.GetName()->GetUnderlying());
242 }
243 statement_cmd_ctl = GetHandlersCmdCtl(statement_cmd_ctl);
244 auto ntrx = Start(flags, statement_cmd_ctl);
245 return ntrx.Execute(statement_cmd_ctl, query, args...);
246}
247
248} // namespace storages::postgres
249
250USERVER_NAMESPACE_END