![]() |
MySQL 9.4.0
Source Code Documentation
|
Manage Connections from clients to MySQL servers. More...
#include <mysql_routing.h>
Public Member Functions | |
| MySQLRouting (const RoutingConfig &routing_config, net::io_context &io_ctx, std::shared_ptr< routing_guidelines::Routing_guidelines_engine > guidelines, const std::string &route_name={}, TlsServerContext *client_ssl_ctx=nullptr, DestinationTlsContext *dest_ssl_ctx=nullptr) | |
| Default constructor. More... | |
| void | run (mysql_harness::PluginFuncEnv *env) |
| Runs the service and accept incoming connections. More... | |
| void | set_destinations (const std::string &dests) |
| void | set_destinations_from_dests (const std::vector< mysql_harness::Destination > &dests) |
| Sets the destinations. More... | |
| void | set_destinations_from_uri (const mysqlrouter::URI &uri) |
| std::chrono::milliseconds | get_destination_connect_timeout () const noexcept |
| Returns timeout when connecting to destination. More... | |
| void | validate_destination_connect_timeout (std::chrono::milliseconds timeout) |
| Sets timeout when connecting to destination. More... | |
| int | set_max_connections (int maximum) |
| Sets maximum active connections. More... | |
| int | get_max_connections () const noexcept override |
| Returns maximum active connections. More... | |
| template<class ClientProtocol > | |
| void | create_connection (typename ClientProtocol::socket client_socket, const typename ClientProtocol::endpoint &client_endpoint) |
| create new connection to MySQL Server than can handle client's traffic and adds it to connection container. More... | |
| std::optional< routing::RoutingStrategy > | get_routing_strategy () const override |
| std::vector< mysql_harness::Destination > | get_destination_candidates () const override |
| std::vector< MySQLRoutingAPI::ConnData > | get_connections () override |
| MySQLRoutingConnectionBase * | get_connection (const std::string &) override |
| DestinationManager * | destination_manager () override |
| void | disconnect_all () |
| void | stop_socket_acceptors (const bool shutting_down) override |
| Stop accepting new connections on a listening socket. More... | |
| bool | is_accepting_connections () const override |
| Check if we are accepting connections on a routing socket. More... | |
| stdx::expected< void, std::string > | start_accepting_connections () override |
| Start accepting new connections on a listening socket. More... | |
| stdx::expected< void, std::string > | restart_accepting_connections () override |
| Start accepting new connections on a listening socket after it has been quarantined for lack of valid destinations. More... | |
| void | on_routing_guidelines_update (const routing_guidelines::Routing_guidelines_engine::RouteChanges &affected_routing_sources) |
| In case when routing guideline was updated go through each established connection and verify if it is allowed according to the new guideline. More... | |
| routing_guidelines::Routing_guidelines_engine::RouteChanges | update_routing_guidelines (const std::string &routing_guidelines_document) |
| Try to update routing guideline with a new guideline. More... | |
| void | on_router_info_update (const routing_guidelines::Router_info &router_info) |
| If the router info was updated then register this info in routing context. More... | |
| bool | is_standalone () const override |
| MySQLRoutingContext & | get_context () override |
| bool | is_running () const override |
| mysqlrouter::ServerMode | purpose () const override |
| get the purpose of connections to this route. More... | |
Public Member Functions inherited from MySQLRoutingBase | |
| MySQLRoutingBase ()=default | |
| MySQLRoutingBase (const MySQLRoutingBase &)=default | |
| MySQLRoutingBase (MySQLRoutingBase &&)=default | |
| MySQLRoutingBase & | operator= (const MySQLRoutingBase &)=default |
| MySQLRoutingBase & | operator= (MySQLRoutingBase &&)=default |
| virtual | ~MySQLRoutingBase ()=default |
Private Member Functions | |
| stdx::expected< void, std::string > | run_acceptor (mysql_harness::PluginFuncEnv *env) |
| stdx::expected< void, std::string > | run_with_no_acceptor (mysql_harness::PluginFuncEnv *env) |
Static Private Member Functions | |
| static void | set_unix_socket_permissions (const char *socket_file) |
| Sets unix socket permissions so that the socket is accessible to all users (no-op on Windows) More... | |
Private Attributes | |
| bool | accept_connections_ {true} |
| WaitableMonitor< Nothing > | acceptor_waitable_ {Nothing{}} |
| Monitor for notifying socket acceptor. More... | |
| MySQLRoutingContext | context_ |
| wrapper for data used by all connections More... | |
| net::io_context & | io_ctx_ |
| std::unique_ptr< DestinationManager > | destination_manager_ {nullptr} |
| Destination object to use when getting next connection. More... | |
| bool | is_destination_standalone_ {false} |
| std::optional< routing::RoutingStrategy > | routing_strategy_ |
| Routing strategy to use when getting next destination. More... | |
| routing::AccessMode | access_mode_ |
| access_mode of the servers in the routing More... | |
| int | max_connections_ |
| Maximum active connections. More... | |
| AllowedNodesChangeCallbacksListIterator | allowed_nodes_list_iterator_ |
| used to unregister from subscription on allowed nodes changes More... | |
| ConnectionContainer | connection_container_ |
| container for connections More... | |
| std::atomic< bool > | is_running_ {true} |
| Information if the routing plugin is still running. More... | |
| net::steady_timer | accept_port_reopen_retry_timer_ {io_ctx_} |
| Used when the accepting port is been reopened and it failed, to schedule another retry for standalone-destination(s) route. More... | |
| std::vector< std::unique_ptr< AcceptingEndpoint > > | accepting_endpoints_ |
Manage Connections from clients to MySQL servers.
The class MySQLRouter is used to start a service listening on a particular TCP port for incoming MySQL Client connection and route these to a MySQL Server.
| MySQLRouting::MySQLRouting | ( | const RoutingConfig & | routing_config, |
| net::io_context & | io_ctx, | ||
| std::shared_ptr< routing_guidelines::Routing_guidelines_engine > | guidelines, | ||
| const std::string & | route_name = {}, |
||
| TlsServerContext * | client_ssl_ctx = nullptr, |
||
| DestinationTlsContext * | dest_ssl_ctx = nullptr |
||
| ) |
Default constructor.
class MySQLRouting
| routing_config | routing configuration |
| io_ctx | IO context |
| guidelines | routing guidelines engine |
| route_name | Name of connection routing (can be empty string) |
| client_ssl_ctx | SSL context of the client side |
| dest_ssl_ctx | SSL contexts of the destinations |
| void MySQLRouting::create_connection | ( | typename ClientProtocol::socket | client_socket, |
| const typename ClientProtocol::endpoint & | client_endpoint | ||
| ) |
create new connection to MySQL Server than can handle client's traffic and adds it to connection container.
| client_socket | socket used to transfer data to/from client |
| client_endpoint | endpoint of client |
|
inlineoverridevirtual |
Implements MySQLRoutingBase.
| void MySQLRouting::disconnect_all | ( | ) |
|
overridevirtual |
Implements MySQLRoutingBase.
|
overridevirtual |
Implements MySQLRoutingBase.
|
inlineoverridevirtual |
Implements MySQLRoutingBase.
|
overridevirtual |
Implements MySQLRoutingBase.
|
inlinenoexcept |
Returns timeout when connecting to destination.
|
inlineoverridevirtualnoexcept |
|
inlineoverridevirtual |
Implements MySQLRoutingBase.
|
overridevirtual |
Check if we are accepting connections on a routing socket.
| true | if we are accepting connections, false otherwise |
Implements MySQLRoutingBase.
|
inlineoverridevirtual |
Implements MySQLRoutingBase.
|
inlineoverridevirtual |
Implements MySQLRoutingBase.
| void MySQLRouting::on_router_info_update | ( | const routing_guidelines::Router_info & | router_info | ) |
If the router info was updated then register this info in routing context.
| router_info | updated router info |
| void MySQLRouting::on_routing_guidelines_update | ( | const routing_guidelines::Routing_guidelines_engine::RouteChanges & | affected_routing_sources | ) |
In case when routing guideline was updated go through each established connection and verify if it is allowed according to the new guideline.
If not then such connection is dropped.
| affected_routing_sources | list of routing guideline route names that were affected by the guideline update |
|
overridevirtual |
get the purpose of connections to this route.
"Unavailable" is used for read-write splitting where the purpose is determined per statement, session, ...
A statement over a read-only server connection may end up on a read-write server in case all read-only servers aren't reachable. Even if the server is read-write, the connections purpose is read-only and if the server changes its role from PRIMARY to SECONDARY, these read-only connections will not be abort as a SECONDARY is good enough to serve read-only connections.
Implements MySQLRoutingBase.
|
overridevirtual |
Start accepting new connections on a listening socket after it has been quarantined for lack of valid destinations.
Implements MySQLRoutingBase.
| void MySQLRouting::run | ( | mysql_harness::PluginFuncEnv * | env | ) |
Runs the service and accept incoming connections.
Runs the connection routing service and starts accepting incoming MySQL client connections.
| std::runtime_error | on errors. |
|
private |
|
private |
| void MySQLRouting::set_destinations | ( | const std::string & | dests | ) |
| void MySQLRouting::set_destinations_from_dests | ( | const std::vector< mysql_harness::Destination > & | dests | ) |
Sets the destinations.
| dests | destinations |
| void MySQLRouting::set_destinations_from_uri | ( | const mysqlrouter::URI & | uri | ) |
| int MySQLRouting::set_max_connections | ( | int | maximum | ) |
Sets maximum active connections.
Sets maximum of active connections. Maximum must be between 1 and 65535.
| std::invalid_argument | when an invalid value was provided. |
| maximum | Max number of connections allowed |
|
staticprivate |
Sets unix socket permissions so that the socket is accessible to all users (no-op on Windows)
| socket_file | path to socket file |
| std::runtime_error | if chmod() inside fails |
|
overridevirtual |
Start accepting new connections on a listening socket.
Implements MySQLRoutingBase.
|
overridevirtual |
Stop accepting new connections on a listening socket.
| shutting_down | is plugin shutting down. |
Implements MySQLRoutingBase.
| routing_guidelines::Routing_guidelines_engine::RouteChanges MySQLRouting::update_routing_guidelines | ( | const std::string & | routing_guidelines_document | ) |
Try to update routing guideline with a new guideline.
| void MySQLRouting::validate_destination_connect_timeout | ( | std::chrono::milliseconds | timeout | ) |
Sets timeout when connecting to destination.
Checks timeout connecting with destination servers.
| std::invalid_argument | when an invalid value was provided. |
| timeout | Timeout |
|
private |
|
private |
Used when the accepting port is been reopened and it failed, to schedule another retry for standalone-destination(s) route.
|
private |
|
private |
Monitor for notifying socket acceptor.
|
private |
access_mode of the servers in the routing
|
private |
used to unregister from subscription on allowed nodes changes
|
private |
container for connections
|
private |
wrapper for data used by all connections
|
private |
Destination object to use when getting next connection.
|
private |
|
private |
|
private |
Information if the routing plugin is still running.
|
private |
Maximum active connections.
Maximum number of incoming connections that will be accepted by this MySQLRouter instances. There is no maximum for outgoing connections since it is one-to-one with incoming.
|
private |
Routing strategy to use when getting next destination.