userver
C++ Async Framework (beta)
Loading...
Searching...
No Matches
userver
storages
postgres
component.hpp
Go to the documentation of this file.
1
#pragma once
2
5
6
#include <chrono>
7
#include <vector>
8
9
#include <
userver/components/loggable_component_base.hpp
>
10
#include <
userver/concurrent/async_event_source.hpp
>
11
#include <
userver/dynamic_config/snapshot.hpp
>
12
#include <
userver/engine/mutex.hpp
>
13
#include <
userver/utils/statistics/entry.hpp
>
14
15
#include <
userver/storages/postgres/database.hpp
>
16
17
USERVER_NAMESPACE_BEGIN
18
19
namespace
components
{
20
21
// clang-format off
22
133
134
// clang-format on
135
136
class
Postgres
:
public
LoggableComponentBase
{
137
public
:
138
static
constexpr
auto
kDefaultMaxReplicationLag = std::chrono::seconds{60};
140
static
constexpr
size_t
kDefaultShardNumber
= 0;
142
static
constexpr
storages::postgres::CommandControl
kDefaultCommandControl
{
143
std::chrono::milliseconds{500},
// network timeout
144
std::chrono::milliseconds{250}
// statement timeout
145
};
146
148
Postgres
(
const
ComponentConfig
&,
const
ComponentContext
&);
150
~Postgres
()
override
;
151
153
storages::postgres::ClusterPtr
GetCluster
()
const
;
154
156
storages::postgres::ClusterPtr
GetClusterForShard
(
size_t
shard)
const
;
157
159
size_t
GetShardCount
()
const
;
160
162
storages::postgres::DatabasePtr
GetDatabase
()
const
{
return
database_; }
163
165
void
ExtendStatistics
(
utils::statistics::Writer
& writer);
166
167
static
yaml_config::Schema
GetStaticConfigSchema();
168
169
private
:
170
void
OnConfigUpdate(
const
dynamic_config::Snapshot
& cfg);
171
172
concurrent::AsyncEventSubscriberScope
config_subscription_;
173
174
utils::statistics::Entry
statistics_holder_;
175
176
std::string name_;
177
std::string db_name_;
178
storages::postgres::ClusterSettings
initial_settings_;
179
storages::postgres::DatabasePtr database_;
180
};
181
182
template
<>
183
inline
constexpr
bool
kHasValidate<Postgres> =
true
;
184
185
}
// namespace components
186
187
USERVER_NAMESPACE_END
Generated on Tue Mar 14 2023 16:21:23 for userver by
Doxygen
1.9.6