26#ifndef ROUTING_CONNECTION_INCLUDED
27#define ROUTING_CONNECTION_INCLUDED
116 const auto now = clock_type::now();
118 stats.last_sent_to_server = now;
119 stats.bytes_down += bytes;
124 const auto now = clock_type::now();
126 stats.last_received_from_server = now;
127 stats.bytes_up += bytes;
143 return disconnect_([](
auto requested) {
return requested; });
186 std::function<
void(std::string, uint16_t, std::error_code)> func) {
237 std::function<void(std::string, uint16_t, std::error_code)>
243template <
class ConnectionType>
252 if (!init_res)
return init_res.get_unexpected();
257 if (!connect_res)
return connect_res.get_unexpected();
266 if (!connect_res)
return connect_res.get_unexpected();
270 return {std::in_place, std::make_unique<TcpConnection>(
275template <
class ConnectionType>
290 if (!init_res)
return init_res.get_unexpected();
295 if (!connect_res)
return connect_res.get_unexpected();
304 return std::move(pool_res.value());
309 if (!connect_res)
return connect_res.get_unexpected();
313 return {std::in_place, std::make_unique<TcpConnection>(
Definition: connection.h:157
server_protocol_type::endpoint & endpoint()
Definition: connection.h:174
void connect_timed_out(bool v)
Definition: connection.h:178
std::function< void(std::string, uint16_t)> on_connect_success_
Definition: connection.h:239
std::function< void(std::string, uint16_t, std::error_code)> on_connect_failure_
Definition: connection.h:238
net::steady_timer & timer()
Definition: connection.h:176
stdx::expected< void, std::error_code > connect_init()
Definition: connection.cc:91
stdx::expected< void, std::error_code > init_destination()
Definition: connection.cc:38
Destinations & destinations_
Definition: connection.h:223
std::error_code last_ec_
Definition: connection.h:228
net::steady_timer connect_timer_
Definition: connection.h:232
stdx::expected< void, std::error_code > resolve()
Definition: connection.cc:55
server_protocol_type::endpoint server_endpoint_
Definition: connection.h:220
Function
Definition: connection.h:168
stdx::expected< void, std::error_code > init_endpoint()
Definition: connection.cc:85
std::string destination_id() const
Definition: connection.h:183
stdx::expected< void, std::error_code > connected()
Definition: connection.cc:219
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:161
void destination_id(std::string id)
Definition: connection.h:182
bool connect_timed_out_
Definition: connection.h:234
void on_connect_success(std::function< void(std::string, uint16_t)> func)
Definition: connection.h:190
Destinations::iterator destinations_it_
Definition: connection.h:224
net::ip::tcp::resolver::results_type endpoints_
Definition: connection.h:225
bool connect_timed_out() const
Definition: connection.h:180
std::function< bool(std::string, uint16_t)> on_is_destination_good_
Definition: connection.h:240
Function func_
Definition: connection.h:230
server_protocol_type::socket & socket()
Definition: connection.h:173
net::ip::tcp::resolver resolver_
Definition: connection.h:218
bool is_destination_good(const std::string &hostname, uint16_t port) const
Definition: connection.h:198
void on_is_destination_good(std::function< bool(std::string, uint16_t)> func)
Definition: connection.h:194
stdx::expected< void, std::error_code > next_destination()
Definition: connection.cc:251
net::io_context & io_ctx_
Definition: connection.h:216
stdx::expected< void, std::error_code > try_connect()
Definition: connection.cc:104
std::string destination_id_
Definition: connection.h:235
net::ip::tcp::resolver::results_type::iterator endpoints_it_
Definition: connection.h:226
stdx::expected< void, std::error_code > connect_finish()
Definition: connection.cc:186
server_protocol_type::socket server_sock_
Definition: connection.h:219
stdx::expected< void, std::error_code > next_endpoint()
Definition: connection.cc:231
void on_connect_failure(std::function< void(std::string, uint16_t, std::error_code)> func)
Definition: connection.h:185
RouteDestination * route_destination_
Definition: connection.h:222
Definition: connection.h:244
stdx::expected< ConnectionType, std::error_code > connect()
Definition: connection.h:248
A forward iterable container of destinations.
Definition: destination.h:97
typename container_type::iterator iterator
Definition: destination.h:101
Monitor pattern.
Definition: monitor.h:39
Definition: connection.h:43
virtual std::string get_destination_id() const =0
void accepted()
Definition: connection.cc:278
MySQLRoutingConnectionBase(MySQLRoutingContext &context, std::function< void(MySQLRoutingConnectionBase *)> remove_callback)
Definition: connection.h:45
clock_type::time_point time_point_type
Definition: connection.h:82
virtual void connected()
Definition: connection.cc:283
const MySQLRoutingContext & context() const
Definition: connection.h:53
time_point_type get_started() const
Definition: connection.h:84
Stats get_stats() const
Definition: connection.h:111
std::size_t get_bytes_down() const
Definition: connection.h:77
std::chrono::system_clock clock_type
Definition: connection.h:81
void transfered_to_server(size_t bytes)
Definition: connection.h:115
std::size_t get_bytes_up() const
Definition: connection.h:73
Monitor< bool > disconnect_
Definition: connection.h:154
void disassociate()
Definition: connection.h:131
Monitor< Stats > stats_
Definition: connection.h:152
virtual void disconnect()=0
time_point_type get_connected_to_server() const
Definition: connection.h:88
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:150
virtual std::string get_client_address() const =0
Returns address of client which connected to router.
virtual ~MySQLRoutingConnectionBase()=default
MySQLRoutingContext & context()
Definition: connection.h:52
void transfered_to_client(size_t bytes)
Definition: connection.h:123
time_point_type get_last_received_from_server() const
Definition: connection.h:96
time_point_type get_last_sent_to_server() const
Definition: connection.h:92
auto disconnect_request(F &&f)
Definition: connection.h:138
bool disconnect_requested() const
Definition: connection.h:142
MySQLRoutingContext & context_
wrapper for common data used by all routing threads
Definition: connection.h:148
MySQLRoutingContext holds data used by MySQLRouting (1 per plugin instances) and MySQLRoutingConnecti...
Definition: context.h:59
Definition: connection.h:276
stdx::expected< ConnectionType, std::error_code > connect()
Definition: connection.h:286
pool_lookup_cb pool_lookup_
Definition: connection.h:322
std::optional< ConnectionType > probe_pool()
Definition: connection.h:318
PooledConnector(net::io_context &io_ctx, RouteDestination *route_destination, Destinations &destinations, pool_lookup_cb pool_lookup)
Definition: connection.h:281
std::function< std::optional< ConnectionType >(const server_protocol_type::endpoint &ep)> pool_lookup_cb
Definition: connection.h:279
Manage destinations for a Connection Routing.
Definition: destination.h:188
Definition: socket.h:1144
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:944
struct stats stats
Definition: mysqlslap.cc:236
bool empty(const Histogram &histogram)
Return true if 'histogram' was built on an empty table.
Definition: histogram.h:672
std::error_code make_error_code(DynamicLoaderErrc ec)
make error_code from a DynamicLoaderErrc.
Definition: dynamic_loader.cc:79
Definition: gcs_xcom_synode.h:64
required uint64 port
Definition: replication_asynchronous_connection_failover.proto:33
Definition: connection.h:101
time_point_type started
Definition: connection.h:105
time_point_type last_sent_to_server
Definition: connection.h:107
time_point_type connected_to_server
Definition: connection.h:106
std::size_t bytes_down
Definition: connection.h:103
time_point_type last_received_from_server
Definition: connection.h:108
std::size_t bytes_up
Definition: connection.h:102
Definition: mysqlslap.cc:238
unsigned long id[MAX_DEAD]
Definition: xcom_base.cc:510