MySQL 8.0.31
Source Code Documentation
routing_component.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2019, 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_COMPONENT_INCLUDED
26#define MYSQLROUTER_ROUTING_COMPONENT_INCLUDED
27
28#include "mysqlrouter/routing_export.h" // ROUTING_EXPORT
29
30#include <chrono>
31#include <map>
32#include <memory>
33#include <mutex>
34#include <string>
35#include <vector>
36
39#include "tcp_address.h"
40
42class BaseProtocol;
43
45 public:
46 MySQLRoutingAPI() = default;
47
48 MySQLRoutingAPI(std::shared_ptr<MySQLRoutingBase> r) : r_{std::move(r)} {}
49
50 // config
51 std::string get_bind_address() const;
52 uint16_t get_bind_port() const;
53
54 std::chrono::milliseconds get_client_connect_timeout() const;
55 std::chrono::milliseconds get_destination_connect_timeout() const;
56 std::string get_destination_cluster_name() const;
57 std::string get_destination_replicaset_name() const;
58
59 int get_max_connections() const;
60 uint64_t get_max_connect_errors() const;
61 std::string get_mode() const;
62
63 std::string get_name() const;
64
65 std::string get_protocol_name() const;
66 std::string get_routing_strategy() const;
67 std::string get_socket() const;
68
69 explicit operator bool() const noexcept { return r_.operator bool(); }
70
71 std::vector<std::string> get_blocked_client_hosts() const;
72
73 struct ConnData {
74 using time_point_type = std::chrono::time_point<std::chrono::system_clock>;
75 std::string src;
76 std::string dst;
77
78 std::size_t bytes_up;
79 std::size_t bytes_down;
80
85 };
86
87 std::vector<ConnData> get_connections() const;
88
89 // status
90 int get_active_connections() const;
91 int get_total_connections() const;
92
93 std::vector<mysql_harness::TCPAddress> get_destinations() const;
94
95 void start_accepting_connections();
96
97 bool is_accepting_connections() const;
98
99 void stop_socket_acceptors();
100
101 bool is_running() const;
102
103 private:
104 std::shared_ptr<MySQLRoutingBase> r_;
105};
106
108 public:
109 static MySQLRoutingComponent &get_instance();
110
111 void deinit();
112
113 void init(const mysql_harness::Config &config);
114
115 void init(const std::string &name, std::shared_ptr<MySQLRoutingBase> srv,
116 std::chrono::seconds quarantine_refresh_interval);
117
118 void erase(const std::string &name);
119
120 MySQLRoutingAPI api(const std::string &name);
121
122 uint64_t current_total_connections();
123 uint64_t max_total_connections() const { return max_total_connections_; }
124
125 std::vector<std::string> route_names() const;
126
127 static const uint64_t kDefaultMaxTotalConnections = 512;
128
129 private:
130 // disable copy, as we are a single-instance
132 void operator=(MySQLRoutingComponent const &) = delete;
133
134 std::mutex routes_mu_;
135 std::map<std::string, std::weak_ptr<MySQLRoutingBase>> routes_;
136
137 uint64_t max_total_connections_{0};
138
140
142};
143
144#endif
static mysql_service_status_t deinit()
Component deinitialization.
Definition: audit_api_message_emit.cc:579
static mysql_service_status_t init()
Component initialization.
Definition: audit_api_message_emit.cc:570
Definition: base_protocol.h:28
Definition: routing_component.h:44
std::shared_ptr< MySQLRoutingBase > r_
Definition: routing_component.h:104
MySQLRoutingAPI(std::shared_ptr< MySQLRoutingBase > r)
Definition: routing_component.h:48
MySQLRoutingAPI()=default
Facade to avoid a tight coupling between Routing component and actual routing endpoint implementation...
Definition: mysql_routing_base.h:40
Definition: routing_component.h:107
MySQLRoutingComponent(MySQLRoutingComponent const &)=delete
std::map< std::string, std::weak_ptr< MySQLRoutingBase > > routes_
Definition: routing_component.h:135
uint64_t max_total_connections() const
Definition: routing_component.h:123
MySQLRoutingComponent()=default
void operator=(MySQLRoutingComponent const &)=delete
RoutingCommonUnreachableDestinations routing_common_unreachable_destinations_
Definition: routing_component.h:141
std::mutex routes_mu_
Definition: routing_component.h:134
Information about unreachable destination candidates that is shared between routing plugin instances.
Definition: routing_common_unreachable_destinations.h:50
Configuration.
Definition: config_parser.h:252
bool is_running(const PluginFuncEnv *env) noexcept
Definition: loader.cc:201
RoutingStrategy ROUTING_EXPORT get_routing_strategy(const std::string &value)
Returns RoutingStrategy for its literal representation.
Definition: routing.cc:90
Definition: srv0dynamic_procedures.h:47
Definition: varlen_sort.h:183
const mysql_service_registry_t * r
Definition: pfs_example_plugin_employee.cc:85
#define ROUTING_EXPORT
Definition: routing_export.h:15
case opt name
Definition: sslopt-case.h:32
Definition: routing_component.h:73
std::size_t bytes_up
Definition: routing_component.h:78
time_point_type last_sent_to_server
Definition: routing_component.h:83
time_point_type connected_to_server
Definition: routing_component.h:82
std::string dst
Definition: routing_component.h:76
time_point_type started
Definition: routing_component.h:81
std::string src
Definition: routing_component.h:75
std::chrono::time_point< std::chrono::system_clock > time_point_type
Definition: routing_component.h:74
std::size_t bytes_down
Definition: routing_component.h:79
time_point_type last_received_from_server
Definition: routing_component.h:84
double seconds()
Definition: task.cc:309
ulong get_max_connections(void)
Get max number of connections.
Definition: sql_thd_api.cc:300