MySQL  8.0.18
Source Code Documentation
rpl_handler.h
Go to the documentation of this file.
1 /* Copyright (c) 2008, 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 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  int after_dd_upgrade_from_57(THD *thd);
191 };
192 
193 #ifdef HAVE_PSI_RWLOCK_INTERFACE
195 #endif
196 
198  public:
200  : Delegate(
203 #endif
204  ) {
205  }
206 
208  int after_flush(THD *thd, const char *log_file, my_off_t log_pos);
209  int after_sync(THD *thd, const char *log_file, my_off_t log_pos);
210 };
211 
212 #ifdef HAVE_PSI_RWLOCK_INTERFACE
214 #endif
215 
217  public:
219  : Delegate(
222 #endif
223  ) {
224  }
225 
227  int transmit_start(THD *thd, ushort flags, const char *log_file,
228  my_off_t log_pos, bool *observe_transmission);
229  int transmit_stop(THD *thd, ushort flags);
230  int reserve_header(THD *thd, ushort flags, String *packet);
231  int before_send_event(THD *thd, ushort flags, String *packet,
232  const char *log_file, my_off_t log_pos);
233  int after_send_event(THD *thd, ushort flags, String *packet,
234  const char *skipped_log_file, my_off_t skipped_log_pos);
235  int after_reset_master(THD *thd, ushort flags);
236 };
237 
238 #ifdef HAVE_PSI_RWLOCK_INTERFACE
240 #endif
241 
243  public:
245  : Delegate(
248 #endif
249  ) {
250  }
251 
253  int thread_start(THD *thd, Master_info *mi);
254  int thread_stop(THD *thd, Master_info *mi);
255  int applier_start(THD *thd, Master_info *mi);
256  int applier_stop(THD *thd, Master_info *mi, bool aborted);
257  int before_request_transmit(THD *thd, Master_info *mi, ushort flags);
258  int after_read_event(THD *thd, Master_info *mi, const char *packet, ulong len,
259  const char **event_buf, ulong *event_len);
260  int after_queue_event(THD *thd, Master_info *mi, const char *event_buf,
261  ulong event_len, bool synced);
262  int after_reset_slave(THD *thd, Master_info *mi);
263  int applier_log_event(THD *thd, int &out);
264 
265  private:
266  void init_param(Binlog_relay_IO_param *param, Master_info *mi);
267 };
268 
269 int delegates_init();
270 void delegates_destroy();
271 
277 
278 /*
279  if there is no observers in the delegate, we can return 0
280  immediately.
281 */
282 #define RUN_HOOK(group, hook, args) \
283  (group##_delegate->is_empty() ? 0 : group##_delegate->hook args)
284 
285 #define NO_HOOK(group) (group##_delegate->is_empty())
286 
287 int launch_hook_trans_begin(THD *thd, TABLE_LIST *table);
288 
289 #endif /* RPL_HANDLER_H */
Definition: sql_plugin_ref.h:44
Definition: result.h:33
unsigned long long int ulonglong
Definition: my_inttypes.h:55
int before_dml(THD *thd, int &result)
Definition: rpl_handler.cc:465
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:216
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:856
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:676
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
int after_dd_upgrade_from_57(THD *thd)
This hook MUST be invoked after upgrade from .frm to data dictionary.
Definition: rpl_handler.cc:690
Observes and extends the service of slave IO thread.
Definition: replication.h:709
int after_rollback(THD *thd, bool all)
Definition: rpl_handler.cc:546
Binlog_relay_IO_delegate()
Definition: rpl_handler.h:244
int applier_start(THD *thd, Master_info *mi)
Definition: rpl_handler.cc:867
Binlog_relay_IO_observer Observer
Definition: rpl_handler.h:252
int after_flush(THD *thd, const char *log_file, my_off_t log_pos)
Definition: rpl_handler.cc:582
Definition: rpl_handler.h:50
int after_reset_master(THD *thd, ushort flags)
Definition: rpl_handler.cc:822
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:615
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:890
void remove()
Definition: sql_list.h:576
st_plugin_int * plugin_int
Definition: rpl_handler.h:53
Observe and extends the binlog dumping thread.
Definition: replication.h:555
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:161
Binlog_storage_observer Observer
Definition: rpl_handler.h:207
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:804
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:699
bool is_inited()
Definition: rpl_handler.h:120
#define DBUG_PRINT(keyword, arglist)
Definition: my_dbug.h:179
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:601
Definition: rpl_handler.h:59
PSI_rwlock_key key_rwlock_Server_state_delegate_lock
Definition: mysqld.cc:10554
int after_reset_slave(THD *thd, Master_info *mi)
Definition: rpl_handler.cc:934
Observes and extends transaction execution.
Definition: replication.h:281
plugin_ref plugin
Definition: rpl_handler.h:54
int transmit_stop(THD *thd, ushort flags)
Definition: rpl_handler.cc:729
PSI_rwlock_key key_rwlock_Binlog_relay_IO_delegate_lock
Definition: mysqld.cc:10557
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:565
#define mysql_rwlock_unlock(T)
Definition: mysql_rwlock.h:84
int after_commit(THD *thd, bool all)
Definition: rpl_handler.cc:516
Definition: rpl_handler.h:242
PSI_rwlock_key key_rwlock_Binlog_storage_delegate_lock
Definition: mysqld.cc:10555
~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
void init_param(Binlog_relay_IO_param *param, Master_info *mi)
Definition: rpl_handler.cc:834
Logfile log_file
Definition: mysqltest.cc:250
MEM_ROOT memroot
Definition: rpl_handler.h:137
#define MYF(v)
Definition: my_inttypes.h:114
Replication binlog relay IO observer parameter.
Definition: replication.h:577
int applier_stop(THD *thd, Master_info *mi, bool aborted)
Definition: rpl_handler.cc:878
int transmit_start(THD *thd, ushort flags, const char *log_file, my_off_t log_pos, bool *observe_transmission)
Definition: rpl_handler.cc:715
#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:917
static const char * key
Definition: suite_stubs.c:14
Definition: rpl_handler.h:147
Observe binlog logging storage.
Definition: replication.h:425
An instrumented rwlock structure.
Definition: mysql_rwlock_bits.h:50
unsigned long my_off_t
Definition: my_inttypes.h:77
Binlog_transmit_delegate()
Definition: rpl_handler.h:218
Definition: rpl_handler.h:173
Definition: rpl_mi.h:86
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:646
#define mysql_rwlock_wrlock(T)
Definition: mysql_rwlock.h:64
Observer server state.
Definition: replication.h:385
PSI_rwlock_key key_rwlock_Binlog_transmit_delegate_lock
Definition: mysqld.cc:10556
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:226
Trans_observer Observer
Definition: rpl_handler.h:157
int launch_hook_trans_begin(THD *thd, TABLE_LIST *table)
Definition: rpl_handler.cc:1022
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:661
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:786
int thread_start(THD *thd, Master_info *mi)
Definition: rpl_handler.cc:845
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:3679
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:79
Definition: table.h:2468
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:250
Binlog_storage_delegate()
Definition: rpl_handler.h:199
PSI_rwlock_key key_rwlock_Trans_delegate_lock
Definition: mysqld.cc:10553
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:902
int applier_log_event(THD *thd, int &out)
Definition: rpl_handler.cc:947
int reserve_header(THD *thd, ushort flags, String *packet)
Definition: rpl_handler.cc:741
#define mysql_rwlock_rdlock(T)
Definition: mysql_rwlock.h:54
int before_rollback(THD *thd, bool all)
Definition: rpl_handler.cc:491
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:778
Definition: rpl_handler.h:197
int after_engine_recovery(THD *thd)
This hook MUST be invoked after the recovery from the engine is complete.
Definition: rpl_handler.cc:630