MySQL  8.0.21
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_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...
 
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

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...
 

Private Attributes

THD thd
 
Diagnostics_area da
 
st_err_protocol_ctx err_protocol_ctx
 
Protocol_callback protocol_error
 
srv_session_state state
 
enum_vio_type vio_type
 

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_CLOSED 

Constructor & Destructor Documentation

◆ Srv_session()

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

Constructs a server session.

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

Member Function Documentation

◆ 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

◆ 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_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_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.

◆ 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

◆ da

Diagnostics_area Srv_session::da
private

◆ err_protocol_ctx

st_err_protocol_ctx Srv_session::err_protocol_ctx
private

◆ protocol_error

Protocol_callback Srv_session::protocol_error
private

◆ state

srv_session_state Srv_session::state
private

◆ thd

THD Srv_session::thd
private

◆ vio_type

enum_vio_type Srv_session::vio_type
private

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