26#ifndef ROUTING_CONNECTION_INCLUDED
27#define ROUTING_CONNECTION_INCLUDED
74 virtual std::optional<net::ip::tcp::endpoint>
140 const auto now = clock_type::now();
142 stats.last_sent_to_server = now;
143 stats.bytes_down += bytes;
148 const auto now = clock_type::now();
150 stats.last_received_from_server = now;
151 stats.bytes_up += bytes;
167 return disconnect_([](
auto requested) {
return requested; });
217 std::function<
void(std::string, uint16_t, std::error_code)> func) {
268 std::function<void(std::string, uint16_t, std::error_code)>
274template <
class ConnectionType>
302 return ret_type{std::in_place,
303 std::make_unique<TcpConnection>(std::move(
socket()),
308template <
class ConnectionType>
337 return std::move(pool_res.value());
346 return {std::in_place, std::make_unique<TcpConnection>(
Definition: connection.h:188
server_protocol_type::endpoint & endpoint()
Definition: connection.h:205
void connect_timed_out(bool v)
Definition: connection.h:209
std::function< void(std::string, uint16_t)> on_connect_success_
Definition: connection.h:270
std::function< void(std::string, uint16_t, std::error_code)> on_connect_failure_
Definition: connection.h:269
net::steady_timer & timer()
Definition: connection.h:207
stdx::expected< void, std::error_code > connect_init()
Definition: connection.cc:90
stdx::expected< void, std::error_code > init_destination()
Definition: connection.cc:38
Destinations & destinations_
Definition: connection.h:254
std::error_code last_ec_
Definition: connection.h:259
net::steady_timer connect_timer_
Definition: connection.h:263
stdx::expected< void, std::error_code > resolve()
Definition: connection.cc:54
server_protocol_type::endpoint server_endpoint_
Definition: connection.h:251
Function
Definition: connection.h:199
stdx::expected< void, std::error_code > init_endpoint()
Definition: connection.cc:84
std::string destination_id() const
Definition: connection.h:214
stdx::expected< void, std::error_code > connected()
Definition: connection.cc:218
stdx::expected< void, std::error_code > connect_failed(std::error_code ec)
ConnectorBase(net::io_context &io_ctx, RouteDestination *route_destination, Destinations &destinations)
Definition: connection.h:192
void destination_id(std::string id)
Definition: connection.h:213
bool connect_timed_out_
Definition: connection.h:265
void on_connect_success(std::function< void(std::string, uint16_t)> func)
Definition: connection.h:221
Destinations::iterator destinations_it_
Definition: connection.h:255
net::ip::tcp::resolver::results_type endpoints_
Definition: connection.h:256
bool connect_timed_out() const
Definition: connection.h:211
std::function< bool(std::string, uint16_t)> on_is_destination_good_
Definition: connection.h:271
Function func_
Definition: connection.h:261
server_protocol_type::socket & socket()
Definition: connection.h:204
net::ip::tcp::resolver resolver_
Definition: connection.h:249
bool is_destination_good(const std::string &hostname, uint16_t port) const
Definition: connection.h:229
void on_is_destination_good(std::function< bool(std::string, uint16_t)> func)
Definition: connection.h:225
stdx::expected< void, std::error_code > next_destination()
Definition: connection.cc:250
net::io_context & io_ctx_
Definition: connection.h:247
stdx::expected< void, std::error_code > try_connect()
Definition: connection.cc:103
std::string destination_id_
Definition: connection.h:266
net::ip::tcp::resolver::results_type::iterator endpoints_it_
Definition: connection.h:257
stdx::expected< void, std::error_code > connect_finish()
Definition: connection.cc:185
server_protocol_type::socket server_sock_
Definition: connection.h:250
stdx::expected< void, std::error_code > next_endpoint()
Definition: connection.cc:230
void on_connect_failure(std::function< void(std::string, uint16_t, std::error_code)> func)
Definition: connection.h:216
RouteDestination * route_destination_
Definition: connection.h:253
Definition: connection.h:275
stdx::expected< ConnectionType, std::error_code > connect()
Definition: connection.h:279
A forward iterable container of destinations.
Definition: destination.h:107
typename container_type::iterator iterator
Definition: destination.h:111
Monitor pattern.
Definition: monitor.h:39
Definition: connection.h:44
virtual std::string get_destination_id() const =0
void accepted()
Definition: connection.cc:277
MySQLRoutingConnectionBase(MySQLRoutingContext &context, std::function< void(MySQLRoutingConnectionBase *)> remove_callback)
Definition: connection.h:46
clock_type::time_point time_point_type
Definition: connection.h:106
virtual void connected()
Definition: connection.cc:285
const MySQLRoutingContext & context() const
Definition: connection.h:54
time_point_type get_started() const
Definition: connection.h:108
Stats get_stats() const
Definition: connection.h:135
std::size_t get_bytes_down() const
Definition: connection.h:101
std::chrono::system_clock clock_type
Definition: connection.h:105
void transfered_to_server(size_t bytes)
Definition: connection.h:139
virtual std::string read_only_destination_id() const
Definition: connection.h:58
virtual std::optional< net::ip::tcp::endpoint > read_write_destination_endpoint() const
Definition: connection.h:75
std::size_t get_bytes_up() const
Definition: connection.h:97
Monitor< bool > disconnect_
Definition: connection.h:178
net::impl::socket::native_handle_type client_fd_
Definition: connection.h:183
virtual std::optional< net::ip::tcp::endpoint > read_only_destination_endpoint() const
Definition: connection.h:69
void disassociate()
Definition: connection.h:155
void log_connection_summary()
Definition: connection.cc:297
Monitor< Stats > stats_
Definition: connection.h:176
virtual void disconnect()=0
time_point_type get_connected_to_server() const
Definition: connection.h:112
virtual std::string get_server_address() const =0
Returns address of server to which connection is established.
std::function< void(MySQLRoutingConnectionBase *)> remove_callback_
callback that is called when thread of execution completes
Definition: connection.h:174
virtual std::string get_client_address() const =0
Returns address of client which connected to router.
virtual ~MySQLRoutingConnectionBase()=default
MySQLRoutingContext & context()
Definition: connection.h:53
void transfered_to_client(size_t bytes)
Definition: connection.h:147
std::string client_id_
Definition: connection.h:184
time_point_type get_last_received_from_server() const
Definition: connection.h:120
virtual std::string read_write_destination_id() const
Definition: connection.h:62
time_point_type get_last_sent_to_server() const
Definition: connection.h:116
auto disconnect_request(F &&f)
Definition: connection.h:162
virtual net::impl::socket::native_handle_type get_client_fd() const =0
virtual std::optional< net::ip::tcp::endpoint > destination_endpoint() const =0
std::string server_id_
Definition: connection.h:185
bool disconnect_requested() const
Definition: connection.h:166
MySQLRoutingContext & context_
wrapper for common data used by all routing threads
Definition: connection.h:172
MySQLRoutingContext holds data used by MySQLRouting (1 per plugin instances) and MySQLRoutingConnecti...
Definition: context.h:59
Definition: connection.h:309
stdx::expected< ConnectionType, std::error_code > connect()
Definition: connection.h:319
pool_lookup_cb pool_lookup_
Definition: connection.h:355
std::optional< ConnectionType > probe_pool()
Definition: connection.h:351
PooledConnector(net::io_context &io_ctx, RouteDestination *route_destination, Destinations &destinations, pool_lookup_cb pool_lookup)
Definition: connection.h:314
std::function< std::optional< ConnectionType >(const server_protocol_type::endpoint &ep)> pool_lookup_cb
Definition: connection.h:312
Manage destinations for a Connection Routing.
Definition: destination.h:189
Definition: socket.h:1090
Definition: io_context.h:61
Definition: internet.h:678
Definition: internet.h:542
const_iterator iterator
Definition: internet.h:550
Definition: internet.h:608
TCP protocol.
Definition: internet.h:1155
Definition: expected.h:286
struct stats stats
Definition: mysqlslap.cc:238
bool empty(const Histogram &histogram)
Return true if 'histogram' was built on an empty table.
Definition: histogram.h:693
std::error_code make_error_code(DynamicLoaderErrc ec)
make error_code from a DynamicLoaderErrc.
Definition: dynamic_loader.cc:79
const char * begin(const char *const c)
Definition: base64.h:44
int native_handle_type
Definition: socket_constants.h:51
Definition: gcs_xcom_synode.h:64
unexpected(E) -> unexpected< E >
required uint64 port
Definition: replication_asynchronous_connection_failover.proto:33
Definition: connection.h:125
time_point_type started
Definition: connection.h:129
time_point_type last_sent_to_server
Definition: connection.h:131
time_point_type connected_to_server
Definition: connection.h:130
std::size_t bytes_down
Definition: connection.h:127
time_point_type last_received_from_server
Definition: connection.h:132
std::size_t bytes_up
Definition: connection.h:126
Definition: mysqlslap.cc:240
unsigned long id[MAX_DEAD]
Definition: xcom_base.cc:510