MySQL 8.0.37
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 */
53 ulong gr_consistency_level,
54 ulong hold_timeout,
55 enum_rpl_channel_type channel_type) = 0;
56
57 /**
58 Executed before commit
59 @param thread_id the transaction thread id
60 @param origin who applied it
61 */
63 enum_transaction_origin origin) = 0;
64
65 /**
66 Executed before rollback
67 @param thread_id the transaction thread id
68 @param origin who applied it
69 */
71 enum_transaction_origin origin) = 0;
72 /**
73 Executed after commit
74 @param thread_id the transaction thread id
75 @param sidno the transaction sidno
76 @param gno the transaction gno
77 */
79 rpl_gno gno) = 0;
80 /**
81 Executed after rollback
82 @param thread_id the transaction thread id
83 */
85};
86
88 public:
89 /*
90 Initialize the class and register an observer.
91 */
93
94 /*
95 Destructor.
96 Deletes all observers
97 */
99
100 /*
101 The method to register new observers
102 @param observer An observer class to register
103 */
105
106 /*
107 The method to unregister new observers
108 @param observer An observer class to unregister
109 */
111
112 /**
113 Executed before a transaction begins
114 @param thread_id the transaction thread id
115 @param gr_consistency_level the current consistency level for this session
116 @param hold_timeout the max time to execute an action on this transaction
117 @param rpl_channel_type type channel that receives transaction
118 */
120 ulong gr_consistency_level, ulong hold_timeout,
121 enum_rpl_channel_type rpl_channel_type);
122
123 /*
124 Executed before commit
125 @param thread_id the transaction thread id
126 @param origin who applied it
127 */
130 /*
131 Executed before rollback
132 @param thread_id the transaction thread id
133 */
135
136 /*
137 Executed after commit
138 @param thread_id the transaction thread id
139 @param sidno the transaction sidno
140 @param gno the transaction gno
141 */
143
144 /*
145 Executed after rollback
146 @param thread_id the transaction thread id
147 */
151
152 /**
153 Are there any observers present
154 @return true if at least one observer is present, false otherwise
155 */
157
158 /**
159 Get all registered observers
160
161 @note to get the list and while using it, you should take a read lock from
162 transaction_observer_list_lock (you can use read_lock_observer_list())
163
164 @return The list of all registered observers
165 */
166 std::list<Group_transaction_listener *> *get_all_observers();
167
168 /** Locks the observer list for reads */
170 /** Locks the observer list for writes */
172 /** Unlocks the observer list */
174
175 private:
176 /** List of observers */
177 std::list<Group_transaction_listener *> group_transaction_listeners;
178
179 /** The lock to protect the list */
181
182 /** Flag that indicates that there are observers (for performance)*/
183 std::atomic<bool> registered_observers;
184};
185
186#endif /* GROUP_TRANSACTION_OBSERVATION_MANAGER_INCLUDED */
This has the functionality of mysql_rwlock_t, with two differences:
Definition: rpl_gtid.h:309
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)=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:87
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
int before_transaction_begin(my_thread_id thread_id, ulong gr_consistency_level, ulong hold_timeout, enum_rpl_channel_type rpl_channel_type)
Executed before a transaction begins.
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:183
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:177
Checkable_rwlock * transaction_observer_list_lock
The lock to protect the list.
Definition: group_transaction_observation_manager.h:180
std::list< Group_transaction_listener * > * get_all_observers()
Get all registered observers.
Definition: group_transaction_observation_manager.cc:72
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:49
int rpl_sidno
Type of SIDNO (source ID number, first component of GTID)
Definition: rpl_gtid.h:96
binary_log::gtids::gno_t rpl_gno
GNO, the second (numeric) component of a GTID, is an alias of binary_log::gtids::gno_t.
Definition: rpl_gtid.h:103