MySQL 8.4.2
Source Code Documentation
LazyConnector Class Reference

attach a server connection and initialize it. More...

#include <classic_lazy_connect.h>

Inheritance diagram for LazyConnector:
[legend]

Classes

struct  RequiredConnectionAttributes
 

Public Types

enum class  Stage {
  FromStash , Connect , Connected , Authenticated ,
  FetchUserAttrs , FetchUserAttrsDone , SendAuthOk , SetVars ,
  SetVarsDone , SetServerOption , SetServerOptionDone , SetSchema ,
  SetSchemaDone , FetchSysVars , FetchSysVarsDone , WaitGtidExecuted ,
  WaitGtidExecutedDone , SetTrxCharacteristics , SetTrxCharacteristicsDone , PoolOrClose ,
  FallbackToWrite , Done
}
 
- Public Types inherited from BasicProcessor
enum class  Result {
  Again , RecvFromClient , SendToClient , RecvFromServer ,
  RecvFromBoth , SendToServer , SendableToServer , Suspend ,
  Done , Void
}
 

Public Member Functions

 LazyConnector (MysqlRoutingClassicConnectionBase *conn, bool in_handshake, std::function< void(const classic_protocol::message::server::Error &err)> on_error, TraceEvent *parent_event)
 create a lazy-connector. More...
 
stdx::expected< Processor::Result, std::error_code > process () override
 
void stage (Stage stage)
 
Stage stage () const
 
void failed (const std::optional< classic_protocol::message::server::Error > &err)
 
std::optional< classic_protocol::message::server::Errorfailed () const
 
- Public Member Functions inherited from Processor
 BasicProcessor (MysqlRoutingClassicConnectionBase *conn)
 
- Public Member Functions inherited from BasicProcessor
 BasicProcessor (MysqlRoutingClassicConnectionBase *conn)
 
virtual ~BasicProcessor ()=default
 
const MysqlRoutingClassicConnectionBaseconnection () const
 
MysqlRoutingClassicConnectionBaseconnection ()
 

Private Member Functions

stdx::expected< Processor::Result, std::error_code > from_stash ()
 
stdx::expected< Processor::Result, std::error_code > connect ()
 
stdx::expected< Processor::Result, std::error_code > connected ()
 the handshake part. More...
 
stdx::expected< Processor::Result, std::error_code > authenticated ()
 
stdx::expected< Processor::Result, std::error_code > fetch_user_attrs ()
 
stdx::expected< Processor::Result, std::error_code > fetch_user_attrs_done ()
 
stdx::expected< Processor::Result, std::error_code > send_auth_ok ()
 
stdx::expected< Processor::Result, std::error_code > set_vars ()
 
stdx::expected< Processor::Result, std::error_code > set_vars_done ()
 
stdx::expected< Processor::Result, std::error_code > set_server_option ()
 
stdx::expected< Processor::Result, std::error_code > set_server_option_done ()
 
stdx::expected< Processor::Result, std::error_code > set_schema ()
 
stdx::expected< Processor::Result, std::error_code > set_schema_done ()
 
stdx::expected< Processor::Result, std::error_code > fetch_sys_vars ()
 
stdx::expected< Processor::Result, std::error_code > fetch_sys_vars_done ()
 
stdx::expected< Processor::Result, std::error_code > wait_gtid_executed ()
 
stdx::expected< Processor::Result, std::error_code > wait_gtid_executed_done ()
 
stdx::expected< Processor::Result, std::error_code > set_trx_characteristics ()
 
stdx::expected< Processor::Result, std::error_code > set_trx_characteristics_done ()
 
stdx::expected< Processor::Result, std::error_code > pool_or_close ()
 
stdx::expected< Processor::Result, std::error_code > fallback_to_write ()
 

Private Attributes

Stage stage_ {Stage::FromStash}
 
bool in_handshake_
 
RouterRequireFetcher::Result required_connection_attributes_fetcher_result_
 
std::function< void(const classic_protocol::message::server::Error &err)> on_error_
 
bool retry_connect_ {false}
 
bool already_fallback_ {false}
 
std::chrono::steady_clock::time_point started_
 
std::optional< classic_protocol::message::server::Errorfailed_
 
std::string trx_stmt_
 
TraceEventparent_event_ {}
 
TraceEventtrace_event_connect_ {}
 
TraceEventtrace_event_authenticate_ {}
 
TraceEventtrace_event_set_vars_ {}
 
TraceEventtrace_event_fetch_sys_vars_ {}
 
TraceEventtrace_event_set_schema_ {}
 
TraceEventtrace_event_wait_gtid_executed_ {}
 
TraceEventtrace_event_check_read_only_ {}
 
TraceEventtrace_event_fallback_to_write_ {}
 
TraceEventtrace_event_set_trx_characteristics_ {}
 

Additional Inherited Members

- Static Public Attributes inherited from ForwardingProcessor
static constexpr const std::chrono::milliseconds kConnectRetryInterval
 interval between connect-retries. More...
 
- Protected Member Functions inherited from ForwardingProcessor
stdx::expected< Result, std::error_code > forward_server_to_client (bool noflush=false)
 forward the current packet from the server-side to the client-side. More...
 
stdx::expected< Result, std::error_code > forward_client_to_server (bool noflush=false)
 forward the current packet from the client-side to the server-side. More...
 
stdx::expected< Processor::Result, std::error_code > skip_or_inject_end_of_columns (bool no_flush=false)
 adjust the end-of-columns packet. More...
 
stdx::expected< bool, std::error_code > pool_server_connection ()
 move the server connection to the pool. More...
 
stdx::expected< Processor::Result, std::error_code > socket_reconnect_start (TraceEvent *parent_event)
 reconnect a socket. More...
 
stdx::expected< Processor::Result, std::error_code > mysql_reconnect_start (TraceEvent *parent_event)
 reconnect a mysql classic connection. More...
 
stdx::expected< Result, std::error_code > recv_server_failed_and_check_client_socket (std::error_code ec)
 handle error-code of a failed receive() from the server-socket and check the status of the client socket. More...
 
stdx::expected< Processor::Result, std::error_code > reconnect_send_error_msg (Channel &src_channel, ClassicProtocolState &src_protocol)
 send a Error msg based on the reconnect_error(). More...
 
template<class Proto >
stdx::expected< Processor::Result, std::error_code > reconnect_send_error_msg (TlsSwitchableConnection< Proto > &conn)
 
void reconnect_error (classic_protocol::message::server::Error err)
 set the reconnect error. More...
 
classic_protocol::message::server::Error reconnect_error () const
 get the reconnect error. More...
 
- Protected Member Functions inherited from Processor
stdx::expected< Result, std::error_code > send_server_failed (std::error_code ec)
 
stdx::expected< Result, std::error_code > recv_server_failed (std::error_code ec)
 
stdx::expected< Result, std::error_code > send_client_failed (std::error_code ec)
 
stdx::expected< Result, std::error_code > recv_client_failed (std::error_code ec)
 
stdx::expected< Result, std::error_code > server_socket_failed (std::error_code ec)
 
stdx::expected< Result, std::error_code > client_socket_failed (std::error_code ec)
 
stdx::expected< void, std::error_code > discard_current_msg (Channel &src_channel, ClassicProtocolState &src_protocol)
 discard to current message. More...
 
template<class Proto >
stdx::expected< void, std::error_code > discard_current_msg (TlsSwitchableConnection< Proto > &conn)
 
void trace (Tracer::Event e)
 
Tracertracer ()
 
TraceEventtrace_span (TraceEvent *parent_span, const std::string_view &prefix)
 start a span. More...
 
void trace_span_end (TraceEvent *event, TraceEvent::StatusCode status_code=TraceEvent::StatusCode::kUnset)
 end a span and set a status-code. More...
 
TraceEventtrace_command (const std::string_view &prefix)
 start a command span. More...
 
TraceEventtrace_connect_and_forward_command (TraceEvent *parent_span)
 start a connect-and-forward span. More...
 
TraceEventtrace_connect (TraceEvent *parent_span)
 start a connect span. More...
 
void trace_set_connection_attributes (TraceEvent *ev)
 start a connect span. More...
 
TraceEventtrace_forward_command (TraceEvent *parent_span)
 start a forward span. More...
 
void trace_command_end (TraceEvent *event, TraceEvent::StatusCode status_code=TraceEvent::StatusCode::kUnset)
 end a command span and set a status-code. More...
 
- Static Protected Member Functions inherited from ForwardingProcessor
template<class T >
static bool message_can_be_forwarded_as_is (ClassicProtocolState &src_protocol, ClassicProtocolState &dst_protocol, const T &msg)
 check of the capabilities of the source and the destination are the same for this message. More...
 
static bool connect_error_is_transient (const classic_protocol::message::server::Error &err)
 check if the error is a transient error. More...
 
- Static Protected Member Functions inherited from Processor
static void log_fatal_error_code (const char *msg, std::error_code ec)
 log a message with error-code as error. More...
 

Detailed Description

attach a server connection and initialize it.

  • if a server-connection is attached to the client connection, leave.
  • otherwise,
    • if a connection can be taken from the pool, take it.
    • otherwise, connect to the server and authenticate.
  • set tracking session-vars
  • set the client's schema, if it differs from the server-connection's.

Precondition:

  • the client's cleartext password must be known.

Member Enumeration Documentation

◆ Stage

enum class LazyConnector::Stage
strong
Enumerator
FromStash 
Connect 
Connected 
Authenticated 
FetchUserAttrs 
FetchUserAttrsDone 
SendAuthOk 
SetVars 
SetVarsDone 
SetServerOption 
SetServerOptionDone 
SetSchema 
SetSchemaDone 
FetchSysVars 
FetchSysVarsDone 
WaitGtidExecuted 
WaitGtidExecutedDone 
SetTrxCharacteristics 
SetTrxCharacteristicsDone 
PoolOrClose 
FallbackToWrite 
Done 

Constructor & Destructor Documentation

◆ LazyConnector()

LazyConnector::LazyConnector ( MysqlRoutingClassicConnectionBase conn,
bool  in_handshake,
std::function< void(const classic_protocol::message::server::Error &err)>  on_error,
TraceEvent parent_event 
)
inline

create a lazy-connector.

Parameters
conna connection handle
in_handshakeif true, the client connection is in Greeting or ChangeUser right now.
on_errorfunction that's called if an error happened.
parent_eventparent event for the tracer

If "in_handshake" the LazyConnector may ask the client for a "auth-method-switch" or a "plaintext-password".

Member Function Documentation

◆ authenticated()

stdx::expected< Processor::Result, std::error_code > LazyConnector::authenticated ( )
private

◆ connect()

stdx::expected< Processor::Result, std::error_code > LazyConnector::connect ( )
private

◆ connected()

stdx::expected< Processor::Result, std::error_code > LazyConnector::connected ( )
private

the handshake part.

◆ failed() [1/2]

std::optional< classic_protocol::message::server::Error > LazyConnector::failed ( ) const
inline

◆ failed() [2/2]

void LazyConnector::failed ( const std::optional< classic_protocol::message::server::Error > &  err)
inline

◆ fallback_to_write()

stdx::expected< Processor::Result, std::error_code > LazyConnector::fallback_to_write ( )
private

◆ fetch_sys_vars()

stdx::expected< Processor::Result, std::error_code > LazyConnector::fetch_sys_vars ( )
private

◆ fetch_sys_vars_done()

stdx::expected< Processor::Result, std::error_code > LazyConnector::fetch_sys_vars_done ( )
private

◆ fetch_user_attrs()

stdx::expected< Processor::Result, std::error_code > LazyConnector::fetch_user_attrs ( )
private

◆ fetch_user_attrs_done()

stdx::expected< Processor::Result, std::error_code > LazyConnector::fetch_user_attrs_done ( )
private

◆ from_stash()

stdx::expected< Processor::Result, std::error_code > LazyConnector::from_stash ( )
private

◆ pool_or_close()

stdx::expected< Processor::Result, std::error_code > LazyConnector::pool_or_close ( )
private

◆ process()

stdx::expected< Processor::Result, std::error_code > LazyConnector::process ( )
overridevirtual

Implements BasicProcessor.

◆ send_auth_ok()

stdx::expected< Processor::Result, std::error_code > LazyConnector::send_auth_ok ( )
private

◆ set_schema()

stdx::expected< Processor::Result, std::error_code > LazyConnector::set_schema ( )
private

◆ set_schema_done()

stdx::expected< Processor::Result, std::error_code > LazyConnector::set_schema_done ( )
private

◆ set_server_option()

stdx::expected< Processor::Result, std::error_code > LazyConnector::set_server_option ( )
private

◆ set_server_option_done()

stdx::expected< Processor::Result, std::error_code > LazyConnector::set_server_option_done ( )
private

◆ set_trx_characteristics()

stdx::expected< Processor::Result, std::error_code > LazyConnector::set_trx_characteristics ( )
private

◆ set_trx_characteristics_done()

stdx::expected< Processor::Result, std::error_code > LazyConnector::set_trx_characteristics_done ( )
private

◆ set_vars()

stdx::expected< Processor::Result, std::error_code > LazyConnector::set_vars ( )
private

◆ set_vars_done()

stdx::expected< Processor::Result, std::error_code > LazyConnector::set_vars_done ( )
private

◆ stage() [1/2]

Stage LazyConnector::stage ( ) const
inline

◆ stage() [2/2]

void LazyConnector::stage ( Stage  stage)
inline

◆ wait_gtid_executed()

stdx::expected< Processor::Result, std::error_code > LazyConnector::wait_gtid_executed ( )
private

◆ wait_gtid_executed_done()

stdx::expected< Processor::Result, std::error_code > LazyConnector::wait_gtid_executed_done ( )
private

Member Data Documentation

◆ already_fallback_

bool LazyConnector::already_fallback_ {false}
private

◆ failed_

std::optional<classic_protocol::message::server::Error> LazyConnector::failed_
private

◆ in_handshake_

bool LazyConnector::in_handshake_
private

◆ on_error_

std::function<void(const classic_protocol::message::server::Error &err)> LazyConnector::on_error_
private

◆ parent_event_

TraceEvent* LazyConnector::parent_event_ {}
private

◆ required_connection_attributes_fetcher_result_

RouterRequireFetcher::Result LazyConnector::required_connection_attributes_fetcher_result_
private

◆ retry_connect_

bool LazyConnector::retry_connect_ {false}
private

◆ stage_

Stage LazyConnector::stage_ {Stage::FromStash}
private

◆ started_

std::chrono::steady_clock::time_point LazyConnector::started_
private
Initial value:
{
std::chrono::steady_clock::now()}

◆ trace_event_authenticate_

TraceEvent* LazyConnector::trace_event_authenticate_ {}
private

◆ trace_event_check_read_only_

TraceEvent* LazyConnector::trace_event_check_read_only_ {}
private

◆ trace_event_connect_

TraceEvent* LazyConnector::trace_event_connect_ {}
private

◆ trace_event_fallback_to_write_

TraceEvent* LazyConnector::trace_event_fallback_to_write_ {}
private

◆ trace_event_fetch_sys_vars_

TraceEvent* LazyConnector::trace_event_fetch_sys_vars_ {}
private

◆ trace_event_set_schema_

TraceEvent* LazyConnector::trace_event_set_schema_ {}
private

◆ trace_event_set_trx_characteristics_

TraceEvent* LazyConnector::trace_event_set_trx_characteristics_ {}
private

◆ trace_event_set_vars_

TraceEvent* LazyConnector::trace_event_set_vars_ {}
private

◆ trace_event_wait_gtid_executed_

TraceEvent* LazyConnector::trace_event_wait_gtid_executed_ {}
private

◆ trx_stmt_

std::string LazyConnector::trx_stmt_
private

The documentation for this class was generated from the following files: