MySQL  8.0.17
Source Code Documentation
rpl_handler.h
Go to the documentation of this file.
1 /* Copyright (c) 2008, 2018, 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 RPL_HANDLER_H
24 #define RPL_HANDLER_H
25 
26 #include <sys/types.h>
27 
28 #include "my_alloc.h"
29 #include "my_dbug.h"
30 #include "my_inttypes.h"
31 #include "my_psi_config.h"
32 #include "my_sys.h" // free_root
35 #include "mysql/psi/mysql_rwlock.h"
36 #include "sql/sql_list.h" // List
37 #include "sql/sql_plugin_ref.h" // plugin_ref
38 
39 class Master_info;
40 class String;
41 class THD;
47 struct Trans_observer;
48 struct TABLE_LIST;
49 
51  public:
52  void *observer;
55 
56  Observer_info(void *ob, st_plugin_int *p);
57 };
58 
59 class Delegate {
60  public:
63 
64  int add_observer(void *observer, st_plugin_int *plugin) {
65  int ret = false;
66  if (!inited) return true;
67  write_lock();
69  Observer_info *info = iter++;
70  while (info && info->observer != observer) info = iter++;
71  if (!info) {
72  info = new Observer_info(observer, plugin);
73  if (!info || observer_info_list.push_back(info, &memroot)) ret = true;
74  } else
75  ret = true;
76  unlock();
77  return ret;
78  }
79 
80  int remove_observer(void *observer) {
81  int ret = false;
82  if (!inited) return true;
83  write_lock();
85  Observer_info *info = iter++;
86  while (info && info->observer != observer) info = iter++;
87  if (info) {
88  iter.remove();
89  delete info;
90  } else
91  ret = true;
92  unlock();
93  return ret;
94  }
95 
98  }
99 
100  inline bool is_empty() {
101  DBUG_PRINT("debug", ("is_empty: %d", observer_info_list.is_empty()));
102  return observer_info_list.is_empty();
103  }
104 
105  inline int read_lock() {
106  if (!inited) return true;
107  return mysql_rwlock_rdlock(&lock);
108  }
109 
110  inline int write_lock() {
111  if (!inited) return true;
112  return mysql_rwlock_wrlock(&lock);
113  }
114 
115  inline int unlock() {
116  if (!inited) return true;
117  return mysql_rwlock_unlock(&lock);
118  }
119 
120  inline bool is_inited() { return inited; }
121 
122  explicit Delegate(
125 #endif
126  );
127 
129  inited = false;
131  free_root(&memroot, MYF(0));
132  }
133 
134  private:
138  bool inited;
139 };
140 
141 #ifdef HAVE_PSI_RWLOCK_INTERFACE
143 #endif
144 
146 
147 class Trans_delegate : public Delegate {
148  public:
150  : Delegate(
153 #endif
154  ) {
155  }
156 
158 
159  int before_dml(THD *thd, int &result);
160  int before_commit(THD *thd, bool all, Binlog_cache_storage *trx_cache_log,
161  Binlog_cache_storage *stmt_cache_log,
162  ulonglong cache_log_max_size, bool is_atomic_ddl);
163  int before_rollback(THD *thd, bool all);
164  int after_commit(THD *thd, bool all);
165  int after_rollback(THD *thd, bool all);
166  int trans_begin(THD *thd, int &result);
167 };
168 
169 #ifdef HAVE_PSI_RWLOCK_INTERFACE
171 #endif
172 
174  public:
176  : Delegate(
179 #endif
180  ) {
181  }
182 
184  int before_handle_connection(THD *thd);
185  int before_recovery(THD *thd);
186  int after_engine_recovery(THD *thd);
187  int after_recovery(THD *thd);
188  int before_server_shutdown(THD *thd);
189  int after_server_shutdown(THD *thd);
190 };
191 
192 #ifdef HAVE_PSI_RWLOCK_INTERFACE
194 #endif
195 
197  public:
199  : Delegate(
202 #endif
203  ) {
204  }
205 
207  int after_flush(THD *thd, const char *log_file, my_off_t log_pos);
208  int after_sync(THD *thd, const char *log_file, my_off_t log_pos);
209 };
210 
211 #ifdef HAVE_PSI_RWLOCK_INTERFACE
213 #endif
214 
216  public:
218  : Delegate(
221 #endif
222  ) {
223  }
224 
226  int transmit_start(THD *thd, ushort flags, const char *log_file,
227  my_off_t log_pos, bool *observe_transmission);
228  int transmit_stop(THD *thd, ushort flags);
229  int reserve_header(THD *thd, ushort flags, String *packet);
230  int before_send_event(THD *thd, ushort flags, String *packet,
231  const char *log_file, my_off_t log_pos);
232  int after_send_event(THD *thd, ushort flags, String *packet,
233  const char *skipped_log_file, my_off_t skipped_log_pos);
234  int after_reset_master(THD *thd, ushort flags);
235 };
236 
237 #ifdef HAVE_PSI_RWLOCK_INTERFACE
239 #endif
240 
242  public:
244  : Delegate(
247 #endif
248  ) {
249  }
250 
252  int thread_start(THD *thd, Master_info *mi);
253  int thread_stop(THD *thd, Master_info *mi);
254  int applier_start(THD *thd, Master_info *mi);
255  int applier_stop(THD *thd, Master_info *mi, bool aborted);
256  int before_request_transmit(THD *thd, Master_info *mi, ushort flags);
257  int after_read_event(THD *thd, Master_info *mi, const char *packet, ulong len,
258  const char **event_buf, ulong *event_len);
259  int after_queue_event(THD *thd, Master_info *mi, const char *event_buf,
260  ulong event_len, bool synced);
261  int after_reset_slave(THD *thd, Master_info *mi);
262  int applier_log_event(THD *thd, int &out);
263 
264  private:
265  void init_param(Binlog_relay_IO_param *param, Master_info *mi);
266 };
267 
268 int delegates_init();
269 void delegates_destroy();
270 
276 
277 /*
278  if there is no observers in the delegate, we can return 0
279  immediately.
280 */
281 #define RUN_HOOK(group, hook, args) \
282  (group##_delegate->is_empty() ? 0 : group##_delegate->hook args)
283 
284 #define NO_HOOK(group) (group##_delegate->is_empty())
285 
286 int launch_hook_trans_begin(THD *thd, TABLE_LIST *table);
287 
288 #endif /* RPL_HANDLER_H */
Definition: sql_plugin_ref.h:44
unsigned long long int ulonglong
Definition: my_inttypes.h:74
int before_dml(THD *thd, int &result)
Definition: rpl_handler.cc:467
Binlog_transmit_delegate * binlog_transmit_delegate
Definition: rpl_handler.cc:73
Binlog_relay_IO_delegate * binlog_relay_io_delegate
Definition: rpl_handler.cc:74
Definition: rpl_handler.h:215
bool inited
Definition: rpl_handler.h:138
Server_state_delegate * server_state_delegate
Definition: rpl_handler.cc:71
Observer_info(void *ob, st_plugin_int *p)
Definition: rpl_handler.cc:76
int unlock()
Definition: rpl_handler.h:115
int thread_stop(THD *thd, Master_info *mi)
Definition: rpl_handler.cc:844
int read_lock()
Definition: rpl_handler.h:105
int after_server_shutdown(THD *thd)
This hook MUST be invoked after server shutdown operation is complete.
Definition: rpl_handler.cc:678
Some integer typedefs for easier portability.
Server_state_delegate()
Definition: rpl_handler.h:175
bool is_empty() const
Definition: sql_list.h:265
#define HAVE_PSI_RWLOCK_INTERFACE
Definition: my_psi_config.h:81
Observes and extends the service of slave IO thread.
Definition: replication.h:696
int after_rollback(THD *thd, bool all)
Definition: rpl_handler.cc:548
Binlog_relay_IO_delegate()
Definition: rpl_handler.h:243
int applier_start(THD *thd, Master_info *mi)
Definition: rpl_handler.cc:855
Binlog_relay_IO_observer Observer
Definition: rpl_handler.h:251
int after_flush(THD *thd, const char *log_file, my_off_t log_pos)
Definition: rpl_handler.cc:584
Definition: rpl_handler.h:50
int after_reset_master(THD *thd, ushort flags)
Definition: rpl_handler.cc:810
int write_lock()
Definition: rpl_handler.h:110
List< Observer_info > Observer_info_list
Definition: rpl_handler.h:61
int before_recovery(THD *thd)
This hook MUST be invoked before ANY recovery action is started.
Definition: rpl_handler.cc:617
static struct st_mysql_daemon plugin
Definition: test_services_host_application_signal.cc:130
int before_request_transmit(THD *thd, Master_info *mi, ushort flags)
Definition: rpl_handler.cc:878
void remove()
Definition: sql_list.h:572
st_plugin_int * plugin_int
Definition: rpl_handler.h:53
Observe and extends the binlog dumping thread.
Definition: replication.h:542
mysql_rwlock_t lock
Definition: rpl_handler.h:136
Using this class is fraught with peril, and you need to be very careful when doing so...
Definition: sql_string.h:159
Binlog_storage_observer Observer
Definition: rpl_handler.h:206
int after_send_event(THD *thd, ushort flags, String *packet, const char *skipped_log_file, my_off_t skipped_log_pos)
Definition: rpl_handler.cc:792
Trans_delegate()
Definition: rpl_handler.h:149
int after_sync(THD *thd, const char *log_file, my_off_t log_pos)
Definition: rpl_handler.cc:687
bool is_inited()
Definition: rpl_handler.h:120
#define DBUG_PRINT(keyword, arglist)
Definition: my_dbug.h:165
int before_handle_connection(THD *thd)
This hook MUST be invoked after ALL recovery operations are performed and the server is ready to serv...
Definition: rpl_handler.cc:603
Definition: rpl_handler.h:59
PSI_rwlock_key key_rwlock_Server_state_delegate_lock
Definition: mysqld.cc:10387
int after_reset_slave(THD *thd, Master_info *mi)
Definition: rpl_handler.cc:922
Observes and extends transaction execution.
Definition: replication.h:280
plugin_ref plugin
Definition: rpl_handler.h:54
int transmit_stop(THD *thd, ushort flags)
Definition: rpl_handler.cc:717
PSI_rwlock_key key_rwlock_Binlog_relay_IO_delegate_lock
Definition: mysqld.cc:10390
Instrumentation helpers for rwlock.
int before_commit(THD *thd, bool all, Binlog_cache_storage *trx_cache_log, Binlog_cache_storage *stmt_cache_log, ulonglong cache_log_max_size, bool is_atomic_ddl)
Definition: rpl_handler.cc:303
int trans_begin(THD *thd, int &result)
Definition: rpl_handler.cc:567
#define mysql_rwlock_unlock(T)
Definition: mysql_rwlock.h:84
int after_commit(THD *thd, bool all)
Definition: rpl_handler.cc:518
Definition: rpl_handler.h:241
PSI_rwlock_key key_rwlock_Binlog_storage_delegate_lock
Definition: mysqld.cc:10388
~Delegate()
Definition: rpl_handler.h:128
Defines various enable/disable and HAVE_ macros related to the performance schema instrumentation sys...
int remove_observer(void *observer)
Definition: rpl_handler.h:80
unsigned int len
Definition: dbug_analyze.cc:216
void init_param(Binlog_relay_IO_param *param, Master_info *mi)
Definition: rpl_handler.cc:822
Logfile log_file
Definition: mysqltest.cc:250
MEM_ROOT memroot
Definition: rpl_handler.h:137
#define MYF(v)
Definition: my_inttypes.h:124
Replication binlog relay IO observer parameter.
Definition: replication.h:564
int applier_stop(THD *thd, Master_info *mi, bool aborted)
Definition: rpl_handler.cc:866
int transmit_start(THD *thd, ushort flags, const char *log_file, my_off_t log_pos, bool *observe_transmission)
Definition: rpl_handler.cc:703
#define mysql_rwlock_destroy(T)
Definition: mysql_rwlock.h:44
Binlog_storage_delegate * binlog_storage_delegate
Definition: rpl_handler.cc:70
unsigned int PSI_rwlock_key
Instrumented rwlock key.
Definition: psi_rwlock_bits.h:41
Common header for many mysys elements.
Delegate(PSI_rwlock_key key)
Definition: rpl_handler.cc:81
int after_queue_event(THD *thd, Master_info *mi, const char *event_buf, ulong event_len, bool synced)
Definition: rpl_handler.cc:905
static const char * key
Definition: suite_stubs.c:14
Definition: rpl_handler.h:147
Observe binlog logging storage.
Definition: replication.h:412
An instrumented rwlock structure.
Definition: mysql_rwlock_bits.h:50
unsigned long my_off_t
Definition: my_inttypes.h:87
Binlog_transmit_delegate()
Definition: rpl_handler.h:217
Definition: rpl_handler.h:173
Definition: rpl_mi.h:85
Trans_delegate * transaction_delegate
Definition: rpl_handler.cc:69
int after_recovery(THD *thd)
This hook MUST be invoked after the server has completed the local recovery.
Definition: rpl_handler.cc:648
#define mysql_rwlock_wrlock(T)
Definition: mysql_rwlock.h:64
Observer server state.
Definition: replication.h:373
PSI_rwlock_key key_rwlock_Binlog_transmit_delegate_lock
Definition: mysqld.cc:10389
List_iterator< Observer_info > Observer_info_iterator
Definition: rpl_handler.h:62
Server_state_observer Observer
Definition: rpl_handler.h:183
Binlog_transmit_observer Observer
Definition: rpl_handler.h:225
Trans_observer Observer
Definition: rpl_handler.h:157
int launch_hook_trans_begin(THD *thd, TABLE_LIST *table)
Definition: rpl_handler.cc:1010
void delegates_destroy()
Definition: rpl_handler.cc:200
int before_server_shutdown(THD *thd)
This hook MUST be invoked before server shutdown action is initiated.
Definition: rpl_handler.cc:663
int delegates_init()
Definition: rpl_handler.cc:161
Observer_info_list observer_info_list
Definition: rpl_handler.h:135
int before_send_event(THD *thd, ushort flags, String *packet, const char *log_file, my_off_t log_pos)
Definition: rpl_handler.cc:774
int thread_start(THD *thd, Master_info *mi)
Definition: rpl_handler.cc:833
bool is_atomic_ddl(THD *thd, bool using_trans_arg)
The function lists all DDL instances that are supported for crash-recovery (WL9175).
Definition: log_event.cc:3668
const char * p
Definition: ctype-mb.cc:1232
void * observer
Definition: rpl_handler.h:52
Log info(cout, "NOTE")
Performance schema instrumentation interface.
int add_observer(void *observer, st_plugin_int *plugin)
Definition: rpl_handler.h:64
Byte container that provides a storage for serializing session binlog events.
Definition: binlog_ostream.h:172
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:77
Definition: item.h:78
Definition: table.h:2442
bool push_back(T *a)
Definition: sql_list.h:442
static int flags[50]
Definition: hp_test1.cc:39
void free_root(MEM_ROOT *root, myf flags)
Definition: my_alloc.cc:255
Binlog_storage_delegate()
Definition: rpl_handler.h:198
PSI_rwlock_key key_rwlock_Trans_delegate_lock
Definition: mysqld.cc:10386
Instrumentation helpers for rwlock.
Observer_info_iterator observer_info_iter()
Definition: rpl_handler.h:96
bool is_empty()
Definition: rpl_handler.h:100
unsigned long ulong
Definition: my_inttypes.h:48
int after_read_event(THD *thd, Master_info *mi, const char *packet, ulong len, const char **event_buf, ulong *event_len)
Definition: rpl_handler.cc:890
int applier_log_event(THD *thd, int &out)
Definition: rpl_handler.cc:935
int reserve_header(THD *thd, ushort flags, String *packet)
Definition: rpl_handler.cc:729
#define mysql_rwlock_rdlock(T)
Definition: mysql_rwlock.h:54
int before_rollback(THD *thd, bool all)
Definition: rpl_handler.cc:493
This file follows Google coding style, except for the name MEM_ROOT (which is kept for historical rea...
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:777
Definition: rpl_handler.h:196
int after_engine_recovery(THD *thd)
This hook MUST be invoked after the recovery from the engine is complete.
Definition: rpl_handler.cc:632