MySQL 9.1.0
Source Code Documentation
group_actions_transaction_controller.h
Go to the documentation of this file.
1/* Copyright (c) 2022, 2024, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef GR_GROUP_ACTIONS_TRANSACTION_CONTROLLER_INCLUDED
25#define GR_GROUP_ACTIONS_TRANSACTION_CONTROLLER_INCLUDED
26
28#include <mysql/components/services/mysql_transaction_delegate_control.h> // Service mysql_transaction_delegate_control
30
31/**
32 @class Transaction_monitor_thread
33 @brief Class for creating a new thread that allows to stop the new
34 transactions allowing some management queries to run. This thread also
35 gracefully disconnects the client which are running the binloggable
36 transaction after specified time.
37*/
39 public:
40 /**
41 Deleted copy constructor.
42 */
44
45 /**
46 Deleted move constructor.
47 */
49
50 /**
51 Deleted assignment operator.
52 */
54 delete;
55
56 /**
57 Deleted move operator.
58 */
60 delete;
61
62 /**
63 Initializes the synchronization primitives of the thread.
64 */
66
67 /**
68 The destructor for the thread will destroy the mutex and cond_var.
69 */
71
72 /**
73 Terminates the thread. Thread sets the abort flag and affectively waits for
74 the operations to terminate.
75
76 @return success
77 @retval true failed to terminate
78 @retval false thread terminated successfully.
79 */
80 bool terminate();
81
82 /**
83 Starts the process of monitoring transactions.
84
85 @return whether or not we managed to launch the transaction_monitor_thread
86 thread.
87 @retval 0 the thread launched successfully
88 @retval != 0 the thread couldn't be launched
89 @sa mysql_thread_create
90 */
91 int start();
92
93 private:
94 /**
95 The thread callback passed onto mysql_thread_create.
96
97 @param[in] arg a pointer to an Transaction_monitor_thread instance.
98
99 @return nullptr, since the return value is not used.
100 */
101 static void *launch_thread(void *arg);
102
103 /**
104 The thread handle, i.e. setups and tearsdown the infrastructure for this
105 mysql_thread.
106 */
107 [[noreturn]] void transaction_thread_handle();
108
109 private:
110 /**
111 This function acquires the below services:
112 mysql_new_transaction_control
113 mysql_before_commit_transaction_control
114 mysql_close_connection_of_binloggable_transaction_not_reached_commit
115
116 @return false success
117 true fail
118 */
119 bool acquire_services();
120 /**
121 This function releases the services.
122
123 @return false success
124 true fail
125 */
126 bool release_services();
127
128 private:
129 /** the state of the thread. */
131 /** the thread handle. */
133 /** the mutex for controlling access to the thread itself. */
135 /** the cond_var used to signal the thread. */
137 /** flag to indicate whether or not the thread is to be aborted. */
139 /**
140 The number of seconds to wait before setting the THD::KILL_CONNECTION flag
141 for the transactions that did not reach commit stage.
142 */
144 /**
145 Stores operation start time.
146 */
147 std::chrono::time_point<std::chrono::steady_clock> m_time_start_of_operation;
148
149 /**
150 Pointer to the `mysql_new_transaction_control_imp` service.
151 */
152 SERVICE_TYPE_NO_CONST(mysql_new_transaction_control) *
154
155 /**
156 Pointer to the `mysql_before_commit_transaction_control` service.
157 */
158 SERVICE_TYPE_NO_CONST(mysql_before_commit_transaction_control) *
160
161 /**
162 Pointer to the
163 `mysql_close_connection_of_binloggable_transaction_not_reached_commit`
164 service.
165 */
167 mysql_close_connection_of_binloggable_transaction_not_reached_commit) *
169 nullptr};
170};
171
172#endif /* GR_GROUP_ACTIONS_TRANSACTION_CONTROLLER_INCLUDED */
Class for creating a new thread that allows to stop the new transactions allowing some management que...
Definition: group_actions_transaction_controller.h:38
mysql_service_mysql_before_commit_transaction_control_t * m_mysql_before_commit_transaction_control
Pointer to the mysql_before_commit_transaction_control service.
Definition: group_actions_transaction_controller.h:159
mysql_cond_t m_run_cond
the cond_var used to signal the thread.
Definition: group_actions_transaction_controller.h:136
Transaction_monitor_thread(const Transaction_monitor_thread &)=delete
Deleted copy constructor.
bool m_abort
flag to indicate whether or not the thread is to be aborted.
Definition: group_actions_transaction_controller.h:138
bool terminate()
Terminates the thread.
Definition: group_actions_transaction_controller.cc:150
mysql_mutex_t m_run_lock
the mutex for controlling access to the thread itself.
Definition: group_actions_transaction_controller.h:134
Transaction_monitor_thread(const Transaction_monitor_thread &&)=delete
Deleted move constructor.
~Transaction_monitor_thread()
The destructor for the thread will destroy the mutex and cond_var.
Definition: group_actions_transaction_controller.cc:42
void transaction_thread_handle()
The thread handle, i.e.
Definition: group_actions_transaction_controller.cc:220
mysql_service_mysql_close_connection_of_binloggable_transaction_not_reached_commit_t * m_mysql_close_connection_of_binloggable_transaction_not_reached_commit
Pointer to the mysql_close_connection_of_binloggable_transaction_not_reached_commit service.
Definition: group_actions_transaction_controller.h:168
mysql_service_mysql_new_transaction_control_t * m_mysql_new_transaction_control
Pointer to the mysql_new_transaction_control_imp service.
Definition: group_actions_transaction_controller.h:153
Transaction_monitor_thread & operator=(const Transaction_monitor_thread &&)=delete
Deleted move operator.
my_thread_handle m_handle
the thread handle.
Definition: group_actions_transaction_controller.h:132
int32 m_transaction_timeout
The number of seconds to wait before setting the THD::KILL_CONNECTION flag for the transactions that ...
Definition: group_actions_transaction_controller.h:143
bool release_services()
This function releases the services.
Definition: group_actions_transaction_controller.cc:113
int start()
Starts the process of monitoring transactions.
Definition: group_actions_transaction_controller.cc:172
static void * launch_thread(void *arg)
The thread callback passed onto mysql_thread_create.
Definition: group_actions_transaction_controller.cc:28
bool acquire_services()
This function acquires the below services: mysql_new_transaction_control mysql_before_commit_transact...
Definition: group_actions_transaction_controller.cc:47
Transaction_monitor_thread & operator=(const Transaction_monitor_thread &)=delete
Deleted assignment operator.
thread_state m_transaction_monitor_thd_state
the state of the thread.
Definition: group_actions_transaction_controller.h:130
std::chrono::time_point< std::chrono::steady_clock > m_time_start_of_operation
Stores operation start time.
Definition: group_actions_transaction_controller.h:147
int32_t int32
Definition: my_inttypes.h:66
uint32_t uint32
Definition: my_inttypes.h:67
#define SERVICE_TYPE_NO_CONST(name)
Generates the standard Service type name.
Definition: service.h:71
Definition: my_thread_bits.h:58
An instrumented cond structure.
Definition: mysql_cond_bits.h:50
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:50
Definition: plugin_utils.h:48