MySQL 8.4.2
Source Code Documentation
group_transaction_observation_manager.h
Go to the documentation of this file.
1/* Copyright (c) 2018, 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 GROUP_TRANSACTION_OBSERVATION_MANAGER_INCLUDED
25#define GROUP_TRANSACTION_OBSERVATION_MANAGER_INCLUDED
26
28#include <list>
29
30#include "my_inttypes.h"
31
32/** Listener for transaction life cycle events */
34 public:
35 /** Enum for transaction origins */
37 GROUP_APPLIER_TRANSACTION = 0, // Group applier transaction
38 GROUP_RECOVERY_TRANSACTION = 1, // Distributed recovery transaction
39 GROUP_LOCAL_TRANSACTION = 2 // Local transaction
40 };
41
42 /** Class destructor */
44
45 /**
46 Executed before a transaction begins
47 @param thread_id the transaction thread id
48 @param gr_consistency_level the current consistency level for this session
49 @param hold_timeout the max time to execute an action on this transaction
50 @param channel_type type channel that receives transaction
51 @param thd server thd that represents client session
52 */
54 ulong gr_consistency_level,
55 ulong hold_timeout,
56 enum_rpl_channel_type channel_type,
57 const THD *thd) = 0;
58
59 /**
60 Executed before commit
61 @param thread_id the transaction thread id
62 @param origin who applied it
63 */
65 enum_transaction_origin origin) = 0;
66
67 /**
68 Executed before rollback
69 @param thread_id the transaction thread id
70 @param origin who applied it
71 */
73 enum_transaction_origin origin) = 0;
74 /**
75 Executed after commit
76 @param thread_id the transaction thread id
77 @param sidno the transaction sidno
78 @param gno the transaction gno
79 */
81 rpl_gno gno) = 0;
82 /**
83 Executed after rollback
84 @param thread_id the transaction thread id
85 */
87};
88
90 public:
91 /*
92 Initialize the class and register an observer.
93 */
95
96 /*
97 Destructor.
98 Deletes all observers
99 */
101
102 /*
103 The method to register new observers
104 @param observer An observer class to register
105 */
107
108 /*
109 The method to unregister new observers
110 @param observer An observer class to unregister
111 */
113
114 /**
115 Executed before a transaction begins
116 @param thread_id the transaction thread id
117 @param gr_consistency_level the current consistency level for this session
118 @param hold_timeout the max time to execute an action on this transaction
119 @param rpl_channel_type type channel that receives transaction
120 @param thd server thd that represents client session
121 */
123 ulong gr_consistency_level, ulong hold_timeout,
124 enum_rpl_channel_type rpl_channel_type,
125 const THD *thd);
126
127 /*
128 Executed before commit
129 @param thread_id the transaction thread id
130 @param origin who applied it
131 */
134 /*
135 Executed before rollback
136 @param thread_id the transaction thread id
137 */
139
140 /*
141 Executed after commit
142 @param thread_id the transaction thread id
143 @param sidno the transaction sidno
144 @param gno the transaction gno
145 */
147
148 /*
149 Executed after rollback
150 @param thread_id the transaction thread id
151 */
155
156 /**
157 Are there any observers present
158 @return true if at least one observer is present, false otherwise
159 */
161
162 /**
163 Get all registered observers
164
165 @note to get the list and while using it, you should take a read lock from
166 transaction_observer_list_lock (you can use read_lock_observer_list())
167
168 @return The list of all registered observers
169 */
170 std::list<Group_transaction_listener *> *get_all_observers();
171
172 /** Locks the observer list for reads */
174 /** Locks the observer list for writes */
176 /** Unlocks the observer list */
178
179 private:
180 /** List of observers */
181 std::list<Group_transaction_listener *> group_transaction_listeners;
182
183 /** The lock to protect the list */
185
186 /** Flag that indicates that there are observers (for performance)*/
187 std::atomic<bool> registered_observers;
188};
189
190#endif /* GROUP_TRANSACTION_OBSERVATION_MANAGER_INCLUDED */
This has the functionality of mysql_rwlock_t, with two differences:
Definition: rpl_gtid.h:324
Listener for transaction life cycle events.
Definition: group_transaction_observation_manager.h:33
virtual int before_commit(my_thread_id thread_id, enum_transaction_origin origin)=0
Executed before commit.
virtual int before_transaction_begin(my_thread_id thread_id, ulong gr_consistency_level, ulong hold_timeout, enum_rpl_channel_type channel_type, const THD *thd)=0
Executed before a transaction begins.
virtual int after_commit(my_thread_id thread_id, rpl_sidno sidno, rpl_gno gno)=0
Executed after commit.
enum_transaction_origin
Enum for transaction origins.
Definition: group_transaction_observation_manager.h:36
@ GROUP_APPLIER_TRANSACTION
Definition: group_transaction_observation_manager.h:37
@ GROUP_LOCAL_TRANSACTION
Definition: group_transaction_observation_manager.h:39
@ GROUP_RECOVERY_TRANSACTION
Definition: group_transaction_observation_manager.h:38
virtual ~Group_transaction_listener()
Class destructor.
virtual int after_rollback(my_thread_id thread_id)=0
Executed after rollback.
virtual int before_rollback(my_thread_id thread_id, enum_transaction_origin origin)=0
Executed before rollback.
Definition: group_transaction_observation_manager.h:89
int before_commit(my_thread_id thread_id, Group_transaction_listener::enum_transaction_origin origin)
int before_rollback(my_thread_id thread_id)
void register_transaction_observer(Group_transaction_listener *observer)
Definition: group_transaction_observation_manager.cc:53
void write_lock_observer_list()
Locks the observer list for writes.
Definition: group_transaction_observation_manager.cc:84
void unregister_transaction_observer(Group_transaction_listener *observer)
Definition: group_transaction_observation_manager.cc:62
void read_lock_observer_list()
Locks the observer list for reads.
Definition: group_transaction_observation_manager.cc:80
Group_transaction_observation_manager()
Definition: group_transaction_observation_manager.cc:30
std::atomic< bool > registered_observers
Flag that indicates that there are observers (for performance)
Definition: group_transaction_observation_manager.h:187
int after_commit(my_thread_id thread_id, rpl_sidno sidno, rpl_gno gno)
int after_rollback(my_thread_id thread_id, Group_transaction_listener::enum_transaction_origin origin)
~Group_transaction_observation_manager()
Definition: group_transaction_observation_manager.cc:40
void unlock_observer_list()
Unlocks the observer list.
Definition: group_transaction_observation_manager.cc:88
bool is_any_observer_present()
Are there any observers present.
Definition: group_transaction_observation_manager.cc:92
std::list< Group_transaction_listener * > group_transaction_listeners
List of observers.
Definition: group_transaction_observation_manager.h:181
int before_transaction_begin(my_thread_id thread_id, ulong gr_consistency_level, ulong hold_timeout, enum_rpl_channel_type rpl_channel_type, const THD *thd)
Executed before a transaction begins.
Checkable_rwlock * transaction_observer_list_lock
The lock to protect the list.
Definition: group_transaction_observation_manager.h:184
std::list< Group_transaction_listener * > * get_all_observers()
Get all registered observers.
Definition: group_transaction_observation_manager.cc:72
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
Some integer typedefs for easier portability.
static my_thread_id thread_id
Definition: my_thr_init.cc:63
uint32 my_thread_id
Definition: my_thread_local.h:34
enum_rpl_channel_type
Type of replication channel thread/transaction might be associated to.
Definition: rpl_context.h:50
mysql::gtid::gno_t rpl_gno
GNO, the second (numeric) component of a GTID, is an alias of mysql::gtid::gno_t.
Definition: rpl_gtid.h:112
cs::index::rpl_sidno rpl_sidno
Type of SIDNO (source ID number, first component of GTID)
Definition: rpl_gtid.h:108