MySQL  8.0.19
Source Code Documentation
group_transaction_observation_manager.h
Go to the documentation of this file.
1 /* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
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 also distributed 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 included with MySQL.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License, version 2.0, for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22 
23 #ifndef GROUP_TRANSACTION_OBSERVATION_MANAGER_INCLUDED
24 #define GROUP_TRANSACTION_OBSERVATION_MANAGER_INCLUDED
25 
27 #include <list>
28 
29 #include "my_inttypes.h"
30 
31 /** Listener for transaction life cycle events */
33  public:
34  /** Enum for transaction origins */
36  GROUP_APPLIER_TRANSACTION = 0, // Group applier transaction
37  GROUP_RECOVERY_TRANSACTION = 1, // Distributed recovery transaction
38  GROUP_LOCAL_TRANSACTION = 2 // Local transaction
39  };
40 
41  /** Class destructor */
43 
44  /**
45  Executed before a transaction begins
46  @param thread_id the transaction thread id
47  @param gr_consistency_level the current consistency level for this session
48  @param hold_timeout the max time to execute an action on this transaction
49  @param channel_type type channel that receives transaction
50  */
52  ulong gr_consistency_level,
53  ulong hold_timeout,
54  enum_rpl_channel_type channel_type) = 0;
55 
56  /**
57  Executed before commit
58  @param thread_id the transaction thread id
59  @param origin who applied it
60  */
62  enum_transaction_origin origin) = 0;
63 
64  /**
65  Executed before rollback
66  @param thread_id the transaction thread id
67  @param origin who applied it
68  */
70  enum_transaction_origin origin) = 0;
71  /**
72  Executed after commit
73  @param thread_id the transaction thread id
74  @param sidno the transaction sidno
75  @param gno the transaction gno
76  */
77  virtual int after_commit(my_thread_id thread_id, rpl_sidno sidno,
78  rpl_gno gno) = 0;
79  /**
80  Executed after rollback
81  @param thread_id the transaction thread id
82  */
83  virtual int after_rollback(my_thread_id thread_id) = 0;
84 };
85 
87  public:
88  /*
89  Initialize the class and register an observer.
90  */
92 
93  /*
94  Destructor.
95  Deletes all observers
96  */
98 
99  /*
100  The method to register new observers
101  @param observer An observer class to register
102  */
104 
105  /*
106  The method to unregister new observers
107  @param observer An observer class to unregister
108  */
110 
111  /**
112  Executed before a transaction begins
113  @param thread_id the transaction thread id
114  @param gr_consistency_level the current consistency level for this session
115  @param hold_timeout the max time to execute an action on this transaction
116  @param rpl_channel_type type channel that receives transaction
117  */
119  ulong gr_consistency_level, ulong hold_timeout,
120  enum_rpl_channel_type rpl_channel_type);
121 
122  /*
123  Executed before commit
124  @param thread_id the transaction thread id
125  @param origin who applied it
126  */
129  /*
130  Executed before rollback
131  @param thread_id the transaction thread id
132  */
134 
135  /*
136  Executed after commit
137  @param thread_id the transaction thread id
138  @param sidno the transaction sidno
139  @param gno the transaction gno
140  */
142 
143  /*
144  Executed after rollback
145  @param thread_id the transaction thread id
146  */
147  int after_rollback(
150 
151  /**
152  Are there any observers present
153  @return true if at least one observer is present, false otherwise
154  */
156 
157  /**
158  Get all registered observers
159 
160  @note to get the list and while using it, you should take a read lock from
161  transaction_observer_list_lock (you can use read_lock_observer_list())
162 
163  @return The list of all registered observers
164  */
165  std::list<Group_transaction_listener *> *get_all_observers();
166 
167  /** Locks the observer list for reads */
169  /** Locks the observer list for writes */
171  /** Unlocks the observer list */
172  void unlock_observer_list();
173 
174  private:
175  /** List of observers */
176  std::list<Group_transaction_listener *> group_transaction_listeners;
177 
178  /** The lock to protect the list */
180 
181  /** Flag that indicates that there are observers (for performance)*/
182  std::atomic<bool> registered_observers;
183 };
184 
185 #endif /* GROUP_TRANSACTION_OBSERVATION_MANAGER_INCLUDED */
Group_transaction_observation_manager::before_rollback
int before_rollback(my_thread_id thread_id)
Group_transaction_listener::before_commit
virtual int before_commit(my_thread_id thread_id, enum_transaction_origin origin)=0
Executed before commit.
Group_transaction_observation_manager::Group_transaction_observation_manager
Group_transaction_observation_manager()
Definition: group_transaction_observation_manager.cc:29
Group_transaction_observation_manager::transaction_observer_list_lock
Checkable_rwlock * transaction_observer_list_lock
The lock to protect the list.
Definition: group_transaction_observation_manager.h:179
Group_transaction_listener::~Group_transaction_listener
virtual ~Group_transaction_listener()
Class destructor.
Definition: group_transaction_observation_manager.cc:27
thread_id
static my_thread_id thread_id
Definition: my_thr_init.cc:62
Group_transaction_observation_manager
Definition: group_transaction_observation_manager.h:86
Group_transaction_listener::after_commit
virtual int after_commit(my_thread_id thread_id, rpl_sidno sidno, rpl_gno gno)=0
Executed after commit.
Group_transaction_observation_manager::read_lock_observer_list
void read_lock_observer_list()
Locks the observer list for reads.
Definition: group_transaction_observation_manager.cc:79
Group_transaction_listener::before_transaction_begin
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.
Group_transaction_observation_manager::before_commit
int before_commit(my_thread_id thread_id, Group_transaction_listener::enum_transaction_origin origin)
Group_transaction_observation_manager::is_any_observer_present
bool is_any_observer_present()
Are there any observers present.
Definition: group_transaction_observation_manager.cc:91
rpl_sidno
int rpl_sidno
Type of SIDNO (source ID number, first component of GTID)
Definition: rpl_gtid.h:94
Group_transaction_observation_manager::unregister_transaction_observer
void unregister_transaction_observer(Group_transaction_listener *observer)
Definition: group_transaction_observation_manager.cc:61
Group_transaction_listener::GROUP_LOCAL_TRANSACTION
@ GROUP_LOCAL_TRANSACTION
Definition: group_transaction_observation_manager.h:38
Group_transaction_listener::GROUP_APPLIER_TRANSACTION
@ GROUP_APPLIER_TRANSACTION
Definition: group_transaction_observation_manager.h:36
Group_transaction_observation_manager::~Group_transaction_observation_manager
~Group_transaction_observation_manager()
Definition: group_transaction_observation_manager.cc:39
my_inttypes.h
Group_transaction_observation_manager::unlock_observer_list
void unlock_observer_list()
Unlocks the observer list.
Definition: group_transaction_observation_manager.cc:87
rpl_gno
long long int rpl_gno
Type of GNO, the second (numeric) component of GTID.
Definition: rpl_gtid.h:100
Group_transaction_observation_manager::group_transaction_listeners
std::list< Group_transaction_listener * > group_transaction_listeners
List of observers.
Definition: group_transaction_observation_manager.h:176
Group_transaction_observation_manager::get_all_observers
std::list< Group_transaction_listener * > * get_all_observers()
Get all registered observers.
Definition: group_transaction_observation_manager.cc:71
Group_transaction_listener::before_rollback
virtual int before_rollback(my_thread_id thread_id, enum_transaction_origin origin)=0
Executed before rollback.
Group_transaction_observation_manager::registered_observers
std::atomic< bool > registered_observers
Flag that indicates that there are observers (for performance)
Definition: group_transaction_observation_manager.h:182
my_thread_id
uint32 my_thread_id
Definition: my_thread_local.h:33
enum_rpl_channel_type
enum_rpl_channel_type
Type of replication channel thread/transaction might be associated to.
Definition: rpl_context.h:37
Group_transaction_observation_manager::register_transaction_observer
void register_transaction_observer(Group_transaction_listener *observer)
Definition: group_transaction_observation_manager.cc:52
Checkable_rwlock
This has the functionality of mysql_rwlock_t, with two differences:
Definition: rpl_gtid.h:430
Group_transaction_observation_manager::after_rollback
int after_rollback(my_thread_id thread_id, Group_transaction_listener::enum_transaction_origin origin)
Group_transaction_observation_manager::write_lock_observer_list
void write_lock_observer_list()
Locks the observer list for writes.
Definition: group_transaction_observation_manager.cc:83
Group_transaction_observation_manager::before_transaction_begin
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.
ulong
unsigned long ulong
Definition: my_inttypes.h:48
Group_transaction_listener
Listener for transaction life cycle events.
Definition: group_transaction_observation_manager.h:32
Group_transaction_listener::GROUP_RECOVERY_TRANSACTION
@ GROUP_RECOVERY_TRANSACTION
Definition: group_transaction_observation_manager.h:37
Group_transaction_observation_manager::after_commit
int after_commit(my_thread_id thread_id, rpl_sidno sidno, rpl_gno gno)
Group_transaction_listener::enum_transaction_origin
enum_transaction_origin
Enum for transaction origins.
Definition: group_transaction_observation_manager.h:35
Group_transaction_listener::after_rollback
virtual int after_rollback(my_thread_id thread_id)=0
Executed after rollback.
group_replication_priv.h