MySQL 9.0.0
Source Code Documentation
context.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2018, 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 ROUTING_CONTEXT_INCLUDED
27#define ROUTING_CONTEXT_INCLUDED
28
29#include <array>
30#include <atomic>
31#include <chrono>
32#include <map>
33#include <memory>
34#include <mutex>
35#include <string>
36#include <vector>
37
38#include "blocked_endpoints.h"
40#include "mysql/harness/filesystem.h" // Path
43#include "mysql_router_thread.h"
47#include "mysqlrouter/routing.h"
49#include "routing_config.h"
51#include "tcp_address.h"
52
53/**
54 * @brief MySQLRoutingContext holds data used by MySQLRouting (1 per plugin
55 * instances) and MySQLRoutingConnection instances (many instances). It is
56 * created and owned by MySQLRouting while MySQLRoutingConnection objects hold
57 * reference to it.
58 */
60 public:
61 MySQLRoutingContext(const RoutingConfig &routing_config, std::string name,
62 TlsServerContext *client_ssl_ctx,
63 DestinationTlsContext *dest_tls_context)
64 : routing_config_(routing_config),
65 name_(std::move(name)),
66 client_ssl_ctx_{client_ssl_ctx},
67 destination_tls_context_{dest_tls_context},
68 blocked_endpoints_{routing_config.max_connect_errors} {}
69
72 return blocked_endpoints_;
73 }
74
78
81 uint64_t get_max_connect_errors() const {
83 }
84
86
87 const std::string &get_name() const { return name_; }
88
89 /**
90 * identifier part of the name.
91 *
92 * name has the form 'routing:{id}'
93 */
94 std::string get_id() const {
95 auto pos = name_.find(':');
96
97 if (pos == name_.npos) return {};
98
99 return name_.substr(pos + 1);
100 }
101
102 unsigned int get_net_buffer_length() const {
104 }
105
106 std::chrono::milliseconds get_destination_connect_timeout() const {
107 return std::chrono::milliseconds{routing_config_.connect_timeout * 1000};
108 }
109
110 std::chrono::milliseconds get_client_connect_timeout() const {
111 return std::chrono::milliseconds{routing_config_.client_connect_timeout *
112 1000};
113 }
114
115 std::chrono::milliseconds connect_retry_timeout() const {
117 }
118
121 }
122
125 }
126
127 SslMode source_ssl_mode() const noexcept {
129 }
130 SslMode dest_ssl_mode() const noexcept {
132 }
133
134 /**
135 * get the SSL context for the client side of the route.
136 */
138
139 /**
140 * get the SSL context for the server side of the route.
141 *
142 * @param dest_id unique id of the destination
143 * @param hostname name of the destination host
144 *
145 * @returns a TlsClientContext for the destination.
146 * @retval nullptr if creating tls-context failed.
147 */
148 TlsClientContext *dest_ssl_ctx(const std::string &dest_id,
149 const std::string &hostname) {
150 if (destination_tls_context_ == nullptr) return nullptr;
151
152 return destination_tls_context_->get(dest_id, hostname);
153 }
154
157 }
158
161 }
162
164
165 std::chrono::milliseconds connection_sharing_delay() const {
167 }
168
171 }
172
174
177 }
178
179 std::string dest_ssl_key() const { return routing_config_.dest_ssl_key; }
180 std::string dest_ssl_cert() const { return routing_config_.dest_ssl_cert; }
181
184 }
185
186 private:
188
189 /** @brief Descriptive name of the connection routing */
190 const std::string name_;
191
192 mutable std::mutex mutex_conn_errors_;
193
194 /** @brief memory in kilobytes allocated for thread's stack */
196
198
200
201 /**
202 * Callbacks for communicating with quarantined destination candidates
203 * instance.
204 */
206
208
209 public:
210 /** @brief Number of active routes */
211 std::atomic<uint16_t> info_active_routes_{0};
212 /** @brief Number of handled routes, not used at the moment */
213 std::atomic<uint64_t> info_handled_routes_{0};
214};
215#endif /* ROUTING_CONTEXT_INCLUDED */
Type
supported protocols
Definition: base_protocol.h:32
Definition: blocked_endpoints.h:34
uint64_t max_connect_errors() const
Definition: blocked_endpoints.h:39
TlsClientContext per destination.
Definition: destination_ssl_context.h:42
TlsClientContext * get(const std::string &dest_id, const std::string &hostname)
get a TlsClientContent for a destination.
Definition: destination_ssl_context.cc:80
MySQLRoutingContext holds data used by MySQLRouting (1 per plugin instances) and MySQLRoutingConnecti...
Definition: context.h:59
const std::string & get_name() const
Definition: context.h:87
std::string dest_ssl_key() const
Definition: context.h:179
const SharedQuarantineHandler & shared_quarantine() const
Definition: context.h:159
std::string get_id() const
identifier part of the name.
Definition: context.h:94
bool router_require_enforce() const
Definition: context.h:182
std::chrono::milliseconds get_client_connect_timeout() const
Definition: context.h:110
std::atomic< uint64_t > info_handled_routes_
Number of handled routes, not used at the moment.
Definition: context.h:213
const mysql_harness::Path & get_bind_named_socket() const
Definition: context.h:123
const BlockedEndpoints & blocked_endpoints() const
Definition: context.h:71
TlsClientContext * dest_ssl_ctx(const std::string &dest_id, const std::string &hostname)
get the SSL context for the server side of the route.
Definition: context.h:148
size_t thread_stack_size_
memory in kilobytes allocated for thread's stack
Definition: context.h:195
uint64_t get_handled_routes()
Definition: context.h:80
void increase_info_handled_routes()
Definition: context.cc:47
SharedQuarantineHandler shared_quarantine_handler_
Callbacks for communicating with quarantined destination candidates instance.
Definition: context.h:205
SharedQuarantineHandler & shared_quarantine()
Definition: context.h:155
bool connection_sharing() const
Definition: context.h:163
unsigned int get_net_buffer_length() const
Definition: context.h:102
routing::AccessMode access_mode() const
Definition: context.h:169
uint64_t get_max_connect_errors() const
Definition: context.h:81
std::atomic< uint16_t > info_active_routes_
Number of active routes.
Definition: context.h:211
BlockedEndpoints blocked_endpoints_
Definition: context.h:207
std::chrono::seconds wait_for_my_writes_timeout() const
Definition: context.h:175
SslMode source_ssl_mode() const noexcept
Definition: context.h:127
std::chrono::milliseconds get_destination_connect_timeout() const
Definition: context.h:106
BlockedEndpoints & blocked_endpoints()
Definition: context.h:70
TlsServerContext * source_ssl_ctx() const
get the SSL context for the client side of the route.
Definition: context.h:137
const mysql_harness::TCPAddress & get_bind_address() const
Definition: context.h:119
DestinationTlsContext * destination_tls_context_
Definition: context.h:199
std::chrono::milliseconds connect_retry_timeout() const
Definition: context.h:115
std::mutex mutex_conn_errors_
Definition: context.h:192
const RoutingConfig routing_config_
Definition: context.h:187
std::string dest_ssl_cert() const
Definition: context.h:180
void increase_info_active_routes()
Definition: context.cc:39
BaseProtocol::Type get_protocol()
Definition: context.h:85
TlsServerContext * client_ssl_ctx_
Definition: context.h:197
MySQLRoutingContext(const RoutingConfig &routing_config, std::string name, TlsServerContext *client_ssl_ctx, DestinationTlsContext *dest_tls_context)
Definition: context.h:61
SslMode dest_ssl_mode() const noexcept
Definition: context.h:130
std::chrono::milliseconds connection_sharing_delay() const
Definition: context.h:165
uint16_t get_active_routes()
Definition: context.h:79
bool wait_for_my_writes() const
Definition: context.h:173
void decrease_info_active_routes()
Definition: context.cc:43
const std::string name_
Descriptive name of the connection routing.
Definition: context.h:190
route specific configuration.
Definition: routing_config.h:40
std::chrono::seconds wait_for_my_writes_timeout
how long to wait for writes to be applied before reads.
Definition: routing_config.h:107
mysql_harness::Path named_socket
unix domain socket path to bind to
Definition: routing_config.h:46
bool wait_for_my_writes
Definition: routing_config.h:105
bool router_require_enforce
Definition: routing_config.h:117
SslMode dest_ssl_mode
SslMode of the server side connection.
Definition: routing_config.h:71
unsigned int client_connect_timeout
client connect timeout in seconds
Definition: routing_config.h:53
SslMode source_ssl_mode
SslMode of the client side connection.
Definition: routing_config.h:57
int connect_timeout
connect-timeout in seconds
Definition: routing_config.h:47
Protocol::Type protocol
protocol (classic, x)
Definition: routing_config.h:42
std::string dest_ssl_cert
Cert file.
Definition: routing_config.h:72
routing::AccessMode access_mode
read_write,read_only,auto
Definition: routing_config.h:102
unsigned int net_buffer_length
Size of buffer to receive packets.
Definition: routing_config.h:54
bool connection_sharing
if connection sharing is allowed.
Definition: routing_config.h:85
mysql_harness::TCPAddress bind_address
IP address to bind to.
Definition: routing_config.h:45
std::chrono::milliseconds connect_retry_timeout
timeout of retrying after a transient connect-failure.
Definition: routing_config.h:100
std::string dest_ssl_key
Key file.
Definition: routing_config.h:73
std::chrono::milliseconds connection_sharing_delay
delay before an idling connection is moved to the pool and connection sharing is allowed.
Definition: routing_config.h:87
Definition: shared_quarantine_handler.h:36
Client TLS Context.
Definition: tls_client_context.h:43
TLS Context for the server side.
Definition: tls_server_context.h:51
Class representing a path in a file system.
Definition: filesystem.h:63
Defines an IP address with port number
Definition: tcp_address.h:40
ulong max_connect_errors
Definition: mysqld.cc:1382
static const size_t kDefaultStackSizeInKiloBytes
Definition: mysql_router_thread.h:44
AccessMode
Definition: routing.h:259
Definition: gcs_xcom_synode.h:64
SslMode
Definition: ssl_mode.h:29
case opt name
Definition: sslopt-case.h:29
double seconds()
Definition: task.cc:310