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