MySQL 8.0.40
Source Code Documentation
routing.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2015, 2024, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef MYSQLROUTER_ROUTING_INCLUDED
27#define MYSQLROUTER_ROUTING_INCLUDED
28
31
32#include <chrono>
33#include <map>
34#include <string>
35
36namespace routing {
37
38/** Timeout for idling clients (in seconds).
39 *
40 * Constant defining how long (in seconds) a client can keep the connection
41 * idling. This is similar to the wait_timeout variable in the MySQL Server.
42 *
43 * 0 == no timeout used.
44 */
45constexpr const int kDefaultWaitTimeout{0};
46
47/** Max number of active routes for this routing instance.
48 *
49 * 0 == no limit per route
50 */
51constexpr const int kDefaultMaxConnections{0};
52
53/** Timeout connecting to destination (in seconds).
54 *
55 * Constant defining how long we wait to establish connection with the server
56 * before we give up.
57 */
60
61/** Maximum connect or handshake errors per host.
62 *
63 * Maximum connect or handshake errors after which a host will be
64 * blocked. Such errors can happen when the client does not reply
65 * the handshake, sends an incorrect packet, or garbage.
66 */
67constexpr const unsigned long long kDefaultMaxConnectErrors{100};
68
69/**
70 * Default bind address.
71 */
72constexpr const std::string_view kDefaultBindAddress{"127.0.0.1"};
73
74/** Default net buffer length.
75 *
76 * Default network buffer length which can be set in the MySQL Server.
77 *
78 * This should match the default of the latest MySQL Server.
79 */
80constexpr const unsigned int kDefaultNetBufferLength{16384};
81
82/**
83 * Timeout waiting for handshake response from client.
84 *
85 * The number of seconds that MySQL Router waits for a handshake response.
86 * The default value is 9 seconds (default MySQL Server minus 1).
87 */
89
90/**
91 * delay in milliseconds before an idling connection may be moved to the pool
92 * when connection sharing is allowed.
93 */
94constexpr const std::chrono::milliseconds kDefaultConnectionSharingDelay{1000};
95
96/**
97 * The number of seconds that MySQL Router waits between checking for
98 * reachability of an unreachable destination.
99 */
100constexpr const std::chrono::seconds
102
103/** @brief Modes supported by Routing plugin */
104enum class AccessMode {
105 kUndefined = 0,
106 kReadWrite = 1,
107 kReadOnly = 2,
108};
109
110/** @brief Routing strategies supported by Routing plugin */
111enum class RoutingStrategy {
112 kUndefined = 0,
113 kFirstAvailable = 1,
114 kNextAvailable = 2,
115 kRoundRobin = 3,
117};
118
119/** @brief Get comma separated list of all access mode names
120 *
121 */
123
124/** @brief Returns AccessMode for its literal representation
125 *
126 * If no AccessMode is found for given string,
127 * AccessMode::kUndefined is returned.
128 *
129 * @param value literal representation of the access mode
130 * @return AccessMode for the given string or AccessMode::kUndefined
131 */
132AccessMode ROUTING_EXPORT get_access_mode(const std::string &value);
133
134/** @brief Returns literal name of given access mode
135 *
136 * Returns literal name of given access mode as a std:string. When
137 * the access mode is not found, empty string is returned.
138 *
139 * @param access_mode Access mode to look up
140 * @return Name of access mode as std::string or empty string
141 */
142std::string ROUTING_EXPORT
143get_access_mode_name(AccessMode access_mode) noexcept;
144
145/** @brief Get comma separated list of all routing stategy names
146 * for a given routing type (metadata cache or static)
147 *
148 *
149 * @param metadata_cache bool flag indicating if the list should contain
150 * strategies supported for metadata_cache
151 * or static routing
152 */
154
155/** @brief Returns RoutingStrategy for its literal representation
156 *
157 * If no RoutingStrategy is found for given string,
158 * RoutingStrategy::kUndefined is returned.
159 *
160 * @param value literal representation of the access mode
161 * @return RoutingStrategy for the given string or RoutingStrategy::kUndefined
162 */
163RoutingStrategy ROUTING_EXPORT get_routing_strategy(const std::string &value);
164
165/** @brief Returns literal name of given routing strategy
166 *
167 * Returns literal name of given routing strategy as a std:string. When
168 * the routing strategy is not found, empty string is returned.
169 *
170 * @param routing_strategy Routing strategy to look up
171 * @return Name of routing strategy as std::string or empty string
172 */
173std::string ROUTING_EXPORT
174get_routing_strategy_name(RoutingStrategy routing_strategy) noexcept;
175
176} // namespace routing
177
178#endif // MYSQLROUTER_ROUTING_INCLUDED
static constexpr int kDefaultConnectTimeout
Definition: mysql_session.h:155
Definition: metadata_cache.h:53
Definition: routing.h:36
RoutingStrategy ROUTING_EXPORT get_routing_strategy(const std::string &value)
Returns RoutingStrategy for its literal representation.
Definition: routing.cc:91
constexpr const std::chrono::seconds kDefaultUnreachableDestinationRefreshInterval
The number of seconds that MySQL Router waits between checking for reachability of an unreachable des...
Definition: routing.h:101
AccessMode ROUTING_EXPORT get_access_mode(const std::string &value)
Returns AccessMode for its literal representation.
Definition: routing.cc:62
constexpr const unsigned long long kDefaultMaxConnectErrors
Maximum connect or handshake errors per host.
Definition: routing.h:67
std::string ROUTING_EXPORT get_routing_strategy_names(bool metadata_cache)
Get comma separated list of all routing stategy names for a given routing type (metadata cache or sta...
Definition: routing.cc:98
AccessMode
Modes supported by Routing plugin.
Definition: routing.h:104
RoutingStrategy
Routing strategies supported by Routing plugin.
Definition: routing.h:111
std::string ROUTING_EXPORT get_routing_strategy_name(RoutingStrategy routing_strategy) noexcept
Returns literal name of given routing strategy.
Definition: routing.cc:118
constexpr const int kDefaultWaitTimeout
Timeout for idling clients (in seconds).
Definition: routing.h:45
constexpr const std::chrono::seconds kDefaultClientConnectTimeout
Timeout waiting for handshake response from client.
Definition: routing.h:88
constexpr const std::chrono::seconds kDefaultDestinationConnectionTimeout
Timeout connecting to destination (in seconds).
Definition: routing.h:58
std::string ROUTING_EXPORT get_access_mode_names()
Get comma separated list of all access mode names.
Definition: routing.cc:68
std::string ROUTING_EXPORT get_access_mode_name(AccessMode access_mode) noexcept
Returns literal name of given access mode.
Definition: routing.cc:74
constexpr const unsigned int kDefaultNetBufferLength
Default net buffer length.
Definition: routing.h:80
constexpr const int kDefaultMaxConnections
Max number of active routes for this routing instance.
Definition: routing.h:51
constexpr const std::chrono::milliseconds kDefaultConnectionSharingDelay
delay in milliseconds before an idling connection may be moved to the pool when connection sharing is...
Definition: routing.h:94
constexpr const std::string_view kDefaultBindAddress
Default bind address.
Definition: routing.h:72
#define ROUTING_EXPORT
Definition: routing_export.h:15
double seconds()
Definition: task.cc:310