userver
C++ Async Framework
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
10
USERVER_NAMESPACE_BEGIN
11
12
namespace
logging
{
13
class
LogHelper;
14
}
// namespace logging
15
16
namespace
storages::
postgres
{
17
18
enum
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.
36
kSlaveOrMaster
=
kMaster
|
kSlave
,
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
50
using
ClusterHostTypeFlags = USERVER_NAMESPACE::utils::Flags<
ClusterHostType
>;
51
52
constexpr
ClusterHostTypeFlags
53
kClusterHostRolesMask{
ClusterHostType
::
kMaster
,
ClusterHostType
::
kSyncSlave
,
ClusterHostType
::
kSlave
};
54
55
constexpr
ClusterHostTypeFlags kClusterHostStrategyMask{
ClusterHostType
::
kRoundRobin
,
ClusterHostType
::
kNearest
};
56
57
std::string ToString(
ClusterHostType
);
58
std::string ToString(ClusterHostTypeFlags);
59
logging
::LogHelper& operator<<(
logging
::LogHelper&,
ClusterHostType
);
60
logging
::LogHelper& operator<<(
logging
::LogHelper&, ClusterHostTypeFlags);
61
62
struct
ClusterHostTypeHash
{
63
size_t operator()(
ClusterHostType
ht)
const
noexcept
{
return
static_cast
<size_t>(ht); }
64
};
65
66
}
// namespace storages::postgres
67
68
USERVER_NAMESPACE_END
userver
storages
postgres
cluster_types.hpp
Generated on Wed Jan 14 2026 19:58:45 for userver by
Doxygen
1.13.2