26#ifndef ROUTING_CLASSIC_CONNECTION_BASE_INCLUDED
27#define ROUTING_CLASSIC_CONNECTION_BASE_INCLUDED
34#include <unordered_map>
56 public std::enable_shared_from_this<MysqlRoutingClassicConnectionBase> {
63 std::unique_ptr<ConnectionBase> client_connection,
64 std::unique_ptr<RoutingConnectionBase> client_routing_connection,
72 std::move(client_routing_connection),
90 template <
typename... Args>
91 [[nodiscard]]
static std::shared_ptr<MysqlRoutingClassicConnectionBase>
98 return std::shared_ptr<MysqlRoutingClassicConnectionBase>(
103 std::shared_ptr<MysqlRoutingClassicConnectionBase>
getptr() {
104 return shared_from_this();
108 std::vector<uint8_t> &error_frame,
const uint8_t seq_id,
110 const uint16_t error_code,
const std::string &msg,
111 const std::string &sql_state);
147 bool call_finish =
true);
196 return processors_.push_back(std::move(processor));
204 bool ignore_some_state_changed =
false);
213 std::string_view stage,
Function func);
322 const std::optional<net::ip::tcp::endpoint> &ep) {
332 const std::optional<net::ip::tcp::endpoint> &ep) {
443 std::optional<classic_protocol::session_track::TransactionCharacteristics>
449 std::optional<classic_protocol::session_track::TransactionCharacteristics>
454 std::optional<classic_protocol::session_track::TransactionState>
trx_state()
477 std::optional<classic_protocol::session_track::TransactionState>
trx_state_;
478 std::optional<classic_protocol::session_track::TransactionCharacteristics>
Kerberos Client Authentication nullptr
Definition: auth_kerberos_client_plugin.cc:251
A forward iterable container of destinations.
Definition: destination.h:107
execution context for SQL.
Definition: sql_exec_context.h:39
Definition: connection.h:44
MySQLRoutingContext & context()
Definition: connection.h:53
MySQLRoutingContext holds data used by MySQLRouting (1 per plugin instances) and MySQLRoutingConnecti...
Definition: context.h:59
Definition: classic_connection_base.h:56
std::chrono::seconds wait_for_my_writes_timeout() const
Definition: classic_connection_base.h:425
ClientSideConnection client_conn_
Definition: classic_connection_base.h:463
std::optional< classic_protocol::session_track::TransactionCharacteristics > trx_characteristics_
Definition: classic_connection_base.h:479
bool wait_for_my_writes_
Definition: classic_connection_base.h:559
bool authenticated_
Definition: classic_connection_base.h:380
RouteDestination * destinations()
Definition: classic_connection_base.h:432
void destination_id(const std::string &id)
Definition: classic_connection_base.h:284
const ServerSideConnection::protocol_state_type & server_protocol() const
Definition: classic_connection_base.h:266
mysqlrouter::ServerMode expected_server_mode_
Definition: classic_connection_base.h:555
void requires_client_cert(bool v)
set if the server-connection requires a client cert
Definition: classic_connection_base.h:403
std::optional< classic_protocol::session_track::TransactionCharacteristics > trx_characteristics() const
Definition: classic_connection_base.h:444
const ClientSideConnection::protocol_state_type & client_protocol() const
Definition: classic_connection_base.h:258
void reset_to_initial()
reset the connection's settings to the initial-values.
Definition: classic_connection_base.cc:996
TraceSpan events_
Definition: classic_connection_base.h:548
bool connection_sharing_possible() const
check if connection sharing is possible.
Definition: classic_connection_base.cc:840
bool authenticated() const
check if the connection is authenticated.
Definition: classic_connection_base.h:345
bool collation_connection_maybe_dirty_
Definition: classic_connection_base.h:482
std::optional< net::ip::tcp::endpoint > read_write_destination_endpoint() const override
Definition: classic_connection_base.h:326
bool requires_client_cert_
Definition: classic_connection_base.h:486
void async_wait_client_closed()
virtual void stash_server_conn()
Definition: classic_connection_base.cc:1029
void on_handshake_received()
Definition: classic_connection_base.cc:96
void recv_server_failed(std::error_code ec, bool call_finish=true)
Definition: classic_connection_base.cc:135
Destinations destinations_
Definition: classic_connection_base.h:461
void destination_endpoint(const std::optional< net::ip::tcp::endpoint > &ep)
Definition: classic_connection_base.h:311
std::optional< net::ip::tcp::endpoint > rw_destination_endpoint_
Definition: classic_connection_base.h:469
std::optional< classic_protocol::session_track::TransactionState > trx_state() const
Definition: classic_connection_base.h:454
void pop_processor()
Definition: classic_connection_base.h:199
void async_recv_server(Function next)
Definition: classic_connection_base.cc:285
virtual void async_run()
Definition: classic_connection_base.h:134
ExecutionContext exec_ctx_
Definition: classic_connection_base.h:493
void trx_characteristics(std::optional< classic_protocol::session_track::TransactionCharacteristics > trx_chars)
Definition: classic_connection_base.h:448
void wait_for_my_writes(bool v)
Definition: classic_connection_base.h:417
net::steady_timer connect_timer_
Definition: classic_connection_base.h:539
static stdx::expected< size_t, std::error_code > encode_error_packet(std::vector< uint8_t > &error_frame, const uint8_t seq_id, const classic_protocol::capabilities::value_type caps, const uint16_t error_code, const std::string &msg, const std::string &sql_state)
Definition: classic_connection_base.cc:58
std::optional< net::ip::tcp::endpoint > destination_endpoint() const override
Definition: classic_connection_base.h:305
void server_socket_failed(std::error_code ec, bool call_finish=true)
Definition: classic_connection_base.cc:162
void call_next_function(Function next)
Definition: classic_connection_base.h:164
bool diagnostic_area_changed_
Definition: classic_connection_base.h:543
void collation_connection_maybe_dirty(bool val)
Definition: classic_connection_base.h:435
ServerSideConnection & server_conn()
Definition: classic_connection_base.h:273
void authenticated(bool v)
Definition: classic_connection_base.h:346
net::steady_timer & connect_timer()
Definition: classic_connection_base.h:505
void send_client_failed(std::error_code ec, bool call_finish=true)
Definition: classic_connection_base.cc:144
bool connection_sharing_allowed() const
check if connection sharing is allowed.
Definition: classic_connection_base.cc:951
void has_transient_error_at_connect(bool val)
Definition: classic_connection_base.h:529
bool requires_tls() const
get if the server-connection requires TLS
Definition: classic_connection_base.h:400
bool has_transient_error_at_connect() const
Definition: classic_connection_base.h:533
SslMode source_ssl_mode() const
Definition: classic_connection_base.h:116
void async_send_server(Function next)
Definition: classic_connection_base.cc:258
stdx::expected< void, std::error_code > track_session_changes(net::const_buffer session_trackers, classic_protocol::capabilities::value_type caps, bool ignore_some_state_changed=false)
Definition: classic_connection_base.cc:481
void trace_and_call_function(Tracer::Event::Direction dir, std::string_view stage, Function func)
Definition: classic_connection_base.cc:790
std::string connection_sharing_blocked_by() const
Definition: classic_connection_base.cc:958
std::string read_only_destination_id() const override
Definition: classic_connection_base.h:290
const ClientSideConnection & client_conn() const
Definition: classic_connection_base.h:271
std::string ro_destination_id_
Definition: classic_connection_base.h:467
virtual void client_socket_failed(std::error_code ec, bool call_finish=true)
Definition: classic_connection_base.cc:179
ServerSideConnection::protocol_state_type & server_protocol()
Definition: classic_connection_base.h:262
void async_send_client_and_finish()
void read_write_destination_id(const std::string &destination_id)
Definition: classic_connection_base.h:301
void connect_error_code(const std::error_code &ec)
Definition: classic_connection_base.h:507
std::optional< net::ip::tcp::endpoint > read_only_destination_endpoint() const override
Definition: classic_connection_base.h:317
std::optional< classic_protocol::session_track::TransactionState > trx_state_
Definition: classic_connection_base.h:477
void async_send_client(Function next)
Definition: classic_connection_base.cc:208
void on_handshake_aborted()
Definition: classic_connection_base.cc:109
std::shared_ptr< MysqlRoutingClassicConnectionBase > getptr()
Definition: classic_connection_base.h:103
void disconnect() override
Definition: classic_connection_base.cc:394
Destinations & current_destinations()
Definition: classic_connection_base.h:433
bool some_state_changed_
Definition: classic_connection_base.h:480
bool requires_tls_
Definition: classic_connection_base.h:484
int active_work_
Definition: classic_connection_base.h:378
std::string rw_destination_id_
Definition: classic_connection_base.h:466
void gtid_at_least_executed(const std::string >id)
Definition: classic_connection_base.h:420
TraceSpan & events()
Definition: classic_connection_base.h:516
static std::shared_ptr< MysqlRoutingClassicConnectionBase > create(Args &&... args)
Definition: classic_connection_base.h:92
void requires_tls(bool v)
set if the server-connection requires TLS
Definition: classic_connection_base.h:397
SslMode dest_ssl_mode() const
Definition: classic_connection_base.h:118
void async_recv_client(Function next)
Definition: classic_connection_base.cc:235
void connection_sharing_allowed_reset()
reset the connection-sharing state.
Definition: classic_connection_base.cc:990
void send_server_failed(std::error_code ec, bool call_finish=true)
Definition: classic_connection_base.cc:126
void some_state_changed(bool v)
Definition: classic_connection_base.h:408
bool requires_client_cert() const
get if the server-connection requires a client cert
Definition: classic_connection_base.h:406
void server_side_client_greeting()
Definition: classic_connection_base.cc:416
void async_wait_send_server(Function next)
Definition: classic_connection_base.cc:377
FromEither
Definition: classic_connection_base.h:518
void expected_server_mode(mysqlrouter::ServerMode v)
Definition: classic_connection_base.h:410
std::vector< std::unique_ptr< BasicProcessor > > processors_
Definition: classic_connection_base.h:192
bool has_transient_error_at_connect_
Definition: classic_connection_base.h:567
RouteDestination * route_destination_
Definition: classic_connection_base.h:460
FromEither recv_from_either_
Definition: classic_connection_base.h:545
void push_processor(std::unique_ptr< BasicProcessor > processor)
Definition: classic_connection_base.h:195
FromEither recv_from_either() const
Definition: classic_connection_base.h:527
std::string gtid_at_least_executed_
Definition: classic_connection_base.h:562
bool in_handshake_
client side handshake isn't finished yet.
Definition: classic_connection_base.h:475
void read_only_destination_endpoint(const std::optional< net::ip::tcp::endpoint > &ep)
Definition: classic_connection_base.h:321
std::optional< net::ip::tcp::endpoint > ro_destination_endpoint_
Definition: classic_connection_base.h:470
std::error_code connect_ec_
Definition: classic_connection_base.h:541
ExecutionContext & execution_context()
Definition: classic_connection_base.h:489
net::impl::socket::native_handle_type get_client_fd() const override
Definition: classic_connection_base.h:120
net::steady_timer & read_timer()
Definition: classic_connection_base.h:504
ClientSideConnection::protocol_state_type & client_protocol()
Definition: classic_connection_base.h:254
void read_only_destination_id(const std::string &destination_id)
Definition: classic_connection_base.h:294
const TraceSpan & events() const
Definition: classic_connection_base.h:515
void read_write_destination_endpoint(const std::optional< net::ip::tcp::endpoint > &ep)
Definition: classic_connection_base.h:331
ClientSideConnection & client_conn()
Definition: classic_connection_base.h:270
std::string get_client_address() const override
Returns address of client which connected to router.
Definition: classic_connection_base.h:124
void async_recv_both(Function next)
Definition: classic_connection_base.cc:304
void loop()
Definition: classic_connection_base.cc:800
void recv_from_either(FromEither v)
Definition: classic_connection_base.h:525
const ServerSideConnection & server_conn() const
Definition: classic_connection_base.h:274
std::string get_destination_id() const override
Definition: classic_connection_base.h:278
bool wait_for_my_writes() const
Definition: classic_connection_base.h:418
std::chrono::seconds wait_for_my_writes_timeout_
Definition: classic_connection_base.h:565
virtual void done()
Definition: classic_connection_base.cc:478
void resume()
Definition: classic_connection_base.h:155
std::string get_server_address() const override
Returns address of server to which connection is established.
Definition: classic_connection_base.h:128
net::steady_timer read_timer_
Definition: classic_connection_base.h:538
Tracer tracer_
Definition: classic_connection_base.h:501
void recv_client_failed(std::error_code ec, bool call_finish=true)
Definition: classic_connection_base.cc:153
void finish()
Definition: classic_connection_base.cc:430
ServerSideConnection server_conn_
Definition: classic_connection_base.h:464
void diagnostic_area_changed(bool diagnostic_area_changed)
Definition: classic_connection_base.h:510
Function
Definition: classic_connection_base.h:158
const ExecutionContext & execution_context() const
Definition: classic_connection_base.h:490
std::string read_write_destination_id() const override
Definition: classic_connection_base.h:298
bool greeting_from_router() const
if the router is sending the initial server-greeting.
Definition: classic_connection_base.h:390
mysqlrouter::ServerMode expected_server_mode() const
Definition: classic_connection_base.h:413
Tracer & tracer()
Definition: classic_connection_base.h:498
void trace(Tracer::Event e)
Definition: classic_connection_base.h:496
MysqlRoutingClassicConnectionBase(MySQLRoutingContext &context, RouteDestination *route_destination, std::unique_ptr< ConnectionBase > client_connection, std::unique_ptr< RoutingConnectionBase > client_routing_connection, std::function< void(MySQLRoutingConnectionBase *)> remove_callback)
Definition: classic_connection_base.h:61
bool diagnostic_area_changed() const
Definition: classic_connection_base.h:513
void wait_for_my_writes_timeout(std::chrono::seconds timeout)
Definition: classic_connection_base.h:428
std::error_code connect_error_code() const
Definition: classic_connection_base.h:508
std::string gtid_at_least_executed() const
Definition: classic_connection_base.h:423
bool collation_connection_maybe_dirty() const
Definition: classic_connection_base.h:439
Manage destinations for a Connection Routing.
Definition: destination.h:188
Definition: classic_protocol_state.h:375
typename base_class_::protocol_state_type protocol_state_type
Definition: basic_protocol_splicer.h:91
std::string endpoint() const
Definition: connection_base.h:386
protocol_state_type & protocol()
Definition: connection_base.h:398
net::impl::socket::native_handle_type native_handle() const
Definition: connection_base.h:367
SslMode ssl_mode() const
Definition: connection_base.h:363
Events of a command.
Definition: trace_span.h:77
Direction
Definition: tracer.h:73
traces the timestamps of events in a stderr log.
Definition: tracer.h:49
void trace(Event e)
Definition: tracer.h:128
std::bitset< 32 > value_type
Definition: classic_protocol_constants.h:73
std::string dir
Double write files location.
Definition: buf0dblwr.cc:77
static bool timeout(bool(*wait_condition)())
Timeout function.
Definition: log0meb.cc:498
ServerMode
Definition: datatypes.h:55
int native_handle_type
Definition: socket_constants.h:51
Definition: gcs_xcom_synode.h:64
SslMode
Definition: ssl_mode.h:29
double seconds()
Definition: task.cc:310