MySQL 8.0.39
Source Code Documentation
Transaction_monitor_thread Class Reference

Class for creating a new thread that allows to stop the new transactions allowing some management queries to run. More...

#include <group_actions_transaction_controller.h>

Public Member Functions

 Transaction_monitor_thread (const Transaction_monitor_thread &)=delete
 Deleted copy constructor. More...
 
 Transaction_monitor_thread (const Transaction_monitor_thread &&)=delete
 Deleted move constructor. More...
 
Transaction_monitor_threadoperator= (const Transaction_monitor_thread &)=delete
 Deleted assignment operator. More...
 
Transaction_monitor_threadoperator= (const Transaction_monitor_thread &&)=delete
 Deleted move operator. More...
 
 Transaction_monitor_thread (uint32 timeout_arg)
 Initializes the synchronization primitives of the thread. More...
 
 ~Transaction_monitor_thread ()
 The destructor for the thread will destroy the mutex and cond_var. More...
 
bool terminate ()
 Terminates the thread. More...
 
int start ()
 Starts the process of monitoring transactions. More...
 

Private Member Functions

void transaction_thread_handle ()
 The thread handle, i.e. More...
 
bool acquire_services ()
 This function acquires the below services: mysql_new_transaction_control mysql_before_commit_transaction_control mysql_close_connection_of_binloggable_transaction_not_reached_commit. More...
 
bool release_services ()
 This function releases the services. More...
 

Static Private Member Functions

static void * launch_thread (void *arg)
 The thread callback passed onto mysql_thread_create. More...
 

Private Attributes

thread_state m_transaction_monitor_thd_state
 the state of the thread. More...
 
my_thread_handle m_handle
 the thread handle. More...
 
mysql_mutex_t m_run_lock
 the mutex for controlling access to the thread itself. More...
 
mysql_cond_t m_run_cond
 the cond_var used to signal the thread. More...
 
bool m_abort
 flag to indicate whether or not the thread is to be aborted. More...
 
int32 m_transaction_timeout {-1}
 The number of seconds to wait before setting the THD::KILL_CONNECTION flag for the transactions that did not reach commit stage. More...
 
std::chrono::time_point< std::chrono::steady_clock > m_time_start_of_operation
 Stores operation start time. More...
 
mysql_service_mysql_new_transaction_control_tm_mysql_new_transaction_control {nullptr}
 Pointer to the mysql_new_transaction_control_imp service. More...
 
mysql_service_mysql_before_commit_transaction_control_tm_mysql_before_commit_transaction_control {nullptr}
 Pointer to the mysql_before_commit_transaction_control service. More...
 
mysql_service_mysql_close_connection_of_binloggable_transaction_not_reached_commit_tm_mysql_close_connection_of_binloggable_transaction_not_reached_commit
 Pointer to the mysql_close_connection_of_binloggable_transaction_not_reached_commit service. More...
 

Detailed Description

Class for creating a new thread that allows to stop the new transactions allowing some management queries to run.

This thread also gracefully disconnects the client which are running the binloggable transaction after specified time.

Constructor & Destructor Documentation

◆ Transaction_monitor_thread() [1/3]

Transaction_monitor_thread::Transaction_monitor_thread ( const Transaction_monitor_thread )
delete

Deleted copy constructor.

◆ Transaction_monitor_thread() [2/3]

Transaction_monitor_thread::Transaction_monitor_thread ( const Transaction_monitor_thread &&  )
delete

Deleted move constructor.

◆ Transaction_monitor_thread() [3/3]

Transaction_monitor_thread::Transaction_monitor_thread ( uint32  timeout_arg)

Initializes the synchronization primitives of the thread.

◆ ~Transaction_monitor_thread()

Transaction_monitor_thread::~Transaction_monitor_thread ( )

The destructor for the thread will destroy the mutex and cond_var.

Member Function Documentation

◆ acquire_services()

bool Transaction_monitor_thread::acquire_services ( )
private

This function acquires the below services: mysql_new_transaction_control mysql_before_commit_transaction_control mysql_close_connection_of_binloggable_transaction_not_reached_commit.

Returns
false success true fail

◆ launch_thread()

void * Transaction_monitor_thread::launch_thread ( void *  arg)
staticprivate

The thread callback passed onto mysql_thread_create.

Parameters
[in]arga pointer to an Transaction_monitor_thread instance.
Returns
nullptr, since the return value is not used.

◆ operator=() [1/2]

Transaction_monitor_thread & Transaction_monitor_thread::operator= ( const Transaction_monitor_thread &&  )
delete

Deleted move operator.

◆ operator=() [2/2]

Transaction_monitor_thread & Transaction_monitor_thread::operator= ( const Transaction_monitor_thread )
delete

Deleted assignment operator.

◆ release_services()

bool Transaction_monitor_thread::release_services ( )
private

This function releases the services.

Returns
false success true fail

◆ start()

int Transaction_monitor_thread::start ( )

Starts the process of monitoring transactions.

Returns
whether or not we managed to launch the transaction_monitor_thread thread.
Return values
0the thread launched successfully
!=0 the thread couldn't be launched
See also
mysql_thread_create

◆ terminate()

bool Transaction_monitor_thread::terminate ( )

Terminates the thread.

Thread sets the abort flag and affectively waits for the operations to terminate.

Returns
success
Return values
truefailed to terminate
falsethread terminated successfully.

◆ transaction_thread_handle()

void Transaction_monitor_thread::transaction_thread_handle ( )
private

The thread handle, i.e.

setups and tearsdown the infrastructure for this mysql_thread.

If time has elapsed disconnect the client connections running the transaction which have yet not reached commit. Else wait for 1 second periods for the primary change to happen until the specified timeout elapses.

Note
if UDF finishes it will call terminate to terminate this thread. terminate will awake this thread and thread will exit due to m_abort flag.
ongoing transactions does not impact this thread. If ongoing transactions finishes UDF will finish execution at Primary_election_action::execute_action later calling the terminate function of this thread. Terminate will simply unblock the wait, allow the transactions and end the execution of this thread.
before closing the client connection, time elapse is checked, so it safe to come out of sleep early.
clients_disconnected makes sure client disconnection only happens once.
post client disconnection this thread waits for UDF to finish so that new queries are still blocked. Once UDF finishes at time of after_primary_election terminate will be called. Terminate will simply unblock the wait, allow the transactions and end the execution of this thread.
  1. Refresh time_now.
  2. Disconnect the clients only once.
  3. Check time has elapsed before disconnecting the clients

Member Data Documentation

◆ m_abort

bool Transaction_monitor_thread::m_abort
private

flag to indicate whether or not the thread is to be aborted.

◆ m_handle

my_thread_handle Transaction_monitor_thread::m_handle
private

the thread handle.

◆ m_mysql_before_commit_transaction_control

mysql_service_mysql_before_commit_transaction_control_t* Transaction_monitor_thread::m_mysql_before_commit_transaction_control {nullptr}
private

Pointer to the mysql_before_commit_transaction_control service.

◆ m_mysql_close_connection_of_binloggable_transaction_not_reached_commit

mysql_service_mysql_close_connection_of_binloggable_transaction_not_reached_commit_t* Transaction_monitor_thread::m_mysql_close_connection_of_binloggable_transaction_not_reached_commit
private
Initial value:
{
nullptr}

Pointer to the mysql_close_connection_of_binloggable_transaction_not_reached_commit service.

◆ m_mysql_new_transaction_control

mysql_service_mysql_new_transaction_control_t* Transaction_monitor_thread::m_mysql_new_transaction_control {nullptr}
private

Pointer to the mysql_new_transaction_control_imp service.

◆ m_run_cond

mysql_cond_t Transaction_monitor_thread::m_run_cond
private

the cond_var used to signal the thread.

◆ m_run_lock

mysql_mutex_t Transaction_monitor_thread::m_run_lock
private

the mutex for controlling access to the thread itself.

◆ m_time_start_of_operation

std::chrono::time_point<std::chrono::steady_clock> Transaction_monitor_thread::m_time_start_of_operation
private

Stores operation start time.

◆ m_transaction_monitor_thd_state

thread_state Transaction_monitor_thread::m_transaction_monitor_thd_state
private

the state of the thread.

◆ m_transaction_timeout

int32 Transaction_monitor_thread::m_transaction_timeout {-1}
private

The number of seconds to wait before setting the THD::KILL_CONNECTION flag for the transactions that did not reach commit stage.


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