MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
log_event_old.h
Go to the documentation of this file.
1 /* Copyright (c) 2007, 2013, 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 as published by
5  the Free Software Foundation; version 2 of the License.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  GNU General Public License for more details.
11 
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software
14  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15 
16 #ifndef LOG_EVENT_OLD_H
17 #define LOG_EVENT_OLD_H
18 
19 /*
20  Need to include this file at the proper position of log_event.h
21  */
22 
23 
30 /*
31  Around 2007-10-31, I made these classes completely separated from
32  the new classes (before, there was a complex class hierarchy
33  involving multiple inheritance; see BUG#31581), by simply copying
34  and pasting the entire contents of Rows_log_event into
35  Old_rows_log_event and the entire contents of
36  {Write|Update|Delete}_rows_log_event into
37  {Write|Update|Delete}_rows_log_event_old. For clarity, I will keep
38  the comments marking which code was cut-and-pasted for some time.
39  With the classes collapsed into one, there is probably some
40  redundancy (maybe some methods can be simplified and/or removed),
41  but we keep them this way for now. /Sven
42 */
43 
44 /* These classes are based on the v1 RowsHeaderLen */
45 #define ROWS_HEADER_LEN ROWS_HEADER_LEN_V1
46 
57 {
58  /********** BEGIN CUT & PASTE FROM Rows_log_event **********/
59 public:
64  {
66  ERR_OK = 0,
71  };
72 
73  /*
74  These definitions allow you to combine the flags into an
75  appropriate flag set using the normal bitwise operators. The
76  implicit conversion from an enum-constant to an integer is
77  accepted by the compiler, which is then used to set the real set
78  of flags.
79  */
80  enum enum_flag
81  {
82  /* Last event of a statement */
83  STMT_END_F = (1U << 0),
84 
85  /* Value of the OPTION_NO_FOREIGN_KEY_CHECKS flag in thd->options */
86  NO_FOREIGN_KEY_CHECKS_F = (1U << 1),
87 
88  /* Value of the OPTION_RELAXED_UNIQUE_CHECKS flag in thd->options */
89  RELAXED_UNIQUE_CHECKS_F = (1U << 2),
90 
95  COMPLETE_ROWS_F = (1U << 3)
96  };
97 
98  typedef uint16 flag_set;
99 
100  /* Special constants representing sets of flags */
101  enum
102  {
103  RLE_NO_FLAGS = 0U
104  };
105 
106  virtual ~Old_rows_log_event();
107 
108  void set_flags(flag_set flags_arg) { m_flags |= flags_arg; }
109  void clear_flags(flag_set flags_arg) { m_flags &= ~flags_arg; }
110  flag_set get_flags(flag_set flags_arg) const { return m_flags & flags_arg; }
111 
112 #if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
113  virtual int pack_info(Protocol *protocol);
114 #endif
115 
116 #ifdef MYSQL_CLIENT
117  /* not for direct call, each derived has its own ::print() */
118  virtual void print(FILE *file, PRINT_EVENT_INFO *print_event_info)= 0;
119 #endif
120 
121 #ifndef MYSQL_CLIENT
122  int add_row_data(uchar *data, size_t length)
123  {
124  return do_add_row_data(data,length);
125  }
126 #endif
127 
128  /* Member functions to implement superclass interface */
129  virtual int get_data_size();
130 
131  MY_BITMAP const *get_cols() const { return &m_cols; }
132  size_t get_width() const { return m_width; }
133  const Table_id& get_table_id() const { return m_table_id; }
134 
135 #ifndef MYSQL_CLIENT
136  virtual bool write_data_header(IO_CACHE *file);
137  virtual bool write_data_body(IO_CACHE *file);
138  virtual const char *get_db() { return m_table->s->db.str; }
139 #endif
140  /*
141  Check that malloc() succeeded in allocating memory for the rows
142  buffer and the COLS vector. Checking that an Update_rows_log_event_old
143  is valid is done in the Update_rows_log_event_old::is_valid()
144  function.
145  */
146  virtual bool is_valid() const
147  {
148  return m_rows_buf && m_cols.bitmap;
149  }
150 
151  uint m_row_count; /* The number of rows added to the event */
152 
153 protected:
154  /*
155  The constructors are protected since you're supposed to inherit
156  this class, not create instances of this class.
157  */
158 #ifndef MYSQL_CLIENT
159  Old_rows_log_event(THD*, TABLE*, ulong table_id,
160  MY_BITMAP const *cols, bool is_transactional);
161 #endif
162  Old_rows_log_event(const char *row_data, uint event_len,
163  Log_event_type event_type,
164  const Format_description_log_event *description_event);
165 
166 #ifdef MYSQL_CLIENT
167  void print_helper(FILE *, PRINT_EVENT_INFO *, char const *const name);
168 #endif
169 
170 #ifndef MYSQL_CLIENT
171  virtual int do_add_row_data(uchar *data, size_t length);
172 #endif
173 
174 #ifndef MYSQL_CLIENT
175  TABLE *m_table; /* The table the rows belong to */
176 #endif
177  Table_id m_table_id; /* Table ID */
178  MY_BITMAP m_cols; /* Bitmap denoting columns available */
179  ulong m_width; /* The width of the columns bitmap */
180 
181  ulong m_master_reclength; /* Length of record on master side */
182 
183  /* Bit buffers in the same memory as the class */
184  uint32 m_bitbuf[128/(sizeof(uint32)*8)];
185  uint32 m_bitbuf_ai[128/(sizeof(uint32)*8)];
186 
187  uchar *m_rows_buf; /* The rows in packed format */
188  uchar *m_rows_cur; /* One-after the end of the data */
189  uchar *m_rows_end; /* One-after the end of the allocated space */
190 
191  flag_set m_flags; /* Flags for row-level events */
192 
193  /* helper functions */
194 
195 #if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
196  const uchar *m_curr_row; /* Start of the row being processed */
197  const uchar *m_curr_row_end; /* One-after the end of the current row */
198  uchar *m_key; /* Buffer to keep key value during searches */
199 
200  int find_row(const Relay_log_info *const);
201  int write_row(const Relay_log_info *const, const bool);
202 
203  // Unpack the current row into m_table->record[0]
204  int unpack_current_row(const Relay_log_info *const rli)
205  {
206  DBUG_ASSERT(m_table);
207  ASSERT_OR_RETURN_ERROR(m_curr_row < m_rows_end, HA_ERR_CORRUPT_EVENT);
208  int const result= ::unpack_row(rli, m_table, m_width, m_curr_row, &m_cols,
209  &m_curr_row_end, &m_master_reclength);
210  ASSERT_OR_RETURN_ERROR(m_curr_row_end <= m_rows_end, HA_ERR_CORRUPT_EVENT);
211  return result;
212  }
213 #endif
214 
215 private:
216 
217 #if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
218  virtual int do_apply_event(Relay_log_info const *rli);
219  virtual int do_update_pos(Relay_log_info *rli);
220  virtual enum_skip_reason do_shall_skip(Relay_log_info *rli);
221 
222  /*
223  Primitive to prepare for a sequence of row executions.
224 
225  DESCRIPTION
226 
227  Before doing a sequence of do_prepare_row() and do_exec_row()
228  calls, this member function should be called to prepare for the
229  entire sequence. Typically, this member function will allocate
230  space for any buffers that are needed for the two member
231  functions mentioned above.
232 
233  RETURN VALUE
234 
235  The member function will return 0 if all went OK, or a non-zero
236  error code otherwise.
237  */
238  virtual
239  int do_before_row_operations(const Slave_reporting_capability *const log) = 0;
240 
241  /*
242  Primitive to clean up after a sequence of row executions.
243 
244  DESCRIPTION
245 
246  After doing a sequence of do_prepare_row() and do_exec_row(),
247  this member function should be called to clean up and release
248  any allocated buffers.
249 
250  The error argument, if non-zero, indicates an error which happened during
251  row processing before this function was called. In this case, even if
252  function is successful, it should return the error code given in the argument.
253  */
254  virtual
255  int do_after_row_operations(const Slave_reporting_capability *const log,
256  int error) = 0;
257 
258  /*
259  Primitive to do the actual execution necessary for a row.
260 
261  DESCRIPTION
262  The member function will do the actual execution needed to handle a row.
263  The row is located at m_curr_row. When the function returns,
264  m_curr_row_end should point at the next row (one byte after the end
265  of the current row).
266 
267  RETURN VALUE
268  0 if execution succeeded, 1 if execution failed.
269 
270  */
271  virtual int do_exec_row(const Relay_log_info *const rli) = 0;
272 #endif /* !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) */
273 
274  /********** END OF CUT & PASTE FROM Rows_log_event **********/
275  protected:
276 
277 #if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
278 
279  int do_apply_event(Old_rows_log_event*,const Relay_log_info*);
280 
281  /*
282  Primitive to prepare for a sequence of row executions.
283 
284  DESCRIPTION
285 
286  Before doing a sequence of do_prepare_row() and do_exec_row()
287  calls, this member function should be called to prepare for the
288  entire sequence. Typically, this member function will allocate
289  space for any buffers that are needed for the two member
290  functions mentioned above.
291 
292  RETURN VALUE
293 
294  The member function will return 0 if all went OK, or a non-zero
295  error code otherwise.
296  */
297  virtual int do_before_row_operations(TABLE *table) = 0;
298 
299  /*
300  Primitive to clean up after a sequence of row executions.
301 
302  DESCRIPTION
303 
304  After doing a sequence of do_prepare_row() and do_exec_row(),
305  this member function should be called to clean up and release
306  any allocated buffers.
307  */
308  virtual int do_after_row_operations(TABLE *table, int error) = 0;
309 
310  /*
311  Primitive to prepare for handling one row in a row-level event.
312 
313  DESCRIPTION
314 
315  The member function prepares for execution of operations needed for one
316  row in a row-level event by reading up data from the buffer containing
317  the row. No specific interpretation of the data is normally done here,
318  since SQL thread specific data is not available: that data is made
319  available for the do_exec function.
320 
321  A pointer to the start of the next row, or NULL if the preparation
322  failed. Currently, preparation cannot fail, but don't rely on this
323  behavior.
324 
325  RETURN VALUE
326  Error code, if something went wrong, 0 otherwise.
327  */
328  virtual int do_prepare_row(THD*, Relay_log_info const*, TABLE*,
329  uchar const *row_start,
330  uchar const **row_end) = 0;
331 
332  /*
333  Primitive to do the actual execution necessary for a row.
334 
335  DESCRIPTION
336  The member function will do the actual execution needed to handle a row.
337 
338  RETURN VALUE
339  0 if execution succeeded, 1 if execution failed.
340 
341  */
342  virtual int do_exec_row(TABLE *table) = 0;
343 
344 #endif /* !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) */
345 };
346 
347 
358 {
359  /********** BEGIN CUT & PASTE FROM Write_rows_log_event **********/
360 public:
361 #if !defined(MYSQL_CLIENT)
362  Write_rows_log_event_old(THD*, TABLE*, ulong table_id,
363  MY_BITMAP const *cols,
364  bool is_transactional);
365 #endif
366 #ifdef HAVE_REPLICATION
367  Write_rows_log_event_old(const char *buf, uint event_len,
368  const Format_description_log_event *description_event);
369 #endif
370 #if !defined(MYSQL_CLIENT)
371  static bool binlog_row_logging_function(THD *thd, TABLE *table,
372  bool is_transactional,
373  const uchar *before_record
374  __attribute__((unused)),
375  const uchar *after_record)
376  {
377  return thd->binlog_write_row(table, is_transactional,
378  after_record, NULL);
379  }
380 #endif
381 
382 private:
383 #ifdef MYSQL_CLIENT
384  void print(FILE *file, PRINT_EVENT_INFO *print_event_info);
385 #endif
386 
387 #if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
388  virtual int do_before_row_operations(const Slave_reporting_capability *const);
389  virtual int do_after_row_operations(const Slave_reporting_capability *const,int);
390  virtual int do_exec_row(const Relay_log_info *const);
391 #endif
392  /********** END OF CUT & PASTE FROM Write_rows_log_event **********/
393 
394 public:
395  enum
396  {
397  /* Support interface to THD::binlog_prepare_pending_rows_event */
398  TYPE_CODE = PRE_GA_WRITE_ROWS_EVENT
399  };
400 
401 private:
402  virtual Log_event_type get_type_code() { return (Log_event_type)TYPE_CODE; }
403 
404 #if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
405  // use old definition of do_apply_event()
406  virtual int do_apply_event(const Relay_log_info *rli)
407  { return Old_rows_log_event::do_apply_event(this,rli); }
408 
409  // primitives for old version of do_apply_event()
410  virtual int do_before_row_operations(TABLE *table);
411  virtual int do_after_row_operations(TABLE *table, int error);
412  virtual int do_prepare_row(THD*, Relay_log_info const*, TABLE*,
413  uchar const *row_start, uchar const **row_end);
414  virtual int do_exec_row(TABLE *table);
415 
416 #endif
417 };
418 
419 
431 {
432  /********** BEGIN CUT & PASTE FROM Update_rows_log_event **********/
433 public:
434 #ifndef MYSQL_CLIENT
435  Update_rows_log_event_old(THD*, TABLE*, ulong table_id,
436  MY_BITMAP const *cols,
437  bool is_transactional);
438 #endif
439 
440 #ifdef HAVE_REPLICATION
441  Update_rows_log_event_old(const char *buf, uint event_len,
442  const Format_description_log_event *description_event);
443 #endif
444 
445 #if !defined(MYSQL_CLIENT)
446  static bool binlog_row_logging_function(THD *thd, TABLE *table,
447  bool is_transactional,
448  const uchar *before_record,
449  const uchar *after_record)
450  {
451  return thd->binlog_update_row(table, is_transactional,
452  before_record, after_record, NULL);
453  }
454 #endif
455 
456 protected:
457 #ifdef MYSQL_CLIENT
458  void print(FILE *file, PRINT_EVENT_INFO *print_event_info);
459 #endif
460 
461 #if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
462  virtual int do_before_row_operations(const Slave_reporting_capability *const);
463  virtual int do_after_row_operations(const Slave_reporting_capability *const,int);
464  virtual int do_exec_row(const Relay_log_info *const);
465 #endif /* !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) */
466  /********** END OF CUT & PASTE FROM Update_rows_log_event **********/
467 
468  uchar *m_after_image, *m_memory;
469 
470 public:
471  enum
472  {
473  /* Support interface to THD::binlog_prepare_pending_rows_event */
474  TYPE_CODE = PRE_GA_UPDATE_ROWS_EVENT
475  };
476 
477 private:
478  virtual Log_event_type get_type_code() { return (Log_event_type)TYPE_CODE; }
479 
480 #if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
481  // use old definition of do_apply_event()
482  virtual int do_apply_event(const Relay_log_info *rli)
483  { return Old_rows_log_event::do_apply_event(this,rli); }
484 
485  // primitives for old version of do_apply_event()
486  virtual int do_before_row_operations(TABLE *table);
487  virtual int do_after_row_operations(TABLE *table, int error);
488  virtual int do_prepare_row(THD*, Relay_log_info const*, TABLE*,
489  uchar const *row_start, uchar const **row_end);
490  virtual int do_exec_row(TABLE *table);
491 #endif /* !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) */
492 };
493 
494 
506 {
507  /********** BEGIN CUT & PASTE FROM Update_rows_log_event **********/
508 public:
509 #ifndef MYSQL_CLIENT
510  Delete_rows_log_event_old(THD*, TABLE*, ulong,
511  MY_BITMAP const *cols,
512  bool is_transactional);
513 #endif
514 #ifdef HAVE_REPLICATION
515  Delete_rows_log_event_old(const char *buf, uint event_len,
516  const Format_description_log_event *description_event);
517 #endif
518 #if !defined(MYSQL_CLIENT)
519  static bool binlog_row_logging_function(THD *thd, TABLE *table,
520  bool is_transactional,
521  const uchar *before_record,
522  const uchar *after_record
523  __attribute__((unused)))
524  {
525  return thd->binlog_delete_row(table, is_transactional,
526  before_record, NULL);
527  }
528 #endif
529 
530 protected:
531 #ifdef MYSQL_CLIENT
532  void print(FILE *file, PRINT_EVENT_INFO *print_event_info);
533 #endif
534 
535 #if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
536  virtual int do_before_row_operations(const Slave_reporting_capability *const);
537  virtual int do_after_row_operations(const Slave_reporting_capability *const,int);
538  virtual int do_exec_row(const Relay_log_info *const);
539 #endif
540  /********** END CUT & PASTE FROM Delete_rows_log_event **********/
541 
542  uchar *m_after_image, *m_memory;
543 
544 public:
545  enum
546  {
547  /* Support interface to THD::binlog_prepare_pending_rows_event */
548  TYPE_CODE = PRE_GA_DELETE_ROWS_EVENT
549  };
550 
551 private:
552  virtual Log_event_type get_type_code() { return (Log_event_type)TYPE_CODE; }
553 
554 #if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
555  // use old definition of do_apply_event()
556  virtual int do_apply_event(const Relay_log_info *rli)
557  { return Old_rows_log_event::do_apply_event(this,rli); }
558 
559  // primitives for old version of do_apply_event()
560  virtual int do_before_row_operations(TABLE *table);
561  virtual int do_after_row_operations(TABLE *table, int error);
562  virtual int do_prepare_row(THD*, Relay_log_info const*, TABLE*,
563  uchar const *row_start, uchar const **row_end);
564  virtual int do_exec_row(TABLE *table);
565 #endif
566 };
567 
568 
569 #endif