MySQL 8.4.2
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 int kDefaultWaitTimeout{0};
46
47/** Max number of active routes for this routing instance.
48 *
49 * 0 == no limit per route
50 */
51constexpr 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 unsigned long long kDefaultMaxConnectErrors{100};
68
69/**
70 * Default bind address used when no bind address is configured.
71 */
72constexpr std::string_view kDefaultBindAddress{"127.0.0.1"};
73
74/**
75 * Default bind address written to the config file during bootstrap.
76 */
77constexpr std::string_view kDefaultBindAddressBootstrap{"0.0.0.0"};
78
79/** Default net buffer length.
80 *
81 * Default network buffer length which can be set in the MySQL Server.
82 *
83 * This should match the default of the latest MySQL Server.
84 */
85constexpr unsigned int kDefaultNetBufferLength{16384};
86
87/**
88 * Timeout waiting for handshake response from client.
89 *
90 * The number of seconds that MySQL Router waits for a handshake response.
91 * The default value is 9 seconds (default MySQL Server minus 1).
92 */
94
95/**
96 * delay in milliseconds before an idling connection may be moved to the pool
97 * when connection sharing is allowed.
98 */
99constexpr std::chrono::milliseconds kDefaultConnectionSharingDelay{1000};
100
101/**
102 * The number of seconds that MySQL Router waits between checking for
103 * reachability of an unreachable destination.
104 */
106
107/**
108 * Default SSL session cache mode.
109 */
110constexpr bool kDefaultSslSessionCacheMode{true};
111
112/**
113 * Default SSL session cache size.
114 */
115constexpr unsigned int kDefaultSslSessionCacheSize{1024};
116
117/**
118 * Default SSL session cache timeout.
119 */
121
122/**
123 * Default Connect Retry timeout.
124 */
126
127/**
128 * Default Wait For My Writes timeout.
129 */
130constexpr bool kDefaultWaitForMyWrites{true};
131
132/**
133 * Default Wait For My Writes timeout.
134 */
136
137/**
138 * Default client SSL mode used when none is configured.
139 */
140constexpr std::string_view kDefaultClientSslMode{""};
141
142/**
143 * Default client SSL mode written to the configuration file on bootstrap.
144 */
145constexpr std::string_view kDefaultClientSslModeBootstrap{"PREFERRED"};
146
147/**
148 * Default client SSL cipher written to the configuration file on bootstrap.
149 */
150constexpr std::string_view kDefaultClientSslCipherBootstrap{""};
151
152/**
153 * Default client SSL curves written to the configuration file on bootstrap.
154 */
155constexpr std::string_view kDefaultClientSslCurvesBootstrap{""};
156
157/**
158 * Default client SSL DH params written to the configuration file on bootstrap.
159 */
160constexpr std::string_view kDefaultClientSslDhParamsBootstrap{""};
161
162/**
163 * Default server SSL mode used when none is configured.
164 */
165constexpr std::string_view kDefaultServerSslMode{"AS_CLIENT"};
166
167/**
168 * Default client SSL mode written to the configuration file on bootstrap.
169 */
170constexpr std::string_view kDefaultServerSslModeBootstrap{"PREFERRED"};
171
172/**
173 * Default server SSL verify.
174 */
175constexpr std::string_view kDefaultServerSslVerify{"DISABLED"};
176
177/**
178 * Default server SSL cipher written to the configuration file on bootstrap.
179 */
180constexpr std::string_view kDefaultServerSslCipherBootstrap{""};
181
182/**
183 * Default server SSL curves written to the configuration file on bootstrap.
184 */
185constexpr std::string_view kDefaultServerSslCurvesBootstrap{""};
186
187/**
188 * Default server SSL CA written to the configuration file on bootstrap.
189 */
190constexpr std::string_view kDefaultServerSslCaBootstrap{""};
191
192/**
193 * Default server SSL CA path written to the configuration file on bootstrap.
194 */
195constexpr std::string_view kDefaultServerSslCaPathBootstrap{""};
196
197/**
198 * Default server SSL CRL file written to the configuration file on bootstrap.
199 */
200constexpr std::string_view kDefaultServerSslCrlFileBootstrap{""};
201
202/**
203 * Default server SSL CRL path written to the configuration file on bootstrap.
204 */
205constexpr std::string_view kDefaultServerSslCrlPathBootstrap{""};
206
207/**
208 * Default connection sharing status.
209 */
210constexpr bool kDefaultConnectionSharing{false};
211
212/**
213 * Default maximum total connections handled by all the routing endpoints.
214 */
215constexpr uint64_t kDefaultMaxTotalConnections{512};
216
217/**
218 * Default for the configuration option determining if the Router enforces the
219 * router_require attribute of the user.
220 */
221constexpr bool kDefaultRequireEnforce{true};
222
226 kXRw,
227 kXRo,
229};
230
231constexpr uint16_t kDefaultPortClassicRw{6446};
232constexpr uint16_t kDefaultPortClassicRo{6447};
233constexpr uint16_t kDefaultPortXRw{6448};
234constexpr uint16_t kDefaultPortXRo{6449};
235constexpr uint16_t kDefaultPortRwSplit{6450};
236// by default sockets are not available
237constexpr std::string_view kDefaultNamedSocket{""};
238
239constexpr std::string_view kDefaultClassicRwSectionName{"bootstrap_rw"};
240constexpr std::string_view kDefaultClassicRoSectionName{"bootstrap_ro"};
241constexpr std::string_view kDefaultXRwSectionName{"bootstrap_x_rw"};
242constexpr std::string_view kDefaultXRoSectionName{"bootstrap_x_ro"};
243constexpr std::string_view kDefaultRwSplitSectionName{"bootstrap_rw_split"};
244
245/** @brief Modes supported by Routing plugin */
246enum class RoutingMode {
247 kUndefined = 0,
248 kReadWrite = 1,
249 kReadOnly = 2,
250};
251
252// the declaration of RoutingMode and then renaming to Mode works around a bug
253// in doxygen which otherwise reports:
254//
255// storage/innobase/include/buf0dblwr.h:365: warning:
256// documented symbol 'bool dblwr::Mode::is_atomic' was not declared or defined.
258
259enum class AccessMode {
260 kUndefined = 0,
261 kAuto = 1,
262};
263
264/** @brief Routing strategies supported by Routing plugin */
265enum class RoutingStrategy {
266 kUndefined = 0,
267 kFirstAvailable = 1,
268 kNextAvailable = 2,
269 kRoundRobin = 3,
271};
272
273/**
274 * Get comma separated list of all access mode names.
275 */
276std::string get_access_mode_names();
277
278/**
279 * Returns AccessMode for its literal representation.
280 *
281 * If no AccessMode is found for given string,
282 * Mode::kUndefined is returned.
283 *
284 * @param value literal representation of the access mode
285 * @return AccessMode for the given string or AccessMode::kUndefined
286 */
287AccessMode get_access_mode(const std::string &value);
288
289/**
290 * Returns literal name of given access mode.
291 *
292 * Returns literal name of given access mode as a std:string. When
293 * the access mode is not found, empty string is returned.
294 *
295 * @param access_mode access_mode to look up
296 * @return Name of access mode as std::string or empty string
297 */
298std::string get_access_mode_name(AccessMode access_mode) noexcept;
299
300/** @brief Get comma separated list of all routing stategy names
301 * for a given routing type (metadata cache or static)
302 *
303 *
304 * @param metadata_cache bool flag indicating if the list should contain
305 * strategies supported for metadata_cache
306 * or static routing
307 */
309
310/** @brief Returns RoutingStrategy for its literal representation
311 *
312 * If no RoutingStrategy is found for given string,
313 * RoutingStrategy::kUndefined is returned.
314 *
315 * @param value literal representation of the access mode
316 * @return RoutingStrategy for the given string or RoutingStrategy::kUndefined
317 */
318RoutingStrategy get_routing_strategy(const std::string &value);
319
320/** @brief Returns literal name of given routing strategy
321 *
322 * Returns literal name of given routing strategy as a std:string. When
323 * the routing strategy is not found, empty string is returned.
324 *
325 * @param routing_strategy Routing strategy to look up
326 * @return Name of routing strategy as std::string or empty string
327 */
328std::string get_routing_strategy_name(
329 RoutingStrategy routing_strategy) noexcept;
330
332 const std::string &name);
333
335 RoutingBootstrapSectionType section_type);
336
337uint16_t get_default_port(RoutingBootstrapSectionType section_type);
338
340 RoutingBootstrapSectionType section_type);
341
342std::string get_destinations_role(RoutingBootstrapSectionType section_type);
343
345
347
349
351 RoutingBootstrapSectionType section_type);
352
353} // namespace routing
354
355#endif // MYSQLROUTER_ROUTING_INCLUDED
Type
supported protocols
Definition: base_protocol.h:32
static constexpr int kDefaultConnectTimeout
Definition: mysql_session.h:155
Definition: metadata_cache.h:53
Definition: routing.h:36
constexpr std::string_view kDefaultServerSslCipherBootstrap
Default server SSL cipher written to the configuration file on bootstrap.
Definition: routing.h:180
constexpr unsigned int kDefaultSslSessionCacheSize
Default SSL session cache size.
Definition: routing.h:115
constexpr std::string_view kDefaultServerSslModeBootstrap
Default client SSL mode written to the configuration file on bootstrap.
Definition: routing.h:170
constexpr std::string_view kDefaultClientSslModeBootstrap
Default client SSL mode written to the configuration file on bootstrap.
Definition: routing.h:145
uint16_t get_default_port(RoutingBootstrapSectionType section_type)
Definition: routing.cc:149
constexpr std::string_view kDefaultXRwSectionName
Definition: routing.h:241
constexpr std::string_view kDefaultClassicRwSectionName
Definition: routing.h:239
constexpr std::string_view kDefaultServerSslCrlFileBootstrap
Default server SSL CRL file written to the configuration file on bootstrap.
Definition: routing.h:200
RoutingStrategy get_routing_strategy(const std::string &value)
Returns RoutingStrategy for its literal representation.
Definition: routing.cc:87
constexpr std::string_view kDefaultServerSslCurvesBootstrap
Default server SSL curves written to the configuration file on bootstrap.
Definition: routing.h:185
constexpr std::string_view kDefaultServerSslMode
Default server SSL mode used when none is configured.
Definition: routing.h:165
constexpr std::string_view kDefaultBindAddress
Default bind address used when no bind address is configured.
Definition: routing.h:72
RoutingStrategy get_default_routing_strategy(RoutingBootstrapSectionType section_type)
Definition: routing.cc:166
AccessMode get_access_mode(const std::string &value)
Returns AccessMode for its literal representation.
Definition: routing.cc:60
constexpr std::string_view kDefaultClientSslCurvesBootstrap
Default client SSL curves written to the configuration file on bootstrap.
Definition: routing.h:155
constexpr std::chrono::seconds kDefaultWaitForMyWritesTimeout
Default Wait For My Writes timeout.
Definition: routing.h:135
constexpr std::string_view kDefaultRwSplitSectionName
Definition: routing.h:243
constexpr std::string_view kDefaultServerSslCaPathBootstrap
Default server SSL CA path written to the configuration file on bootstrap.
Definition: routing.h:195
RoutingBootstrapSectionType
Definition: routing.h:223
constexpr unsigned int kDefaultNetBufferLength
Default net buffer length.
Definition: routing.h:85
AccessMode get_default_access_mode(RoutingBootstrapSectionType section_type)
Definition: routing.cc:215
std::string 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:94
constexpr bool kDefaultConnectionSharing
Default connection sharing status.
Definition: routing.h:210
constexpr std::chrono::seconds kDefaultConnectRetryTimeout
Default Connect Retry timeout.
Definition: routing.h:125
constexpr bool kDefaultSslSessionCacheMode
Default SSL session cache mode.
Definition: routing.h:110
std::string get_access_mode_name(AccessMode access_mode) noexcept
Returns literal name of given access mode.
Definition: routing.cc:72
AccessMode
Definition: routing.h:259
RoutingStrategy
Routing strategies supported by Routing plugin.
Definition: routing.h:265
constexpr std::chrono::seconds kDefaultSslSessionCacheTimeout
Default SSL session cache timeout.
Definition: routing.h:120
constexpr std::string_view kDefaultClassicRoSectionName
Definition: routing.h:240
constexpr std::chrono::milliseconds kDefaultConnectionSharingDelay
delay in milliseconds before an idling connection may be moved to the pool when connection sharing is...
Definition: routing.h:99
constexpr uint64_t kDefaultMaxTotalConnections
Default maximum total connections handled by all the routing endpoints.
Definition: routing.h:215
constexpr bool kDefaultWaitForMyWrites
Default Wait For My Writes timeout.
Definition: routing.h:130
constexpr uint16_t kDefaultPortClassicRw
Definition: routing.h:231
constexpr bool kDefaultRequireEnforce
Default for the configuration option determining if the Router enforces the router_require attribute ...
Definition: routing.h:221
RoutingBootstrapSectionType get_section_type_from_routing_name(const std::string &name)
Definition: routing.cc:122
constexpr std::chrono::seconds kDefaultClientConnectTimeout
Timeout waiting for handshake response from client.
Definition: routing.h:93
constexpr std::string_view kDefaultBindAddressBootstrap
Default bind address written to the config file during bootstrap.
Definition: routing.h:77
constexpr std::string_view kDefaultClientSslCipherBootstrap
Default client SSL cipher written to the configuration file on bootstrap.
Definition: routing.h:150
constexpr std::string_view kDefaultClientSslDhParamsBootstrap
Default client SSL DH params written to the configuration file on bootstrap.
Definition: routing.h:160
constexpr uint16_t kDefaultPortRwSplit
Definition: routing.h:235
constexpr std::string_view kDefaultClientSslMode
Default client SSL mode used when none is configured.
Definition: routing.h:140
constexpr int kDefaultMaxConnections
Max number of active routes for this routing instance.
Definition: routing.h:51
RoutingMode
Modes supported by Routing plugin.
Definition: routing.h:246
constexpr int kDefaultWaitTimeout
Timeout for idling clients (in seconds).
Definition: routing.h:45
bool get_default_router_require_enforce(RoutingBootstrapSectionType section_type)
Definition: routing.cc:227
constexpr std::string_view kDefaultServerSslVerify
Default server SSL verify.
Definition: routing.h:175
constexpr std::chrono::seconds kDefaultDestinationConnectionTimeout
Timeout connecting to destination (in seconds).
Definition: routing.h:58
constexpr std::string_view kDefaultServerSslCaBootstrap
Default server SSL CA written to the configuration file on bootstrap.
Definition: routing.h:190
constexpr uint16_t kDefaultPortClassicRo
Definition: routing.h:232
constexpr std::string_view kDefaultXRoSectionName
Definition: routing.h:242
constexpr std::string_view kDefaultNamedSocket
Definition: routing.h:237
std::string get_routing_strategy_name(RoutingStrategy routing_strategy) noexcept
Returns literal name of given routing strategy.
Definition: routing.cc:114
std::string get_destinations_role(RoutingBootstrapSectionType section_type)
Definition: routing.cc:182
constexpr std::string_view kDefaultServerSslCrlPathBootstrap
Default server SSL CRL path written to the configuration file on bootstrap.
Definition: routing.h:205
BaseProtocol::Type get_default_protocol(RoutingBootstrapSectionType section_type)
Definition: routing.cc:139
bool get_default_connection_sharing(RoutingBootstrapSectionType section_type)
Definition: routing.cc:223
std::string get_access_mode_names()
Get comma separated list of all access mode names.
Definition: routing.cc:66
constexpr std::chrono::seconds kDefaultUnreachableDestinationRefreshInterval
The number of seconds that MySQL Router waits between checking for reachability of an unreachable des...
Definition: routing.h:105
constexpr uint16_t kDefaultPortXRo
Definition: routing.h:234
constexpr uint16_t kDefaultPortXRw
Definition: routing.h:233
std::string get_default_routing_name(RoutingBootstrapSectionType section_type)
Definition: routing.cc:198
constexpr unsigned long long kDefaultMaxConnectErrors
Maximum connect or handshake errors per host.
Definition: routing.h:67
case opt name
Definition: sslopt-case.h:29
double seconds()
Definition: task.cc:310