MySQL  8.0.18
Source Code Documentation
log_event.h
Go to the documentation of this file.
1 /* Copyright (c) 2000, 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 /**
24  @file sql/log_event.h
25 
26  @brief Binary log event definitions. This includes generic code
27  common to all types of log events, as well as specific code for each
28  type of log event.
29 
30  @addtogroup Replication
31  @{
32 */
33 
34 #ifndef _log_event_h
35 #define _log_event_h
36 
37 #include <atomic>
38 #include <functional>
39 #include <list>
40 #include <map>
41 #include <set>
42 #include <string>
43 
44 #include "lex_string.h"
51 #include "m_string.h" // native_strncasecmp
52 #include "my_bitmap.h" // MY_BITMAP
53 #include "my_dbug.h"
54 #include "my_inttypes.h"
55 #include "my_psi_config.h"
56 #include "my_sharedlib.h"
57 #include "my_sys.h"
58 #include "my_thread_local.h"
62 #include "mysql_com.h" // SERVER_VERSION_LENGTH
63 #include "partition_info.h"
64 #include "sql/query_options.h" // OPTION_AUTO_IS_NULL
65 #include "sql/rpl_gtid.h" // enum_gtid_type
66 #include "sql/rpl_utility.h" // Hash_slave_rows
67 #include "sql/sql_const.h"
68 #include "sql/thr_malloc.h"
69 #include "sql_string.h"
70 #include "typelib.h" // TYPELIB
71 
72 class THD;
73 class Table_id;
74 struct CHARSET_INFO;
75 
76 enum class enum_row_image_type;
77 class Basic_ostream;
78 
79 #ifdef MYSQL_SERVER
80 #include <stdio.h>
81 
82 #include "my_compiler.h"
83 #include "sql/key.h"
84 #include "sql/rpl_filter.h" // rpl_filter
85 #include "sql/table.h"
86 #include "sql/xa.h"
87 #endif
88 
89 #ifndef MYSQL_SERVER
90 #include "sql/rpl_tblmap.h" // table_mapping
91 #endif
92 
93 #include <limits.h>
94 #include <stdint.h>
95 #include <string.h>
96 #include <sys/types.h>
97 #include <time.h>
98 
99 #ifdef HAVE_PSI_STAGE_INTERFACE
100 #include "mysql/psi/mysql_stage.h"
101 #endif
102 
103 #ifndef MYSQL_SERVER
105 #endif
106 
110 
111 /* Forward declarations */
119 
122 
124 #if defined(MYSQL_SERVER)
125 int ignored_error_code(int err_code);
126 #endif
127 #define PREFIX_SQL_LOAD "SQL_LOAD-"
128 
129 /**
130  Maximum length of the name of a temporary file
131  PREFIX LENGTH - 9
132  UUID - UUID_LENGTH
133  SEPARATORS - 2
134  SERVER ID - 10 (range of server ID 1 to (2^32)-1 = 4,294,967,295)
135  FILE ID - 10 (uint)
136  EXTENSION - 7 (Assuming that the extension is always less than 7
137  characters)
138 */
139 #define TEMP_FILE_MAX_LEN UUID_LENGTH + 38
140 
141 /**
142  Either assert or return an error.
143 
144  In debug build, the condition will be checked, but in non-debug
145  builds, the error code given will be returned instead.
146 
147  @param COND Condition to check
148  @param ERRNO Error number to return in non-debug builds
149 */
150 #ifdef DBUG_OFF
151 #define ASSERT_OR_RETURN_ERROR(COND, ERRNO) \
152  do { \
153  if (!(COND)) return ERRNO; \
154  } while (0)
155 #else
156 #define ASSERT_OR_RETURN_ERROR(COND, ERRNO) DBUG_ASSERT(COND)
157 #endif
158 
159 #define LOG_EVENT_OFFSET 4
160 
161 #define NUM_LOAD_DELIM_STRS 5
162 
163 /*****************************************************************************
164 
165  MySQL Binary Log
166 
167  This log consists of events. Each event has a fixed-length header,
168  possibly followed by a variable length data body.
169 
170  The data body consists of an optional fixed length segment (post-header)
171  and an optional variable length segment.
172 
173  See the #defines below for the format specifics.
174 
175  The events which really update data are Query_log_event,
176  Execute_load_query_log_event and old Load_log_event and
177  Execute_load_log_event events (Execute_load_query is used together with
178  Begin_load_query and Append_block events to replicate LOAD DATA INFILE.
179  Create_file/Append_block/Execute_load (which includes Load_log_event)
180  were used to replicate LOAD DATA before the 5.0.3).
181 
182  ****************************************************************************/
183 
184 #define MAX_LOG_EVENT_HEADER \
185  ( /* in order of Query_log_event::write */ \
186  (LOG_EVENT_HEADER_LEN + /* write_header */ \
187  Binary_log_event::QUERY_HEADER_LEN + /* write_data */ \
188  Binary_log_event:: \
189  EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN) + /*write_post_header_for_derived \
190  */ \
191  MAX_SIZE_LOG_EVENT_STATUS + /* status */ \
192  NAME_LEN + \
193  1)
194 
195 /*
196  The new option is added to handle large packets that are sent from the master
197  to the slave. It is used to increase the thd(max_allowed) for both the
198  DUMP thread on the master and the SQL/IO thread on the slave.
199 */
200 #define MAX_MAX_ALLOWED_PACKET 1024 * 1024 * 1024
201 
202 /* slave event post-header (this event is never written) */
203 
204 #define SL_MASTER_PORT_OFFSET 8
205 #define SL_MASTER_POS_OFFSET 0
206 #define SL_MASTER_HOST_OFFSET 10
207 
208 /* Intvar event post-header */
209 
210 /* Intvar event data */
211 #define I_TYPE_OFFSET 0
212 #define I_VAL_OFFSET 1
213 
214 /* 4 bytes which all binlogs should begin with */
215 #define BINLOG_MAGIC "\xfe\x62\x69\x6e"
216 #define BINLOG_MAGIC_SIZE 4
217 
218 /**
219  @addtogroup group_cs_binglog_event_header_flags Binlog Event Header Flags
220  @ingroup group_cs
221  @{
222 */
223 
224 /*
225  The 2 flags below were useless :
226  - the first one was never set
227  - the second one was set in all Rotate events on the master, but not used for
228  anything useful.
229  So they are now removed and their place may later be reused for other
230  flags. Then one must remember that Rotate events in 4.x have
231  LOG_EVENT_FORCED_ROTATE_F set, so one should not rely on the value of the
232  replacing flag when reading a Rotate event.
233  I keep the defines here just to remember what they were.
234 
235  #define LOG_EVENT_TIME_F 0x1
236  #define LOG_EVENT_FORCED_ROTATE_F 0x2
237 */
238 
239 /**
240  @def LOG_EVENT_THREAD_SPECIFIC_F
241 
242  If the query depends on the thread (for example: TEMPORARY TABLE).
243  Currently this is used by mysqlbinlog to know it must print
244  SET @@PSEUDO_THREAD_ID=xx; before the query (it would not hurt to print it
245  for every query but this would be slow).
246 */
247 #define LOG_EVENT_THREAD_SPECIFIC_F 0x4
248 
249 /**
250  @def LOG_EVENT_SUPPRESS_USE_F
251 
252  Suppress the generation of 'USE' statements before the actual
253  statement. This flag should be set for any events that does not need
254  the current database set to function correctly. Most notable cases
255  are 'CREATE DATABASE' and 'DROP DATABASE'.
256 
257  This flags should only be used in exceptional circumstances, since
258  it introduce a significant change in behaviour regarding the
259  replication logic together with the flags --binlog-do-db and
260  --replicated-do-db.
261  */
262 #define LOG_EVENT_SUPPRESS_USE_F 0x8
263 
264 /*
265  Note: this is a place holder for the flag
266  LOG_EVENT_UPDATE_TABLE_MAP_VERSION_F (0x10), which is not used any
267  more, please do not reused this value for other flags.
268  */
269 
270 /**
271  @def LOG_EVENT_ARTIFICIAL_F
272 
273  Artificial events are created arbitarily and not written to binary
274  log
275 
276  These events should not update the master log position when slave
277  SQL thread executes them.
278 */
279 #define LOG_EVENT_ARTIFICIAL_F 0x20
280 
281 /**
282  @def LOG_EVENT_RELAY_LOG_F
283 
284  Events with this flag set are created by slave IO thread and written
285  to relay log
286 */
287 #define LOG_EVENT_RELAY_LOG_F 0x40
288 
289 /**
290  @def LOG_EVENT_IGNORABLE_F
291 
292  For an event, 'e', carrying a type code, that a slave,
293  's', does not recognize, 's' will check 'e' for
294  LOG_EVENT_IGNORABLE_F, and if the flag is set, then 'e'
295  is ignored. Otherwise, 's' acknowledges that it has
296  found an unknown event in the relay log.
297 */
298 #define LOG_EVENT_IGNORABLE_F 0x80
299 
300 /**
301  @def LOG_EVENT_NO_FILTER_F
302 
303  Events with this flag are not filtered (e.g. on the current
304  database) and are always written to the binary log regardless of
305  filters.
306 */
307 #define LOG_EVENT_NO_FILTER_F 0x100
308 
309 /**
310  MTS: group of events can be marked to force its execution
311  in isolation from any other Workers.
312  So it's a marker for Coordinator to memorize and perform necessary
313  operations in order to guarantee no interference from other Workers.
314  The flag can be set ON only for an event that terminates its group.
315  Typically that is done for a transaction that contains
316  a query accessing more than OVER_MAX_DBS_IN_EVENT_MTS databases.
317 */
318 #define LOG_EVENT_MTS_ISOLATE_F 0x200
319 
320 /** @}*/
321 
322 /**
323  @def OPTIONS_WRITTEN_TO_BIN_LOG
324 
325  OPTIONS_WRITTEN_TO_BIN_LOG are the bits of thd->options which must
326  be written to the binlog. OPTIONS_WRITTEN_TO_BIN_LOG could be
327  written into the Format_description_log_event, so that if later we
328  don't want to replicate a variable we did replicate, or the
329  contrary, it's doable. But it should not be too hard to decide once
330  for all of what we replicate and what we don't, among the fixed 32
331  bits of thd->options.
332 
333  I (Guilhem) have read through every option's usage, and it looks
334  like OPTION_AUTO_IS_NULL and OPTION_NO_FOREIGN_KEYS are the only
335  ones which alter how the query modifies the table. It's good to
336  replicate OPTION_RELAXED_UNIQUE_CHECKS too because otherwise, the
337  slave may insert data slower than the master, in InnoDB.
338  OPTION_BIG_SELECTS is not needed (the slave thread runs with
339  max_join_size=HA_POS_ERROR) and OPTION_BIG_TABLES is not needed
340  either, as the manual says (because a too big in-memory temp table
341  is automatically written to disk).
342 */
343 #define OPTIONS_WRITTEN_TO_BIN_LOG \
344  (OPTION_AUTO_IS_NULL | OPTION_NO_FOREIGN_KEY_CHECKS | \
345  OPTION_RELAXED_UNIQUE_CHECKS | OPTION_NOT_AUTOCOMMIT)
346 
347 /* Shouldn't be defined before */
348 #define EXPECTED_OPTIONS \
349  ((1ULL << 14) | (1ULL << 26) | (1ULL << 27) | (1ULL << 19))
350 
351 #if OPTIONS_WRITTEN_TO_BIN_LOG != EXPECTED_OPTIONS
352 #error OPTIONS_WRITTEN_TO_BIN_LOG must NOT change their values!
353 #endif
354 #undef EXPECTED_OPTIONS /* You shouldn't use this one */
355 
356 /**
357  Maximum value of binlog logical timestamp.
358 */
359 const int64 SEQ_MAX_TIMESTAMP = LLONG_MAX;
360 
361 /**
362  This method is used to extract the partition_id
363  from a partitioned table.
364 
365  @param part_info an object of class partition_info it will be used
366  to call the methods responsible for returning the
367  value of partition_id
368 
369  @retval The return value is the partition_id.
370 
371 */
372 int get_rpl_part_id(partition_info *part_info);
373 
374 #ifdef MYSQL_SERVER
375 class Item;
376 class Protocol;
378 class Slave_worker;
379 class sql_exchange;
380 template <class T>
381 class List;
382 #endif
383 
384 class Relay_log_info;
385 
386 #ifndef MYSQL_SERVER
387 enum enum_base64_output_mode {
388  BASE64_OUTPUT_NEVER = 0,
389  BASE64_OUTPUT_AUTO = 1,
390  BASE64_OUTPUT_UNSPEC = 2,
391  BASE64_OUTPUT_DECODE_ROWS = 3,
392  /* insert new output modes here */
393  BASE64_OUTPUT_MODE_COUNT
394 };
395 
396 /*
397  A structure for mysqlbinlog to know how to print events
398 
399  This structure is passed to the event's print() methods,
400 
401  There are two types of settings stored here:
402  1. Last db, flags2, sql_mode etc comes from the last printed event.
403  They are stored so that only the necessary USE and SET commands
404  are printed.
405  2. Other information on how to print the events, e.g. short_form,
406  hexdump_from. These are not dependent on the last event.
407 */
408 struct PRINT_EVENT_INFO {
409  /*
410  Settings for database, sql_mode etc that comes from the last event
411  that was printed. We cache these so that we don't have to print
412  them if they are unchanged.
413  */
414  // TODO: have the last catalog here ??
415  char db[FN_REFLEN + 1]; // TODO: make this a LEX_STRING when thd->db is
416  bool flags2_inited;
417  uint32 flags2;
418  bool sql_mode_inited;
419  sql_mode_t sql_mode; /* must be same as THD.variables.sql_mode */
420  ulong auto_increment_increment, auto_increment_offset;
421  bool charset_inited;
422  char charset[6]; // 3 variables, each of them storable in 2 bytes
423  char time_zone_str[MAX_TIME_ZONE_NAME_LENGTH];
424  uint lc_time_names_number;
425  uint charset_database_number;
426  uint default_collation_for_utf8mb4_number;
427  uint8_t sql_require_primary_key;
429  bool thread_id_printed;
430  uint8_t default_table_encryption;
431 
432  PRINT_EVENT_INFO();
433 
434  ~PRINT_EVENT_INFO() {
435  close_cached_file(&head_cache);
436  close_cached_file(&body_cache);
437  close_cached_file(&footer_cache);
438  }
439  bool init_ok() /* tells if construction was successful */
440  {
441  return my_b_inited(&head_cache) && my_b_inited(&body_cache) &&
442  my_b_inited(&footer_cache);
443  }
444 
445  /* Settings on how to print the events */
446  // True if the --short-form flag was specified
447  bool short_form;
448  // The X in --base64-output=X
449  enum_base64_output_mode base64_output_mode;
450  // True if the --skip-gtids flag was specified.
451  bool skip_gtids;
452  /*
453  This is set whenever a Format_description_event is printed.
454  Later, when an event is printed in base64, this flag is tested: if
455  no Format_description_event has been seen, it is unsafe to print
456  the base64 event, so an error message is generated.
457  */
458  bool printed_fd_event;
459  my_off_t hexdump_from;
460  uint8 common_header_len;
461  char delimiter[16];
462 
463  uint verbose;
464  table_mapping m_table_map;
465  table_mapping m_table_map_ignored;
466 
467  /*
468  These three caches are used by the row-based replication events to
469  collect the header information and the main body of the events
470  making up a statement and in footer section any verbose related details
471  or comments related to the statment.
472  */
473  IO_CACHE head_cache;
474  IO_CACHE body_cache;
475  IO_CACHE footer_cache;
476  /* Indicate if the body cache has unflushed events */
477  bool have_unflushed_events;
478 
479  /*
480  True if an event was skipped while printing the events of
481  a transaction and no COMMIT statement or XID event was ever
482  output (ie, was filtered out as well). This can be triggered
483  by the --database option of mysqlbinlog.
484 
485  False, otherwise.
486  */
487  bool skipped_event_in_transaction;
488 
489  bool print_table_metadata;
490 };
491 #endif
492 
493 /*
494  A specific to the database-scheduled MTS type.
495 */
496 struct Mts_db_names {
498  int num;
499 };
500 
501 /**
502  @class Log_event
503 
504  This is the abstract base class for binary log events.
505 
506  @section Log_event_binary_format Binary Format
507 
508  The format of the event is described @ref Binary_log_event_format "here".
509 
510  @subsection Log_event_format_of_atomic_primitives Format of Atomic Primitives
511 
512  - All numbers, whether they are 16-, 24-, 32-, or 64-bit numbers,
513  are stored in little endian, i.e., the least significant byte first,
514  unless otherwise specified.
515 
516 */
517 class Log_event {
518  public:
519  /**
520  Enumeration of what kinds of skipping (and non-skipping) that can
521  occur when the slave executes an event.
522 
523  @see shall_skip
524  @see do_shall_skip
525  */
527  /**
528  Don't skip event.
529  */
531 
532  /**
533  Skip event by ignoring it.
534 
535  This means that the slave skip counter will not be changed.
536  */
538 
539  /**
540  Skip event and decrease skip counter.
541  */
543  };
544 
545  protected:
548  /*
549  If possible the event should use a non-transactional cache before
550  being flushed to the binary log. This means that it must be flushed
551  right after its correspondent statement is completed.
552  */
554  /*
555  The event should use a transactional cache before being flushed to
556  the binary log. This means that it must be flushed upon commit or
557  rollback.
558  */
560  /*
561  The event must be written directly to the binary log without going
562  through any cache.
563  */
565  /*
566  If there is a need for different types, introduce them before this.
567  */
569  };
570 
573  /*
574  The event must be written to a cache and upon commit or rollback
575  written to the binary log.
576  */
578  /*
579  The event must be written to an empty cache and immediatly written
580  to the binary log without waiting for any other event.
581  */
583  /*
584  If there is a need for different types, introduce them before this.
585  */
587  };
588 
589  /**
590  Writes the common header of this event to the given memory buffer.
591 
592  This does not update the checksum.
593 
594  @note This has the following form:
595 
596  +---------+---------+---------+------------+-----------+-------+
597  |timestamp|type code|server_id|event_length|end_log_pos|flags |
598  |4 bytes |1 byte |4 bytes |4 bytes |4 bytes |2 bytes|
599  +---------+---------+---------+------------+-----------+-------+
600 
601  @param buf Memory buffer to write to. This must be at least
602  LOG_EVENT_HEADER_LEN bytes long.
603 
604  @return The number of bytes written, i.e., always
605  LOG_EVENT_HEADER_LEN.
606  */
608  /**
609  Writes the common-header of this event to the given output stream and
610  updates the checksum.
611 
612  @param ostream The event will be written to this output stream.
613 
614  @param data_length The length of the post-header section plus the
615  length of the data section; i.e., the length of the event minus
616  the common-header and the checksum.
617  */
618  bool write_header(Basic_ostream *ostream, size_t data_length);
619  bool write_footer(Basic_ostream *ostream);
620  bool need_checksum();
621 
622  public:
623  /*
624  A temp buffer for read_log_event; it is later analysed according to the
625  event's type, and its content is distributed in the event-specific fields.
626  */
627  char *temp_buf;
628 
629  /*
630  This variable determines whether the event is responsible for deallocating
631  the memory pointed by temp_buf. When set to true temp_buf is deallocated
632  and when it is set to false just make temp_buf point to NULL.
633  */
635 
636  /* The number of seconds the query took to run on the master. */
638 
639  /*
640  The master's server id (is preserved in the relay log; used to
641  prevent from infinite loops in circular replication).
642  */
644 
645  /**
646  A storage to cache the global system variable's value.
647  Handling of a separate event will be governed its member.
648  */
650 
651  /**
652  Defines the type of the cache, if any, where the event will be
653  stored before being flushed to disk.
654  */
656 
657  /**
658  Defines when information, i.e. event or cache, will be flushed
659  to disk.
660  */
662  /**
663  Placeholder for event checksum while writing to binlog.
664  */
666  /**
667  Index in @c rli->gaq array to indicate a group that this event is
668  purging. The index is set by Coordinator to a group terminator
669  event is checked by Worker at the event execution. The indexed
670  data represent the Worker progress status.
671  */
673 
674  /**
675  The Log_event_header class contains the variable present
676  in the common header
677  */
679 
680  /**
681  The Log_event_footer class contains the variable present
682  in the common footer. Currently, footer contains only the checksum_alg.
683  */
685  /**
686  MTS: associating the event with either an assigned Worker or Coordinator.
687  Additionally the member serves to tag deferred (IRU) events to avoid
688  the event regular time destruction.
689  */
691 
692  /**
693  A copy of the main rli value stored into event to pass to MTS worker rli
694  */
696 
697 #ifdef MYSQL_SERVER
699  /**
700  Partition info associate with event to deliver to MTS event applier
701  */
703 
705  enum_event_cache_type cache_type_arg,
706  enum_event_logging_type logging_type_arg);
707  Log_event(THD *thd_arg, uint16 flags_arg,
708  enum_event_cache_type cache_type_arg,
709  enum_event_logging_type logging_type_arg, Log_event_header *header,
710  Log_event_footer *footer);
711  /*
712  init_show_field_list() prepares the column names and types for the
713  output of SHOW BINLOG EVENTS; it is used only by SHOW BINLOG
714  EVENTS.
715  */
716  static void init_show_field_list(List<Item> *field_list);
717 
718  int net_send(Protocol *protocol, const char *log_name, my_off_t pos);
719 
720  /**
721  Stores a string representation of this event in the Protocol.
722  This is used by SHOW BINLOG EVENTS.
723 
724  @retval 0 success
725  @retval nonzero error
726  */
727  virtual int pack_info(Protocol *protocol);
728 
729  virtual const char *get_db();
730 #else // ifdef MYSQL_SERVER
731  /* print*() functions are used by mysqlbinlog */
732  virtual void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const = 0;
733  void print_timestamp(IO_CACHE *file, time_t *ts) const;
734  void print_header(IO_CACHE *file, PRINT_EVENT_INFO *print_event_info,
735  bool is_more) const;
736  void print_base64(IO_CACHE *file, PRINT_EVENT_INFO *print_event_info,
737  bool is_more) const;
738 #endif // ifdef MYSQL_SERVER ... else
739 
740  void *operator new(size_t size);
741 
742  static void operator delete(void *ptr, size_t) { my_free(ptr); }
743 
744  /* Placement version of the above operators */
745  static void *operator new(size_t, void *ptr) { return ptr; }
746  static void operator delete(void *, void *) {}
747  /**
748  Write the given buffer to the given output stream, updating the
749  checksum if checksums are enabled.
750 
751  @param ostream The output stream to write to.
752  @param buf The buffer to write.
753  @param data_length The number of bytes to write.
754 
755  @retval false Success.
756  @retval true Error.
757  */
758  bool wrapper_my_b_safe_write(Basic_ostream *ostream, const uchar *buf,
759  size_t data_length);
760 
761 #ifdef MYSQL_SERVER
762  virtual bool write(Basic_ostream *ostream) {
763  return (write_header(ostream, get_data_size()) ||
764  write_data_header(ostream) || write_data_body(ostream) ||
765  write_footer(ostream));
766  }
767 
768  time_t get_time();
769 
770  virtual bool write_data_header(Basic_ostream *) { return 0; }
771  virtual bool write_data_body(Basic_ostream *) { return 0; }
772 #endif
773 
775 
776  /**
777  Return true if the event has to be logged using SBR for DMLs.
778  */
779  virtual bool is_sbr_logging_format() const { return false; }
780  /**
781  Return true if the event has to be logged using RBR for DMLs.
782  */
783  virtual bool is_rbr_logging_format() const { return false; }
784 
785  /*
786  is_valid is event specific sanity checks to determine that the
787  object is correctly initialized.
788  */
789  bool is_valid();
792  /*
793  Artificial events are automatically generated and do not exist
794  in master's binary log, so log_pos should be set to 0.
795  */
796  common_header->log_pos = 0;
797  }
799  bool is_artificial_event() const {
801  }
802  bool is_relay_log_event() const {
804  }
805  bool is_ignorable_event() const {
807  }
808  bool is_no_filter_event() const {
810  }
811  inline bool is_using_trans_cache() const {
813  }
814  inline bool is_using_stmt_cache() const {
816  }
817  inline bool is_using_immediate_logging() const {
819  }
820 
821  /*
822  For the events being decoded in BAPI, common_header should
823  point to the header object which is contained within the class
824  Binary_log_event.
825  */
826  Log_event(Log_event_header *header, Log_event_footer *footer);
827 
828  virtual ~Log_event() { free_temp_buf(); }
829  void register_temp_buf(char *buf, bool free_in_destructor = true) {
830  m_free_temp_buf_in_destructor = free_in_destructor;
831  temp_buf = buf;
832  }
833  void free_temp_buf() {
834  if (temp_buf) {
836  temp_buf = nullptr;
837  }
838  }
839  /*
840  Get event length for simple events. For complicated events the length
841  is calculated during write()
842  */
843  virtual size_t get_data_size() { return 0; }
844  /**
845  Returns the human readable name of the given event type.
846  */
847  static const char *get_type_str(Log_event_type type);
848  /**
849  Returns the human readable name of this event's type.
850  */
851  const char *get_type_str() const;
852  /* Return start of query time or current time */
853 
854 #if defined(MYSQL_SERVER)
855  /**
856  Is called from get_mts_execution_mode() to
857 
858  @return true if the event needs applying with synchronization
859  agaist Workers, otherwise
860  false
861 
862  @note There are incompatile combinations such as referred further events
863  are wrapped with BEGIN/COMMIT. Such cases should be identified
864  by the caller and treats correspondingly.
865 
866  todo: to mts-support Old master Load-data related events
867  */
869  switch (get_type_code()) {
875  return true;
876  default:
877  return false;
878  }
879  }
880 
881  private:
882  /*
883  possible decisions by get_mts_execution_mode().
884  The execution mode can be PARALLEL or not (thereby sequential
885  unless impossible at all). When it's sequential it further breaks into
886  ASYNChronous and SYNChronous.
887  */
889  /*
890  Event is run by a Worker.
891  */
893  /*
894  Event is run by Coordinator.
895  */
897  /*
898  Event is run by Coordinator and requires synchronization with Workers.
899  */
901  /*
902  Event can't be executed neither by Workers nor Coordinator.
903  */
905  };
906 
907  /**
908  MTS Coordinator finds out a way how to execute the current event.
909 
910  Besides the parallelizable case, some events have to be applied by
911  Coordinator concurrently with Workers and some to require synchronization
912  with Workers (@c see wait_for_workers_to_finish) before to apply them.
913 
914  @param mts_in_group the being group parsing status, true
915  means inside the group
916 
917  @retval EVENT_EXEC_PARALLEL if event is executed by a Worker
918  @retval EVENT_EXEC_ASYNC if event is executed by Coordinator
919  @retval EVENT_EXEC_SYNC if event is executed by Coordinator
920  with synchronization against the Workers
921  */
923  /*
924  Slave workers are unable to handle Format_description_log_event,
925  Rotate_log_event and Previous_gtids_log_event correctly.
926  However, when a transaction spans multiple relay logs, these
927  events occur in the middle of a transaction. The way we handle
928  this is by marking the events as 'ASYNC', meaning that the
929  coordinator thread will handle the events without stopping the
930  worker threads.
931 
932  @todo Refactor this: make Log_event::get_slave_worker handle
933  transaction boundaries in a more robust way, so that it is able
934  to process Format_description_log_event, Rotate_log_event, and
935  Previous_gtids_log_event. Then, when these events occur in the
936  middle of a transaction, make them part of the transaction so
937  that the worker that handles the transaction handles these
938  events too. /Sven
939  */
940  if (
941  /*
942  When a Format_description_log_event occurs in the middle of
943  a transaction, it either has the slave's server_id, or has
944  end_log_pos==0.
945 
946  @todo This does not work when master and slave have the same
947  server_id and replicate-same-server-id is enabled, since
948  events that are not in the middle of a transaction will be
949  executed in ASYNC mode in that case.
950  */
952  ((server_id == (uint32)::server_id) ||
953  (common_header->log_pos == 0))) ||
954  /*
955  All Previous_gtids_log_events in the relay log are generated
956  by the slave. They don't have any meaning to the applier, so
957  they can always be ignored by the applier. So we can process
958  them asynchronously by the coordinator. It is also important
959  to not feed them to workers because that confuses
960  get_slave_worker.
961  */
963  /*
964  Rotate_log_event can occur in the middle of a transaction.
965  When this happens, either it is a Rotate event generated on
966  the slave which has the slave's server_id, or it is a Rotate
967  event that originates from a master but has end_log_pos==0.
968  */
970  ((server_id == (uint32)::server_id) ||
971  (common_header->log_pos == 0 && mts_in_group))))
972  return EVENT_EXEC_ASYNC;
973  else if (is_mts_sequential_exec())
974  return EVENT_EXEC_SYNC;
975  else
976  return EVENT_EXEC_PARALLEL;
977  }
978 
979  /**
980  @return index in [0, M] range to indicate
981  to be assigned worker;
982  M is the max index of the worker pool.
983  */
985 
986  /*
987  Group of events can be marked to force its execution
988  in isolation from any other Workers.
989  Typically that is done for a transaction that contains
990  a query accessing more than OVER_MAX_DBS_IN_EVENT_MTS databases.
991  Factually that's a sequential mode where a Worker remains to
992  be the applier.
993  */
994  virtual void set_mts_isolate_group() {
998  }
999 
1000  public:
1001  /**
1002  The method fills in pointers to event's database name c-strings
1003  to a supplied array.
1004  In other than Query-log-event case the returned array contains
1005  just one item.
1006  @param[out] arg pointer to a struct containing char* array
1007  pointers to be filled in and the number
1008  of filled instances.
1009  @param rpl_filter pointer to a replication filter.
1010 
1011  @return number of the filled intances indicating how many
1012  databases the event accesses.
1013  */
1015  Rpl_filter *rpl_filter MY_ATTRIBUTE((unused))) {
1016  arg->name[0] = get_db();
1017 
1018  return arg->num = mts_number_dbs();
1019  }
1020 
1021  /**
1022  @return true if events carries partitioning data (database names).
1023  */
1024  bool contains_partition_info(bool);
1025 
1026  /*
1027  @return the number of updated by the event databases.
1028 
1029  @note In other than Query-log-event case that's one.
1030  */
1031  virtual uint8 mts_number_dbs() { return 1; }
1032 
1033  /**
1034  @return true if the terminal event of a group is marked to
1035  execute in isolation from other Workers,
1036  false otherwise
1037  */
1040  }
1041 
1042  /**
1043  Events of a certain type can start or end a group of events treated
1044  transactionally wrt binlog.
1045 
1046  Public access is required by implementation of recovery + skip.
1047 
1048  @return true if the event starts a group (transaction)
1049  false otherwise
1050  */
1051 #endif
1052  virtual bool starts_group() const { return false; }
1053  /**
1054  @return true if the event ends a group (transaction)
1055  false otherwise
1056  */
1057  virtual bool ends_group() const { return false; }
1058 #ifdef MYSQL_SERVER
1059  /**
1060  Apply the event to the database.
1061 
1062  This function represents the public interface for applying an
1063  event.
1064 
1065  @see do_apply_event
1066  */
1067  int apply_event(Relay_log_info *rli);
1068 
1069  /**
1070  Apply the GTID event in curr_group_data to the database.
1071 
1072  @param rli Pointer to coordinato's relay log info.
1073 
1074  @retval 0 success
1075  @retval 1 error
1076  */
1077  inline int apply_gtid_event(Relay_log_info *rli);
1078 
1079  /**
1080  Update the relay log position.
1081 
1082  This function represents the public interface for "stepping over"
1083  the event and will update the relay log information.
1084 
1085  @see do_update_pos
1086  */
1087  int update_pos(Relay_log_info *rli) { return do_update_pos(rli); }
1088 
1089  /**
1090  Decide if the event shall be skipped, and the reason for skipping
1091  it.
1092 
1093  @see do_shall_skip
1094  */
1096  DBUG_TRACE;
1097  enum_skip_reason ret = do_shall_skip(rli);
1098  DBUG_PRINT("info", ("skip reason=%d=%s", ret,
1099  ret == EVENT_SKIP_NOT
1100  ? "NOT"
1101  : ret == EVENT_SKIP_IGNORE ? "IGNORE" : "COUNT"));
1102  return ret;
1103  }
1104 
1105  /**
1106  Primitive to apply an event to the database.
1107 
1108  This is where the change to the database is made.
1109 
1110  @note The primitive is protected instead of private, since there
1111  is a hierarchy of actions to be performed in some cases.
1112 
1113  @see Format_description_log_event::do_apply_event()
1114 
1115  @param rli Pointer to relay log info structure
1116 
1117  @retval 0 Event applied successfully
1118  @retval errno Error code if event application failed
1119  */
1120  virtual int do_apply_event(Relay_log_info const *rli MY_ATTRIBUTE((unused))) {
1121  return 0; /* Default implementation does nothing */
1122  }
1123 
1124  virtual int do_apply_event_worker(Slave_worker *w);
1125 
1126  protected:
1127  /**
1128  Helper function to ignore an event w.r.t. the slave skip counter.
1129 
1130  This function can be used inside do_shall_skip() for functions
1131  that cannot end a group. If the slave skip counter is 1 when
1132  seeing such an event, the event shall be ignored, the counter
1133  left intact, and processing continue with the next event.
1134 
1135  A typical usage is:
1136  @code
1137  enum_skip_reason do_shall_skip(Relay_log_info *rli) {
1138  return continue_group(rli);
1139  }
1140  @endcode
1141 
1142  @return Skip reason
1143  */
1145 
1146  /**
1147  Advance relay log coordinates.
1148 
1149  This function is called to advance the relay log coordinates to
1150  just after the event. It is essential that both the relay log
1151  coordinate and the group log position is updated correctly, since
1152  this function is used also for skipping events.
1153 
1154  Normally, each implementation of do_update_pos() shall:
1155 
1156  - Update the event position to refer to the position just after
1157  the event.
1158 
1159  - Update the group log position to refer to the position just
1160  after the event <em>if the event is last in a group</em>
1161 
1162  @param rli Pointer to relay log info structure
1163 
1164  @retval 0 Coordinates changed successfully
1165  @retval errno Error code if advancing failed (usually just
1166  1). Observe that handler errors are returned by the
1167  do_apply_event() function, and not by this one.
1168  */
1169  virtual int do_update_pos(Relay_log_info *rli);
1170 
1171  /**
1172  Decide if this event shall be skipped or not and the reason for
1173  skipping it.
1174 
1175  The default implementation decide that the event shall be skipped
1176  if either:
1177 
1178  - the server id of the event is the same as the server id of the
1179  server and <code>rli->replicate_same_server_id</code> is true,
1180  or
1181 
1182  - if <code>rli->slave_skip_counter</code> is greater than zero.
1183 
1184  @see do_apply_event
1185  @see do_update_pos
1186 
1187  @retval Log_event::EVENT_SKIP_NOT
1188  The event shall not be skipped and should be applied.
1189 
1190  @retval Log_event::EVENT_SKIP_IGNORE
1191  The event shall be skipped by just ignoring it, i.e., the slave
1192  skip counter shall not be changed. This happends if, for example,
1193  the originating server id of the event is the same as the server
1194  id of the slave.
1195 
1196  @retval Log_event::EVENT_SKIP_COUNT
1197  The event shall be skipped because the slave skip counter was
1198  non-zero. The caller shall decrease the counter by one.
1199  */
1201 #endif
1202 };
1203 
1204 /*
1205  One class for each type of event.
1206  Two constructors for each class:
1207  - one to create the event for logging (when the server acts as a master),
1208  called after an update to the database is done,
1209  which accepts parameters like the query, the database, the options for LOAD
1210  DATA INFILE...
1211  - one to create the event from a packet (when the server acts as a slave),
1212  called before reproducing the update, which accepts parameters (like a
1213  buffer). Used to read from the master, from the relay log, and in
1214  mysqlbinlog. This constructor must be format-tolerant.
1215 */
1216 
1217 /**
1218  A Query event is written to the binary log whenever the database is
1219  modified on the master, unless row based logging is used.
1220 
1221  Query_log_event is created for logging, and is called after an update to the
1222  database is done. It is used when the server acts as the master.
1223 
1224  Virtual inheritance is required here to handle the diamond problem in
1225  the class @c Execute_load_query_log_event.
1226  The diamond structure is explained in @c Excecute_load_query_log_event
1227 
1228  @internal
1229  The inheritance structure is as follows:
1230 
1231  Binary_log_event
1232  ^
1233  |
1234  |
1235  Query_event Log_event
1236  \ /
1237  <<virtual>>\ /
1238  \ /
1239  Query_log_event
1240  @endinternal
1241 */
1243  public Log_event {
1244  protected:
1245  Log_event_header::Byte *data_buf;
1246 
1247  public:
1248  /*
1249  For events created by Query_log_event::do_apply_event (and
1250  Load_log_event::do_apply_event()) we need the *original* thread
1251  id, to be able to log the event with the original (=master's)
1252  thread id (fix for BUG#1686).
1253  */
1255 
1256  /**
1257  True if this is a ROLLBACK event injected by the mts coordinator to finish a
1258  group corresponding to a partial transaction in the relay log.
1259  False otherwise and by default, as it must be explicitly set to true by the
1260  coordinator.
1261  */
1263 
1264  /**
1265  The flag indicates whether the DDL query has been (already)
1266  committed or not. It's initialized as OFF at the event instantiation,
1267  flips ON when the DDL transaction has been committed with
1268  all its possible extra statement due to replication or GTID.
1269 
1270  The flag status is also checked in few places to catch uncommitted
1271  transactions which can normally happen due to filtering out. In
1272  such a case the commit is deferred to @c Log_event::do_update_pos().
1273  */
1275 
1276 #ifdef MYSQL_SERVER
1277 
1278  Query_log_event(THD *thd_arg, const char *query_arg, size_t query_length,
1279  bool using_trans, bool immediate, bool suppress_use,
1280  int error, bool ignore_command = false);
1281  const char *get_db() override { return db; }
1282 
1283  /**
1284  @param[out] arg pointer to a struct containing char* array
1285  pointers be filled in and the number of
1286  filled instances.
1287  In case the number exceeds MAX_DBS_IN_EVENT_MTS,
1288  the overfill is indicated with assigning the number to
1289  OVER_MAX_DBS_IN_EVENT_MTS.
1290  @param rpl_filter pointer to a replication filter.
1291 
1292  @return number of databases in the array or OVER_MAX_DBS_IN_EVENT_MTS.
1293  */
1295  Rpl_filter *rpl_filter) override {
1297  // the empty string db name is special to indicate sequential applying
1298  mts_accessed_db_names[0][0] = 0;
1299  } else {
1300  for (uchar i = 0; i < mts_accessed_dbs; i++) {
1301  const char *db_name = mts_accessed_db_names[i];
1302 
1303  // Only default database is rewritten.
1304  if (!rpl_filter->is_rewrite_empty() && !strcmp(get_db(), db_name)) {
1305  size_t dummy_len;
1306  const char *db_filtered =
1307  rpl_filter->get_rewrite_db(db_name, &dummy_len);
1308  // db_name != db_filtered means that db_name is rewritten.
1309  if (strcmp(db_name, db_filtered)) db_name = db_filtered;
1310  }
1311  arg->name[i] = db_name;
1312  }
1313  }
1314  return arg->num = mts_accessed_dbs;
1315  }
1316 
1317  void attach_temp_tables_worker(THD *, const Relay_log_info *);
1318  void detach_temp_tables_worker(THD *, const Relay_log_info *);
1319 
1320  virtual uchar mts_number_dbs() override { return mts_accessed_dbs; }
1321 
1322  int pack_info(Protocol *protocol) override;
1323 #else
1324  void print_query_header(IO_CACHE *file,
1325  PRINT_EVENT_INFO *print_event_info) const;
1326  void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
1327  static bool rewrite_db_in_buffer(char **buf, ulong *event_len,
1328  const Format_description_event &fde);
1329 #endif
1330 
1331  Query_log_event();
1332 
1333  Query_log_event(const char *buf,
1334  const Format_description_event *description_event,
1336  ~Query_log_event() override {
1337  if (data_buf) my_free(data_buf);
1338  }
1339 #ifdef MYSQL_SERVER
1340  bool write(Basic_ostream *ostream) override;
1341  virtual bool write_post_header_for_derived(Basic_ostream *) { return false; }
1342 #endif
1343 
1344  /*
1345  Returns number of bytes additionally written to post header by derived
1346  events (so far it is only Execute_load_query event).
1347  */
1348  virtual ulong get_post_header_size_for_derived() { return 0; }
1349  /* Writes derived event-specific part of post header. */
1350 
1351  public: /* !!! Public in this patch to allow old usage */
1352 #if defined(MYSQL_SERVER)
1353  virtual enum_skip_reason do_shall_skip(Relay_log_info *rli) override;
1354  virtual int do_apply_event(Relay_log_info const *rli) override;
1355  virtual int do_update_pos(Relay_log_info *rli) override;
1356 
1357  int do_apply_event(Relay_log_info const *rli, const char *query_arg,
1358  size_t q_len_arg);
1359 #endif /* MYSQL_SERVER */
1360  /*
1361  If true, the event always be applied by slave SQL thread or be printed by
1362  mysqlbinlog
1363  */
1364  bool is_trans_keyword() const {
1365  /*
1366  Before the patch for bug#50407, The 'SAVEPOINT and ROLLBACK TO'
1367  queries input by user was written into log events directly.
1368  So the keywords can be written in both upper case and lower case
1369  together, strncasecmp is used to check both cases. they also could be
1370  binlogged with comments in the front of these keywords. for examples:
1371  / * bla bla * / SAVEPOINT a;
1372  / * bla bla * / ROLLBACK TO a;
1373  but we don't handle these cases and after the patch, both quiries are
1374  binlogged in upper case with no comments.
1375  */
1376  return !strncmp(query, "BEGIN", q_len) ||
1377  !strncmp(query, "COMMIT", q_len) ||
1378  !native_strncasecmp(query, "SAVEPOINT", 9) ||
1379  !native_strncasecmp(query, "ROLLBACK", 8) ||
1380  !native_strncasecmp(query, STRING_WITH_LEN("XA START")) ||
1381  !native_strncasecmp(query, STRING_WITH_LEN("XA END")) ||
1382  !native_strncasecmp(query, STRING_WITH_LEN("XA PREPARE")) ||
1383  !native_strncasecmp(query, STRING_WITH_LEN("XA COMMIT")) ||
1384  !native_strncasecmp(query, STRING_WITH_LEN("XA ROLLBACK"));
1385  }
1386 
1387  /**
1388  When a query log event contains a non-transaction control statement, we
1389  assume that it is changing database content (DML) and was logged using
1390  binlog_format=statement.
1391 
1392  @return True the event represents a statement that was logged using SBR
1393  that can change database content.
1394  False for transaction control statements.
1395  */
1396  bool is_sbr_logging_format() const override { return !is_trans_keyword(); }
1397 
1398  /**
1399  Notice, DDL queries are logged without BEGIN/COMMIT parentheses
1400  and identification of such single-query group
1401  occures within logics of @c get_slave_worker().
1402  */
1403 
1404  bool starts_group() const override {
1405  return !strncmp(query, "BEGIN", q_len) ||
1406  !strncmp(query, STRING_WITH_LEN("XA START"));
1407  }
1408 
1409  virtual bool ends_group() const override {
1410  return !strncmp(query, "COMMIT", q_len) ||
1411  (!native_strncasecmp(query, STRING_WITH_LEN("ROLLBACK")) &&
1412  native_strncasecmp(query, STRING_WITH_LEN("ROLLBACK TO "))) ||
1413  !strncmp(query, STRING_WITH_LEN("XA ROLLBACK"));
1414  }
1415  static size_t get_query(const char *buf, size_t length,
1416  const Format_description_event *fd_event,
1417  const char **query_arg);
1418 
1419  bool is_query_prefix_match(const char *pattern, uint p_len) {
1420  return !strncmp(query, pattern, p_len);
1421  }
1422 
1423  private:
1424  /** Whether or not the statement represented by this event requires
1425  `Q_SQL_REQUIRE_PRIMARY_KEY` to be logged along aside. */
1427 
1428  /** Whether or not the statement represented by this event requires
1429  `Q_DEFAULT_TABLE_ENCRYPTION` to be logged along aside. */
1431 };
1432 
1433 /**
1434  @class Format_description_log_event
1435 
1436  For binlog version 4.
1437  This event is saved by threads which read it, as they need it for future
1438  use (to decode the ordinary events).
1439  This is the subclass of Format_description_event
1440 
1441  @internal
1442  The inheritance structure in the current design for the classes is
1443  as follows:
1444 
1445  Binary_log_event
1446  ^
1447  |
1448  |
1449  Format_description_event Log_event
1450  \ /
1451  \ /
1452  \ /
1453  Format_description_log_event
1454  @endinternal
1455  @section Format_description_log_event_binary_format Binary Format
1456 */
1457 
1459  public Log_event {
1460  public:
1461  /*
1462  MTS Workers and Coordinator share the event and that affects its
1463  destruction. Instantiation is always done by Coordinator/SQL thread.
1464  Workers are allowed to destroy only "obsolete" instances, those
1465  that are not actual for Coordinator anymore but needed to Workers
1466  that are processing queued events depending on the old instance.
1467  The counter of a new FD is incremented by Coordinator or Worker at
1468  time of {Relay_log_info,Slave_worker}::set_rli_description_event()
1469  execution.
1470  In the same methods the counter of the "old" FD event is decremented
1471  and when it drops to zero the old FD is deleted.
1472  The latest read from relay-log event is to be
1473  destroyed by Coordinator/SQL thread at its thread exit.
1474  Notice the counter is processed even in the single-thread mode where
1475  decrement and increment are done by the single SQL thread.
1476  */
1477  std::atomic<int32> atomic_usage_counter{0};
1478 
1481  const char *buf, const Format_description_event *description_event);
1482 #ifdef MYSQL_SERVER
1483  bool write(Basic_ostream *ostream) override;
1484  int pack_info(Protocol *protocol) override;
1485 #else
1486  void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
1487 #endif
1488 
1489  size_t get_data_size() override {
1490  /*
1491  The vector of post-header lengths is considered as part of the
1492  post-header, because in a given version it never changes (contrary to the
1493  query in a Query_log_event).
1494  */
1495  return Binary_log_event::FORMAT_DESCRIPTION_HEADER_LEN;
1496  }
1497 
1498  protected:
1499 #if defined(MYSQL_SERVER)
1500  virtual int do_apply_event(Relay_log_info const *rli) override;
1501  virtual int do_update_pos(Relay_log_info *rli) override;
1502  virtual enum_skip_reason do_shall_skip(Relay_log_info *rli) override;
1503 #endif
1504 };
1505 
1506 /**
1507  @class Intvar_log_event
1508 
1509  The class derives from the class Intvar_event in Binlog API,
1510  defined in the header binlog_event.h. An Intvar_log_event is
1511  created just before a Query_log_event, if the query uses one
1512  of the variables LAST_INSERT_ID or INSERT_ID. This class is used
1513  by the slave for applying the event.
1514 
1515  @internal
1516  The inheritance structure in the current design for the classes is
1517  as follows:
1518 
1519  Binary_log_event
1520  ^
1521  |
1522  |
1523  Intvar_event Log_event
1524  \ /
1525  \ /
1526  \ /
1527  Intvar_log_event
1528  @endinternal
1529 */
1531  public:
1532 #ifdef MYSQL_SERVER
1533  Intvar_log_event(THD *thd_arg, uchar type_arg, ulonglong val_arg,
1534  enum_event_cache_type cache_type_arg,
1535  enum_event_logging_type logging_type_arg)
1536  : binary_log::Intvar_event(type_arg, val_arg),
1537  Log_event(thd_arg, 0, cache_type_arg, logging_type_arg, header(),
1538  footer()) {
1539  common_header->set_is_valid(true);
1540  }
1541  int pack_info(Protocol *protocol) override;
1542 #else
1543  void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
1544 #endif
1545 
1546  Intvar_log_event(const char *buf,
1547  const Format_description_event *description_event);
1548  ~Intvar_log_event() override {}
1549  size_t get_data_size() override {
1550  return 9; /* sizeof(type) + sizeof(val) */
1551  ;
1552  }
1553 #ifdef MYSQL_SERVER
1554  bool write(Basic_ostream *ostream) override;
1555 #endif
1556 
1557  bool is_sbr_logging_format() const override { return true; }
1558 
1559  private:
1560 #if defined(MYSQL_SERVER)
1561  virtual int do_apply_event(Relay_log_info const *rli) override;
1562  virtual int do_update_pos(Relay_log_info *rli) override;
1563  virtual enum_skip_reason do_shall_skip(Relay_log_info *rli) override;
1564 #endif
1565 };
1566 
1567 /**
1568  @class Rand_log_event
1569 
1570  Logs random seed used by the next RAND(), and by PASSWORD() in 4.1.0.
1571  4.1.1 does not need it (it's repeatable again) so this event needn't be
1572  written in 4.1.1 for PASSWORD() (but the fact that it is written is just a
1573  waste, it does not cause bugs).
1574 
1575  The state of the random number generation consists of 128 bits,
1576  which are stored internally as two 64-bit numbers.
1577 
1578  @internal
1579  The inheritance structure in the current design for the classes is
1580  as follows:
1581  Binary_log_event
1582  ^
1583  |
1584  |
1585  Rand_event Log_event
1586  \ /
1587  \ /
1588  \ /
1589  Rand_log_event
1590  @endinternal
1591 */
1593  public:
1594 #ifdef MYSQL_SERVER
1595  Rand_log_event(THD *thd_arg, ulonglong seed1_arg, ulonglong seed2_arg,
1596  enum_event_cache_type cache_type_arg,
1597  enum_event_logging_type logging_type_arg)
1598  : binary_log::Rand_event(seed1_arg, seed2_arg),
1599  Log_event(thd_arg, 0, cache_type_arg, logging_type_arg, header(),
1600  footer()) {
1601  common_header->set_is_valid(true);
1602  }
1603  int pack_info(Protocol *protocol) override;
1604 #else
1605  void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
1606 #endif
1607 
1608  Rand_log_event(const char *buf,
1609  const Format_description_event *description_event);
1610  ~Rand_log_event() override {}
1611  size_t get_data_size() override { return 16; /* sizeof(ulonglong) * 2*/ }
1612 #ifdef MYSQL_SERVER
1613  bool write(Basic_ostream *ostream) override;
1614 #endif
1615 
1616  bool is_sbr_logging_format() const override { return true; }
1617 
1618  private:
1619 #if defined(MYSQL_SERVER)
1620  virtual int do_apply_event(Relay_log_info const *rli) override;
1621  virtual int do_update_pos(Relay_log_info *rli) override;
1622  virtual enum_skip_reason do_shall_skip(Relay_log_info *rli) override;
1623 #endif
1624 };
1625 
1626 /**
1627  @class Xid_log_event
1628 
1629  This is the subclass of Xid_event defined in libbinlogevent,
1630  An XID event is generated for a commit of a transaction that modifies one or
1631  more tables of an XA-capable storage engine
1632  Logs xid of the transaction-to-be-committed in the 2pc protocol.
1633  Has no meaning in replication, slaves ignore it
1634  The inheritance structure in the current design for the classes is
1635  as follows
1636 
1637  @internal
1638  The inheritance structure in the current design for the classes is
1639  as follows:
1640  Binary_log_event
1641  ^
1642  |
1643  |
1644  Xid_event Log_event
1645  \ /
1646  \ /
1647  \ /
1648  Xid_log_event
1649  @endinternal
1650 */
1651 #ifndef MYSQL_SERVER
1652 typedef ulonglong my_xid; // this line is the same as in handler.h
1653 #endif
1654 
1656  protected:
1657 #ifdef MYSQL_SERVER
1659  Log_event_footer *footer_arg)
1661  Log_event::EVENT_NORMAL_LOGGING, header_arg, footer_arg) {}
1662 #endif
1664  Log_event_footer *footer_arg)
1665  : Log_event(header_arg, footer_arg) {}
1666  ~Xid_apply_log_event() override {}
1667  virtual bool ends_group() const override { return true; }
1668 #if defined(MYSQL_SERVER)
1669  virtual enum_skip_reason do_shall_skip(Relay_log_info *rli) override;
1670  virtual int do_apply_event(Relay_log_info const *rli) override;
1671  virtual int do_apply_event_worker(Slave_worker *rli) override;
1672  virtual bool do_commit(THD *thd_arg) = 0;
1673 #endif
1674 };
1675 
1677  public:
1678 #ifdef MYSQL_SERVER
1679  Xid_log_event(THD *thd_arg, my_xid x)
1680  : binary_log::Xid_event(x),
1681  Xid_apply_log_event(thd_arg, header(), footer()) {
1682  common_header->set_is_valid(true);
1683  }
1684  int pack_info(Protocol *protocol) override;
1685 #else
1686  void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
1687 #endif
1688 
1689  Xid_log_event(const char *buf,
1690  const Format_description_event *description_event);
1691  ~Xid_log_event() override {}
1692  size_t get_data_size() override { return sizeof(xid); }
1693 #ifdef MYSQL_SERVER
1694  bool write(Basic_ostream *ostream) override;
1695 #endif
1696  private:
1697 #if defined(MYSQL_SERVER)
1698  bool do_commit(THD *thd_arg) override;
1699 #endif
1700 };
1701 
1702 /**
1703  @class XA_prepare_log_event
1704 
1705  Similar to Xid_log_event except that
1706  - it is specific to XA transaction
1707  - it carries out the prepare logics rather than the final committing
1708  when @c one_phase member is off.
1709  From the groupping perspective the event finalizes the current "prepare" group
1710  started with XA START Query-log-event.
1711  When @c one_phase is false Commit of Rollback for XA transaction are
1712  logged separately to the prepare-group events so being a groups of
1713  their own.
1714 */
1715 
1717  public Xid_apply_log_event {
1718  private:
1719  /* Total size of buffers to hold serialized members of XID struct */
1720  static const int xid_bufs_size = 12;
1721 
1722  public:
1723 #ifdef MYSQL_SERVER
1724  XA_prepare_log_event(THD *thd_arg, XID *xid_arg, bool one_phase_arg = false)
1725  : binary_log::XA_prepare_event((void *)xid_arg, one_phase_arg),
1726  Xid_apply_log_event(thd_arg, header(), footer()) {}
1727 #endif
1728  XA_prepare_log_event(const char *buf,
1729  const Format_description_event *description_event)
1730  : binary_log::XA_prepare_event(buf, description_event),
1732  DBUG_TRACE;
1733  xid = nullptr;
1734  return;
1735  }
1737  size_t get_data_size() override {
1738  return xid_bufs_size + my_xid.gtrid_length + my_xid.bqual_length;
1739  }
1740 #ifdef MYSQL_SERVER
1741  bool write(Basic_ostream *ostream) override;
1742 #else
1743  void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
1744 #endif
1745 #if defined(MYSQL_SERVER)
1746  int pack_info(Protocol *protocol) override;
1747  bool do_commit(THD *thd) override;
1748 #endif
1749 };
1750 
1751 /**
1752  @class User_var_log_event
1753 
1754  Every time a query uses the value of a user variable, a User_var_log_event is
1755  written before the Query_log_event, to set the user variable.
1756 
1757  @internal
1758  The inheritance structure in the current design for the classes is
1759  as follows:
1760  Binary_log_event
1761  ^
1762  |
1763  |
1764  User_var_event Log_event
1765  \ /
1766  \ /
1767  \ /
1768  User_var_log_event
1769  @endinternal
1770 */
1772  public:
1773 #ifdef MYSQL_SERVER
1774  bool deferred;
1776  User_var_log_event(THD *thd_arg, const char *name_arg, uint name_len_arg,
1777  char *val_arg, ulong val_len_arg, Item_result type_arg,
1778  uint charset_number_arg, uchar flags_arg,
1779  enum_event_cache_type cache_type_arg,
1780  enum_event_logging_type logging_type_arg)
1781  : binary_log::User_var_event(name_arg, name_len_arg, val_arg, val_len_arg,
1782  type_arg, charset_number_arg, flags_arg),
1783  Log_event(thd_arg, 0, cache_type_arg, logging_type_arg, header(),
1784  footer()),
1785  deferred(false) {
1787  }
1788  int pack_info(Protocol *protocol) override;
1789 #else
1790  void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
1791 #endif
1792 
1793  User_var_log_event(const char *buf,
1794  const Format_description_event *description_event);
1795  ~User_var_log_event() override {}
1796 #ifdef MYSQL_SERVER
1797  bool write(Basic_ostream *ostream) override;
1798  /*
1799  Getter and setter for deferred User-event.
1800  Returns true if the event is not applied directly
1801  and which case the applier adjusts execution path.
1802  */
1803  bool is_deferred() { return deferred; }
1804  /*
1805  In case of the deffered applying the variable instance is flagged
1806  and the parsing time query id is stored to be used at applying time.
1807  */
1809  deferred = true;
1810  query_id = qid;
1811  }
1812 #endif
1813 
1814  bool is_sbr_logging_format() const override { return true; }
1815 
1816  private:
1817 #if defined(MYSQL_SERVER)
1818  virtual int do_apply_event(Relay_log_info const *rli) override;
1819  virtual int do_update_pos(Relay_log_info *rli) override;
1820  virtual enum_skip_reason do_shall_skip(Relay_log_info *rli) override;
1821 #endif
1822 };
1823 
1824 /**
1825  @class Stop_log_event
1826 
1827 */
1829  public:
1830 #ifdef MYSQL_SERVER
1834  common_header->set_is_valid(true);
1835  }
1836 
1837 #else
1838  void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
1839 #endif
1840 
1841  Stop_log_event(const char *buf,
1842  const Format_description_event *description_event)
1843  : binary_log::Stop_event(buf, description_event),
1844  Log_event(header(), footer()) {
1845  DBUG_TRACE;
1846  return;
1847  }
1848 
1849  ~Stop_log_event() override {}
1851 
1852  private:
1853 #if defined(MYSQL_SERVER)
1854  virtual int do_update_pos(Relay_log_info *rli) override;
1856  /*
1857  Events from ourself should be skipped, but they should not
1858  decrease the slave skip counter.
1859  */
1860  if (this->server_id == ::server_id)
1862  else
1864  }
1865 #endif
1866 };
1867 
1868 /**
1869  @class Rotate_log_event
1870 
1871  This will be deprecated when we move to using sequence ids.
1872  This class is a subclass of Rotate_event, defined in binlogevent, and is used
1873  by the slave for updating the position in the relay log.
1874 
1875  It is used by the master inorder to write the rotate event in the binary log.
1876 
1877  @internal
1878  The inheritance structure in the current design for the classes is
1879  as follows:
1880 
1881  Binary_log_event
1882  ^
1883  |
1884  |
1885  Rotate_event Log_event
1886  \ /
1887  \ /
1888  \ /
1889  Rotate_log_event
1890  @endinternal
1891 */
1893  public:
1894 #ifdef MYSQL_SERVER
1895  Rotate_log_event(const char *new_log_ident_arg, size_t ident_len_arg,
1896  ulonglong pos_arg, uint flags);
1897  int pack_info(Protocol *protocol) override;
1898 #else
1899  void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
1900 #endif
1901 
1902  Rotate_log_event(const char *buf,
1903  const Format_description_event *description_event);
1904  ~Rotate_log_event() override {}
1905  size_t get_data_size() override {
1906  return ident_len + Binary_log_event::ROTATE_HEADER_LEN;
1907  }
1908 #ifdef MYSQL_SERVER
1909  bool write(Basic_ostream *ostream) override;
1910 #endif
1911 
1912  private:
1913 #if defined(MYSQL_SERVER)
1914  virtual int do_update_pos(Relay_log_info *rli) override;
1915  virtual enum_skip_reason do_shall_skip(Relay_log_info *rli) override;
1916 #endif
1917 };
1918 
1919 /**
1920  @class Append_block_log_event
1921 
1922  This event is created to contain the file data. One LOAD_DATA_INFILE
1923  can have 0 or more instances of this event written to the binary log
1924  depending on the size of the file.
1925 
1926  @internal
1927  The inheritance structure is as follows
1928 
1929  Binary_log_event
1930  ^
1931  |
1932  |
1933  B_l:A_B_E Log_event
1934  \ /
1935  \ /
1936  <<vir>>\ /
1937  \ /
1938  Append_block_log_event
1939  B_l: Namespace Binary_log
1940  A_B_E: class Append_block_event
1941  @endinternal
1942 
1943 */
1945  public Log_event {
1946  public:
1947 #ifdef MYSQL_SERVER
1948  Append_block_log_event(THD *thd, const char *db_arg, uchar *block_arg,
1949  uint block_len_arg, bool using_trans);
1950  int pack_info(Protocol *protocol) override;
1951  virtual int get_create_or_append() const;
1952 #else
1953  void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
1954 #endif
1955 
1956  Append_block_log_event(const char *buf,
1957  const Format_description_event *description_event);
1959  size_t get_data_size() override {
1960  return block_len + Binary_log_event::APPEND_BLOCK_HEADER_LEN;
1961  }
1962 #ifdef MYSQL_SERVER
1963  bool write(Basic_ostream *ostream) override;
1964  const char *get_db() override { return db; }
1965 #endif
1966 
1967  bool is_sbr_logging_format() const override { return true; }
1968 
1969  private:
1970 #if defined(MYSQL_SERVER)
1971  virtual int do_apply_event(Relay_log_info const *rli) override;
1972 #endif
1973 };
1974 
1975 /**
1976  @class Delete_file_log_event
1977 
1978  Delete_file_log_event is created when the LOAD_DATA query fails on the
1979  master for some reason, and the slave should be notified to abort the
1980  load. The event is required since the master starts writing the loaded
1981  block into the binary log before the statement ends. In case of error,
1982  the slave should abort, and delete any temporary file created while
1983  applying the (NEW_)LOAD_EVENT.
1984 
1985  @internal
1986  The inheritance structure is as follows
1987 
1988  Binary_log_event
1989  ^
1990  |
1991  |
1992  B_l:D_F_E Log_event
1993  \ /
1994  \ /
1995  \ /
1996  \ /
1997  Delete_file_log_event
1998 
1999  B_l: Namespace Binary_log
2000  D_F_E: class Delete_file_event
2001  @endinternal
2002 
2003 */
2005  public Log_event {
2006  public:
2007 #ifdef MYSQL_SERVER
2008  Delete_file_log_event(THD *thd, const char *db_arg, bool using_trans);
2009  int pack_info(Protocol *protocol) override;
2010 #else
2011  void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
2012  void print(FILE *file, PRINT_EVENT_INFO *print_event_info, bool enable_local);
2013 #endif
2014 
2015  Delete_file_log_event(const char *buf,
2016  const Format_description_event *description_event);
2018  size_t get_data_size() override {
2019  return Binary_log_event::DELETE_FILE_HEADER_LEN;
2020  }
2021 #ifdef MYSQL_SERVER
2022  bool write(Basic_ostream *ostream) override;
2023  const char *get_db() override { return db; }
2024 #endif
2025 
2026  bool is_sbr_logging_format() const override { return true; }
2027 
2028  private:
2029 #if defined(MYSQL_SERVER)
2030  virtual int do_apply_event(Relay_log_info const *rli) override;
2031 #endif
2032 };
2033 
2034 /**
2035  @class Begin_load_query_log_event
2036 
2037  Event for the first block of file to be loaded, its only difference from
2038  Append_block event is that this event creates or truncates existing file
2039  before writing data.
2040 
2041  @internal
2042  The inheritance structure is as follows
2043 
2044  Binary_log_event
2045  ^
2046  |
2047  |
2048  |
2049  Log_event B_l:A_B_E
2050  ^ /\
2051  | / \
2052  | <<vir>>/ \ <<vir>>
2053  | / \
2054  | / \
2055  | / \
2056  Append_block_log_event B_l:B_L_Q_E
2057  \ /
2058  \ /
2059  \ /
2060  \ /
2061  \ /
2062  Begin_load_query_log_event
2063 
2064  B_l: Namespace Binary_log
2065  A_B_E: class Append_block_event
2066  B_L_Q_E: Begin_load_query_event
2067  @endinternal
2068 
2069  @section Begin_load_query_log_event_binary_format Binary Format
2070 */
2073  public:
2074 #ifdef MYSQL_SERVER
2075  Begin_load_query_log_event(THD *thd_arg, const char *db_arg, uchar *block_arg,
2076  uint block_len_arg, bool using_trans);
2078  int get_create_or_append() const override;
2079 #endif
2080  Begin_load_query_log_event(const char *buf,
2081  const Format_description_event *description_event);
2083 
2084  private:
2085 #if defined(MYSQL_SERVER)
2086  virtual enum_skip_reason do_shall_skip(Relay_log_info *rli) override;
2087 #endif
2088 };
2089 
2090 /**
2091  @class Execute_load_query_log_event
2092 
2093  Event responsible for LOAD DATA execution, it similar to Query_log_event
2094  but before executing the query it substitutes original filename in LOAD DATA
2095  query with name of temporary file.
2096 
2097  @internal
2098  The inheritance structure is as follows:
2099 
2100  Binary_log_event
2101  ^
2102  |
2103  |
2104  |
2105  Log_event B_l:Query_event
2106  ^ /\
2107  | / \
2108  | <<vir>>/ \ <<vir>>
2109  | / \
2110  | / \
2111  | / \
2112  Query_log_event B_l:E_L_Q_E
2113  \ /
2114  \ /
2115  \ /
2116  \ /
2117  \ /
2118  Execute_load_query_log_event
2119 
2120  B_l: Namespace Binary_log
2121  E_L_Q_E: class Execute_load_query
2122  @endinternal
2123 
2124  @section Execute_load_query_log_event_binary_format Binary Format
2125 */
2127  : public Query_log_event,
2129  public:
2130 #ifdef MYSQL_SERVER
2132  THD *thd, const char *query_arg, ulong query_length,
2133  uint fn_pos_start_arg, uint fn_pos_end_arg,
2134  binary_log::enum_load_dup_handling dup_handling_arg, bool using_trans,
2135  bool immediate, bool suppress_use, int errcode);
2136  int pack_info(Protocol *protocol) override;
2137 #else
2138  void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
2139  /* Prints the query as LOAD DATA LOCAL and with rewritten filename */
2140  void print(FILE *file, PRINT_EVENT_INFO *print_event_info,
2141  const char *local_fname) const;
2142 #endif
2144  const char *buf, const Format_description_event *description_event);
2146 
2148 #ifdef MYSQL_SERVER
2149  bool write_post_header_for_derived(Basic_ostream *ostream) override;
2150 #endif
2151 
2152  bool is_sbr_logging_format() const override { return true; }
2153 
2154  private:
2155 #if defined(MYSQL_SERVER)
2156  virtual int do_apply_event(Relay_log_info const *rli) override;
2157 #endif
2158 };
2159 
2160 #if defined MYSQL_SERVER
2162  public:
2163  Load_query_generator(THD *thd_arg, const sql_exchange *ex, const char *db_arg,
2164  const char *table_name_arg, bool is_concurrent_arg,
2165  bool replace, bool ignore);
2166 
2167  const String *generate(size_t *fn_start, size_t *fn_end);
2168 
2169  private:
2170  const size_t BUF_SIZE = 2048;
2172  char *buf[2048];
2173 
2176  const char *db;
2177  const char *table_name;
2178  const char *fname;
2179 
2183 };
2184 #endif
2185 #ifndef MYSQL_SERVER
2186 /**
2187  @class Unknown_log_event
2188 
2189 */
2190 class Unknown_log_event : public binary_log::Unknown_event, public Log_event {
2191  public:
2192  /**
2193  Even if this is an unknown event, we still pass description_event to
2194  Log_event's ctor, this way we can extract maximum information from the
2195  event's header (the unique ID for example).
2196  */
2197  Unknown_log_event(const char *buf,
2198  const Format_description_event *description_event)
2199  : binary_log::Unknown_event(buf, description_event),
2200  Log_event(header(), footer()) {
2201  DBUG_TRACE;
2202  if (!is_valid()) return;
2203  common_header->set_is_valid(true);
2204  return;
2205  }
2206 
2207  ~Unknown_log_event() override {}
2208  void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
2210 };
2211 #endif
2212 char *str_to_hex(char *to, const char *from, size_t len);
2213 
2214 /**
2215  @class Table_map_log_event
2216 
2217  Table_map_log_event which maps a table definition to a number.
2218 
2219  @internal
2220  The inheritance structure in the current design for the classes is
2221  as follows:
2222 
2223  Binary_log_event
2224  ^
2225  |
2226  |
2227  Table_map_event Log_event
2228  \ /
2229  \ /
2230  \ /
2231  Table_map_log_event
2232  @endinternal
2233 */
2235  public Log_event {
2236  public:
2237  /** Constants */
2239 
2240  /**
2241  Enumeration of the errors that can be returned.
2242  */
2243  enum enum_error {
2244  ERR_OPEN_FAILURE = -1, /**< Failure to open table */
2245  ERR_OK = 0, /**< No error */
2246  ERR_TABLE_LIMIT_EXCEEDED = 1, /**< No more room for tables */
2247  ERR_OUT_OF_MEM = 2, /**< Out of memory */
2248  ERR_BAD_TABLE_DEF = 3, /**< Table definition does not match */
2249  ERR_RBR_TO_SBR = 4 /**< daisy-chanining RBR to SBR not allowed */
2250  };
2251 
2252  enum enum_flag {
2253  /**
2254  Nothing here right now, but the flags support is there in
2255  preparation for changes that are coming. Need to add a
2256  constant to make it compile under HP-UX: aCC does not like
2257  empty enumerations.
2258  */
2260  };
2261 
2262  /** Special constants representing sets of flags */
2263  enum {
2267  };
2268 
2270 
2271 #ifdef MYSQL_SERVER
2272  Table_map_log_event(THD *thd_arg, TABLE *tbl, const Table_id &tid,
2273  bool is_transactional);
2274 #endif
2275  Table_map_log_event(const char *buf,
2276  const Format_description_event *description_event);
2277 
2278  ~Table_map_log_event() override;
2279 
2280 #ifndef MYSQL_SERVER
2281  table_def *create_table_def() {
2282  DBUG_ASSERT(m_colcnt > 0);
2285  }
2286  static bool rewrite_db_in_buffer(char **buf, ulong *event_len,
2287  const Format_description_event &fde);
2288 #endif
2289  const Table_id &get_table_id() const { return m_table_id; }
2290  const char *get_table_name() const { return m_tblnam.c_str(); }
2291  const char *get_db_name() const { return m_dbnam.c_str(); }
2292 
2293  virtual size_t get_data_size() override { return m_data_size; }
2294 #ifdef MYSQL_SERVER
2295  virtual int save_field_metadata();
2296  virtual bool write_data_header(Basic_ostream *ostream) override;
2297  virtual bool write_data_body(Basic_ostream *ostream) override;
2298  virtual const char *get_db() override { return m_dbnam.c_str(); }
2299  virtual uint8 mts_number_dbs() override {
2301  }
2302  /**
2303  @param[out] arg pointer to a struct containing char* array
2304  pointers be filled in and the number of filled instances.
2305  @param rpl_filter pointer to a replication filter.
2306 
2307  @return number of databases in the array: either one or
2308  OVER_MAX_DBS_IN_EVENT_MTS, when the Table map event reports
2309  foreign keys constraint.
2310  */
2312  Rpl_filter *rpl_filter) override {
2313  const char *db_name = get_db();
2314 
2316  size_t dummy_len;
2317  const char *db_filtered = rpl_filter->get_rewrite_db(db_name, &dummy_len);
2318  // db_name != db_filtered means that db_name is rewritten.
2319  if (strcmp(db_name, db_filtered)) db_name = db_filtered;
2320  }
2321 
2322  if (!get_flags(TM_REFERRED_FK_DB_F)) arg->name[0] = db_name;
2323 
2324  return arg->num = mts_number_dbs();
2325  }
2326 
2327 #endif
2328 
2329 #if defined(MYSQL_SERVER)
2330  virtual int pack_info(Protocol *protocol) override;
2331 #endif
2332 
2333 #ifndef MYSQL_SERVER
2334  virtual void print(FILE *file,
2335  PRINT_EVENT_INFO *print_event_info) const override;
2336 
2337  /**
2338  Print column metadata. Its format looks like:
2339  # Columns(colume_name type, colume_name type, ...)
2340  if colume_name field is not logged into table_map_log_event, then
2341  only type is printed.
2342 
2343  @@param[out] file the place where colume metadata is printed
2344  @@param[in] The metadata extracted from optional metadata fields
2345  */
2346  void print_columns(IO_CACHE *file,
2347  const Optional_metadata_fields &fields) const;
2348  /**
2349  Print primary information. Its format looks like:
2350  # Primary Key(colume_name, column_name(prifix), ...)
2351  if colume_name field is not logged into table_map_log_event, then
2352  colume index is printed.
2353 
2354  @@param[out] file the place where primary key is printed
2355  @@param[in] The metadata extracted from optional metadata fields
2356  */
2357  void print_primary_key(IO_CACHE *file,
2358  const Optional_metadata_fields &fields) const;
2359 #endif
2360 
2361  bool is_rbr_logging_format() const override { return true; }
2362 
2363  private:
2364 #if defined(MYSQL_SERVER)
2365  virtual int do_apply_event(Relay_log_info const *rli) override;
2366  virtual int do_update_pos(Relay_log_info *rli) override;
2367  virtual enum_skip_reason do_shall_skip(Relay_log_info *rli) override;
2368 #endif
2369 
2370 #ifdef MYSQL_SERVER
2372 
2373  // Metadata fields buffer
2375 
2376  /**
2377  Capture the optional metadata fields which should be logged into
2378  table_map_log_event and serialize them into m_metadata_buf.
2379  */
2380  void init_metadata_fields();
2381  bool init_signedness_field();
2382  /**
2383  Capture and serialize character sets. Character sets for
2384  character columns (TEXT etc) and character sets for ENUM and SET
2385  columns are stored in different metadata fields. The reason is
2386  that TEXT character sets are included even when
2387  binlog_row_metadata=MINIMAL, whereas ENUM and SET character sets
2388  are included only when binlog_row_metadata=FULL.
2389 
2390  @param include_type Predicate to determine if a given Field object
2391  is to be included in the metadata field.
2392 
2393  @param default_charset_type Type code when storing in "default
2394  charset" format. (See comment above Table_maps_log_event in
2395  libbinlogevents/include/rows_event.h)
2396 
2397  @param column_charset_type Type code when storing in "column
2398  charset" format. (See comment above Table_maps_log_event in
2399  libbinlogevents/include/rows_event.h)
2400  */
2401  bool init_charset_field(std::function<bool(const Field *)> include_type,
2402  Optional_metadata_field_type default_charset_type,
2403  Optional_metadata_field_type column_charset_type);
2404  bool init_column_name_field();
2405  bool init_set_str_value_field();
2407  bool init_geometry_type_field();
2408  bool init_primary_key_field();
2409 #endif
2410 
2411 #ifndef MYSQL_SERVER
2412  class Charset_iterator;
2413  class Default_charset_iterator;
2414  class Column_charset_iterator;
2415 #endif
2416 };
2417 
2418 #ifdef HAVE_PSI_STAGE_INTERFACE
2419 /*
2420  Helper class for PSI context while applying a Rows_log_event.
2421  */
2423  private:
2426 
2427  /**
2428  A cached pointer to this stage PSI_stage_progress.
2429  */
2431 
2432  /**
2433  Counter that is unconditionally incremented on each row that is processed.
2434  This is helpful in case estimation is needed after started processing
2435  a Rows_log_event.
2436  */
2438 
2439  public:
2441 
2442  void set_progress(PSI_stage_progress *progress) { m_progress = progress; }
2443 
2444  /**
2445  If instrumentation is enabled this member function SHALL return true.
2446  @return true if instrumentation is enabled for the given stage, false
2447  otherwise.
2448  */
2449  bool is_enabled() { return m_progress != nullptr; }
2450 
2451  /**
2452  This member function shall update the progress and reestimate the remaining
2453  work needed. This MUST be called after setting n_rows_applied correctly
2454  by calling inc_n_rows_applied beforehand.
2455 
2456  Cursor, begin and end are used in case estimation is needed.
2457 
2458  @param cursor Pointer to where we are in the buffer of rows to be processed.
2459  @param begin Pointer to the beginning of the rows buffer.
2460  @param end Pointer to the end of the rows buffer.
2461  */
2463  const uchar *begin,
2464  const uchar *end) {
2465  if (!is_enabled()) return;
2466 
2468 
2469  /* Estimate if need be. */
2470  if (estimated == 0) {
2471  DBUG_ASSERT(cursor > begin);
2472  ulonglong avg_row_change_size = (cursor - begin) / m_n_rows_applied;
2473  estimated = (end - begin) / avg_row_change_size;
2475  }
2476 
2477  /* reset estimated if done more work than estimated */
2478  if (m_n_rows_applied > estimated)
2481  }
2482 
2483  /**
2484  Resets this object.
2485  */
2486  void end_work() {
2487  m_progress = nullptr;
2488  m_n_rows_applied = 0;
2489  }
2490 
2491  /**
2492  Updates the counter of processed rows.
2493  @param delta the amount of increment to be done.
2494  */
2496 
2497  /**
2498  Gets the value of the counter of rows that have been processed.
2499  @return the value of the counter of rows processed so far.
2500  */
2502 };
2503 #endif
2504 
2505 /**
2506  @class Rows_log_event
2507 
2508  Common base class for all row-containing log events.
2509 
2510  RESPONSIBILITIES
2511 
2512  Encode the common parts of all events containing rows, which are:
2513  - Write data header and data body to an IO_CACHE.
2514 
2515  Virtual inheritance is required here to handle the diamond problem in
2516  the class Write_rows_log_event, Update_rows_log_event and
2517  Delete_rows_log_event.
2518  The diamond structure is explained in @c Write_rows_log_event,
2519  @c Update_rows_log_event,
2520  @c Delete_rows_log_event
2521 
2522  @internal
2523  The inheritance structure in the current design for the classes is
2524  as follows:
2525 
2526  Binary_log_event
2527  ^
2528  |
2529  |
2530  Rows_event Log_event
2531  \ /
2532  <<vir>>\ /
2533  \ /
2534  Rows_log_event
2535  @endinternal
2536 
2537 */
2538 class Rows_log_event : public virtual binary_log::Rows_event, public Log_event {
2539 #ifdef HAVE_PSI_STAGE_INTERFACE
2540  protected:
2542 #endif
2543 
2544  public:
2545  typedef uint16 flag_set;
2546 
2553  };
2554 
2555  /**
2556  Enumeration of the errors that can be returned.
2557  */
2558  enum enum_error {
2559  ERR_OPEN_FAILURE = -1, /**< Failure to open table */
2560  ERR_OK = 0, /**< No error */
2561  ERR_TABLE_LIMIT_EXCEEDED = 1, /**< No more room for tables */
2562  ERR_OUT_OF_MEM = 2, /**< Out of memory */
2563  ERR_BAD_TABLE_DEF = 3, /**< Table definition does not match */
2564  ERR_RBR_TO_SBR = 4 /**< daisy-chanining RBR to SBR not allowed */
2565  };
2566 
2567  /* Special constants representing sets of flags */
2568  enum { RLE_NO_FLAGS = 0U };
2569 
2570  ~Rows_log_event() override;
2571 
2572  void set_flags(flag_set flags_arg) { m_flags |= flags_arg; }
2573  void clear_flags(flag_set flags_arg) { m_flags &= ~flags_arg; }
2574  flag_set get_flags(flag_set flags_arg) const { return m_flags & flags_arg; }
2575 
2576  virtual Log_event_type
2577  get_general_type_code() = 0; /* General rows op type, no version */
2578 
2579 #if defined(MYSQL_SERVER)
2580  virtual int pack_info(Protocol *protocol) override;
2581 #endif
2582 
2583 #ifndef MYSQL_SERVER
2584  void print_verbose(IO_CACHE *file, PRINT_EVENT_INFO *print_event_info);
2585  size_t print_verbose_one_row(IO_CACHE *file, table_def *td,
2586  PRINT_EVENT_INFO *print_event_info,
2587  MY_BITMAP *cols_bitmap, const uchar *ptr,
2588  const uchar *prefix,
2589  enum_row_image_type row_image_type);
2590 #endif
2591 
2592 #ifdef MYSQL_SERVER
2593  int add_row_data(uchar *data, size_t length) {
2594  return do_add_row_data(data, length);
2595  }
2596 #endif
2597 
2598  /* Member functions to implement superclass interface */
2599  virtual size_t get_data_size() override;
2600 
2601  MY_BITMAP const *get_cols() const { return &m_cols; }
2602  MY_BITMAP const *get_cols_ai() const { return &m_cols_ai; }
2603  size_t get_width() const { return m_width; }
2604  const Table_id &get_table_id() const { return m_table_id; }
2605 
2606 #if defined(MYSQL_SERVER)
2607  /**
2608  Compares the table's read/write_set with the columns included in
2609  this event's before-image and/or after-image. Each subclass
2610  (Write/Update/Delete) implements this function by comparing on the
2611  image(s) pertinent to the subclass.
2612 
2613  @param[in] table The table to compare this events bitmaps
2614  against.
2615 
2616  @retval true if sets match
2617  @retval false otherwise (following bitmap_cmp return logic).
2618  */
2619  virtual bool read_write_bitmaps_cmp(const TABLE *table) const = 0;
2620 #endif
2621 
2622 #ifdef MYSQL_SERVER
2623  virtual bool write_data_header(Basic_ostream *ostream) override;
2624  virtual bool write_data_body(Basic_ostream *ostream) override;
2625  virtual const char *get_db() override { return m_table->s->db.str; }
2626 #endif
2627 
2628  uint m_row_count; /* The number of rows added to the event */
2629 
2630  protected:
2631  /*
2632  The constructors are protected since you're supposed to inherit
2633  this class, not create instances of this class.
2634  */
2635 #ifdef MYSQL_SERVER
2636  Rows_log_event(THD *, TABLE *, const Table_id &table_id,
2637  MY_BITMAP const *cols, bool is_transactional,
2639  const unsigned char *extra_row_ndb_info);
2640 #endif
2641  Rows_log_event(const char *row_data,
2642  const Format_description_event *description_event);
2643 
2644 #ifndef MYSQL_SERVER
2645  void print_helper(FILE *, PRINT_EVENT_INFO *) const;
2646 #endif
2647 
2648 #ifdef MYSQL_SERVER
2649  virtual int do_add_row_data(uchar *data, size_t length);
2650 #endif
2651 
2652 #ifdef MYSQL_SERVER
2653  TABLE *m_table; /* The table the rows belong to */
2654 #endif
2655  MY_BITMAP m_cols; /* Bitmap denoting columns available */
2656 #ifdef MYSQL_SERVER
2657  /**
2658  Hash table that will hold the entries for while using HASH_SCAN
2659  algorithm to search and update/delete rows.
2660  */
2662 
2663  /**
2664  The algorithm to use while searching for rows using the before
2665  image.
2666  */
2668 #endif
2669  /*
2670  Bitmap for columns available in the after image, if present. These
2671  fields are only available for Update_rows events. Observe that the
2672  width of both the before image COLS vector and the after image
2673  COLS vector is the same: the number of columns of the table on the
2674  master.
2675  */
2677 
2678  /* Bit buffers in the same memory as the class */
2679  uint32 m_bitbuf[128 / (sizeof(uint32) * 8)];
2680  uint32 m_bitbuf_ai[128 / (sizeof(uint32) * 8)];
2681 
2682  /*
2683  is_valid depends on the value of m_rows_buf, so while changing the value
2684  of m_rows_buf check if is_valid also needs to be modified
2685  */
2686  uchar *m_rows_buf; /* The rows in packed format */
2687  uchar *m_rows_cur; /* One-after the end of the data */
2688  uchar *m_rows_end; /* One-after the end of the allocated space */
2689 
2690  /* helper functions */
2691 
2692 #if defined(MYSQL_SERVER)
2693  const uchar *m_curr_row; /* Start of the row being processed */
2694  const uchar *m_curr_row_end; /* One-after the end of the current row */
2695  uchar *m_key; /* Buffer to keep key value during searches */
2697  KEY *m_key_info; /* Points to description of index #m_key_index */
2698  class Key_compare {
2699  public:
2700  /**
2701  @param ki Where to find KEY description
2702  @note m_distinct_keys is instantiated when Rows_log_event is constructed;
2703  it stores a Key_compare object internally. However at that moment, the
2704  index (KEY*) to use for comparisons, is not yet known. So, at
2705  instantiation, we indicate the Key_compare the place where it can
2706  find the KEY* when needed (this place is Rows_log_event::m_key_info),
2707  Key_compare remembers the place in member m_key_info.
2708  Before we need to do comparisons - i.e. before we need to insert
2709  elements, we update Rows_log_event::m_key_info once for all.
2710  */
2711  Key_compare(KEY **ki = nullptr) : m_key_info(ki) {}
2712  bool operator()(uchar *k1, uchar *k2) const {
2713  return key_cmp2((*m_key_info)->key_part, k1, (*m_key_info)->key_length,
2714  k2, (*m_key_info)->key_length) < 0;
2715  }
2716 
2717  private:
2719  };
2720  std::set<uchar *, Key_compare> m_distinct_keys;
2721  std::set<uchar *, Key_compare>::iterator m_itr;
2722  /**
2723  A spare buffer which will be used when saving the distinct keys
2724  for doing an index scan with HASH_SCAN search algorithm.
2725  */
2727 
2728  /**
2729  Unpack the current row image from the event into m_table->record[0].
2730 
2731  @param rli The applier context.
2732 
2733  @param cols The bitmap of columns included in the update.
2734 
2735  @param is_after_image Should be true if this is an after-image,
2736  false if it is a before-image.
2737 
2738  @param only_seek @see unpack_row()
2739 
2740  @retval 0 Success
2741 
2742  @retval ER_* On error, it is guaranteed that the error has been
2743  reported through my_error, and the corresponding ER_* code is
2744  returned. Currently the error codes are: EE_OUTOFMEMORY,
2745  ER_SLAVE_CORRUPT_EVENT, or various JSON errors when applying JSON
2746  diffs (ER_COULD_NOT_APPLY_JSON_DIFF, ER_INVALID_JSON_BINARY_DATA,
2747  and maybe others).
2748  */
2749  int unpack_current_row(const Relay_log_info *const rli, MY_BITMAP const *cols,
2750  bool is_after_image, bool only_seek = false);
2751 
2752  /*
2753  This member function is called when deciding the algorithm to be used to
2754  find the rows to be updated on the slave during row based replication.
2755  This this functions sets the m_rows_lookup_algorithm and also the
2756  m_key_index with the key index to be used if the algorithm is dependent on
2757  an index.
2758  */
2760 
2761  /*
2762  Encapsulates the operations to be done before applying
2763  row event for update and delete.
2764  */
2766 
2767  /*
2768  Encapsulates the operations to be done after applying
2769  row event for update and delete.
2770  */
2772 
2773  /**
2774  Helper function to check whether there is an auto increment
2775  column on the table where the event is to be applied.
2776 
2777  @return true if there is an autoincrement field on the extra
2778  columns, false otherwise.
2779  */
2781 #endif
2782 
2783  bool is_rbr_logging_format() const override { return true; }
2784 
2785  private:
2786 #if defined(MYSQL_SERVER)
2787  virtual int do_apply_event(Relay_log_info const *rli) override;
2788  virtual int do_update_pos(Relay_log_info *rli) override;
2789  virtual enum_skip_reason do_shall_skip(Relay_log_info *rli) override;
2790 
2791  /*
2792  Primitive to prepare for a sequence of row executions.
2793 
2794  DESCRIPTION
2795 
2796  Before doing a sequence of do_prepare_row() and do_exec_row()
2797  calls, this member function should be called to prepare for the
2798  entire sequence. Typically, this member function will allocate
2799  space for any buffers that are needed for the two member
2800  functions mentioned above.
2801 
2802  RETURN VALUE
2803 
2804  The member function will return 0 if all went OK, or a non-zero
2805  error code otherwise.
2806  */
2807  virtual int do_before_row_operations(
2808  const Slave_reporting_capability *const log) = 0;
2809 
2810  /*
2811  Primitive to clean up after a sequence of row executions.
2812 
2813  DESCRIPTION
2814 
2815  After doing a sequence of do_prepare_row() and do_exec_row(),
2816  this member function should be called to clean up and release
2817  any allocated buffers.
2818 
2819  The error argument, if non-zero, indicates an error which happened during
2820  row processing before this function was called. In this case, even if
2821  function is successful, it should return the error code given in the
2822  argument.
2823  */
2824  virtual int do_after_row_operations(
2825  const Slave_reporting_capability *const log, int error) = 0;
2826 
2827  /*
2828  Primitive to do the actual execution necessary for a row.
2829 
2830  DESCRIPTION
2831  The member function will do the actual execution needed to handle a row.
2832  The row is located at m_curr_row. When the function returns,
2833  m_curr_row_end should point at the next row (one byte after the end
2834  of the current row).
2835 
2836  RETURN VALUE
2837  0 if execution succeeded, 1 if execution failed.
2838 
2839  */
2840  virtual int do_exec_row(const Relay_log_info *const rli) = 0;
2841 
2842  /**
2843  Private member function called while handling idempotent errors.
2844 
2845  @param rli Pointer to relay log info structure.
2846  @param [in,out] err the error to handle. If it is listed as
2847  idempotent/ignored related error, then it is cleared.
2848  @returns true if the slave should stop executing rows.
2849  */
2851 
2852  /**
2853  Private member function called after updating/deleting a row. It
2854  performs some assertions and more importantly, it updates
2855  m_curr_row so that the next row is processed during the row
2856  execution main loop (@c Rows_log_event::do_apply_event()).
2857 
2858  @param rli Pointer to relay log info structure.
2859  @param err the current error code.
2860  */
2861  void do_post_row_operations(Relay_log_info const *rli, int err);
2862 
2863  /**
2864  Commodity wrapper around do_exec_row(), that deals with resetting
2865  the thd reference in the table.
2866  */
2867  int do_apply_row(Relay_log_info const *rli);
2868 
2869  /**
2870  Implementation of the index scan and update algorithm. It uses
2871  PK, UK or regular Key to search for the record to update. When
2872  found it updates it.
2873  */
2874  int do_index_scan_and_update(Relay_log_info const *rli);
2875 
2876  /**
2877  Implementation of the hash_scan and update algorithm. It collects
2878  rows positions in a hashtable until the last row is
2879  unpacked. Then it scans the table to update and when a record in
2880  the table matches the one in the hashtable, the update/delete is
2881  performed.
2882  */
2883  int do_hash_scan_and_update(Relay_log_info const *rli);
2884 
2885  /**
2886  Implementation of the legacy table_scan and update algorithm. For
2887  each unpacked row it scans the storage engine table for a
2888  match. When a match is found, the update/delete operations are
2889  performed.
2890  */
2891  int do_table_scan_and_update(Relay_log_info const *rli);
2892 
2893  /**
2894  Seek past the after-image of an update event, in case a row was processed
2895  without reading the after-image.
2896 
2897  An update event may process a row without reading the after-image,
2898  e.g. in case of ignored or idempotent errors. To ensure that the
2899  read position for the next row is correct, we need to seek past
2900  the after-image.
2901 
2902  @param rli The applier context
2903 
2904  @param curr_bi_start The read position of the beginning of the
2905  before-image. (The function compares this with m_curr_row to know
2906  if the after-image has been read or not.)
2907 
2908  @retval 0 Success
2909  @retval ER_* Error code returned by unpack_current_row
2910  */
2912  const Relay_log_info *rli MY_ATTRIBUTE((unused)),
2913  const uchar *curr_bi_start MY_ATTRIBUTE((unused))) {
2914  return 0;
2915  }
2916 
2917  /**
2918  Initializes scanning of rows. Opens an index and initailizes an iterator
2919  over a list of distinct keys (m_distinct_keys) if it is a HASH_SCAN
2920  over an index or the table if its a HASH_SCAN over the table.
2921  */
2922  int open_record_scan();
2923 
2924  /**
2925  Does the cleanup
2926  - closes the index if opened by open_record_scan
2927  - closes the table if opened for scanning.
2928  */
2929  int close_record_scan();
2930 
2931  /**
2932  Fetches next row. If it is a HASH_SCAN over an index, it populates
2933  table->record[0] with the next row corresponding to the index. If
2934  the indexes are in non-contigous ranges it fetches record corresponding
2935  to the key value in the next range.
2936 
2937  @param first_read signifying if this is the first time we are reading a row
2938  over an index.
2939  @return error code when there are no more records to be fetched or some
2940  other error occurred,
2941  - 0 otherwise.
2942  */
2943  int next_record_scan(bool first_read);
2944 
2945  /**
2946  Populates the m_distinct_keys with unique keys to be modified
2947  during HASH_SCAN over keys.
2948  @returns 0 success, or the error code.
2949  */
2951 
2952  /**
2953  Populates the m_hash when using HASH_SCAN. Thence, it:
2954  - unpacks the before image (BI)
2955  - saves the positions
2956  - saves the positions into the hash map, using the
2957  BI checksum as key
2958  - unpacks the after image (AI) if needed, so that
2959  m_curr_row_end gets updated correctly.
2960 
2961  @param rli The reference to the relay log info object.
2962  @returns 0 on success. Otherwise, the error code.
2963  */
2964  int do_hash_row(Relay_log_info const *rli);
2965 
2966  /**
2967  This member function scans the table and applies the changes
2968  that had been previously hashed. As such, m_hash MUST be filled
2969  by do_hash_row before calling this member function.
2970 
2971  @param rli The reference to the relay log info object.
2972  @returns 0 on success. Otherwise, the error code.
2973  */
2974  int do_scan_and_update(Relay_log_info const *rli);
2975 #endif /* defined(MYSQL_SERVER) */
2976 
2977  friend class Old_rows_log_event;
2978 
2979  /**
2980  This bitmap is used as a backup for the write set while we calculate
2981  the values for any hidden generated columns (functional indexes). In order
2982  to calculate the values, the columns must be marked in the write set. After
2983  the values are caluclated, we set the write set back to it's original value.
2984  */
2986 };
2987 
2988 /**
2989  @class Write_rows_log_event
2990 
2991  Log row insertions and updates. The event contain several
2992  insert/update rows for a table. Note that each event contains only
2993  rows for one table.
2994 
2995  @internal
2996  The inheritance structure is as follows
2997 
2998  Binary_log_event
2999  ^
3000  |
3001  |
3002  |
3003  Log_event B_l:Rows_event
3004  ^ /\
3005  | / \
3006  | <<vir>>/ \ <<vir>>
3007  | / \
3008  | / \
3009  | / \
3010  Rows_log_event B_l:W_R_E
3011  \ /
3012  \ /
3013  \ /
3014  \ /
3015  \ /
3016  \/
3017  Write_rows_log_event
3018 
3019  B_l: Namespace Binary_log
3020  W_R_E: class Write_rows_event
3021  @endinternal
3022 
3023 */
3026  public:
3027  enum {
3028  /* Support interface to THD::binlog_prepare_pending_rows_event */
3030  };
3031 
3032 #if defined(MYSQL_SERVER)
3033  Write_rows_log_event(THD *, TABLE *, const Table_id &table_id,
3034  bool is_transactional,
3035  const unsigned char *extra_row_ndb_info);
3036 #endif
3037  Write_rows_log_event(const char *buf,
3038  const Format_description_event *description_event);
3039 #if defined(MYSQL_SERVER)
3040  static bool binlog_row_logging_function(
3041  THD *thd, TABLE *table, bool is_transactional,
3042  const uchar *before_record MY_ATTRIBUTE((unused)),
3043  const uchar *after_record);
3044  bool read_write_bitmaps_cmp(const TABLE *table) const override {
3045  return bitmap_cmp(get_cols(), table->write_set);
3046  }
3047 #endif
3048 
3049  protected:
3050  int write_row(const Relay_log_info *const, const bool);
3051 
3052  private:
3054  return (Log_event_type)TYPE_CODE;
3055  }
3056 
3057 #ifndef MYSQL_SERVER
3058  void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
3059 #endif
3060 
3061 #if defined(MYSQL_SERVER)
3062  virtual int do_before_row_operations(
3063  const Slave_reporting_capability *const) override;
3064  virtual int do_after_row_operations(const Slave_reporting_capability *const,
3065  int) override;
3066  virtual int do_exec_row(const Relay_log_info *const) override;
3067 #endif
3068 };
3069 
3070 /**
3071  @class Update_rows_log_event
3072 
3073  Log row updates with a before image. The event contain several
3074  update rows for a table. Note that each event contains only rows for
3075  one table.
3076 
3077  Also note that the row data consists of pairs of row data: one row
3078  for the old data and one row for the new data.
3079 
3080  @internal
3081  The inheritance structure is as follows
3082 
3083  Binary_log_event
3084  ^
3085  |
3086  |
3087  |
3088  Log_event B_l:Rows_event
3089  ^ /\
3090  | / \
3091  | <<vir>>/ \ <<vir>>
3092  | / \
3093  | / \
3094  | / \
3095  Rows_log_event B_l:U_R_E
3096  \ /
3097  \ /
3098  \ /
3099  \ /
3100  \ /
3101  \/
3102  Update_rows_log_event
3103 
3104 
3105  B_l: Namespace Binary_log
3106  U_R_E: class Update_rows_event
3107  @eninternal
3108 
3109 */
3112  public:
3113  enum {
3114  /* Support interface to THD::binlog_prepare_pending_rows_event */
3116  };
3117 
3118 #ifdef MYSQL_SERVER
3119  Update_rows_log_event(THD *, TABLE *, const Table_id &table_id,
3120  MY_BITMAP const *cols_bi, MY_BITMAP const *cols_ai,
3121  bool is_transactional,
3122  const unsigned char *extra_row_ndb_info);
3123 
3124  Update_rows_log_event(THD *, TABLE *, const Table_id &table_id,
3125  bool is_transactional,
3126  const unsigned char *extra_row_ndb_info);
3127 
3128  void init(MY_BITMAP const *cols, const MY_BITMAP &cols_to_subtract);
3129 #endif
3130 
3131  ~Update_rows_log_event() override;
3132 
3133  Update_rows_log_event(const char *buf,
3134  const Format_description_event *description_event);
3135 
3136 #ifdef MYSQL_SERVER
3137  static bool binlog_row_logging_function(THD *thd, TABLE *table,
3138  bool is_transactional,
3139  const uchar *before_record,
3140  const uchar *after_record);
3141  bool read_write_bitmaps_cmp(const TABLE *table) const override {
3142  return (bitmap_cmp(get_cols(), table->read_set) &&
3143  bitmap_cmp(get_cols_ai(), table->write_set));
3144  }
3145 #endif
3146 
3147  protected:
3149  return (Log_event_type)TYPE_CODE;
3150  }
3151 
3152 #ifndef MYSQL_SERVER
3153  void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
3154 #endif
3155 
3156 #if defined(MYSQL_SERVER)
3157  virtual int do_before_row_operations(
3158  const Slave_reporting_capability *const) override;
3159  virtual int do_after_row_operations(const Slave_reporting_capability *const,
3160  int) override;
3161  virtual int do_exec_row(const Relay_log_info *const) override;
3162 
3164  const Relay_log_info *rli, const uchar *curr_bi_start) override;
3165 
3166  private:
3167  /**
3168  Auxiliary function used in the (THD*, ...) constructor to
3169  determine the type code based on configuration options.
3170 
3171  @param thd_arg The THD object for the session.
3172 
3173  @return One of UPDATE_ROWS_EVENT_V1, PARTIAL_UPDATE_ROWS_EVENT, or
3174  UPDATE_ROWS_EVENT.
3175  */
3177  const THD *thd_arg);
3178 #endif /* defined(MYSQL_SERVER) */
3179 };
3180 
3181 /**
3182  @class Delete_rows_log_event
3183 
3184  Log row deletions. The event contain several delete rows for a
3185  table. Note that each event contains only rows for one table.
3186 
3187  RESPONSIBILITIES
3188 
3189  - Act as a container for rows that has been deleted on the master
3190  and should be deleted on the slave.
3191 
3192  COLLABORATION
3193 
3194  Row_writer
3195  Create the event and add rows to the event.
3196  Row_reader
3197  Extract the rows from the event.
3198 
3199  @internal
3200  The inheritance structure is as follows
3201 
3202  Binary_log_event
3203  ^
3204  |
3205  |
3206  |
3207  Log_event B_l:Rows_event
3208  ^ /\
3209  | / \
3210  | <<vir>>/ \ <<vir>>
3211  | / \
3212  | / \
3213  | / \
3214  Rows_log_event B_l:D_R_E
3215  \ /
3216  \ /
3217  \ /
3218  \ /
3219  \ /
3220  \/
3221  Delete_rows_log_event
3222 
3223  B_l: Namespace Binary_log
3224  D_R_E: class Delete_rows_event
3225  @endinternal
3226 
3227 */
3230  public:
3231  enum {
3232  /* Support interface to THD::binlog_prepare_pending_rows_event */
3234  };
3235 
3236 #ifdef MYSQL_SERVER
3237  Delete_rows_log_event(THD *, TABLE *, const Table_id &, bool is_transactional,
3238  const unsigned char *extra_row_ndb_info);
3239 #endif
3240  Delete_rows_log_event(const char *buf,
3241  const Format_description_event *description_event);
3242 #ifdef MYSQL_SERVER
3243  static bool binlog_row_logging_function(
3244  THD *thd, TABLE *table, bool is_transactional, const uchar *before_record,
3245  const uchar *after_record MY_ATTRIBUTE((unused)));
3246  bool read_write_bitmaps_cmp(const TABLE *table) const override {
3247  return bitmap_cmp(get_cols(), table->read_set);
3248  }
3249 #endif
3250 
3251  protected:
3253  return (Log_event_type)TYPE_CODE;
3254  }
3255 
3256 #ifndef MYSQL_SERVER
3257  void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
3258 #endif
3259 
3260 #if defined(MYSQL_SERVER)
3261  virtual int do_before_row_operations(
3262  const Slave_reporting_capability *const) override;
3263  virtual int do_after_row_operations(const Slave_reporting_capability *const,
3264  int) override;
3265  virtual int do_exec_row(const Relay_log_info *const) override;
3266 #endif
3267 };
3268 
3269 /**
3270  @class Incident_log_event
3271 
3272  Class representing an incident, an occurance out of the ordinary,
3273  that happened on the master.
3274 
3275  The event is used to inform the slave that something out of the
3276  ordinary happened on the master that might cause the database to be
3277  in an inconsistent state.
3278  Its the derived class of Incident_event
3279 
3280  @internal
3281  The inheritance structure is as follows
3282 
3283  Binary_log_event
3284  ^
3285  |
3286  |
3287  B_l:Incident_event Log_event
3288  \ /
3289  \ /
3290  \ /
3291  \ /
3292  Incident_log_event
3293 
3294  B_l: Namespace Binary_log
3295  @endinternal
3296 
3297 */
3299  public:
3300 #ifdef MYSQL_SERVER
3301  Incident_log_event(THD *thd_arg, enum_incident incident_arg)
3302  : binary_log::Incident_event(incident_arg),
3305  DBUG_TRACE;
3306  DBUG_PRINT("enter", ("incident: %d", incident_arg));
3307  common_header->set_is_valid(incident_arg > INCIDENT_NONE &&
3308  incident_arg < INCIDENT_COUNT);
3309  DBUG_ASSERT(message == nullptr && message_length == 0);
3310  return;
3311  }
3312 
3313  Incident_log_event(THD *thd_arg, enum_incident incident_arg,
3314  LEX_CSTRING const msg)
3315  : binary_log::Incident_event(incident_arg),
3318  DBUG_TRACE;
3319  DBUG_PRINT("enter", ("incident: %d", incident_arg));
3320  common_header->set_is_valid(incident_arg > INCIDENT_NONE &&
3321  incident_arg < INCIDENT_COUNT);
3322  DBUG_ASSERT(message == nullptr && message_length == 0);
3324  msg.length + 1, MYF(MY_WME)))) {
3325  // The allocation failed. Mark this binlog event as invalid.
3326  common_header->set_is_valid(false);
3327  return;
3328  }
3329  strmake(message, msg.str, msg.length);
3330  message_length = msg.length;
3331  return;
3332  }
3333 #endif
3334 
3335 #ifdef MYSQL_SERVER
3336  int pack_info(Protocol *) override;
3337 #endif
3338 
3339  Incident_log_event(const char *buf,
3340  const Format_description_event *description_event);
3341 
3342  ~Incident_log_event() override;
3343 
3344 #ifndef MYSQL_SERVER
3345  virtual void print(FILE *file,
3346  PRINT_EVENT_INFO *print_event_info) const override;
3347 #endif
3348 
3349 #if defined(MYSQL_SERVER)
3350  virtual int do_apply_event(Relay_log_info const *rli) override;
3351  virtual bool write_data_header(Basic_ostream *ostream) override;
3352  virtual bool write_data_body(Basic_ostream *ostream) override;
3353 #endif
3354 
3355  virtual size_t get_data_size() override {
3356  return Binary_log_event::INCIDENT_HEADER_LEN + 1 + message_length;
3357  }
3358 
3359  virtual bool ends_group() const override { return true; }
3360 
3361  private:
3362  const char *description() const;
3363 };
3364 
3365 /**
3366  @class Ignorable_log_event
3367 
3368  Base class for ignorable log events is Ignorable_event.
3369  Events deriving from this class can be safely ignored
3370  by slaves that cannot recognize them.
3371 
3372  Its the derived class of Ignorable_event
3373 
3374  @internal
3375  The inheritance structure is as follows
3376 
3377  Binary_log_event
3378  ^
3379  |
3380  |
3381  B_l:Ignorable_event Log_event
3382  \ /
3383  <<virtual>>\ /
3384  \ /
3385  Ignorable_log_event
3386 
3387  B_l: Namespace Binary_log
3388  @endinternal
3389 */
3391  public Log_event {
3392  public:
3393 #ifdef MYSQL_SERVER
3397  DBUG_TRACE;
3398  common_header->set_is_valid(true);
3399  return;
3400  }
3401 #endif
3402 
3403  Ignorable_log_event(const char *buf,
3404  const Format_description_event *descr_event);
3405  ~Ignorable_log_event() override;
3406 
3407 #ifdef MYSQL_SERVER
3408  int pack_info(Protocol *) override;
3409 #endif
3410 
3411 #ifndef MYSQL_SERVER
3412  virtual void print(FILE *file,
3413  PRINT_EVENT_INFO *print_event_info) const override;
3414 #endif
3415 
3416  virtual size_t get_data_size() override {
3417  return Binary_log_event::IGNORABLE_HEADER_LEN;
3418  }
3419 };
3420 
3421 /**
3422  @class Rows_query_log_event
3423  It is used to record the original query for the rows
3424  events in RBR.
3425  It is the subclass of Ignorable_log_event and Rows_query_event
3426 
3427  @internal
3428  The inheritance structure in the current design for the classes is
3429  as follows:
3430  Binary_log_event
3431  ^
3432  |
3433  |
3434  |
3435  Log_event B_l:Ignorable_event
3436  ^ /\
3437  | / \
3438  | <<vir>>/ \ <<vir>>
3439  | / \
3440  | / \
3441  | / \
3442  Ignorable_log_event B_l:Rows_query_event
3443  \ /
3444  \ /
3445  \ /
3446  \ /
3447  \ /
3448  \/
3449  Rows_query_log_event
3450 
3451  B_l : namespace binary_log
3452  @endinternal
3453 */
3456  public:
3457 #ifdef MYSQL_SERVER
3458  Rows_query_log_event(THD *thd_arg, const char *query, size_t query_len)
3459  : Ignorable_log_event(thd_arg) {
3460  DBUG_TRACE;
3462  if (!(m_rows_query =
3464  query_len + 1, MYF(MY_WME))))
3465  return;
3466  snprintf(m_rows_query, query_len + 1, "%s", query);
3467  DBUG_PRINT("enter", ("%s", m_rows_query));
3468  return;
3469  }
3470 #endif
3471 
3472 #ifdef MYSQL_SERVER
3473  int pack_info(Protocol *) override;
3474  virtual int do_apply_event(Relay_log_info const *rli) override;
3475  virtual bool write_data_body(Basic_ostream *ostream) override;
3476 #endif
3477 
3478  Rows_query_log_event(const char *buf,
3479  const Format_description_event *descr_event);
3480 
3483  m_rows_query = nullptr;
3484  }
3485 #ifndef MYSQL_SERVER
3486  virtual void print(FILE *file,
3487  PRINT_EVENT_INFO *print_event_info) const override;
3488 #endif
3489  virtual size_t get_data_size() override {
3490  return Binary_log_event::IGNORABLE_HEADER_LEN + 1 + strlen(m_rows_query);
3491  }
3492 };
3493 
3495  FILE *file,
3496  bool flush_stream) {
3497  return my_b_copy_to_file(cache, file) ||
3498  (flush_stream ? (fflush(file) || ferror(file)) : 0) ||
3499  reinit_io_cache(cache, WRITE_CACHE, 0, false, true);
3500 }
3501 
3502 #ifdef MYSQL_SERVER
3503 /*****************************************************************************
3504 
3505  Heartbeat Log Event class
3506 
3507  The class is not logged to a binary log, and is not applied on to the slave.
3508  The decoding of the event on the slave side is done by its superclass,
3509  binary_log::Heartbeat_event.
3510 
3511  ****************************************************************************/
3513  public Log_event {
3514  public:
3515  Heartbeat_log_event(const char *buf,
3516  const Format_description_event *description_event);
3517 };
3518 
3519 /**
3520  The function is called by slave applier in case there are
3521  active table filtering rules to force gathering events associated
3522  with Query-log-event into an array to execute
3523  them once the fate of the Query is determined for execution.
3524 */
3526 #endif
3527 
3528 int append_query_string(const THD *thd, const CHARSET_INFO *csinfo,
3529  String const *from, String *to);
3531 
3532 /**
3533  @class Gtid_log_event
3534 
3535  This is a subclass if Gtid_event and Log_event. It contains
3536  per-transaction fields, including the GTID and logical timestamps
3537  used by MTS.
3538 
3539  @internal
3540  The inheritance structure is as follows
3541 
3542  Binary_log_event
3543  ^
3544  |
3545  |
3546  B_l:Gtid_event Log_event
3547  \ /
3548  \ /
3549  \ /
3550  \ /
3551  Gtid_log_event
3552 
3553  B_l: Namespace Binary_log
3554  @endinternal
3555 */
3557  public:
3558 #ifdef MYSQL_SERVER
3559  /**
3560  Create a new event using the GTID owned by the given thread.
3561  */
3562  Gtid_log_event(THD *thd_arg, bool using_trans, int64 last_committed_arg,
3563  int64 sequence_number_arg, bool may_have_sbr_stmts_arg,
3564  ulonglong original_commit_timestamp_arg,
3565  ulonglong immediate_commit_timestamp_arg,
3566  uint32_t original_server_version_arg,
3567  uint32_t immediate_server_version_arg);
3568 
3569  /**
3570  Create a new event using the GTID from the given Gtid_specification
3571  without a THD object.
3572  */
3573  Gtid_log_event(uint32 server_id_arg, bool using_trans,
3574  int64 last_committed_arg, int64 sequence_number_arg,
3575  bool may_have_sbr_stmts_arg,
3576  ulonglong original_commit_timestamp_arg,
3577  ulonglong immediate_commit_timestamp_arg,
3578  const Gtid_specification spec_arg,
3579  uint32_t original_server_version_arg,
3580  uint32_t immediate_server_version_arg);
3581 #endif
3582 
3583 #ifdef MYSQL_SERVER
3584  int pack_info(Protocol *) override;
3585 #endif
3586  Gtid_log_event(const char *buffer,
3587  const Format_description_event *description_event);
3588 
3589  ~Gtid_log_event() override {}
3590 
3591  size_t get_data_size() override {
3592  DBUG_EXECUTE_IF("do_not_write_rpl_timestamps", return POST_HEADER_LENGTH;);
3595  }
3596 
3598 
3599  private:
3600  /// Used internally by both print() and pack_info().
3601  size_t to_string(char *buf) const;
3602 
3603 #ifdef MYSQL_SERVER
3604  /**
3605  Writes the post-header to the given output stream.
3606 
3607  This is an auxiliary function typically used by the write() member
3608  function.
3609 
3610  @param ostream The output stream to write to.
3611 
3612  @retval true Error.
3613  @retval false Success.
3614  */
3615  bool write_data_header(Basic_ostream *ostream) override;
3616  bool write_data_body(Basic_ostream *ostream) override;
3617  /**
3618  Writes the post-header to the given memory buffer.
3619 
3620  This is an auxiliary function used by write_to_memory.
3621 
3622  @param[in,out] buffer Buffer to which the post-header will be written.
3623 
3624  @return The number of bytes written, i.e., always
3625  Gtid_log_event::POST_HEADER_LENGTH.
3626  */
3628 
3629  /**
3630  Writes the body to the given memory buffer.
3631 
3632  This is an auxiliary function used by write_to_memory.
3633 
3634  @param [in,out] buff Buffer to which the data will be written.
3635 
3636  @return The number of bytes written, i.e.,
3637  If the transaction did not originated on this server
3638  Gtid_event::IMMEDIATE_COMMIT_TIMESTAMP_LENGTH.
3639  else
3640  FULL_COMMIT_TIMESTAMP_LENGTH.
3641  */
3643 #endif
3644 
3645  public:
3646 #ifndef MYSQL_SERVER
3647  void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
3648 #endif
3649 #ifdef MYSQL_SERVER
3650  /**
3651  Writes this event to a memory buffer.
3652 
3653  @param buf The event will be written to this buffer.
3654 
3655  @return the number of bytes written, i.e., always
3656  LOG_EVENT_HEADER_LEN + Gtid_log_event::POST_HEADEr_LENGTH.
3657  */
3660  uint32 len = write_header_to_memory(buf);
3661  len += write_post_header_to_memory(buf + len);
3662  len += write_body_to_memory(buf + len);
3663  return len;
3664  }
3665 #endif
3666 
3667 #if defined(MYSQL_SERVER)
3668  int do_apply_event(Relay_log_info const *rli) override;
3669  int do_update_pos(Relay_log_info *rli) override;
3671 #endif
3672 
3673  /**
3674  Return the gtid type for this Gtid_log_event: this can be
3675  either ANONYMOUS_GTID, AUTOMATIC_GTID, or ASSIGNED_GTID.
3676  */
3677  enum_gtid_type get_type() const { return spec.type; }
3678 
3679  /**
3680  Return the SID for this GTID. The SID is shared with the
3681  Log_event so it should not be modified.
3682  */
3683  const rpl_sid *get_sid() const { return &sid; }
3684  /**
3685  Return the SIDNO relative to the global sid_map for this GTID.
3686 
3687  This requires a lookup and possibly even update of global_sid_map,
3688  hence global_sid_lock must be held. If global_sid_lock is not
3689  held, the caller must pass need_lock=true. If there is an error
3690  (e.g. out of memory) while updating global_sid_map, this function
3691  returns a negative number.
3692 
3693  @param need_lock If true, the read lock on global_sid_lock is
3694  acquired and released inside this function; if false, the read
3695  lock or write lock must be held prior to calling this function.
3696  @retval SIDNO if successful
3697  @retval negative if adding SID to global_sid_map causes an error.
3698  */
3699  rpl_sidno get_sidno(bool need_lock);
3700 
3701  /**
3702  Return the SIDNO relative to the given Sid_map for this GTID.
3703 
3704  This assumes that the Sid_map is local to the thread, and thus
3705  does not use locks.
3706 
3707  @param sid_map The sid_map to use.
3708  @retval SIDNO if successful.
3709  @retval negative if adding SID to sid_map causes an error.
3710  */
3711  rpl_sidno get_sidno(Sid_map *sid_map) { return sid_map->add_sid(sid); }
3712  /// Return the GNO for this GTID.
3713  rpl_gno get_gno() const { return spec.gtid.gno; }
3714 
3715  /// string holding the text "SET @@GLOBAL.GTID_NEXT = '"
3716  static const char *SET_STRING_PREFIX;
3717 
3718  private:
3719  /// Length of SET_STRING_PREFIX
3720  static const size_t SET_STRING_PREFIX_LENGTH = 26;
3721  /// The maximal length of the entire "SET ..." query.
3724  1 + MAX_GNO_TEXT_LENGTH + 1;
3725 
3726  private:
3727  /**
3728  Internal representation of the GTID. The SIDNO will be
3729  uninitialized (value -1) until the first call to get_sidno(bool).
3730  */
3732  /// SID for this GTID.
3734 
3735  public:
3736  /**
3737  Set the transaction length information based on binlog cache size.
3738 
3739  Note that is_checksum_enabled and event_counter are optional parameters.
3740  When not specified, the function will assume that no checksum will be used
3741  and the informed cache_size is the final transaction size without
3742  considering the GTID event size.
3743 
3744  The high level formula that will be used by the function is:
3745 
3746  trx_length = cache_size +
3747  cache_checksum_active * cache_events * CRC32_payload +
3748  gtid_length +
3749  cache_checksum_active * CRC32_payload; // For the GTID.
3750 
3751  @param cache_size The size of the binlog cache in bytes.
3752  @param is_checksum_enabled If checksum will be added to events on flush.
3753  @param event_counter The amount of events in the cache.
3754  */
3756  bool is_checksum_enabled = false,
3757  int event_counter = 0);
3758 };
3759 
3760 /**
3761  @class Previous_gtids_log_event
3762 
3763  This is the subclass of Previous_gtids_event and Log_event
3764  It is used to record the gtid_executed in the last binary log file,
3765  for ex after flush logs, or at the starting of the binary log file
3766 
3767  @internal
3768  The inheritance structure is as follows
3769 
3770  Binary_log_event
3771  ^
3772  |
3773  |
3774 B_l:Previous_gtids_event Log_event
3775  \ /
3776  \ /
3777  \ /
3778  \ /
3779  Previous_gtids_log_event
3780 
3781  B_l: Namespace Binary_log
3782  @endinternal
3783 */
3785  public Log_event {
3786  public:
3787 #ifdef MYSQL_SERVER
3788  Previous_gtids_log_event(const Gtid_set *set);
3789 #endif
3790 
3791 #ifdef MYSQL_SERVER
3792  int pack_info(Protocol *) override;
3793 #endif
3794 
3795  Previous_gtids_log_event(const char *buf,
3796  const Format_description_event *description_event);
3798 
3799  size_t get_data_size() override { return buf_size; }
3800 
3801 #ifndef MYSQL_SERVER
3802  void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
3803 #endif
3804 #ifdef MYSQL_SERVER
3805  bool write(Basic_ostream *ostream) override {
3806  if (DBUG_EVALUATE_IF("skip_writing_previous_gtids_log_event", 1, 0) &&
3807  /*
3808  The skip_writing_previous_gtids_log_event debug point was designed
3809  for skipping the writing of the previous_gtids_log_event on binlog
3810  files only.
3811  */
3812  !is_relay_log_event()) {
3813  DBUG_PRINT("info",
3814  ("skip writing Previous_gtids_log_event because of"
3815  "debug option 'skip_writing_previous_gtids_log_event'"));
3816  return false;
3817  }
3818 
3819  if (DBUG_EVALUATE_IF("write_partial_previous_gtids_log_event", 1, 0) &&
3820  /*
3821  The write_partial_previous_gtids_log_event debug point was designed
3822  for writing a partial previous_gtids_log_event on binlog files only.
3823  */
3824  !is_relay_log_event()) {
3825  DBUG_PRINT("info",
3826  ("writing partial Previous_gtids_log_event because of"
3827  "debug option 'write_partial_previous_gtids_log_event'"));
3828  return (Log_event::write_header(ostream, get_data_size()) ||
3829  Log_event::write_data_header(ostream));
3830  }
3831 
3832  return (Log_event::write_header(ostream, get_data_size()) ||
3833  Log_event::write_data_header(ostream) || write_data_body(ostream) ||
3834  Log_event::write_footer(ostream));
3835  }
3836  bool write_data_body(Basic_ostream *ostream) override;
3837 #endif
3838 
3839  /// Return the encoded buffer, or NULL on error.
3840  const uchar *get_buf() { return buf; }
3841  /**
3842  Return the formatted string, or NULL on error.
3843  The string is allocated using my_malloc and it is the
3844  responsibility of the caller to free it.
3845  */
3846  char *get_str(size_t *length,
3847  const Gtid_set::String_format *string_format) const;
3848  /// Add all GTIDs from this event to the given Gtid_set.
3849  int add_to_set(Gtid_set *gtid_set) const;
3850  /*
3851  Previous Gtid Log events should always be skipped
3852  there is nothing to apply there, whether it is
3853  relay log's (generated on Slave) or it is binary log's
3854  (generated on Master, copied to slave as relay log).
3855  Also, we should not increment slave_skip_counter
3856  for this event, hence return EVENT_SKIP_IGNORE.
3857  */
3858 #if defined(MYSQL_SERVER)
3860  {
3861  return EVENT_SKIP_IGNORE;
3862  }
3863 
3864  int do_apply_event(Relay_log_info const *) override { return 0; }
3865  int do_update_pos(Relay_log_info *rli) override;
3866 #endif
3867 };
3868 
3869 /**
3870  @class Transaction_context_log_event
3871 
3872  This is the subclass of Transaction_context_event and Log_event
3873  This class encodes the transaction_context_log_event.
3874 
3875  @internal
3876  The inheritance structure is as follows
3877 
3878  Binary_log_event
3879  ^
3880  |
3881  |
3882 B_l:Transaction_context_event Log_event
3883  \ /
3884  \ /
3885  \ /
3886  \ /
3887  Transaction_context_log_event
3888 
3889  B_l: Namespace Binary_log
3890  @endinternal
3891 */
3894  public Log_event {
3895  private:
3896  /// The Sid_map to use for creating the Gtid_set.
3898  /// A gtid_set which is used to store the transaction set used for
3899  /// conflict detection.
3901 
3902 #ifdef MYSQL_SERVER
3903  bool write_data_header(Basic_ostream *ostream) override;
3904 
3905  bool write_data_body(Basic_ostream *ostream) override;
3906 
3907  bool write_snapshot_version(Basic_ostream *ostream);
3908 
3909  bool write_data_set(Basic_ostream *ostream, std::list<const char *> *set);
3910 #endif
3911 
3912  size_t get_snapshot_version_size();
3913 
3914  static int get_data_set_size(std::list<const char *> *set);
3915 
3916  size_t to_string(char *buf, ulong len) const;
3917 
3918  public:
3919 #ifdef MYSQL_SERVER
3920  Transaction_context_log_event(const char *server_uuid_arg, bool using_trans,
3921  my_thread_id thread_id_arg,
3922  bool is_gtid_specified_arg);
3923 #endif
3924 
3926  const Format_description_event *descr_event);
3927 
3928  ~Transaction_context_log_event() override;
3929 
3930  size_t get_data_size() override;
3931 
3932 #ifdef MYSQL_SERVER
3933  int pack_info(Protocol *protocol) override;
3934 #endif
3935 
3936 #ifndef MYSQL_SERVER
3937  void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
3938 #endif
3939 
3940 #if defined(MYSQL_SERVER)
3941  int do_apply_event(Relay_log_info const *) override { return 0; }
3942  int do_update_pos(Relay_log_info *rli) override;
3943 #endif
3944 
3945  /**
3946  Add a hash which identifies a inserted/updated/deleted row on the
3947  ongoing transaction.
3948 
3949  @param[in] hash row identifier
3950  */
3951  void add_write_set(const char *hash);
3952 
3953  /**
3954  Return a pointer to write-set list.
3955  */
3956  std::list<const char *> *get_write_set() { return &write_set; }
3957 
3958  /**
3959  Add a hash which identifies a read row on the ongoing transaction.
3960 
3961  @param[in] hash row identifier
3962  */
3963  void add_read_set(const char *hash);
3964 
3965  /**
3966  Return a pointer to read-set list.
3967  */
3968  std::list<const char *> *get_read_set() { return &read_set; }
3969 
3970  /**
3971  Read snapshot version from encoded buffers.
3972  Cannot be executed during data read from file (event constructor),
3973  since its required locks will collide with the server gtid state
3974  initialization procedure.
3975  */
3976  bool read_snapshot_version();
3977 
3978  /**
3979  Return the transaction snapshot timestamp.
3980  */
3982 
3983  /**
3984  Return the server uuid.
3985  */
3986  const char *get_server_uuid() { return server_uuid; }
3987 
3988  /**
3989  Return the id of the committing thread.
3990  */
3991  my_thread_id get_thread_id() { return static_cast<my_thread_id>(thread_id); }
3992 
3993  /**
3994  Return true if transaction has GTID_NEXT specified, false otherwise.
3995  */
3996  bool is_gtid_specified() { return gtid_specified == true; }
3997 };
3998 
3999 /**
4000  @class View_change_log_event
4001 
4002  This is the subclass of View_change_log_event and Log_event
4003  This class created the view_change_log_event which is used as a marker in
4004  case a new node joins or leaves the group.
4005 
4006  @internal
4007  The inheritance structure is as follows
4008 
4009  Binary_log_event
4010  ^
4011  |
4012  |
4013 B_l: View_change_event Log_event
4014  \ /
4015  \ /
4016  \ /
4017  \ /
4018  View_change_log_event
4019 
4020  B_l: Namespace Binary_log
4021  @endinternal
4022 */
4023 
4025  public Log_event {
4026  private:
4027  size_t to_string(char *buf, ulong len) const;
4028 
4029 #ifdef MYSQL_SERVER
4030  bool write_data_header(Basic_ostream *ostream) override;
4031 
4032  bool write_data_body(Basic_ostream *ostream) override;
4033 
4034  bool write_data_map(Basic_ostream *ostream,
4035  std::map<std::string, std::string> *map);
4036 #endif
4037 
4038  size_t get_size_data_map(std::map<std::string, std::string> *map);
4039 
4040  public:
4041  View_change_log_event(const char *view_id);
4042 
4043  View_change_log_event(const char *buffer,
4044  const Format_description_event *descr_event);
4045 
4046  ~View_change_log_event() override;
4047 
4048  size_t get_data_size() override;
4049 
4050 #ifdef MYSQL_SERVER
4051  int pack_info(Protocol *protocol) override;
4052 #endif
4053 
4054 #ifndef MYSQL_SERVER
4055  void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
4056 #endif
4057 
4058 #if defined(MYSQL_SERVER)
4059  int do_apply_event(Relay_log_info const *rli) override;
4060  int do_update_pos(Relay_log_info *rli) override;
4061 #endif
4062 
4063  /**
4064  Returns the view id.
4065  */
4066  char *get_view_id() { return view_id; }
4067 
4068  /**
4069  Sets the certification info in the event
4070 
4071  @note size is calculated on this method as the size of the data
4072  might render the log even invalid. Also due to its size doing it
4073  here avoid looping over the data multiple times.
4074 
4075  @param[in] info certification info to be written
4076  @param[out] event_size the event size after this operation
4077  */
4078  void set_certification_info(std::map<std::string, std::string> *info,
4079  size_t *event_size);
4080 
4081  /**
4082  Returns the certification info
4083  */
4084  std::map<std::string, std::string> *get_certification_info() {
4085  return &certification_info;
4086  }
4087 
4088  /**
4089  Set the certification sequence number
4090 
4091  @param number the sequence number
4092  */
4093  void set_seq_number(rpl_gno number) { seq_number = number; }
4094 
4095  /**
4096  Returns the certification sequence number
4097  */
4099 };
4100 
4101 inline bool is_gtid_event(Log_event *evt) {
4102  return (evt->get_type_code() == binary_log::GTID_LOG_EVENT ||
4104 }
4105 
4106 /**
4107  The function checks the argument event properties to deduce whether
4108  it represents an atomic DDL.
4109 
4110  @param evt a reference to Log_event
4111  @return true when the DDL properties are found,
4112  false otherwise
4113 */
4114 inline bool is_atomic_ddl_event(Log_event *evt) {
4115  return evt != nullptr && evt->get_type_code() == binary_log::QUERY_EVENT &&
4116  static_cast<Query_log_event *>(evt)->ddl_xid !=
4118 }
4119 
4120 /**
4121  The function lists all DDL instances that are supported
4122  for crash-recovery (WL9175).
4123  todo: the supported feature list is supposed to grow. Once
4124  a feature has been readied for 2pc through WL7743,9536(7141/7016) etc
4125  it needs registering in the function.
4126 
4127  @param thd an Query-log-event creator thread handle
4128  @param using_trans
4129  The caller must specify the value accoding to the following
4130  rules:
4131  @c true when
4132  - on master the current statement is not processing
4133  a table in SE which does not support atomic DDL
4134  - on slave the relay-log repository is transactional.
4135  @c false otherwise.
4136  @return true when the being created (master) or handled (slave) event
4137  is 2pc-capable, @c false otherwise.
4138 */
4139 bool is_atomic_ddl(THD *thd, bool using_trans);
4140 
4141 #ifdef MYSQL_SERVER
4142 /**
4143  Serialize an binary event to the given output stream. It is more general
4144  than call ev->write() directly. The caller will not be affected if any
4145  change happens in serialization process. For example, serializing the
4146  event in different format.
4147  */
4148 template <class EVENT>
4149 bool binary_event_serialize(EVENT *ev, Basic_ostream *ostream) {
4150  return ev->write(ostream);
4151 }
4152 
4153 /*
4154  This is an utility function that adds a quoted identifier into the a buffer.
4155  This also escapes any existance of the quote string inside the identifier.
4156  */
4157 size_t my_strmov_quoted_identifier(THD *thd, char *buffer,
4158  const char *identifier, size_t length);
4159 #else
4160 size_t my_strmov_quoted_identifier(char *buffer, const char *identifier);
4161 #endif
4162 size_t my_strmov_quoted_identifier_helper(int q, char *buffer,
4163  const char *identifier,
4164  size_t length);
4165 
4166 /**
4167  Read an integer in net_field_length format, guarding against read out of
4168  bounds and advancing the position.
4169 
4170  @param[in,out] packet Pointer to buffer to read from. On successful
4171  return, the buffer position will be incremented to point to the next
4172  byte after what was read.
4173 
4174  @param[in,out] max_length Pointer to the number of bytes in the
4175  buffer. If the function would need to look at more than *max_length
4176  bytes in order to decode the number, the function will do nothing
4177  and return true.
4178 
4179  @param[out] out Pointer where the value will be stored.
4180 
4181  @retval false Success.
4182  @retval true Failure, i.e., reached end of buffer.
4183 */
4184 template <typename T>
4185 bool net_field_length_checked(const uchar **packet, size_t *max_length, T *out);
4186 
4187 /**
4188  @} (end of group Replication)
4189 */
4190 
4191 #endif /* _log_event_h */
bool net_field_length_checked(const uchar **packet, size_t *max_length, T *out)
Read an integer in net_field_length format, guarding against read out of bounds and advancing the pos...
Definition: log_event.cc:721
int do_hash_row(Relay_log_info const *rli)
Populates the m_hash when using HASH_SCAN.
Definition: log_event.cc:8926
bool write_data_set(Basic_ostream *ostream, std::list< const char *> *set)
Definition: log_event.cc:13214
virtual enum_skip_reason do_shall_skip(Relay_log_info *rli) override
Decide if this event shall be skipped or not and the reason for skipping it.
Definition: log_event.cc:5389
Execute_load_query_log_event(THD *thd, const char *query_arg, ulong query_length, uint fn_pos_start_arg, uint fn_pos_end_arg, binary_log::enum_load_dup_handling dup_handling_arg, bool using_trans, bool immediate, bool suppress_use, int errcode)
Definition: log_event.cc:7106
int pack_info(Protocol *protocol) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:13125
bool is_ignorable_event() const
Definition: log_event.h:805
char mts_accessed_db_names[MAX_DBS_IN_EVENT_MTS][NAME_LEN]
Definition: statement_events.h:640
enum_skip_reason
Enumeration of what kinds of skipping (and non-skipping) that can occur when the slave executes an ev...
Definition: log_event.h:526
int do_update_pos(Relay_log_info *rli) override
Advance relay log coordinates.
Definition: log_event.cc:12860
This class is used to combine the information of the ongoing transaction including the write set and ...
Definition: control_events.h:1073
static bool replace
Definition: mysqlimport.cc:65
std::list< const char * > * get_read_set()
Return a pointer to read-set list.
Definition: log_event.h:3968
No incident.
Definition: control_events.h:436
unsigned long long log_pos
Definition: binlog_event.h:653
unsigned long long int ulonglong
Definition: my_inttypes.h:55
Definition: my_sys.h:280
const uint64_t INVALID_XID
The following constant represents the maximum of MYSQL_XID domain.
Definition: statement_events.h:48
synode_no q[FIFO_SIZE]
Definition: xcom_base.c:2941
virtual size_t get_data_size() override
Definition: log_event.h:3355
virtual bool ends_group() const
Definition: log_event.h:1057
const char * delimiter
Definition: mysqlslap.cc:154
virtual enum_skip_reason do_shall_skip(Relay_log_info *rli) override
Decide if this event shall be skipped or not and the reason for skipping it.
Definition: log_event.cc:6206
Definition: partition_info.h:208
size_t get_data_size() override
Definition: log_event.h:3799
#define U
Definition: ctype-tis620.cc:72
int rpl_sidno
Type of SIDNO (source ID number, first component of GTID)
Definition: rpl_gtid.h:93
No more room for tables.
Definition: log_event.h:2246
virtual enum_skip_reason do_shall_skip(Relay_log_info *rli)
Decide if this event shall be skipped or not and the reason for skipping it.
Definition: log_event.cc:1026
static void print(const char *key, int keylen, const char *val, int vallen)
Print the key value pair.
Definition: mcstat.c:106
bool write_data_header(Basic_ostream *ostream) override
Definition: log_event.cc:13399
virtual const char * get_db() override
Definition: log_event.h:2625
char * get_str(size_t *length, const Gtid_set::String_format *string_format) const
Return the formatted string, or NULL on error.
Definition: log_event.cc:13004
unsigned char * m_coltype
Definition: rows_event.h:677
Base class for ignorable log events.
Definition: control_events.h:649
Rpl_filter.
Definition: rpl_filter.h:211
unsigned char uchar
Definition: my_inttypes.h:51
void free_temp_buf()
Definition: log_event.h:833
Table definition does not match.
Definition: log_event.h:2248
Our own string classes, used pervasively throughout the executor.
TABLE * m_table
Definition: log_event.h:2371
virtual int save_field_metadata()
Save the field metadata based on the real_type of the field.
Definition: log_event.cc:10213
virtual int skip_after_image_for_update_event(const Relay_log_info *rli, const uchar *curr_bi_start) override
Seek past the after-image of an update event, in case a row was processed without reading the after-i...
Definition: log_event.cc:8868
Definition: log_event.h:2161
Log_event_type get_type_code()
Definition: log_event.h:1736
Previous_gtids_log_event(const Gtid_set *set)
Definition: log_event.cc:12947
This is the subclass of View_change_log_event and Log_event This class created the view_change_log_e...
Definition: log_event.h:4024
int do_hash_scan_and_update(Relay_log_info const *rli)
Implementation of the hash_scan and update algorithm.
Definition: log_event.cc:9160
~View_change_log_event() override
Definition: log_event.cc:13305
XA_prepare_event(void *xid_arg, bool oph_arg)
The minimal constructor of XA_prepare_event, it initializes the instance variable xid and set the typ...
Definition: control_events.h:605
Ignorable_log_event(THD *thd_arg)
Definition: log_event.h:3394
bool is_gtid_event(Log_event *evt)
Definition: log_event.h:4101
std::map< std::string, std::string > * get_certification_info()
Returns the certification info.
Definition: log_event.h:4084
Item_result
Type of the user defined function return slot and arguments
Definition: udf_registration_types.h:38
ulonglong sql_mode_t
Definition: log_event.h:120
virtual int do_exec_row(const Relay_log_info *const) override
Definition: log_event.cc:12129
Gtid_log_event(THD *thd_arg, bool using_trans, int64 last_committed_arg, int64 sequence_number_arg, bool may_have_sbr_stmts_arg, ulonglong original_commit_timestamp_arg, ulonglong immediate_commit_timestamp_arg, uint32_t original_server_version_arg, uint32_t immediate_server_version_arg)
Create a new event using the GTID owned by the given thread.
Definition: log_event.cc:12446
const char * db_name
Definition: rules_table_service.cc:54
char * str_to_hex(char *to, const char *from, size_t len)
Transforms a string into "" or its expression in 0x...
Definition: log_event.cc:761
virtual enum_skip_reason do_shall_skip(Relay_log_info *rli) override
Decide if this event shall be skipped or not and the reason for skipping it.
Definition: log_event.cc:9883
enum_event_cache_type
Definition: log_event.h:546
size_t to_string(char *buf, ulong len) const
Definition: log_event.cc:13118
virtual int do_apply_event(Relay_log_info const *rli) override
Primitive to apply an event to the database.
Definition: log_event.cc:5739
virtual bool write(Basic_ostream *ostream)
Definition: log_event.h:762
const char * db
&#39;db&#39; is filled when the event is created in mysql_load() (the event needs to have a &#39;db&#39; member to be...
Definition: load_data_events.h:310
bool write(Basic_ostream *ostream) override
Definition: log_event.cc:5690
static bool copy_event_cache_to_file_and_reinit(IO_CACHE *cache, FILE *file, bool flush_stream)
Definition: log_event.h:3494
This event is created to contain the file data.
Definition: load_data_events.h:273
rpl_sidno get_sidno(Sid_map *sid_map)
Return the SIDNO relative to the given Sid_map for this GTID.
Definition: log_event.h:3711
Class Gtid_set::String_format defines the separators used by Gtid_set::to_string. ...
Definition: rpl_gtid.h:1610
bool is_gtid_specified()
Return true if transaction has GTID_NEXT specified, false otherwise.
Definition: log_event.h:3996
int do_table_scan_and_update(Relay_log_info const *rli)
Implementation of the legacy table_scan and update algorithm.
Definition: log_event.cc:9181
size_t get_data_size() override
Definition: log_event.h:1905
bool is_sbr_logging_format() const override
When a query log event contains a non-transaction control statement, we assume that it is changing da...
Definition: log_event.h:1396
bool is_enabled()
If instrumentation is enabled this member function SHALL return true.
Definition: log_event.h:2449
#define MY_WME
Definition: my_sys.h:116
Definition: binlog_event.h:340
bool is_rewrite_empty()
Definition: rpl_filter.cc:567
static char * query
Definition: myisam_ftdump.cc:44
unsigned char * m_field_metadata
Definition: rows_event.h:683
Stop_event()
It is the minimal constructor, and all it will do is set the type_code as STOP_EVENT in the header ob...
Definition: control_events.h:374
const uchar * get_buf()
Return the encoded buffer, or NULL on error.
Definition: log_event.h:3840
bool write_header(Basic_ostream *ostream, size_t data_length)
Writes the common-header of this event to the given output stream and updates the checksum...
Definition: log_event.cc:1263
Delete_rows_log_event(THD *, TABLE *, const Table_id &, bool is_transactional, const unsigned char *extra_row_ndb_info)
Definition: log_event.cc:11929
Gtid_specification spec
Internal representation of the GTID.
Definition: log_event.h:3731
Table_map_log_event(THD *thd_arg, TABLE *tbl, const Table_id &tid, bool is_transactional)
Definition: log_event.cc:10234
bool is_using_immediate_logging() const
Definition: log_event.h:817
char buffer[STRING_BUFFER]
Definition: test_sql_9_sessions.cc:57
Logs random seed used by the next RAND(), and by PASSWORD() in 4.1.0.
Definition: statement_events.h:1032
ulonglong get_n_rows_applied()
Gets the value of the counter of rows that have been processed.
Definition: log_event.h:2501
Failure to open table.
Definition: log_event.h:2559
const char * get_db() override
Definition: log_event.h:1964
virtual enum_skip_reason do_shall_skip(Relay_log_info *) override
Decide if this event shall be skipped or not and the reason for skipping it.
Definition: log_event.h:1855
static const int POST_HEADER_LENGTH
Total length of post header.
Definition: control_events.h:918
File containing constants that can be used throughout the server.
~Query_log_event() override
Definition: log_event.h:1336
MY_BITMAP m_cols
Definition: log_event.h:2655
enum_incident
Enumeration of the incidents that can occur for the server.
Definition: control_events.h:434
virtual bool write_data_header(Basic_ostream *ostream) override
Definition: log_event.cc:10612
This is the subclass of Previous_gtids_event and Log_event It is used to record the gtid_executed in...
Definition: log_event.h:3784
int pack_info(Protocol *protocol) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:5781
Include file for Sun RPC to compile out of the box.
virtual int do_update_pos(Relay_log_info *rli)
Advance relay log coordinates.
Definition: log_event.cc:1018
my_thread_id get_thread_id()
Return the id of the committing thread.
Definition: log_event.h:3991
virtual size_t get_data_size() override
Definition: log_event.h:2293
bool is_deferred()
Definition: log_event.h:1803
const char * name[MAX_DBS_IN_EVENT_MTS]
Definition: log_event.h:497
Some integer typedefs for easier portability.
void decide_row_lookup_algorithm_and_key()
Definition: log_event.cc:8077
virtual int do_before_row_operations(const Slave_reporting_capability *const) override
Definition: log_event.cc:12099
size_t message_length
Definition: control_events.h:481
virtual bool is_rbr_logging_format() const
Return true if the event has to be logged using RBR for DMLs.
Definition: log_event.h:783
~Stop_log_event() override
Definition: log_event.h:1849
size_t get_data_size() override
Definition: log_event.h:1959
bool has_replace
Definition: log_event.h:2181
virtual bool write_data_header(Basic_ostream *ostream) override
Definition: log_event.cc:10011
int update_pos(Relay_log_info *rli)
Update the relay log position.
Definition: log_event.h:1087
~Rand_log_event() override
Definition: log_event.h:1610
Transaction_context_log_event(const char *server_uuid_arg, bool using_trans, my_thread_id thread_id_arg, bool is_gtid_specified_arg)
Definition: log_event.cc:13039
uchar * m_distinct_key_spare_buf
A spare buffer which will be used when saving the distinct keys for doing an index scan with HASH_SCA...
Definition: log_event.h:2726
bool init_geometry_type_field()
Definition: log_event.cc:10979
virtual Log_event_type get_general_type_code() override
Definition: log_event.h:3252
flag_set get_flags(flag_set flags_arg) const
Definition: log_event.h:2574
Definition: control_events.h:985
void clear_flags(flag_set flags_arg)
Definition: log_event.h:2573
bool init_set_str_value_field()
Definition: log_event.cc:10931
int do_apply_event(Relay_log_info const *) override
Primitive to apply an event to the database.
Definition: log_event.h:3941
bool binary_event_serialize(EVENT *ev, Basic_ostream *ostream)
Serialize an binary event to the given output stream.
Definition: log_event.h:4149
uchar * m_rows_cur
Definition: log_event.h:2687
static uint verbose
Definition: mysqlcheck.cc:63
A Query_event is created for each query that modifies the database, unless the query is logged row-ba...
Definition: statement_events.h:450
int add_key_to_distinct_keyset()
Populates the m_distinct_keys with unique keys to be modified during HASH_SCAN over keys...
Definition: log_event.cc:8662
bool is_trans_keyword() const
Definition: log_event.h:1364
bool is_using_stmt_cache() const
Definition: log_event.h:814
DELETE_FILE_EVENT occurs when the LOAD DATA failed on the master.
Definition: load_data_events.h:201
virtual int do_update_pos(Relay_log_info *rli) override
Advance relay log coordinates.
Definition: log_event.cc:5509
bool my_b_inited(const IO_CACHE *info)
Definition: my_sys.h:504
int get_rpl_part_id(partition_info *part_info)
This method is used to extract the partition_id from a partitioned table.
Definition: log_event.cc:7477
bool short_form
long long int seq_number
Definition: control_events.h:1228
#define MYSQL_PLUGIN_IMPORT
Definition: my_sharedlib.h:70
const String * generate(size_t *fn_start, size_t *fn_end)
Definition: log_event.cc:7330
int apply_gtid_event(Relay_log_info *rli)
Apply the GTID event in curr_group_data to the database.
Definition: log_event.cc:2985
Heartbeat_log_event(const char *buf, const Format_description_event *description_event)
Definition: log_event.cc:13514
Base class for ignorable log events is Ignorable_event.
Definition: log_event.h:3390
View_change_log_event(const char *view_id)
Definition: log_event.cc:13281
bool starts_group() const override
Notice, DDL queries are logged without BEGIN/COMMIT parentheses and identification of such single-que...
Definition: log_event.h:1404
rpl_gno get_seq_number()
Returns the certification sequence number.
Definition: log_event.h:4098
Contains the classes representing events occurring in the replication stream.
Replication event to ensure to slave that master is alive.
Definition: control_events.h:1267
bool read_write_bitmaps_cmp(const TABLE *table) const override
Compares the table&#39;s read/write_set with the columns included in this event&#39;s before-image and/or aft...
Definition: log_event.h:3141
enum_error
Enumeration of the errors that can be returned.
Definition: log_event.h:2558
bool is_sbr_logging_format() const override
Return true if the event has to be logged using SBR for DMLs.
Definition: log_event.h:1616
ha_checksum crc
Placeholder for event checksum while writing to binlog.
Definition: log_event.h:665
Definition: log_event.h:2422
const char * get_type_str() const
Returns the human readable name of this event&#39;s type.
Definition: log_event.cc:920
const char * str
Definition: mysql_lex_string.h:40
Stop_log_event(const char *buf, const Format_description_event *description_event)
Definition: log_event.h:1841
virtual uint8 mts_number_dbs() override
Definition: log_event.h:2299
virtual int skip_after_image_for_update_event(const Relay_log_info *rli, const uchar *curr_bi_start)
Seek past the after-image of an update event, in case a row was processed without reading the after-i...
Definition: log_event.h:2911
int close_record_scan()
Does the cleanup.
Definition: log_event.cc:8522
Incident_log_event(THD *thd_arg, enum_incident incident_arg, LEX_CSTRING const msg)
Definition: log_event.h:3313
Definition: field.h:700
void end_work()
Resets this object.
Definition: log_event.h:2486
static bool binlog_row_logging_function(THD *thd, TABLE *table, bool is_transactional, const uchar *before_record, const uchar *after_record)
Definition: log_event.cc:12051
bool init_signedness_field()
Definition: log_event.cc:10795
const char * get_db() override
Definition: log_event.h:2023
int open_record_scan()
Initializes scanning of rows.
Definition: log_event.cc:8606
size_t get_data_size() override
Definition: log_event.h:1737
#define SERVER_VERSION_LENGTH
Definition: mysql_com.h:74
static int get_data_set_size(std::list< const char *> *set)
Definition: log_event.cc:13254
For binlog version 4.
Definition: log_event.h:1458
void register_temp_buf(char *buf, bool free_in_destructor=true)
Definition: log_event.h:829
Definition: log_event.h:572
Hash_slave_rows m_hash
Hash table that will hold the entries for while using HASH_SCAN algorithm to search and update/delete...
Definition: log_event.h:2661
int add_row_data(uchar *data, size_t length)
Definition: log_event.h:2593
This is the abstract base class for binary log events.
Definition: binlog_event.h:785
This is a subclass if Gtid_event and Log_event.
Definition: log_event.h:3556
MYSQL_PLUGIN_IMPORT ulong server_id
Definition: log_event.h:109
#define mysql_stage_set_work_estimated(P1, P2)
Definition: mysql_stage.h:144
const size_t BUF_SIZE
Definition: log_event.h:2170
Definition: mysql_lex_string.h:39
Definition: rpl_utility.h:106
~User_var_log_event() override
Definition: log_event.h:1795
time_t get_time()
Prints a "session_var=value" string.
Definition: log_event.cc:834
virtual enum_skip_reason do_shall_skip(Relay_log_info *rli) override
Decide if this event shall be skipped or not and the reason for skipping it.
Definition: log_event.cc:5016
Begin_load_query_log_event(THD *thd_arg, const char *db_arg, uchar *block_arg, uint block_len_arg, bool using_trans)
Definition: log_event.cc:7065
size_t get_data_size() override
Definition: log_event.h:1611
virtual uint8 get_mts_dbs(Mts_db_names *arg, Rpl_filter *rpl_filter)
The method fills in pointers to event&#39;s database name c-strings to a supplied array.
Definition: log_event.h:1014
bool write(Basic_ostream *ostream) override
Query_log_event::write().
Definition: log_event.cc:3320
Log row deletions.
Definition: rows_event.h:1092
Write_rows_log_event(THD *, TABLE *, const Table_id &table_id, bool is_transactional, const unsigned char *extra_row_ndb_info)
Definition: log_event.cc:11455
bool write_data_body(Basic_ostream *ostream) override
Definition: log_event.cc:13410
const char * server_uuid
Definition: control_events.h:1108
ulong exec_time
Definition: log_event.h:637
int get_create_or_append() const override
Definition: log_event.cc:7089
#define LOG_EVENT_ARTIFICIAL_F
Artificial events are created arbitarily and not written to binary log.
Definition: log_event.h:279
bool need_checksum()
A decider of whether to trigger checksum computation or not.
Definition: log_event.cc:1136
#define LOG_EVENT_RELAY_LOG_F
Events with this flag set are created by slave IO thread and written to relay log.
Definition: log_event.h:287
MY_BITMAP * read_set
Definition: table.h:1424
virtual int do_apply_event(Relay_log_info const *rli) override
Primitive to apply an event to the database.
Definition: log_event.cc:12228
virtual int do_after_row_operations(const Slave_reporting_capability *const, int) override
Definition: log_event.cc:11991
Version 2 of the Row events.
Definition: binlog_event.h:326
bool m_free_temp_buf_in_destructor
Definition: log_event.h:634
size_t to_string(char *buf, ulong len) const
Definition: log_event.cc:13333
No more room for tables.
Definition: log_event.h:2561
Update_rows_log_event(THD *, TABLE *, const Table_id &table_id, MY_BITMAP const *cols_bi, MY_BITMAP const *cols_ai, bool is_transactional, const unsigned char *extra_row_ndb_info)
Mix-in to handle the message logging and reporting for relay log info and master log info structures...
Definition: rpl_reporting.h:52
virtual bool starts_group() const
Events of a certain type can start or end a group of events treated transactionally wrt binlog...
Definition: log_event.h:1052
Table definition does not match.
Definition: log_event.h:2563
int get_commit_timestamp_length() const
Definition: control_events.h:892
~Transaction_context_log_event() override
Definition: log_event.cc:13107
Out of memory.
Definition: log_event.h:2562
int unpack_current_row(const Relay_log_info *const rli, MY_BITMAP const *cols, bool is_after_image, bool only_seek=false)
Unpack the current row image from the event into m_table->record[0].
Definition: log_event.cc:7706
#define DBUG_EVALUATE_IF(keyword, a1, a2)
Definition: my_dbug.h:177
Definition: log_event.h:2552
virtual int pack_info(Protocol *protocol) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:10125
Log_event_header::Byte * data_buf
Definition: log_event.h:1245
std::set< uchar *, Key_compare >::iterator m_itr
Definition: log_event.h:2721
MYSQL_PLUGIN_IMPORT char server_version[SERVER_VERSION_LENGTH]
Definition: log_event.h:121
int num
Definition: log_event.h:498
Definition: log_event.h:892
int pack_info(Protocol *protocol) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:6866
virtual bool write_data_header(Basic_ostream *ostream) override
Definition: log_event.cc:12267
virtual size_t get_data_size() override
Definition: log_event.h:3489
bool write_data_body(Basic_ostream *ostream) override
Definition: log_event.cc:13023
Represents a bidirectional map between SID and SIDNO.
Definition: rpl_gtid.h:582
int pack_info(Protocol *protocol) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:5402
~Append_block_log_event() override
Definition: log_event.h:1958
void my_free(void *ptr)
Frees the memory pointed by the ptr.
Definition: my_memory.cc:81
virtual ~Log_event()
Definition: log_event.h:828
bool deferred
Definition: log_event.h:1774
bool write(Basic_ostream *ostream) override
Definition: log_event.cc:6234
virtual int do_exec_row(const Relay_log_info *const) override
Definition: log_event.cc:11998
void update_work_estimated_and_completed(const uchar *cursor, const uchar *begin, const uchar *end)
This member function shall update the progress and reestimate the remaining work needed...
Definition: log_event.h:2462
unsigned int PSI_memory_key
Instrumented memory key.
Definition: psi_memory_bits.h:46
const char * get_db() override
Definition: log_event.h:1281
~Xid_log_event() override
Definition: log_event.h:1691
const char * db
Definition: load_data_events.h:214
Log row updates with a before image.
Definition: rows_event.h:1073
bool write(Basic_ostream *ostream) override
Definition: log_event.cc:6834
XA_prepare_log_event(const char *buf, const Format_description_event *description_event)
Definition: log_event.h:1728
This is the subclass of Xid_event defined in libbinlogevent, An XID event is generated for a commit o...
Definition: log_event.h:1676
bool rollback_injected_by_coord
True if this is a ROLLBACK event injected by the mts coordinator to finish a group corresponding to ...
Definition: log_event.h:1262
const std::string FILE("FILE")
virtual bool write_data_header(Basic_ostream *)
Definition: log_event.h:770
enum_row_image_type
Definition: rpl_record.h:36
bool is_atomic_ddl_event(Log_event *evt)
The function checks the argument event properties to deduce whether it represents an atomic DDL...
Definition: log_event.h:4114
MY_BITMAP const * get_cols() const
Definition: log_event.h:2601
protocol
Definition: memcached.h:112
uint m_key_index
Definition: log_event.h:2696
bool is_auto_inc_in_extra_columns()
Helper function to check whether there is an auto increment column on the table where the event is to...
Definition: log_event.cc:8262
Definition: log_event.h:3512
bool write(Basic_ostream *ostream) override
Definition: log_event.cc:5902
Used to hold information about file and file structure in exchange via non-DB file (...
Definition: sql_exchange.h:76
virtual int pack_info(Protocol *protocol)
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:1074
unsigned long long int transaction_length
The length of the transaction in bytes.
Definition: control_events.h:815
int apply_event(Relay_log_info *rli)
Apply the event to the database.
Definition: log_event.cc:3029
Log_event_type
Enumeration type for the different types of log events.
Definition: binlog_event.h:265
uint32 ha_checksum
Definition: my_sys.h:561
static const int xid_bufs_size
Definition: log_event.h:1720
Logs random seed used by the next RAND(), and by PASSWORD() in 4.1.0.
Definition: log_event.h:1592
uint16_t flag_set
Definition: rows_event.h:530
#define mysql_stage_set_work_completed(P1, P2)
Definition: mysql_stage.h:119
virtual Log_event_type get_general_type_code() override
Definition: log_event.h:3148
enum_event_logging_type
Definition: log_event.h:571
bool write(Basic_ostream *ostream) override
Definition: log_event.cc:6434
virtual int do_update_pos(Relay_log_info *rli) override
Advance relay log coordinates.
Definition: log_event.cc:5840
enum_skip_reason continue_group(Relay_log_info *rli)
Helper function to ignore an event w.r.t.
Definition: log_event.cc:2448
bool write_data_header(Basic_ostream *ostream) override
Definition: log_event.cc:13170
virtual ulong get_post_header_size_for_derived()
Definition: log_event.h:1348
Using this class is fraught with peril, and you need to be very careful when doing so...
Definition: sql_string.h:161
bool is_rbr_logging_format() const override
Return true if the event has to be logged using RBR for DMLs.
Definition: log_event.h:2783
An Intvar_event will be created just before a Query_event, if the query uses one of the variables LAS...
Definition: statement_events.h:920
bool write_post_header_for_derived(Basic_ostream *ostream) override
Definition: log_event.cc:7150
daisy-chanining RBR to SBR not allowed
Definition: log_event.h:2249
flag_set m_flags
Definition: rows_event.h:667
bool needs_default_table_encryption
Whether or not the statement represented by this event requires Q_DEFAULT_TABLE_ENCRYPTION to be logg...
Definition: log_event.h:1430
const char * db
Definition: log_event.h:2176
Definition: log_event.h:896
LOAD DATA INFILE is not written to the binary log like other statements.
static const size_t TEXT_LENGTH
The number of bytes in the textual representation of a Uuid.
Definition: uuid.h:154
#define OVER_MAX_DBS_IN_EVENT_MTS
When the actual number of databases exceeds MAX_DBS_IN_EVENT_MTS the value of OVER_MAX_DBS_IN_EVENT_M...
Definition: binlog_event.h:111
bool slave_execute_deferred_events(THD *thd)
The function is called by slave applier in case there are active table filtering rules to force gathe...
Definition: log_event.cc:5865
Definition: log_event.h:904
Definition: log_event.h:586
unsigned long m_width
Flags for row-level events.
Definition: rows_event.h:945
#define DBUG_EXECUTE_IF(keyword, a1)
Definition: my_dbug.h:169
Rows_applier_psi_stage()
Definition: log_event.h:2440
Definition: table.h:1301
bool is_mts_sequential_exec()
Is called from get_mts_execution_mode() to.
Definition: log_event.h:868
bool is_sbr_logging_format() const override
Return true if the event has to be logged using SBR for DMLs.
Definition: log_event.h:1967
db_worker_hash_entry * mts_assigned_partitions[MAX_DBS_IN_EVENT_MTS]
Partition info associate with event to deliver to MTS event applier.
Definition: log_event.h:702
Common base class for all row-containing binary log events.
Definition: rows_event.h:873
char * temp_buf
Definition: log_event.h:627
int next_record_scan(bool first_read)
Fetches next row.
Definition: log_event.cc:8547
virtual uint8 mts_number_dbs()
Definition: log_event.h:1031
Common definition between mysql server & client.
Functions related to handling of plugins and other dynamically loaded libraries.
virtual int do_apply_event(Relay_log_info const *rli) override
Primitive to apply an event to the database.
Definition: log_event.cc:10471
Definition: binlog_event.h:294
This struct represents a specification of a GTID for a statement to be executed: either "AUTOMATIC"...
Definition: rpl_gtid.h:3621
Definition: log_event.h:582
bool is_sbr_logging_format() const override
When a query log event contains a non-transaction control statement, we assume that it is changing da...
Definition: log_event.h:2152
const Table_id & get_table_id() const
Definition: log_event.h:2604
Something out of the ordinary happened on the master.
Definition: binlog_event.h:308
Incident_log_event(THD *thd_arg, enum_incident incident_arg)
Definition: log_event.h:3301
static uint64_t cache_size
Definition: xcom_cache.c:389
virtual int do_apply_event(Relay_log_info const *rli) override
Primitive to apply an event to the database.
Definition: log_event.cc:7038
const char * get_db_name() const
Definition: log_event.h:2291
int pack_info(Protocol *) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:12534
virtual size_t get_data_size()
Definition: log_event.h:843
bool is_sbr_logging_format() const override
Return true if the event has to be logged using SBR for DMLs.
Definition: log_event.h:2026
uint16_t m_flags
Definition: rows_event.h:942
bool write(Basic_ostream *ostream) override
Definition: log_event.cc:5234
Event responsible for LOAD DATA execution, it similar to Query_event but before executing the query i...
Definition: load_data_events.h:118
size_t get_data_size() override
Definition: log_event.h:1692
int my_b_copy_to_file(IO_CACHE *cache, FILE *file)
Definition: mf_iocache2.cc:73
Format_description_log_event()
Format_description_log_event 1st ctor.
Definition: log_event.cc:5114
Definition: binlog_event.h:279
#define DBUG_PRINT(keyword, arglist)
Definition: my_dbug.h:179
rpl_gno gno
GNO of this Gtid.
Definition: rpl_gtid.h:928
virtual int do_update_pos(Relay_log_info *rli) override
The method either increments the relay log position or commits the current statement and increments t...
Definition: log_event.cc:9988
enum_mts_event_exec_mode
Definition: log_event.h:888
virtual enum_skip_reason do_shall_skip(Relay_log_info *rli) override
Decide if this event shall be skipped or not and the reason for skipping it.
Definition: log_event.cc:5641
Skip event and decrease skip counter.
Definition: log_event.h:542
Log_event_type get_type_code()
Definition: log_event.h:1850
uint32_t thread_id
Definition: control_events.h:1109
Definition: log_event.h:2266
bool write(Basic_ostream *ostream) override
Definition: log_event.cc:6998
Contains the classes representing events which are used for row based replication.
KEY * m_key_info
Definition: log_event.h:2697
bool is_relay_log_event() const
Definition: log_event.h:802
#define DBUG_ASSERT(A)
Definition: my_dbug.h:197
unsigned int net_length_size(unsigned long long num)
void add_write_set(const char *hash)
Add a hash which identifies a inserted/updated/deleted row on the ongoing transaction.
Definition: log_event.cc:13266
Definition: log_event.h:2550
Event for the first block of file to be loaded, its only difference from Append_block event is that t...
Definition: load_data_events.h:357
ulonglong m_n_rows_applied
Counter that is unconditionally incremented on each row that is processed.
Definition: log_event.h:2437
virtual bool read_write_bitmaps_cmp(const TABLE *table) const =0
Compares the table&#39;s read/write_set with the columns included in this event&#39;s before-image and/or aft...
Rand_event(unsigned long long seed1_arg, unsigned long long seed2_arg)
This will initialize the instance variables seed1 & seed2, and set the type_code as RAND_EVENT in th...
Definition: statement_events.h:1042
Rows query event type, which is a subclass of the Ignorable_event, to record the original query for t...
Definition: rows_event.h:1128
virtual int do_after_row_operations(const Slave_reporting_capability *const, int) override
Definition: log_event.cc:11591
char * strmake(char *dst, const char *src, size_t length)
Definition: strmake.cc:42
size_t q_len
Definition: statement_events.h:586
uchar * m_rows_buf
Definition: log_event.h:2686
~Gtid_log_event() override
Definition: log_event.h:3589
void close_cached_file(IO_CACHE *cache)
Definition: mf_cache.cc:86
Legends running throughout the module:
Definition: rpl_rli_pdb.h:72
~Table_map_log_event() override
Definition: log_event.cc:10359
An XA_prepare event is generated for a XA prepared transaction.
Definition: control_events.h:577
size_t data_written
Definition: binlog_event.h:646
std::atomic< int32 > atomic_usage_counter
Definition: log_event.h:1477
Skip event by ignoring it.
Definition: log_event.h:537
unsigned int block_len
Definition: load_data_events.h:297
Definition: rpl_rli.h:164
virtual bool is_sbr_logging_format() const
Return true if the event has to be logged using SBR for DMLs.
Definition: log_event.h:779
virtual bool write_data_body(Basic_ostream *)
Definition: log_event.h:771
Query_log_event()
The simplest constructor that could possibly work.
Definition: log_event.cc:3612
bool write_data_body(Basic_ostream *ostream) override
Definition: log_event.cc:13186
char * pos
Definition: do_ctype.cc:76
bool is_using_trans_cache() const
Definition: log_event.h:811
virtual int do_apply_event(Relay_log_info const *rli) override
Primitive to apply an event to the database.
Definition: log_event.cc:5316
ulong get_post_header_size_for_derived() override
Definition: log_event.cc:7145
ulonglong future_event_relay_log_pos
A copy of the main rli value stored into event to pass to MTS worker rli.
Definition: log_event.h:695
size_t ident_len
Definition: control_events.h:108
Rotate_log_event(const char *new_log_ident_arg, size_t ident_len_arg, ulonglong pos_arg, uint flags)
Definition: log_event.cc:5438
virtual int do_apply_event(Relay_log_info const *rli)
Primitive to apply an event to the database.
Definition: log_event.h:1120
int ignored_error_code(int err_code)
Ignore error code specified on command line.
Definition: log_event.cc:567
int do_apply_event(Relay_log_info const *) override
Primitive to apply an event to the database.
Definition: log_event.h:3864
std::list< const char * > * get_write_set()
Return a pointer to write-set list.
Definition: log_event.h:3956
virtual int do_before_row_operations(const Slave_reporting_capability *const log)=0
virtual bool write_data_body(Basic_ostream *ostream) override
Definition: log_event.cc:12390
virtual int do_apply_event(Relay_log_info const *rli) override
Primitive to apply an event to the database.
Definition: log_event.cc:6887
ulong rbr_exec_mode
A storage to cache the global system variable&#39;s value.
Definition: log_event.h:649
int pack_info(Protocol *) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:12201
const uchar * m_curr_row
Definition: log_event.h:2693
Definition: log_event.h:577
uint32_t checksum_crc32(uint32_t crc, const unsigned char *pos, size_t length)
Calculate a long checksum for a memoryblock.
Definition: binlog_event.h:433
row_lookup_mode
Definition: log_event.h:2547
bool write(Basic_ostream *ostream) override
Definition: log_event.cc:5800
Written every time a statement uses a user variable; precedes other events for the statement...
Definition: statement_events.h:803
char * m_rows_query
Definition: rows_event.h:1155
Definition: log_event.h:564
virtual size_t get_data_size() override
Definition: log_event.cc:7767
binary_log::Log_event_footer * common_footer
The Log_event_footer class contains the variable present in the common footer.
Definition: log_event.h:684
Table_id m_table_id
Actual event type.
Definition: rows_event.h:941
size_t my_strmov_quoted_identifier(THD *thd, char *buffer, const char *identifier, size_t length)
Definition: log_event.cc:13534
Definition: aggregate_check.h:523
Rows_query_log_event(THD *thd_arg, const char *query, size_t query_len)
Definition: log_event.h:3458
Definition: my_bitmap.h:42
my_thread_id slave_proxy_id
Definition: log_event.h:1254
bool write(Basic_ostream *ostream) override
Definition: log_event.h:3805
Definition: log_event.h:547
flag_set get_flags(flag_set flag) const
Definition: log_event.h:2269
virtual enum_skip_reason do_shall_skip(Relay_log_info *rli) override
Decide if this event shall be skipped or not and the reason for skipping it.
Definition: log_event.cc:7093
Gtid gtid
The GTID: { SIDNO, GNO } if type == GTID; { 0, 0 } if type == AUTOMATIC or ANONYMOUS.
Definition: rpl_gtid.h:3629
unsigned long m_field_metadata_size
The size of field metadata buffer set by calling save_field_metadata()
Definition: rows_event.h:682
Definition: log_event.h:1655
bool read_snapshot_version()
Read snapshot version from encoded buffers.
Definition: log_event.cc:13234
Cursor end()
A past-the-end Cursor.
Definition: rules_table_service.cc:188
ulonglong my_xid
recover() step of xa.
Definition: handler.h:6788
virtual bool write_data_body(Basic_ostream *ostream) override
Definition: log_event.cc:10626
std::string m_tblnam
Definition: rows_event.h:674
virtual bool ends_group() const override
Definition: log_event.h:1409
Load_query_generator(THD *thd_arg, const sql_exchange *ex, const char *db_arg, const char *table_name_arg, bool is_concurrent_arg, bool replace, bool ignore)
Definition: log_event.cc:7313
int64_t int64
Definition: my_inttypes.h:67
int do_apply_event(Relay_log_info const *rli) override
Primitive to apply an event to the database.
Definition: log_event.cc:12749
Sid_map * sid_map
The Sid_map to use for creating the Gtid_set.
Definition: log_event.h:3897
An unknown event should never occur.
Definition: binlog_event.h:922
When a binary log file exceeds a size limit, a ROTATE_EVENT is written at the end of the file that po...
Definition: control_events.h:105
enum_skip_reason do_shall_skip(Relay_log_info *rli) override
Decide if this event shall be skipped or not and the reason for skipping it.
Definition: log_event.cc:12874
void detach_temp_tables_worker(THD *, const Relay_log_info *)
Dissociating slave Worker thread from its thd->temporary_tables to possibly update the involved entri...
Definition: log_event.cc:4327
TABLE_SHARE * s
Definition: table.h:1302
static bool ignore
Definition: mysqlimport.cc:65
uint m_rows_lookup_algorithm
The algorithm to use while searching for rows using the before image.
Definition: log_event.h:2667
query_id_t query_id
Definition: log_event.h:1775
std::set< uchar *, Key_compare > m_distinct_keys
Definition: log_event.h:2720
virtual int do_update_pos(Relay_log_info *rli) override
Advance relay log coordinates.
Definition: log_event.cc:6713
Maps table id&#39;s (integers) to table pointers.
Definition: rpl_tblmap.h:50
virtual int do_apply_event(Relay_log_info const *rli) override
Primitive to apply an event to the database.
Definition: log_event.cc:12400
Definition: my_sys.h:360
Event for the first block of file to be loaded, its only difference from Append_block event is that t...
Definition: log_event.h:2071
virtual Log_event_type get_general_type_code() override
Definition: log_event.h:3053
bool is_query_prefix_match(const char *pattern, uint p_len)
Definition: log_event.h:1419
Definition: log_event.h:3115
This is the abstract base class for binary log events.
Definition: log_event.h:517
const char * table_name
Definition: log_event.h:2177
User_var_event(const char *name_arg, unsigned int name_len_arg, char *val_arg, unsigned long val_len_arg, Value_type type_arg, unsigned int charset_number_arg, unsigned char flags_arg)
This constructor will initialize the instance variables and the type_code, it will be used only by th...
Definition: statement_events.h:819
int key_cmp2(KEY_PART_INFO *key_part, const uchar *key1, uint key1_length, const uchar *key2, uint key2_length)
Compare two given keys.
Definition: key.cc:497
int do_update_pos(Relay_log_info *rli) override
Advance relay log coordinates.
Definition: log_event.cc:13030
int append_query_string(const THD *thd, const CHARSET_INFO *csinfo, String const *from, String *to)
Append a version of the &#39;from&#39; string suitable for use in a query to the &#39;to&#39; string.
Definition: log_event.cc:779
virtual bool ends_group() const override
Definition: log_event.h:3359
void set_deferred(query_id_t qid)
Definition: log_event.h:1808
enum_gtid_type
Enumeration of different types of values for Gtid_specification, i.e, the different internal states t...
Definition: rpl_gtid.h:3517
In row-based mode, every row operation event is preceded by a Table_map_event which maps a table defi...
Definition: rows_event.h:521
size_t get_data_size() override
Definition: log_event.h:2018
std::map< std::string, std::string > certification_info
Definition: control_events.h:1230
enum_event_logging_type event_logging_type
Defines when information, i.e.
Definition: log_event.h:661
virtual uint8 get_mts_dbs(Mts_db_names *arg, Rpl_filter *rpl_filter) override
Definition: log_event.h:2311
unsigned int flags
Definition: control_events.h:109
Header for compiler-dependent features.
Gtid_set * get_snapshot_version()
Return the transaction snapshot timestamp.
Definition: log_event.h:3981
Common base class for all row-containing log events.
Definition: log_event.h:2538
Xid_log_event(THD *thd_arg, my_xid x)
Definition: log_event.h:1679
virtual enum_skip_reason do_shall_skip(Relay_log_info *rli) override
Decide if this event shall be skipped or not and the reason for skipping it.
Definition: log_event.cc:10598
void * xid
Definition: control_events.h:596
Log row updates with a before image.
Definition: log_event.h:3110
No error.
Definition: log_event.h:2560
rpl_sid sid
SID for this GTID.
Definition: log_event.h:3733
rpl_sidno get_sidno(bool need_lock)
Return the SIDNO relative to the global sid_map for this GTID.
Definition: log_event.cc:12927
virtual uint8 get_mts_dbs(Mts_db_names *arg, Rpl_filter *rpl_filter) override
Definition: log_event.h:1294
virtual enum_skip_reason do_shall_skip(Relay_log_info *rli) override
Decide if this event shall be skipped or not and the reason for skipping it.
Definition: log_event.cc:6718
char * message
Definition: control_events.h:480
MY_BITMAP * write_set
Definition: table.h:1424
Defines various enable/disable and HAVE_ macros related to the performance schema instrumentation sys...
Similar to Xid_log_event except that.
Definition: log_event.h:1716
bool init_enum_str_value_field()
Definition: log_event.cc:10958
void set_progress(PSI_stage_progress *progress)
Definition: log_event.h:2442
uint16_t uint16
Definition: my_inttypes.h:64
Definition: item.h:668
virtual int do_update_pos(Relay_log_info *rli) override
Advance relay log coordinates.
Definition: log_event.cc:6775
void set_artificial_event()
Definition: log_event.h:790
unsigned int uint
Definition: uca-dump.cc:29
bool write_data_map(Basic_ostream *ostream, std::map< std::string, std::string > *map)
Definition: log_event.cc:13418
~Update_rows_log_event() override
Definition: log_event.cc:12075
bool write_data_body(Basic_ostream *ostream) override
Definition: log_event.cc:12740
Definition: binlog_event.h:281
virtual int do_apply_event(Relay_log_info const *rli) override
Primitive to apply an event to the database.
Definition: log_event.cc:6037
bool init_charset_field(std::function< bool(const Field *)> include_type, Optional_metadata_field_type default_charset_type, Optional_metadata_field_type column_charset_type)
Capture and serialize character sets.
Definition: log_event.cc:10825
bool is_valid()
Definition: log_event.cc:1316
#define FN_REFLEN
Definition: my_io.h:82
void attach_temp_tables_worker(THD *, const Relay_log_info *)
Associating slave Worker thread to a subset of temporary tables.
Definition: log_event.cc:4314
bool is_sbr_logging_format() const override
Return true if the event has to be logged using SBR for DMLs.
Definition: log_event.h:1814
Definition: log_event.h:2568
Gtid_set * snapshot_version
A gtid_set which is used to store the transaction set used for conflict detection.
Definition: log_event.h:3900
virtual void set_mts_isolate_group()
Definition: log_event.h:994
~Rotate_log_event() override
Definition: log_event.h:1904
~Rows_log_event() override
Definition: log_event.cc:7693
int pack_info(Protocol *protocol) override
This (which is used only for SHOW BINLOG EVENTS) could be updated to print SET @session_var=.
Definition: log_event.cc:3269
The abstract class for basic output streams which provides write operation.
Definition: basic_ostream.h:32
bool has_ddl_committed
The flag indicates whether the DDL query has been (already) committed or not.
Definition: log_event.h:1274
Optional_metadata_field_type
DEFAULT_CHARSET and COLUMN_CHARSET don&#39;t appear together, and ENUM_AND_SET_DEFAULT_CHARSET and ENUM_A...
Definition: rows_event.h:544
#define MYF(v)
Definition: my_inttypes.h:114
std::list< const char * > write_set
Definition: control_events.h:1113
const uchar * m_curr_row_end
Definition: log_event.h:2694
int pack_info(Protocol *) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:12317
const int64 SEQ_MAX_TIMESTAMP
Maximum value of binlog logical timestamp.
Definition: log_event.h:359
Relay_log_info * worker
MTS: associating the event with either an assigned Worker or Coordinator.
Definition: log_event.h:690
KEY ** m_key_info
Definition: log_event.h:2718
bool is_mts_group_isolated()
Definition: log_event.h:1038
struct xid_t is binary compatible with the XID structure as in the X/Open CAE Specification, Distributed Transaction Processing: The XA Specification, X/Open Company Ltd., 1991.
Definition: xa.h:213
int pack_info(Protocol *protocol) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:5224
const char * description() const
Definition: log_event.cc:12191
Table_map_log_event which maps a table definition to a number.
Definition: log_event.h:2234
uint32_t uint32
Definition: my_inttypes.h:66
virtual int do_exec_row(const Relay_log_info *const) override
Definition: log_event.cc:11897
Class representing an incident, an occurance out of the ordinary, that happened on the master...
Definition: control_events.h:429
static Value err()
Create a Value object that represents an error condition.
Definition: json_binary.cc:908
int do_scan_and_update(Relay_log_info const *rli)
This member function scans the table and applies the changes that had been previously hashed...
Definition: log_event.cc:8994
Log row insertions and updates.
Definition: log_event.h:3024
int pack_info(Protocol *protocol) override
This (which is used only for SHOW BINLOG EVENTS) could be updated to print SET @session_var=.
Definition: log_event.cc:7209
size_t get_event_length()
Definition: log_event.h:3597
char msg[1024]
Definition: test_sql_9_sessions.cc:281
const char * query
Definition: statement_events.h:533
An XID event is generated for a commit of a transaction that modifies one or more tables of an XA-ca...
Definition: control_events.h:512
static bool binlog_row_logging_function(THD *thd, TABLE *table, bool is_transactional, const uchar *before_record, const uchar *after_record)
Definition: log_event.cc:11469
Nothing here right now, but the flags support is there in preparation for changes that are coming...
Definition: log_event.h:2259
virtual int get_create_or_append() const
Definition: log_event.cc:6879
This will be deprecated when we move to using sequence ids.
Definition: log_event.h:1892
const char * get_table_name() const
Definition: log_event.h:2290
GTID stands for Global Transaction IDentifier It is composed of two parts:
Definition: control_events.h:795
char * buf[2048]
Definition: log_event.h:2172
Definition: m_ctype.h:359
uint8_t uint8
Definition: my_inttypes.h:62
#define LOG_EVENT_NO_FILTER_F
Events with this flag are not filtered (e.g.
Definition: log_event.h:307
Definition: binlog_event.h:333
Definition: log_event.h:2548
virtual bool write_data_body(Basic_ostream *ostream) override
Definition: log_event.cc:10092
virtual uchar mts_number_dbs() override
Definition: log_event.h:1320
int pack_info(Protocol *) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:12348
~Previous_gtids_log_event() override
Definition: log_event.h:3797
const int MAX_GNO_TEXT_LENGTH
The length of MAX_GNO when printed in decimal.
Definition: rpl_gtid.h:391
TABLE * m_table
Definition: log_event.h:2653
uint32 write_header_to_memory(uchar *buf)
Writes the common header of this event to the given memory buffer.
Definition: log_event.cc:1227
size_t get_size_data_map(std::map< std::string, std::string > *map)
Definition: log_event.cc:13319
bool contains_partition_info(bool)
Definition: log_event.cc:2468
PSI_memory_key key_memory_Incident_log_event_message
Definition: log_event.cc:169
void init(MY_BITMAP const *cols, const MY_BITMAP &cols_to_subtract)
Definition: log_event.cc:12058
uint32 m_bitbuf_ai[128/(sizeof(uint32) *8)]
Definition: log_event.h:2680
Common header for many mysys elements.
For binlog version 4.
Definition: control_events.h:228
int pack_info(Protocol *protocol) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:5665
void init_metadata_fields()
Capture the optional metadata fields which should be logged into table_map_log_event and serialize th...
Definition: log_event.cc:10772
int do_apply_row(Relay_log_info const *rli)
Commodity wrapper around do_exec_row(), that deals with resetting the thd reference in the table...
Definition: log_event.cc:8497
Each table share has a table id, it is mainly used for row based replication.
Definition: table_id.h:39
virtual size_t get_data_size() override
Definition: log_event.h:3416
Definition: log_event.h:2264
Definition: log_event.h:2549
virtual int do_update_pos(Relay_log_info *rli) override
Advance relay log coordinates.
Definition: log_event.cc:5002
Append_block_log_event(THD *thd, const char *db_arg, uchar *block_arg, uint block_len_arg, bool using_trans)
Definition: log_event.cc:6804
DBUG_TRACE
Definition: do_ctype.cc:46
static const size_t MAX_SET_STRING_LENGTH
The maximal length of the entire "SET ..." query.
Definition: log_event.h:3722
uint32_t hash(const void *key, size_t length, const uint32_t initval)
Definition: hash.c:121
const char * get_server_uuid()
Return the server uuid.
Definition: log_event.h:3986
Represents a set of GTIDs.
Definition: rpl_gtid.h:1302
enum_skip_reason do_shall_skip(Relay_log_info *) override
Decide if this event shall be skipped or not and the reason for skipping it.
Definition: log_event.h:3859
uint32 write_body_to_memory(uchar *buff)
Writes the body to the given memory buffer.
Definition: log_event.cc:12683
Definition: typelib.h:34
size_t get_width() const
Definition: log_event.h:2603
~Intvar_log_event() override
Definition: log_event.h:1548
~Begin_load_query_log_event() override
Definition: log_event.h:2082
int pack_info(Protocol *protocol) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:5884
Incident_event(enum_incident incident_arg)
This will create an Incident_event with an empty message and set the type_code as INCIDENT_EVENT in t...
Definition: control_events.h:450
Xid_apply_log_event(THD *thd_arg, Log_event_header *header_arg, Log_event_footer *footer_arg)
Definition: log_event.h:1658
const unsigned char * buf
Definition: control_events.h:1014
static bool bitmap_cmp(const MY_BITMAP *map1, const MY_BITMAP *map2)
Quite unlike other C comparison functions ending with &#39;cmp&#39;, e.g.
Definition: my_bitmap.h:116
bool do_commit(THD *thd) override
Differs from Xid_log_event::do_commit in that it carries out XA prepare (not the commit).
Definition: log_event.cc:6291
Log row deletions.
Definition: log_event.h:3228
virtual enum_skip_reason do_shall_skip(Relay_log_info *rli) override
Decide if this event shall be skipped or not and the reason for skipping it.
Definition: log_event.cc:5845
uint16 flag_set
Definition: log_event.h:2545
#define mysql_stage_get_work_estimated(P1)
Definition: mysql_stage.h:147
Log_event(Log_event_header *header, Log_event_footer *footer, enum_event_cache_type cache_type_arg, enum_event_logging_type logging_type_arg)
This minimal constructor is for when you are not even sure that there is a valid THD.
Definition: log_event.cc:956
virtual bool write_post_header_for_derived(Basic_ostream *)
Definition: log_event.h:1341
Rand_log_event(THD *thd_arg, ulonglong seed1_arg, ulonglong seed2_arg, enum_event_cache_type cache_type_arg, enum_event_logging_type logging_type_arg)
Definition: log_event.h:1595
~Xid_apply_log_event() override
Definition: log_event.h:1666
Definition: log_event.h:2238
bool reinit_io_cache(IO_CACHE *info, enum cache_type type, my_off_t seek_offset, bool use_async_io, bool clear_cache)
Definition: mf_iocache.cc:327
bool read_write_bitmaps_cmp(const TABLE *table) const override
Compares the table&#39;s read/write_set with the columns included in this event&#39;s before-image and/or aft...
Definition: log_event.h:3044
unsigned long my_off_t
Definition: my_inttypes.h:77
Definition: binlog_event.h:331
Intvar_log_event(THD *thd_arg, uchar type_arg, ulonglong val_arg, enum_event_cache_type cache_type_arg, enum_event_logging_type logging_type_arg)
Definition: log_event.h:1533
const char * name
Definition: statement_events.h:852
bool need_sql_require_primary_key
Whether or not the statement represented by this event requires Q_SQL_REQUIRE_PRIMARY_KEY to be logge...
Definition: log_event.h:1426
uint32 server_id
Definition: log_event.h:643
Xid_apply_log_event(Log_event_header *header_arg, Log_event_footer *footer_arg)
Definition: log_event.h:1663
const sql_exchange * sql_ex
Definition: log_event.h:2175
static binary_log::Log_event_type get_update_rows_event_type(const THD *thd_arg)
Auxiliary function used in the (THD*, ...) constructor to determine the type code based on configurat...
Definition: log_event.cc:12022
Definition: log_event.h:559
unsigned long m_colcnt
Definition: rows_event.h:676
uint32 my_thread_id
Definition: my_thread_local.h:33
String str
Definition: log_event.h:2171
const char * fname
Definition: log_event.h:2178
void inc_n_rows_applied(ulonglong delta)
Updates the counter of processed rows.
Definition: log_event.h:2495
const char * get_rewrite_db(const char *db, size_t *new_len)
Definition: rpl_filter.cc:1182
virtual int do_apply_event(Relay_log_info const *rli) override
Primitive to apply an event to the database.
Definition: log_event.cc:6606
THD * thd
Definition: log_event.h:2174
size_t get_data_size() override
Definition: log_event.h:1549
binary_log::Log_event_header * common_header
The Log_event_header class contains the variable present in the common header
Definition: log_event.h:678
virtual enum_skip_reason do_shall_skip(Relay_log_info *rli) override
Decide if this event shall be skipped or not and the reason for skipping it.
Definition: log_event.cc:5764
Definition: protocol.h:34
Performance schema instrumentation interface.
~Delete_file_log_event() override
Definition: log_event.h:2017
#define MAX_DBS_IN_EVENT_MTS
The maximum number of updated databases that a status of Query-log-event can carry.
Definition: binlog_event.h:104
virtual int do_apply_event_worker(Slave_worker *w)
Definition: log_event.cc:1004
friend class Old_rows_log_event
Definition: log_event.h:2977
static int flag
Definition: hp_test1.cc:39
bool init_column_name_field()
Definition: log_event.cc:10919
size_t buf_size
Definition: control_events.h:1013
int do_update_pos(Relay_log_info *rli) override
Advance relay log coordinates.
Definition: log_event.cc:13393
void set_relay_log_event()
Definition: log_event.h:798
ulong mts_group_idx
Index in rli->gaq array to indicate a group that this event is purging.
Definition: log_event.h:672
A stop event is written to the log files under these circumstances:
Definition: control_events.h:368
uint16_t flags
Definition: binlog_event.h:661
PSI_stage_progress * m_progress
A cached pointer to this stage PSI_stage_progress.
Definition: log_event.h:2430
enum_gtid_type type
The type of this GTID.
Definition: rpl_gtid.h:3623
int type
Definition: http_common.h:411
void set_is_valid(bool is_valid)
Set if the event object shall be considered valid or not.
Definition: binlog_event.h:702
Interface for an instrumented stage progress.
Definition: psi_stage_bits.h:60
virtual int do_add_row_data(uchar *data, size_t length)
Definition: log_event.cc:7806
virtual const char * get_db()
Definition: log_event.cc:1079
enum enum_mts_event_exec_mode get_mts_execution_mode(bool mts_in_group)
MTS Coordinator finds out a way how to execute the current event.
Definition: log_event.h:922
const char * db
Definition: statement_events.h:534
virtual int do_after_row_operations(const Slave_reporting_capability *const log, int error)=0
const Table_id & get_table_id() const
Definition: log_event.h:2289
Every time a query uses the value of a user variable, a User_var_log_event is written before the Quer...
Definition: log_event.h:1771
int pack_info(Protocol *protocol) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:13339
virtual int do_apply_event(Relay_log_info const *rli) override
Primitive to apply an event to the database.
Definition: log_event.cc:7240
void set_seq_number(rpl_gno number)
Set the certification sequence number.
Definition: log_event.h:4093
size_t get_data_size() override
Definition: log_event.h:3591
const Log_event_footer * footer() const
Return a const pointer to the footer of the log event.
Definition: binlog_event.h:892
Definition: rpl_rli_pdb.h:515
Every time you add a type, you have to.
Definition: binlog_event.h:273
Rows_applier_psi_stage & operator=(const Rows_applier_psi_stage &rhs)
int write_row(const Relay_log_info *const, const bool)
Write the current row into event&#39;s table.
Definition: log_event.cc:11662
Definition: key.h:111
uint64_t xid
Definition: control_events.h:529
bool operator()(uchar *k1, uchar *k2) const
Definition: log_event.h:2712
static const size_t SET_STRING_PREFIX_LENGTH
Length of SET_STRING_PREFIX.
Definition: log_event.h:3720
bool is_artificial_event() const
Definition: log_event.h:799
Definition: binlog_event.h:284
~Rows_query_log_event() override
Definition: log_event.h:3481
size_t to_string(char *buf) const
Used internally by both print() and pack_info().
Definition: log_event.cc:12542
XA_prepare_log_event(THD *thd_arg, XID *xid_arg, bool one_phase_arg=false)
Definition: log_event.h:1724
int64 query_id_t
Definition: binlog.h:69
Definition: binlog_event.h:291
void set_trx_length_by_cache_size(ulonglong cache_size, bool is_checksum_enabled=false, int event_counter=0)
Set the transaction length information based on binlog cache size.
Definition: log_event.cc:12879
The Common-Header always has the same form and length within one version of MySQL.
Definition: binlog_event.h:622
void do_post_row_operations(Relay_log_info const *rli, int err)
Private member function called after updating/deleting a row.
Definition: log_event.cc:8379
Intvar_event(const char *buf, const Format_description_event *fde)
Constructor receives a packet from the MySQL master or the binary log and decodes it to create an Int...
Definition: statement_events.cpp:483
virtual int do_before_row_operations(const Slave_reporting_capability *const) override
Definition: log_event.cc:11968
char * get_view_id()
Returns the view id.
Definition: log_event.h:4066
~Ignorable_log_event() override
Definition: log_event.cc:12313
static bool binlog_row_logging_function(THD *thd, TABLE *table, bool is_transactional, const uchar *before_record, const uchar *after_record)
Definition: log_event.cc:11945
int net_send(Protocol *protocol, const char *log_name, my_off_t pos)
Only called by SHOW BINLOG EVENTS.
Definition: log_event.cc:1084
bool read_write_bitmaps_cmp(const TABLE *table) const override
Compares the table&#39;s read/write_set with the columns included in this event&#39;s before-image and/or aft...
Definition: log_event.h:3246
bool is_sbr_logging_format() const override
Return true if the event has to be logged using SBR for DMLs.
Definition: log_event.h:1557
Definition: log_event.h:3029
int row_operations_scan_and_key_teardown(int error)
Definition: log_event.cc:8232
bool wrapper_my_b_safe_write(Basic_ostream *ostream, const uchar *buf, size_t data_length)
Write the given buffer to the given output stream, updating the checksum if checksums are enabled...
Definition: log_event.cc:1205
size_t m_data_size
Definition: rows_event.h:669
Definition: log_event.h:3233
virtual Log_event_type get_