userver: userver/storages/mysql/component.hpp Source File
Loading...
Searching...
No Matches
component.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/storages/mysql/component.hpp
4/// @brief @copybrief storages::mysql::Component
5
6#include <memory>
7
8#include <userver/components/component_base.hpp>
9#include <userver/utils/statistics/entry.hpp>
10
11USERVER_NAMESPACE_BEGIN
12
13namespace clients::dns {
14class Component;
15}
16
17namespace storages::mysql {
18class Cluster;
19}
20
21namespace storages::mysql {
22
23// clang-format off
24/// @ingroup userver_components
25///
26/// @brief MySQL/MariaDB client component
27///
28/// Provides access to a MySQL/MariaDB cluster.
29///
30/// ## Static configuration example:
31///
32/// @snippet samples/mysql_service/static_config.yaml MySQL service sample - static config
33///
34/// The component will lookup connection data in secdist.json via its name.
35///
36/// ## Secdist format:
37///
38/// Connection settings are described as a JSON object `mysql_settings`,
39/// containing descriptions of MySQL/MariaDB clusters.
40///
41/// @snippet samples/mysql_service/tests/conftest.py Mysql service sample - secdist
42///
43/// **Important note**: the uMySQL driver does **NOT** perform an automatic
44/// primary detection and always considers the first host in `hosts` list
45/// an only primary node in the cluster.
46///
47/// ## Static options (more to come)
48/// Name | Description | Default value
49/// -------------------------|---------------------------------------------|---------------
50/// initial_pool_size | initial connection pool size (per host) | 5
51/// max_pool_size | maximum connection pool size (per host) | 10
52///
53// clang-format on
54class Component final : public components::ComponentBase {
55public:
56 /// Component constructor
57 Component(const components::ComponentConfig& config, const components::ComponentContext& context);
58
59 /// Component destructor
60 ~Component() override;
61
62 /// Cluster accessor
63 std::shared_ptr<storages::mysql::Cluster> GetCluster() const;
64
65 static yaml_config::Schema GetStaticConfigSchema();
66
67private:
68 clients::dns::Component& dns_;
69
70 const std::shared_ptr<storages::mysql::Cluster> cluster_;
71 utils::statistics::Entry statistics_holder_;
72};
73
74} // namespace storages::mysql
75
76USERVER_NAMESPACE_END