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) {
450 std::optional<classic_protocol::session_track::TransactionCharacteristics>
456 std::optional<classic_protocol::session_track::TransactionCharacteristics>
461 std::optional<classic_protocol::session_track::TransactionState>
trx_state()
484 std::optional<classic_protocol::session_track::TransactionState>
trx_state_;
485 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:432
ClientSideConnection client_conn_
Definition: classic_connection_base.h:470
std::optional< classic_protocol::session_track::TransactionCharacteristics > trx_characteristics_
Definition: classic_connection_base.h:486
bool wait_for_my_writes_
Definition: classic_connection_base.h:579
bool authenticated_
Definition: classic_connection_base.h:380
RouteDestination * destinations()
Definition: classic_connection_base.h:439
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:565
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:451
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:1000
TraceSpan events_
Definition: classic_connection_base.h:555
bool connection_sharing_possible() const
check if connection sharing is possible.
Definition: classic_connection_base.cc:844
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:489
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:493
void async_wait_client_closed()
virtual void stash_server_conn()
Definition: classic_connection_base.cc:1033
void on_handshake_received()
Definition: classic_connection_base.cc:100
void recv_server_failed(std::error_code ec, bool call_finish=true)
Definition: classic_connection_base.cc:139
Destinations destinations_
Definition: classic_connection_base.h:468
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:476
std::optional< classic_protocol::session_track::TransactionState > trx_state() const
Definition: classic_connection_base.h:461
void pop_processor()
Definition: classic_connection_base.h:199
void current_server_mode(mysqlrouter::ServerMode v)
Definition: classic_connection_base.h:417
void async_recv_server(Function next)
Definition: classic_connection_base.cc:289
virtual void async_run()
Definition: classic_connection_base.h:134
ExecutionContext exec_ctx_
Definition: classic_connection_base.h:500
void trx_characteristics(std::optional< classic_protocol::session_track::TransactionCharacteristics > trx_chars)
Definition: classic_connection_base.h:455
void wait_for_my_writes(bool v)
Definition: classic_connection_base.h:424
net::steady_timer connect_timer_
Definition: classic_connection_base.h:546
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:62
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:166
void call_next_function(Function next)
Definition: classic_connection_base.h:164
bool diagnostic_area_changed_
Definition: classic_connection_base.h:550
void collation_connection_maybe_dirty(bool val)
Definition: classic_connection_base.h:442
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:512
void send_client_failed(std::error_code ec, bool call_finish=true)
Definition: classic_connection_base.cc:148
bool connection_sharing_allowed() const
check if connection sharing is allowed.
Definition: classic_connection_base.cc:955
void has_transient_error_at_connect(bool val)
Definition: classic_connection_base.h:536
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:540
SslMode source_ssl_mode() const
Definition: classic_connection_base.h:116
mysqlrouter::ServerMode current_server_mode() const
Definition: classic_connection_base.h:420
void async_send_server(Function next)
Definition: classic_connection_base.cc:262
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:485
void trace_and_call_function(Tracer::Event::Direction dir, std::string_view stage, Function func)
Definition: classic_connection_base.cc:794
std::string connection_sharing_blocked_by() const
Definition: classic_connection_base.cc:962
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:474
virtual void client_socket_failed(std::error_code ec, bool call_finish=true)
Definition: classic_connection_base.cc:183
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:514
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:484
void async_send_client(Function next)
Definition: classic_connection_base.cc:212
void on_handshake_aborted()
Definition: classic_connection_base.cc:113
std::shared_ptr< MysqlRoutingClassicConnectionBase > getptr()
Definition: classic_connection_base.h:103
void disconnect() override
Definition: classic_connection_base.cc:398
Destinations & current_destinations()
Definition: classic_connection_base.h:440
bool some_state_changed_
Definition: classic_connection_base.h:487
bool requires_tls_
Definition: classic_connection_base.h:491
int active_work_
Definition: classic_connection_base.h:378
std::string rw_destination_id_
Definition: classic_connection_base.h:473
void gtid_at_least_executed(const std::string >id)
Definition: classic_connection_base.h:427
TraceSpan & events()
Definition: classic_connection_base.h:523
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:239
void connection_sharing_allowed_reset()
reset the connection-sharing state.
Definition: classic_connection_base.cc:994
void send_server_failed(std::error_code ec, bool call_finish=true)
Definition: classic_connection_base.cc:130
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:420
void async_wait_send_server(Function next)
Definition: classic_connection_base.cc:381
FromEither
Definition: classic_connection_base.h:525
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:587
RouteDestination * route_destination_
Definition: classic_connection_base.h:467
FromEither recv_from_either_
Definition: classic_connection_base.h:552
void push_processor(std::unique_ptr< BasicProcessor > processor)
Definition: classic_connection_base.h:195
FromEither recv_from_either() const
Definition: classic_connection_base.h:534
mysqlrouter::ServerMode current_server_mode_
Definition: classic_connection_base.h:575
std::string gtid_at_least_executed_
Definition: classic_connection_base.h:582
bool in_handshake_
client side handshake isn't finished yet.
Definition: classic_connection_base.h:482
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:477
std::error_code connect_ec_
Definition: classic_connection_base.h:548
ExecutionContext & execution_context()
Definition: classic_connection_base.h:496
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:511
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:522
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:308
void loop()
Definition: classic_connection_base.cc:804
void recv_from_either(FromEither v)
Definition: classic_connection_base.h:532
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:425
std::chrono::seconds wait_for_my_writes_timeout_
Definition: classic_connection_base.h:585
virtual void done()
Definition: classic_connection_base.cc:482
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:545
Tracer tracer_
Definition: classic_connection_base.h:508
void recv_client_failed(std::error_code ec, bool call_finish=true)
Definition: classic_connection_base.cc:157
void finish()
Definition: classic_connection_base.cc:434
ServerSideConnection server_conn_
Definition: classic_connection_base.h:471
void diagnostic_area_changed(bool diagnostic_area_changed)
Definition: classic_connection_base.h:517
Function
Definition: classic_connection_base.h:158
const ExecutionContext & execution_context() const
Definition: classic_connection_base.h:497
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:505
void trace(Tracer::Event e)
Definition: classic_connection_base.h:503
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:520
void wait_for_my_writes_timeout(std::chrono::seconds timeout)
Definition: classic_connection_base.h:435
std::error_code connect_error_code() const
Definition: classic_connection_base.h:515
std::string gtid_at_least_executed() const
Definition: classic_connection_base.h:430
bool collation_connection_maybe_dirty() const
Definition: classic_connection_base.h:446
Manage destinations for a Connection Routing.
Definition: destination.h:189
Definition: classic_protocol_state.h:406
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:50
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