MySQL 8.0.39
Source Code Documentation
Srv_session Class Reference

#include <srv_session.h>

Classes

class  Session_backup_and_attach
 
struct  st_err_protocol_ctx
 

Public Types

enum  srv_session_state {
  SRV_SESSION_CREATED , SRV_SESSION_OPENED , SRV_SESSION_ATTACHED , SRV_SESSION_DETACHED ,
  SRV_SESSION_ASSOCIATE , SRV_SESSION_ASSOCIATED , SRV_SESSION_DISASSOCIATED , SRV_SESSION_CLOSED
}
 Enum for the state of the session. More...
 

Public Member Functions

 Srv_session (srv_session_error_cb err_cb, void *err_cb_ctx)
 Constructs a server session. More...
 
 Srv_session (srv_session_error_cb err_cb, void *err_cb_ctx, THD *thd)
 Have a THD object and wish to associate the same to session object. More...
 
 ~Srv_session ()
 
bool open ()
 Opens a server session. More...
 
bool attach ()
 Attaches the session to the current physical thread. More...
 
bool detach ()
 Detaches the session from current physical thread. More...
 
bool close ()
 Closes the session. More...
 
bool is_attached () const
 Returns if the session is in attached state. More...
 
int execute_command (enum enum_server_command command, const union COM_DATA *data, const CHARSET_INFO *client_cs, const struct st_command_service_cbs *command_callbacks, enum cs_text_or_binary text_or_binary, void *callbacks_context)
 Executes a server command. More...
 
THDget_thd ()
 Returns the internal THD object. More...
 
my_thread_id get_session_id () const
 Returns the ID of a session. More...
 
uint16_t get_client_port () const
 Returns the client port. More...
 
void set_client_port (uint16_t port)
 Sets the client port. More...
 
LEX_CSTRING get_current_database () const
 Returns the current database of a session. More...
 
bool set_connection_type (enum_vio_type type)
 Sets the connection type. More...
 

Static Public Member Functions

static bool module_init ()
 Initializes the module. More...
 
static bool module_deinit ()
 Deinitializes the module. More...
 
static bool init_thread (const void *plugin)
 Initializes the current physical thread for use with this class. More...
 
static void deinit_thread ()
 Deinitializes the current physical thread for use with session service. More...
 
static void check_for_stale_threads (const st_plugin_int *plugin)
 Checks if a plugin has left threads and sessions. More...
 
static bool is_valid (const Srv_session *session)
 Checks if the session is valid. More...
 
static unsigned int session_count ()
 Returns the number opened sessions in thread initialized by this class. More...
 
static unsigned int thread_count (const void *plugin_name)
 Returns the number currently running threads initialized by this class. More...
 
static bool is_srv_session_thread ()
 Check if current physical thread was created to be used with this class. More...
 

Private Member Functions

 Srv_session (srv_session_error_cb err_cb, void *err_cb_ctx, srv_session_state state, bool free_resources, THD *thd)
 Delegated constructor to intialize the members. More...
 
void set_attached (const char *stack)
 Sets session's state to attached. More...
 
void set_detached ()
 Changes the state of a session to detached. More...
 
void set_associate ()
 Changes the state of a session to associate. More...
 
void set_disassociate ()
 Changes the state of a session to disassociate. More...
 
bool is_associate () const
 Check is the session state is associate. More...
 
bool is_associated () const
 Check if the session state is associated. More...
 
bool associate ()
 Installs the thd pointed by the session object as the current_thd. More...
 
bool disassociate ()
 Uninstall the thd pointed by the session object as the current_thd. More...
 

Private Attributes

Diagnostics_area m_da
 
st_err_protocol_ctx m_err_protocol_ctx
 
Protocol_callback m_protocol_error
 
srv_session_state m_state
 
enum_vio_type m_vio_type
 
THDm_thd
 
const bool m_free_resources
 

Member Enumeration Documentation

◆ srv_session_state

Enum for the state of the session.

Enumerator
SRV_SESSION_CREATED 
SRV_SESSION_OPENED 
SRV_SESSION_ATTACHED 
SRV_SESSION_DETACHED 
SRV_SESSION_ASSOCIATE 
SRV_SESSION_ASSOCIATED 
SRV_SESSION_DISASSOCIATED 
SRV_SESSION_CLOSED 

Constructor & Destructor Documentation

◆ Srv_session() [1/3]

Srv_session::Srv_session ( srv_session_error_cb  err_cb,
void *  err_cb_ctx 
)

Constructs a server session.

That means This session object owns the THD.

Note
May throw if it fails to construct server session.
Parameters
err_cbDefault completion callback
err_cb_ctxPlugin's context, opaque pointer that would be provided to callbacks. Might be NULL.

◆ Srv_session() [2/3]

Srv_session::Srv_session ( srv_session_error_cb  err_cb,
void *  err_cb_ctx,
THD thd 
)

Have a THD object and wish to associate the same to session object.

Session object will use the thd. It won't own it.

Parameters
err_cbDefault completion callback
err_cb_ctxPlugin's context, opaque pointer that would be provided to callbacks. Might be NULL.
thdA valid THD

◆ ~Srv_session()

Srv_session::~Srv_session ( )

◆ Srv_session() [3/3]

Srv_session::Srv_session ( srv_session_error_cb  err_cb,
void *  err_cb_ctx,
srv_session_state  state,
bool  free_resources,
THD thd 
)
private

Delegated constructor to intialize the members.

Member Function Documentation

◆ associate()

bool Srv_session::associate ( )
private

Installs the thd pointed by the session object as the current_thd.

Returns
false success true failure

◆ attach()

bool Srv_session::attach ( )

Attaches the session to the current physical thread.

Returns
false success true failure

◆ check_for_stale_threads()

void Srv_session::check_for_stale_threads ( const st_plugin_int plugin)
static

Checks if a plugin has left threads and sessions.

Parameters
pluginThe plugin to be checked

◆ close()

bool Srv_session::close ( void  )

Closes the session.

Returns
false Session successfully closed true Session wasn't found or key doesn't match
false Session successfully closed true No such session exists / Session is attached to a different thread

◆ deinit_thread()

void Srv_session::deinit_thread ( )
static

Deinitializes the current physical thread for use with session service.

Deinitializes physical thread to use with session service.

◆ detach()

bool Srv_session::detach ( )

Detaches the session from current physical thread.

Detaches the session from the current physical thread.

Returns
false success true failure

◆ disassociate()

bool Srv_session::disassociate ( )
private

Uninstall the thd pointed by the session object as the current_thd.

Returns
false success true failure

◆ execute_command()

int Srv_session::execute_command ( enum enum_server_command  command,
const union COM_DATA data,
const CHARSET_INFO client_cs,
const struct st_command_service_cbs command_callbacks,
enum cs_text_or_binary  text_or_binary,
void *  callbacks_context 
)

Executes a server command.

Parameters
commandCommand to be executed
dataCommand's arguments
client_csThe charset for the string data input (COM_QUERY for example)
command_callbacksCallbacks to be used by the server to encode data and to communicate with the client (plugin) side.
text_or_binarySee enum cs_text_or_binary
callbacks_contextContext passed to the callbacks
Returns
1 error 0 success

◆ get_client_port()

uint16_t Srv_session::get_client_port ( ) const
inline

Returns the client port.

Note
The client port in SHOW PROCESSLIST, INFORMATION_SCHEMA.PROCESSLIST. This port is NOT shown in PERFORMANCE_SCHEMA.THREADS.

◆ get_current_database()

LEX_CSTRING Srv_session::get_current_database ( ) const
inline

Returns the current database of a session.

Note
This call is not thread-safe. Don't invoke the method from a thread different than the one in which the invocation happens. This means that the call should NOT happen during run_command(). The value returned is valid until the next run_command() call, which may change it.

◆ get_session_id()

my_thread_id Srv_session::get_session_id ( ) const
inline

Returns the ID of a session.

The value returned from THD::thread_id()

◆ get_thd()

THD * Srv_session::get_thd ( )
inline

Returns the internal THD object.

◆ init_thread()

bool Srv_session::init_thread ( const void *  plugin)
static

Initializes the current physical thread for use with this class.

Initializes physical thread to use with session service.

Parameters
pluginPointer to the plugin structure, passed to the plugin over the plugin init function.
Returns
false success true failure

◆ is_associate()

bool Srv_session::is_associate ( ) const
private

Check is the session state is associate.

In other words, session is using the THD provided explicitly.

Returns
true session state is associate false Otherwise

◆ is_associated()

bool Srv_session::is_associated ( ) const
private

Check if the session state is associated.

In other words, explicit thd which pointed by this, is installed

Returns
true session state is associated false Otherwise

◆ is_attached()

bool Srv_session::is_attached ( ) const
inline

Returns if the session is in attached state.

Returns
false Not attached true Attached

◆ is_srv_session_thread()

bool Srv_session::is_srv_session_thread ( )
static

Check if current physical thread was created to be used with this class.

◆ is_valid()

bool Srv_session::is_valid ( const Srv_session session)
static

Checks if the session is valid.

Checked is if session is NULL, or in the list of opened sessions. If the session is not in this list it was either closed or the address is invalid.

Returns
true valid false not valid

Checked is if session is NULL, or the state of the session is SRV_SESSION_OPENED, SRV_SESSION_ATTACHED or SRV_SESSION_DETACHED.

Returns
true valid false not valid

◆ module_deinit()

bool Srv_session::module_deinit ( )
static

Deinitializes the module.

Deinits the module.

This method has to be called at server shutdown.

Returns
false success true failure

Never fails

Returns
false success

◆ module_init()

bool Srv_session::module_init ( )
static

Initializes the module.

Inits the module.

This method has to be called at server startup.

Returns
false success true failure
false success true failure

◆ open()

bool Srv_session::open ( )

Opens a server session.

Returns
session on success NULL on failure
false on success true on failure

◆ session_count()

unsigned int Srv_session::session_count ( )
static

Returns the number opened sessions in thread initialized by this class.

◆ set_associate()

void Srv_session::set_associate ( )
private

Changes the state of a session to associate.

◆ set_attached()

void Srv_session::set_attached ( const char *  stack)
private

Sets session's state to attached.

Parameters
stackNew stack address

◆ set_client_port()

void Srv_session::set_client_port ( uint16_t  port)

Sets the client port.

Note
The client port in SHOW PROCESSLIST, INFORMATION_SCHEMA.PROCESSLIST. This port is NOT shown in PERFORMANCE_SCHEMA.THREADS.
Parameters
portPort number

◆ set_connection_type()

bool Srv_session::set_connection_type ( enum_vio_type  v_type)

Sets the connection type.

See also
enum_vio_type
Note
If NO_VIO_TYPE passed as type the call will fail.
Returns
false success true failure
See also
enum_vio_type
Returns
false success true failure

◆ set_detached()

void Srv_session::set_detached ( )
private

Changes the state of a session to detached.

◆ set_disassociate()

void Srv_session::set_disassociate ( )
private

Changes the state of a session to disassociate.

◆ thread_count()

unsigned int Srv_session::thread_count ( const void *  plugin_name)
static

Returns the number currently running threads initialized by this class.

Member Data Documentation

◆ m_da

Diagnostics_area Srv_session::m_da
private

◆ m_err_protocol_ctx

st_err_protocol_ctx Srv_session::m_err_protocol_ctx
private

◆ m_free_resources

const bool Srv_session::m_free_resources
private

◆ m_protocol_error

Protocol_callback Srv_session::m_protocol_error
private

◆ m_state

srv_session_state Srv_session::m_state
private

◆ m_thd

THD* Srv_session::m_thd
private

◆ m_vio_type

enum_vio_type Srv_session::m_vio_type
private

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