userver: userver/storages/postgres/cluster_types.hpp Source File
Loading...
Searching...
No Matches
cluster_types.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/storages/postgres/cluster_types.hpp
4/// @brief Cluster properties
5
6#include <string>
7
8#include <userver/utils/flags.hpp>
9
10USERVER_NAMESPACE_BEGIN
11
12namespace logging {
13class LogHelper;
14} // namespace logging
15
16namespace storages::postgres {
17
18enum class ClusterHostType {
19 /// @name Cluster roles
20 /// @{
21 /// No host role detected yet.
22 kNone = 0x00,
23 /// Connect to cluster's master. Only this connection may be
24 /// used for read-write transactions.
25 kMaster = 0x01,
26 /// Connect to cluster's sync slave. May fallback to master. Can be used only
27 /// for read only transactions.
28 /// @warning Not available for clusters with quorum commit,
29 /// prefer kSlave or kMaster.
30 kSyncSlave = 0x02,
31 /// Connect to one of cluster's slaves. May fallback to master. Can be used
32 /// only for read only transactions.
33 kSlave = 0x04,
34 /// Connect to either a master or to a slave, whatever the host selection
35 /// strategy chooses. Can be used only for read only transactions.
37 /// @}
38
39 /// @name Host selection strategies
40 /// @{
41
42 /// Chooses a host using the round-robin algorithm
43 kRoundRobin = 0x08,
44
45 /// Chooses a host with the lowest RTT
46 kNearest = 0x10,
47 /// @}
48};
49
50using ClusterHostTypeFlags = USERVER_NAMESPACE::utils::Flags<ClusterHostType>;
51
52constexpr ClusterHostTypeFlags kClusterHostRolesMask{
55
56constexpr ClusterHostTypeFlags kClusterHostStrategyMask{
58
59std::string ToString(ClusterHostType);
60std::string ToString(ClusterHostTypeFlags);
61logging::LogHelper& operator<<(logging::LogHelper&, ClusterHostType);
62logging::LogHelper& operator<<(logging::LogHelper&, ClusterHostTypeFlags);
63
65 size_t operator()(ClusterHostType ht) const noexcept {
66 return static_cast<size_t>(ht);
67 }
68};
69
70} // namespace storages::postgres
71
72USERVER_NAMESPACE_END