userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
component.hpp
Go to the documentation of this file.
1
#
pragma
once
2
3
/// @file userver/ydb/component.hpp
4
/// @brief @copybrief ydb::YdbComponent
5
6
#
include
<
memory
>
7
#
include
<
string
>
8
#
include
<
unordered_map
>
9
10
#
include
<
userver
/
components
/
component_base
.
hpp
>
11
#
include
<
userver
/
dynamic_config
/
source
.
hpp
>
12
#
include
<
userver
/
formats
/
json
.
hpp
>
13
#
include
<
userver
/
utils
/
statistics
/
fwd
.
hpp
>
14
#
include
<
userver
/
utils
/
statistics
/
storage
.
hpp
>
15
16
#
include
<
userver
/
ydb
/
fwd
.
hpp
>
17
18
#
include
<
ydb
-
cpp
-
sdk
/
client
/
driver
/
fwd
.
h
>
19
20
USERVER_NAMESPACE_BEGIN
21
22
namespace
ydb {
23
24
namespace
impl {
25
class
Driver;
26
}
// namespace impl
27
28
/// @ingroup userver_components
29
///
30
/// @brief YDB client component
31
///
32
/// Provides access to @ref ydb::TableClient, @ref ydb::TopicClient, @ref ydb::FederatedTopicClient,
33
/// @ref ydb::CoordinationClient.
34
///
35
/// ## Static options of ydb::YdbComponent :
36
/// @include{doc} scripts/docs/en/components_schema/ydb/src/ydb/component.md
37
///
38
/// Options inherited from @ref components::ComponentBase :
39
/// @include{doc} scripts/docs/en/components_schema/core/src/components/impl/component_base.md
40
class
YdbComponent
final
:
public
components
::
ComponentBase
{
41
public
:
42
/// @ingroup userver_component_names
43
/// @brief The default name of ydb::YdbComponent component
44
static
constexpr
std::string_view
kName
=
"ydb"
;
45
46
YdbComponent(
const
components
::ComponentConfig&,
const
components
::ComponentContext&);
47
48
~YdbComponent()
override
;
49
50
/// Get table client
51
/// @param dbname database name from static config key
52
std::shared_ptr<TableClient>
GetTableClient
(
const
std::string& dbname)
const
;
53
54
/// Get topic client
55
/// @param dbname database name from static config key
56
std::shared_ptr<TopicClient>
GetTopicClient
(
const
std::string& dbname)
const
;
57
58
/// Get topic client
59
/// @param dbname database name from static config key
60
std::shared_ptr<FederatedTopicClient>
GetFederatedTopicClient
(
const
std::string& dbname)
const
;
61
62
/// Get coordination client
63
/// @param dbname database name from static config key
64
std::shared_ptr<CoordinationClient>
GetCoordinationClient
(
const
std::string& dbname)
const
;
65
66
/// Get native driver
67
/// @param dbname database name from static config key
68
/// @warning Use with care! Facilities from
69
/// `<core/include/userver/drivers/subscribable_futures.hpp>` can help with
70
/// non-blocking wait operations.
71
const
NYdb::TDriver&
GetNativeDriver
(
const
std::string& dbname)
const
;
72
73
/// Get database path
74
/// @param dbname database name from static config key
75
const
std::string&
GetDatabasePath
(
const
std::string& dbname)
const
;
76
77
static
yaml_config::Schema GetStaticConfigSchema();
78
79
private
:
80
struct
DatabaseUtils;
81
82
struct
Database {
83
std::shared_ptr<impl::Driver> driver;
84
std::shared_ptr<TableClient> table_client;
85
std::shared_ptr<TopicClient> topic_client;
86
std::shared_ptr<FederatedTopicClient> federated_topic_client;
87
std::shared_ptr<CoordinationClient> coordination_client;
88
};
89
90
void
OnConfigUpdate(
const
dynamic_config::Snapshot& cfg);
91
void
WriteStatistics(
utils
::
statistics
::Writer& writer)
const
;
92
const
Database& FindDatabase(
const
std::string& dbname)
const
;
93
94
std::unordered_map<std::string, Database> databases_;
95
96
dynamic_config::Source config_;
97
98
// These fields must be the last ones
99
concurrent
::AsyncEventSubscriberScope config_subscription_;
100
};
101
102
}
// namespace ydb
103
104
template
<>
105
inline
constexpr
bool
components
::kHasValidate<ydb::YdbComponent> =
true
;
106
107
USERVER_NAMESPACE_END
userver
ydb
component.hpp
Generated on
for userver by
Doxygen
1.17.0