MySQL  8.0.16
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 "binlog_event.h"
45 #include "control_events.h"
46 #include "lex_string.h"
47 #include "load_data_events.h"
48 #include "m_string.h" // native_strncasecmp
49 #include "my_bitmap.h" // MY_BITMAP
50 #include "my_dbug.h"
51 #include "my_inttypes.h"
52 #include "my_psi_config.h"
53 #include "my_sharedlib.h"
54 #include "my_sys.h"
55 #include "my_thread_local.h"
59 #include "mysql_com.h" // SERVER_VERSION_LENGTH
60 #include "partition_info.h"
61 #include "rows_event.h"
62 #include "sql/query_options.h" // OPTION_AUTO_IS_NULL
63 #include "sql/rpl_gtid.h" // enum_gtid_type
64 #include "sql/rpl_utility.h" // Hash_slave_rows
65 #include "sql/sql_const.h"
66 #include "sql/thr_malloc.h"
67 #include "sql_string.h"
68 #include "statement_events.h"
69 #include "typelib.h" // TYPELIB
70 #include "uuid.h"
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  */
607  uint32 write_header_to_memory(uchar *buf);
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  */
643  uint32 server_id;
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 = 0;
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_ENTER("Log_event::shall_skip");
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  DBUG_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  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 = (char *)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_ENTER(
1733  "XA_prepare_log_event::XA_prepare_log_event(const char*, const "
1734  "Format_description_log_event *)");
1735  xid = NULL;
1737  }
1739  size_t get_data_size() override {
1740  return xid_bufs_size + my_xid.gtrid_length + my_xid.bqual_length;
1741  }
1742 #ifdef MYSQL_SERVER
1743  bool write(Basic_ostream *ostream) override;
1744 #else
1745  void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
1746 #endif
1747 #if defined(MYSQL_SERVER)
1748  int pack_info(Protocol *protocol) override;
1749  bool do_commit(THD *thd) override;
1750 #endif
1751 };
1752 
1753 /**
1754  @class User_var_log_event
1755 
1756  Every time a query uses the value of a user variable, a User_var_log_event is
1757  written before the Query_log_event, to set the user variable.
1758 
1759  @internal
1760  The inheritance structure in the current design for the classes is
1761  as follows:
1762  Binary_log_event
1763  ^
1764  |
1765  |
1766  User_var_event Log_event
1767  \ /
1768  \ /
1769  \ /
1770  User_var_log_event
1771  @endinternal
1772 */
1774  public:
1775 #ifdef MYSQL_SERVER
1776  bool deferred;
1778  User_var_log_event(THD *thd_arg, const char *name_arg, uint name_len_arg,
1779  char *val_arg, ulong val_len_arg, Item_result type_arg,
1780  uint charset_number_arg, uchar flags_arg,
1781  enum_event_cache_type cache_type_arg,
1782  enum_event_logging_type logging_type_arg)
1783  : binary_log::User_var_event(name_arg, name_len_arg, val_arg, val_len_arg,
1784  type_arg, charset_number_arg, flags_arg),
1785  Log_event(thd_arg, 0, cache_type_arg, logging_type_arg, header(),
1786  footer()),
1787  deferred(false) {
1789  }
1790  int pack_info(Protocol *protocol) override;
1791 #else
1792  void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
1793 #endif
1794 
1795  User_var_log_event(const char *buf,
1796  const Format_description_event *description_event);
1797  ~User_var_log_event() override {}
1798 #ifdef MYSQL_SERVER
1799  bool write(Basic_ostream *ostream) override;
1800  /*
1801  Getter and setter for deferred User-event.
1802  Returns true if the event is not applied directly
1803  and which case the applier adjusts execution path.
1804  */
1805  bool is_deferred() { return deferred; }
1806  /*
1807  In case of the deffered applying the variable instance is flagged
1808  and the parsing time query id is stored to be used at applying time.
1809  */
1811  deferred = true;
1812  query_id = qid;
1813  }
1814 #endif
1815 
1816  bool is_sbr_logging_format() const override { return true; }
1817 
1818  private:
1819 #if defined(MYSQL_SERVER)
1820  virtual int do_apply_event(Relay_log_info const *rli) override;
1821  virtual int do_update_pos(Relay_log_info *rli) override;
1822  virtual enum_skip_reason do_shall_skip(Relay_log_info *rli) override;
1823 #endif
1824 };
1825 
1826 /**
1827  @class Stop_log_event
1828 
1829 */
1831  public:
1832 #ifdef MYSQL_SERVER
1836  common_header->set_is_valid(true);
1837  }
1838 
1839 #else
1840  void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
1841 #endif
1842 
1843  Stop_log_event(const char *buf,
1844  const Format_description_event *description_event)
1845  : binary_log::Stop_event(buf, description_event),
1846  Log_event(header(), footer()) {
1847  DBUG_ENTER(
1848  "Stop_log_event::Stop_log_event(const char*, const "
1849  "Format_description_log_event *)");
1851  }
1852 
1853  ~Stop_log_event() override {}
1855 
1856  private:
1857 #if defined(MYSQL_SERVER)
1858  virtual int do_update_pos(Relay_log_info *rli) override;
1860  /*
1861  Events from ourself should be skipped, but they should not
1862  decrease the slave skip counter.
1863  */
1864  if (this->server_id == ::server_id)
1866  else
1868  }
1869 #endif
1870 };
1871 
1872 /**
1873  @class Rotate_log_event
1874 
1875  This will be deprecated when we move to using sequence ids.
1876  This class is a subclass of Rotate_event, defined in binlogevent, and is used
1877  by the slave for updating the position in the relay log.
1878 
1879  It is used by the master inorder to write the rotate event in the binary log.
1880 
1881  @internal
1882  The inheritance structure in the current design for the classes is
1883  as follows:
1884 
1885  Binary_log_event
1886  ^
1887  |
1888  |
1889  Rotate_event Log_event
1890  \ /
1891  \ /
1892  \ /
1893  Rotate_log_event
1894  @endinternal
1895 */
1897  public:
1898 #ifdef MYSQL_SERVER
1899  Rotate_log_event(const char *new_log_ident_arg, size_t ident_len_arg,
1900  ulonglong pos_arg, uint flags);
1901  int pack_info(Protocol *protocol) override;
1902 #else
1903  void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
1904 #endif
1905 
1906  Rotate_log_event(const char *buf,
1907  const Format_description_event *description_event);
1908  ~Rotate_log_event() override {}
1909  size_t get_data_size() override {
1910  return ident_len + Binary_log_event::ROTATE_HEADER_LEN;
1911  }
1912 #ifdef MYSQL_SERVER
1913  bool write(Basic_ostream *ostream) override;
1914 #endif
1915 
1916  private:
1917 #if defined(MYSQL_SERVER)
1918  virtual int do_update_pos(Relay_log_info *rli) override;
1919  virtual enum_skip_reason do_shall_skip(Relay_log_info *rli) override;
1920 #endif
1921 };
1922 
1923 /**
1924  @class Append_block_log_event
1925 
1926  This event is created to contain the file data. One LOAD_DATA_INFILE
1927  can have 0 or more instances of this event written to the binary log
1928  depending on the size of the file.
1929 
1930  @internal
1931  The inheritance structure is as follows
1932 
1933  Binary_log_event
1934  ^
1935  |
1936  |
1937  B_l:A_B_E Log_event
1938  \ /
1939  \ /
1940  <<vir>>\ /
1941  \ /
1942  Append_block_log_event
1943  B_l: Namespace Binary_log
1944  A_B_E: class Append_block_event
1945  @endinternal
1946 
1947 */
1949  public Log_event {
1950  public:
1951 #ifdef MYSQL_SERVER
1952  Append_block_log_event(THD *thd, const char *db_arg, uchar *block_arg,
1953  uint block_len_arg, bool using_trans);
1954  int pack_info(Protocol *protocol) override;
1955  virtual int get_create_or_append() const;
1956 #else
1957  void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
1958 #endif
1959 
1960  Append_block_log_event(const char *buf,
1961  const Format_description_event *description_event);
1963  size_t get_data_size() override {
1964  return block_len + Binary_log_event::APPEND_BLOCK_HEADER_LEN;
1965  }
1966 #ifdef MYSQL_SERVER
1967  bool write(Basic_ostream *ostream) override;
1968  const char *get_db() override { return db; }
1969 #endif
1970 
1971  bool is_sbr_logging_format() const override { return true; }
1972 
1973  private:
1974 #if defined(MYSQL_SERVER)
1975  virtual int do_apply_event(Relay_log_info const *rli) override;
1976 #endif
1977 };
1978 
1979 /**
1980  @class Delete_file_log_event
1981 
1982  Delete_file_log_event is created when the LOAD_DATA query fails on the
1983  master for some reason, and the slave should be notified to abort the
1984  load. The event is required since the master starts writing the loaded
1985  block into the binary log before the statement ends. In case of error,
1986  the slave should abort, and delete any temporary file created while
1987  applying the (NEW_)LOAD_EVENT.
1988 
1989  @internal
1990  The inheritance structure is as follows
1991 
1992  Binary_log_event
1993  ^
1994  |
1995  |
1996  B_l:D_F_E Log_event
1997  \ /
1998  \ /
1999  \ /
2000  \ /
2001  Delete_file_log_event
2002 
2003  B_l: Namespace Binary_log
2004  D_F_E: class Delete_file_event
2005  @endinternal
2006 
2007 */
2009  public Log_event {
2010  public:
2011 #ifdef MYSQL_SERVER
2012  Delete_file_log_event(THD *thd, const char *db_arg, bool using_trans);
2013  int pack_info(Protocol *protocol) override;
2014 #else
2015  void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
2016  void print(FILE *file, PRINT_EVENT_INFO *print_event_info, bool enable_local);
2017 #endif
2018 
2019  Delete_file_log_event(const char *buf,
2020  const Format_description_event *description_event);
2022  size_t get_data_size() override {
2023  return Binary_log_event::DELETE_FILE_HEADER_LEN;
2024  }
2025 #ifdef MYSQL_SERVER
2026  bool write(Basic_ostream *ostream) override;
2027  const char *get_db() override { return db; }
2028 #endif
2029 
2030  bool is_sbr_logging_format() const override { return true; }
2031 
2032  private:
2033 #if defined(MYSQL_SERVER)
2034  virtual int do_apply_event(Relay_log_info const *rli) override;
2035 #endif
2036 };
2037 
2038 /**
2039  @class Begin_load_query_log_event
2040 
2041  Event for the first block of file to be loaded, its only difference from
2042  Append_block event is that this event creates or truncates existing file
2043  before writing data.
2044 
2045  @internal
2046  The inheritance structure is as follows
2047 
2048  Binary_log_event
2049  ^
2050  |
2051  |
2052  |
2053  Log_event B_l:A_B_E
2054  ^ /\
2055  | / \
2056  | <<vir>>/ \ <<vir>>
2057  | / \
2058  | / \
2059  | / \
2060  Append_block_log_event B_l:B_L_Q_E
2061  \ /
2062  \ /
2063  \ /
2064  \ /
2065  \ /
2066  Begin_load_query_log_event
2067 
2068  B_l: Namespace Binary_log
2069  A_B_E: class Append_block_event
2070  B_L_Q_E: Begin_load_query_event
2071  @endinternal
2072 
2073  @section Begin_load_query_log_event_binary_format Binary Format
2074 */
2077  public:
2078 #ifdef MYSQL_SERVER
2079  Begin_load_query_log_event(THD *thd_arg, const char *db_arg, uchar *block_arg,
2080  uint block_len_arg, bool using_trans);
2082  int get_create_or_append() const override;
2083 #endif
2084  Begin_load_query_log_event(const char *buf,
2085  const Format_description_event *description_event);
2087 
2088  private:
2089 #if defined(MYSQL_SERVER)
2090  virtual enum_skip_reason do_shall_skip(Relay_log_info *rli) override;
2091 #endif
2092 };
2093 
2094 /**
2095  @class Execute_load_query_log_event
2096 
2097  Event responsible for LOAD DATA execution, it similar to Query_log_event
2098  but before executing the query it substitutes original filename in LOAD DATA
2099  query with name of temporary file.
2100 
2101  @internal
2102  The inheritance structure is as follows:
2103 
2104  Binary_log_event
2105  ^
2106  |
2107  |
2108  |
2109  Log_event B_l:Query_event
2110  ^ /\
2111  | / \
2112  | <<vir>>/ \ <<vir>>
2113  | / \
2114  | / \
2115  | / \
2116  Query_log_event B_l:E_L_Q_E
2117  \ /
2118  \ /
2119  \ /
2120  \ /
2121  \ /
2122  Execute_load_query_log_event
2123 
2124  B_l: Namespace Binary_log
2125  E_L_Q_E: class Execute_load_query
2126  @endinternal
2127 
2128  @section Execute_load_query_log_event_binary_format Binary Format
2129 */
2131  : public Query_log_event,
2133  public:
2134 #ifdef MYSQL_SERVER
2136  THD *thd, const char *query_arg, ulong query_length,
2137  uint fn_pos_start_arg, uint fn_pos_end_arg,
2138  binary_log::enum_load_dup_handling dup_handling_arg, bool using_trans,
2139  bool immediate, bool suppress_use, int errcode);
2140  int pack_info(Protocol *protocol) override;
2141 #else
2142  void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
2143  /* Prints the query as LOAD DATA LOCAL and with rewritten filename */
2144  void print(FILE *file, PRINT_EVENT_INFO *print_event_info,
2145  const char *local_fname) const;
2146 #endif
2148  const char *buf, const Format_description_event *description_event);
2150 
2152 #ifdef MYSQL_SERVER
2153  bool write_post_header_for_derived(Basic_ostream *ostream) override;
2154 #endif
2155 
2156  bool is_sbr_logging_format() const override { return true; }
2157 
2158  private:
2159 #if defined(MYSQL_SERVER)
2160  virtual int do_apply_event(Relay_log_info const *rli) override;
2161 #endif
2162 };
2163 
2164 #if defined MYSQL_SERVER
2166  public:
2167  Load_query_generator(THD *thd_arg, const sql_exchange *ex, const char *db_arg,
2168  const char *table_name_arg, bool is_concurrent_arg,
2169  bool replace, bool ignore);
2170 
2171  const String *generate(size_t *fn_start, size_t *fn_end);
2172 
2173  private:
2174  const size_t BUF_SIZE = 2048;
2176  char *buf[2048];
2177 
2180  const char *db;
2181  const char *table_name;
2182  const char *fname;
2183 
2187 };
2188 #endif
2189 #ifndef MYSQL_SERVER
2190 /**
2191  @class Unknown_log_event
2192 
2193 */
2194 class Unknown_log_event : public binary_log::Unknown_event, public Log_event {
2195  public:
2196  /**
2197  Even if this is an unknown event, we still pass description_event to
2198  Log_event's ctor, this way we can extract maximum information from the
2199  event's header (the unique ID for example).
2200  */
2201  Unknown_log_event(const char *buf,
2202  const Format_description_event *description_event)
2203  : binary_log::Unknown_event(buf, description_event),
2204  Log_event(header(), footer()) {
2205  DBUG_ENTER(
2206  "Unknown_log_event::Unknown_log_event(const char *, const "
2207  "Format_description_log_event *)");
2208  if (!is_valid()) DBUG_VOID_RETURN;
2209  common_header->set_is_valid(true);
2211  }
2212 
2213  ~Unknown_log_event() override {}
2214  void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
2216 };
2217 #endif
2218 char *str_to_hex(char *to, const char *from, size_t len);
2219 
2220 /**
2221  @class Table_map_log_event
2222 
2223  Table_map_log_event which maps a table definition to a number.
2224 
2225  @internal
2226  The inheritance structure in the current design for the classes is
2227  as follows:
2228 
2229  Binary_log_event
2230  ^
2231  |
2232  |
2233  Table_map_event Log_event
2234  \ /
2235  \ /
2236  \ /
2237  Table_map_log_event
2238  @endinternal
2239 */
2241  public Log_event {
2242  public:
2243  /** Constants */
2245 
2246  /**
2247  Enumeration of the errors that can be returned.
2248  */
2249  enum enum_error {
2250  ERR_OPEN_FAILURE = -1, /**< Failure to open table */
2251  ERR_OK = 0, /**< No error */
2252  ERR_TABLE_LIMIT_EXCEEDED = 1, /**< No more room for tables */
2253  ERR_OUT_OF_MEM = 2, /**< Out of memory */
2254  ERR_BAD_TABLE_DEF = 3, /**< Table definition does not match */
2255  ERR_RBR_TO_SBR = 4 /**< daisy-chanining RBR to SBR not allowed */
2256  };
2257 
2258  enum enum_flag {
2259  /**
2260  Nothing here right now, but the flags support is there in
2261  preparation for changes that are coming. Need to add a
2262  constant to make it compile under HP-UX: aCC does not like
2263  empty enumerations.
2264  */
2266  };
2267 
2268  /** Special constants representing sets of flags */
2269  enum {
2273  };
2274 
2276 
2277 #ifdef MYSQL_SERVER
2278  Table_map_log_event(THD *thd_arg, TABLE *tbl, const Table_id &tid,
2279  bool is_transactional);
2280 #endif
2281  Table_map_log_event(const char *buf,
2282  const Format_description_event *description_event);
2283 
2284  ~Table_map_log_event() override;
2285 
2286 #ifndef MYSQL_SERVER
2287  table_def *create_table_def() {
2288  DBUG_ASSERT(m_colcnt > 0);
2291  }
2292  static bool rewrite_db_in_buffer(char **buf, ulong *event_len,
2293  const Format_description_event &fde);
2294 #endif
2295  const Table_id &get_table_id() const { return m_table_id; }
2296  const char *get_table_name() const { return m_tblnam.c_str(); }
2297  const char *get_db_name() const { return m_dbnam.c_str(); }
2298 
2299  virtual size_t get_data_size() override { return m_data_size; }
2300 #ifdef MYSQL_SERVER
2301  virtual int save_field_metadata();
2302  virtual bool write_data_header(Basic_ostream *ostream) override;
2303  virtual bool write_data_body(Basic_ostream *ostream) override;
2304  virtual const char *get_db() override { return m_dbnam.c_str(); }
2305  virtual uint8 mts_number_dbs() override {
2307  }
2308  /**
2309  @param[out] arg pointer to a struct containing char* array
2310  pointers be filled in and the number of filled instances.
2311  @param rpl_filter pointer to a replication filter.
2312 
2313  @return number of databases in the array: either one or
2314  OVER_MAX_DBS_IN_EVENT_MTS, when the Table map event reports
2315  foreign keys constraint.
2316  */
2318  Rpl_filter *rpl_filter) override {
2319  const char *db_name = get_db();
2320 
2322  size_t dummy_len;
2323  const char *db_filtered = rpl_filter->get_rewrite_db(db_name, &dummy_len);
2324  // db_name != db_filtered means that db_name is rewritten.
2325  if (strcmp(db_name, db_filtered)) db_name = db_filtered;
2326  }
2327 
2328  if (!get_flags(TM_REFERRED_FK_DB_F)) arg->name[0] = db_name;
2329 
2330  return arg->num = mts_number_dbs();
2331  }
2332 
2333 #endif
2334 
2335 #if defined(MYSQL_SERVER)
2336  virtual int pack_info(Protocol *protocol) override;
2337 #endif
2338 
2339 #ifndef MYSQL_SERVER
2340  virtual void print(FILE *file,
2341  PRINT_EVENT_INFO *print_event_info) const override;
2342 
2343  /**
2344  Print column metadata. Its format looks like:
2345  # Columns(colume_name type, colume_name type, ...)
2346  if colume_name field is not logged into table_map_log_event, then
2347  only type is printed.
2348 
2349  @@param[out] file the place where colume metadata is printed
2350  @@param[in] The metadata extracted from optional metadata fields
2351  */
2352  void print_columns(IO_CACHE *file,
2353  const Optional_metadata_fields &fields) const;
2354  /**
2355  Print primary information. Its format looks like:
2356  # Primary Key(colume_name, column_name(prifix), ...)
2357  if colume_name field is not logged into table_map_log_event, then
2358  colume index is printed.
2359 
2360  @@param[out] file the place where primary key is printed
2361  @@param[in] The metadata extracted from optional metadata fields
2362  */
2363  void print_primary_key(IO_CACHE *file,
2364  const Optional_metadata_fields &fields) const;
2365 #endif
2366 
2367  bool is_rbr_logging_format() const override { return true; }
2368 
2369  private:
2370 #if defined(MYSQL_SERVER)
2371  virtual int do_apply_event(Relay_log_info const *rli) override;
2372  virtual int do_update_pos(Relay_log_info *rli) override;
2373  virtual enum_skip_reason do_shall_skip(Relay_log_info *rli) override;
2374 #endif
2375 
2376 #ifdef MYSQL_SERVER
2378 
2379  // Metadata fields buffer
2381 
2382  /**
2383  Capture the optional metadata fields which should be logged into
2384  table_map_log_event and serialize them into m_metadata_buf.
2385  */
2386  void init_metadata_fields();
2387  bool init_signedness_field();
2388  /**
2389  Capture and serialize character sets. Character sets for
2390  character columns (TEXT etc) and character sets for ENUM and SET
2391  columns are stored in different metadata fields. The reason is
2392  that TEXT character sets are included even when
2393  binlog_row_metadata=MINIMAL, whereas ENUM and SET character sets
2394  are included only when binlog_row_metadata=FULL.
2395 
2396  @param include_type Predicate to determine if a given Field object
2397  is to be included in the metadata field.
2398 
2399  @param default_charset_type Type code when storing in "default
2400  charset" format. (See comment above Table_maps_log_event in
2401  libbinlogevents/include/rows_event.h)
2402 
2403  @param column_charset_type Type code when storing in "column
2404  charset" format. (See comment above Table_maps_log_event in
2405  libbinlogevents/include/rows_event.h)
2406  */
2407  bool init_charset_field(std::function<bool(const Field *)> include_type,
2408  Optional_metadata_field_type default_charset_type,
2409  Optional_metadata_field_type column_charset_type);
2410  bool init_column_name_field();
2411  bool init_set_str_value_field();
2413  bool init_geometry_type_field();
2414  bool init_primary_key_field();
2415 #endif
2416 
2417 #ifndef MYSQL_SERVER
2418  class Charset_iterator;
2419  class Default_charset_iterator;
2420  class Column_charset_iterator;
2421 #endif
2422 };
2423 
2424 #ifdef HAVE_PSI_STAGE_INTERFACE
2425 /*
2426  Helper class for PSI context while applying a Rows_log_event.
2427  */
2429  private:
2432 
2433  /**
2434  A cached pointer to this stage PSI_stage_progress.
2435  */
2437 
2438  /**
2439  Counter that is unconditionally incremented on each row that is processed.
2440  This is helpful in case estimation is needed after started processing
2441  a Rows_log_event.
2442  */
2444 
2445  public:
2447 
2448  void set_progress(PSI_stage_progress *progress) { m_progress = progress; }
2449 
2450  /**
2451  If instrumentation is enabled this member function SHALL return true.
2452  @return true if instrumentation is enabled for the given stage, false
2453  otherwise.
2454  */
2455  bool is_enabled() { return m_progress != NULL; }
2456 
2457  /**
2458  This member function shall update the progress and reestimate the remaining
2459  work needed. This MUST be called after setting n_rows_applied correctly
2460  by calling inc_n_rows_applied beforehand.
2461 
2462  Cursor, begin and end are used in case estimation is needed.
2463 
2464  @param cursor Pointer to where we are in the buffer of rows to be processed.
2465  @param begin Pointer to the beginning of the rows buffer.
2466  @param end Pointer to the end of the rows buffer.
2467  */
2469  const uchar *begin,
2470  const uchar *end) {
2471  if (!is_enabled()) return;
2472 
2474 
2475  /* Estimate if need be. */
2476  if (estimated == 0) {
2477  DBUG_ASSERT(cursor > begin);
2478  ulonglong avg_row_change_size = (cursor - begin) / m_n_rows_applied;
2479  estimated = (end - begin) / avg_row_change_size;
2481  }
2482 
2483  /* reset estimated if done more work than estimated */
2484  if (m_n_rows_applied > estimated)
2487  }
2488 
2489  /**
2490  Resets this object.
2491  */
2492  void end_work() {
2493  m_progress = NULL;
2494  m_n_rows_applied = 0;
2495  }
2496 
2497  /**
2498  Updates the counter of processed rows.
2499  @param delta the amount of increment to be done.
2500  */
2502 
2503  /**
2504  Gets the value of the counter of rows that have been processed.
2505  @return the value of the counter of rows processed so far.
2506  */
2508 };
2509 #endif
2510 
2511 /**
2512  @class Rows_log_event
2513 
2514  Common base class for all row-containing log events.
2515 
2516  RESPONSIBILITIES
2517 
2518  Encode the common parts of all events containing rows, which are:
2519  - Write data header and data body to an IO_CACHE.
2520 
2521  Virtual inheritance is required here to handle the diamond problem in
2522  the class Write_rows_log_event, Update_rows_log_event and
2523  Delete_rows_log_event.
2524  The diamond structure is explained in @c Write_rows_log_event,
2525  @c Update_rows_log_event,
2526  @c Delete_rows_log_event
2527 
2528  @internal
2529  The inheritance structure in the current design for the classes is
2530  as follows:
2531 
2532  Binary_log_event
2533  ^
2534  |
2535  |
2536  Rows_event Log_event
2537  \ /
2538  <<vir>>\ /
2539  \ /
2540  Rows_log_event
2541  @endinternal
2542 
2543 */
2544 class Rows_log_event : public virtual binary_log::Rows_event, public Log_event {
2545 #ifdef HAVE_PSI_STAGE_INTERFACE
2546  protected:
2548 #endif
2549 
2550  public:
2551  typedef uint16 flag_set;
2552 
2559  };
2560 
2561  /**
2562  Enumeration of the errors that can be returned.
2563  */
2564  enum enum_error {
2565  ERR_OPEN_FAILURE = -1, /**< Failure to open table */
2566  ERR_OK = 0, /**< No error */
2567  ERR_TABLE_LIMIT_EXCEEDED = 1, /**< No more room for tables */
2568  ERR_OUT_OF_MEM = 2, /**< Out of memory */
2569  ERR_BAD_TABLE_DEF = 3, /**< Table definition does not match */
2570  ERR_RBR_TO_SBR = 4 /**< daisy-chanining RBR to SBR not allowed */
2571  };
2572 
2573  /* Special constants representing sets of flags */
2574  enum { RLE_NO_FLAGS = 0U };
2575 
2576  ~Rows_log_event() override;
2577 
2578  void set_flags(flag_set flags_arg) { m_flags |= flags_arg; }
2579  void clear_flags(flag_set flags_arg) { m_flags &= ~flags_arg; }
2580  flag_set get_flags(flag_set flags_arg) const { return m_flags & flags_arg; }
2581 
2582  virtual Log_event_type
2583  get_general_type_code() = 0; /* General rows op type, no version */
2584 
2585 #if defined(MYSQL_SERVER)
2586  virtual int pack_info(Protocol *protocol) override;
2587 #endif
2588 
2589 #ifndef MYSQL_SERVER
2590  void print_verbose(IO_CACHE *file, PRINT_EVENT_INFO *print_event_info);
2591  size_t print_verbose_one_row(IO_CACHE *file, table_def *td,
2592  PRINT_EVENT_INFO *print_event_info,
2593  MY_BITMAP *cols_bitmap, const uchar *ptr,
2594  const uchar *prefix,
2595  enum_row_image_type row_image_type);
2596 #endif
2597 
2598 #ifdef MYSQL_SERVER
2599  int add_row_data(uchar *data, size_t length) {
2600  return do_add_row_data(data, length);
2601  }
2602 #endif
2603 
2604  /* Member functions to implement superclass interface */
2605  virtual size_t get_data_size() override;
2606 
2607  MY_BITMAP const *get_cols() const { return &m_cols; }
2608  MY_BITMAP const *get_cols_ai() const { return &m_cols_ai; }
2609  size_t get_width() const { return m_width; }
2610  const Table_id &get_table_id() const { return m_table_id; }
2611 
2612 #if defined(MYSQL_SERVER)
2613  /**
2614  Compares the table's read/write_set with the columns included in
2615  this event's before-image and/or after-image. Each subclass
2616  (Write/Update/Delete) implements this function by comparing on the
2617  image(s) pertinent to the subclass.
2618 
2619  @param[in] table The table to compare this events bitmaps
2620  against.
2621 
2622  @retval true if sets match
2623  @retval false otherwise (following bitmap_cmp return logic).
2624  */
2625  virtual bool read_write_bitmaps_cmp(const TABLE *table) const = 0;
2626 #endif
2627 
2628 #ifdef MYSQL_SERVER
2629  virtual bool write_data_header(Basic_ostream *ostream) override;
2630  virtual bool write_data_body(Basic_ostream *ostream) override;
2631  virtual const char *get_db() override { return m_table->s->db.str; }
2632 #endif
2633 
2634  uint m_row_count; /* The number of rows added to the event */
2635 
2636  protected:
2637  /*
2638  The constructors are protected since you're supposed to inherit
2639  this class, not create instances of this class.
2640  */
2641 #ifdef MYSQL_SERVER
2642  Rows_log_event(THD *, TABLE *, const Table_id &table_id,
2643  MY_BITMAP const *cols, bool is_transactional,
2645  const unsigned char *extra_row_ndb_info);
2646 #endif
2647  Rows_log_event(const char *row_data,
2648  const Format_description_event *description_event);
2649 
2650 #ifndef MYSQL_SERVER
2651  void print_helper(FILE *, PRINT_EVENT_INFO *) const;
2652 #endif
2653 
2654 #ifdef MYSQL_SERVER
2655  virtual int do_add_row_data(uchar *data, size_t length);
2656 #endif
2657 
2658 #ifdef MYSQL_SERVER
2659  TABLE *m_table; /* The table the rows belong to */
2660 #endif
2661  MY_BITMAP m_cols; /* Bitmap denoting columns available */
2662 #ifdef MYSQL_SERVER
2663  /**
2664  Hash table that will hold the entries for while using HASH_SCAN
2665  algorithm to search and update/delete rows.
2666  */
2668 
2669  /**
2670  The algorithm to use while searching for rows using the before
2671  image.
2672  */
2674 #endif
2675  /*
2676  Bitmap for columns available in the after image, if present. These
2677  fields are only available for Update_rows events. Observe that the
2678  width of both the before image COLS vector and the after image
2679  COLS vector is the same: the number of columns of the table on the
2680  master.
2681  */
2683 
2684  /* Bit buffers in the same memory as the class */
2685  uint32 m_bitbuf[128 / (sizeof(uint32) * 8)];
2686  uint32 m_bitbuf_ai[128 / (sizeof(uint32) * 8)];
2687 
2688  /*
2689  is_valid depends on the value of m_rows_buf, so while changing the value
2690  of m_rows_buf check if is_valid also needs to be modified
2691  */
2692  uchar *m_rows_buf; /* The rows in packed format */
2693  uchar *m_rows_cur; /* One-after the end of the data */
2694  uchar *m_rows_end; /* One-after the end of the allocated space */
2695 
2696  /* helper functions */
2697 
2698 #if defined(MYSQL_SERVER)
2699  const uchar *m_curr_row; /* Start of the row being processed */
2700  const uchar *m_curr_row_end; /* One-after the end of the current row */
2701  uchar *m_key; /* Buffer to keep key value during searches */
2703  KEY *m_key_info; /* Points to description of index #m_key_index */
2704  class Key_compare {
2705  public:
2706  /**
2707  @param ki Where to find KEY description
2708  @note m_distinct_keys is instantiated when Rows_log_event is constructed;
2709  it stores a Key_compare object internally. However at that moment, the
2710  index (KEY*) to use for comparisons, is not yet known. So, at
2711  instantiation, we indicate the Key_compare the place where it can
2712  find the KEY* when needed (this place is Rows_log_event::m_key_info),
2713  Key_compare remembers the place in member m_key_info.
2714  Before we need to do comparisons - i.e. before we need to insert
2715  elements, we update Rows_log_event::m_key_info once for all.
2716  */
2717  Key_compare(KEY **ki = NULL) : m_key_info(ki) {}
2718  bool operator()(uchar *k1, uchar *k2) const {
2719  return key_cmp2((*m_key_info)->key_part, k1, (*m_key_info)->key_length,
2720  k2, (*m_key_info)->key_length) < 0;
2721  }
2722 
2723  private:
2725  };
2726  std::set<uchar *, Key_compare> m_distinct_keys;
2727  std::set<uchar *, Key_compare>::iterator m_itr;
2728  /**
2729  A spare buffer which will be used when saving the distinct keys
2730  for doing an index scan with HASH_SCAN search algorithm.
2731  */
2733 
2734  /**
2735  Unpack the current row image from the event into m_table->record[0].
2736 
2737  @param rli The applier context.
2738 
2739  @param cols The bitmap of columns included in the update.
2740 
2741  @param is_after_image Should be true if this is an after-image,
2742  false if it is a before-image.
2743 
2744  @param only_seek @see unpack_row()
2745 
2746  @retval 0 Success
2747 
2748  @retval ER_* On error, it is guaranteed that the error has been
2749  reported through my_error, and the corresponding ER_* code is
2750  returned. Currently the error codes are: EE_OUTOFMEMORY,
2751  ER_SLAVE_CORRUPT_EVENT, or various JSON errors when applying JSON
2752  diffs (ER_COULD_NOT_APPLY_JSON_DIFF, ER_INVALID_JSON_BINARY_DATA,
2753  and maybe others).
2754  */
2755  int unpack_current_row(const Relay_log_info *const rli, MY_BITMAP const *cols,
2756  bool is_after_image, bool only_seek = false);
2757 
2758  /*
2759  This member function is called when deciding the algorithm to be used to
2760  find the rows to be updated on the slave during row based replication.
2761  This this functions sets the m_rows_lookup_algorithm and also the
2762  m_key_index with the key index to be used if the algorithm is dependent on
2763  an index.
2764  */
2766 
2767  /*
2768  Encapsulates the operations to be done before applying
2769  row event for update and delete.
2770  */
2772 
2773  /*
2774  Encapsulates the operations to be done after applying
2775  row event for update and delete.
2776  */
2778 
2779  /**
2780  Helper function to check whether there is an auto increment
2781  column on the table where the event is to be applied.
2782 
2783  @return true if there is an autoincrement field on the extra
2784  columns, false otherwise.
2785  */
2787 #endif
2788 
2789  bool is_rbr_logging_format() const override { return true; }
2790 
2791  private:
2792 #if defined(MYSQL_SERVER)
2793  virtual int do_apply_event(Relay_log_info const *rli) override;
2794  virtual int do_update_pos(Relay_log_info *rli) override;
2795  virtual enum_skip_reason do_shall_skip(Relay_log_info *rli) override;
2796 
2797  /*
2798  Primitive to prepare for a sequence of row executions.
2799 
2800  DESCRIPTION
2801 
2802  Before doing a sequence of do_prepare_row() and do_exec_row()
2803  calls, this member function should be called to prepare for the
2804  entire sequence. Typically, this member function will allocate
2805  space for any buffers that are needed for the two member
2806  functions mentioned above.
2807 
2808  RETURN VALUE
2809 
2810  The member function will return 0 if all went OK, or a non-zero
2811  error code otherwise.
2812  */
2813  virtual int do_before_row_operations(
2814  const Slave_reporting_capability *const log) = 0;
2815 
2816  /*
2817  Primitive to clean up after a sequence of row executions.
2818 
2819  DESCRIPTION
2820 
2821  After doing a sequence of do_prepare_row() and do_exec_row(),
2822  this member function should be called to clean up and release
2823  any allocated buffers.
2824 
2825  The error argument, if non-zero, indicates an error which happened during
2826  row processing before this function was called. In this case, even if
2827  function is successful, it should return the error code given in the
2828  argument.
2829  */
2830  virtual int do_after_row_operations(
2831  const Slave_reporting_capability *const log, int error) = 0;
2832 
2833  /*
2834  Primitive to do the actual execution necessary for a row.
2835 
2836  DESCRIPTION
2837  The member function will do the actual execution needed to handle a row.
2838  The row is located at m_curr_row. When the function returns,
2839  m_curr_row_end should point at the next row (one byte after the end
2840  of the current row).
2841 
2842  RETURN VALUE
2843  0 if execution succeeded, 1 if execution failed.
2844 
2845  */
2846  virtual int do_exec_row(const Relay_log_info *const rli) = 0;
2847 
2848  /**
2849  Private member function called while handling idempotent errors.
2850 
2851  @param rli Pointer to relay log info structure.
2852  @param [in,out] err the error to handle. If it is listed as
2853  idempotent/ignored related error, then it is cleared.
2854  @returns true if the slave should stop executing rows.
2855  */
2857 
2858  /**
2859  Private member function called after updating/deleting a row. It
2860  performs some assertions and more importantly, it updates
2861  m_curr_row so that the next row is processed during the row
2862  execution main loop (@c Rows_log_event::do_apply_event()).
2863 
2864  @param rli Pointer to relay log info structure.
2865  @param err the current error code.
2866  */
2867  void do_post_row_operations(Relay_log_info const *rli, int err);
2868 
2869  /**
2870  Commodity wrapper around do_exec_row(), that deals with resetting
2871  the thd reference in the table.
2872  */
2873  int do_apply_row(Relay_log_info const *rli);
2874 
2875  /**
2876  Implementation of the index scan and update algorithm. It uses
2877  PK, UK or regular Key to search for the record to update. When
2878  found it updates it.
2879  */
2880  int do_index_scan_and_update(Relay_log_info const *rli);
2881 
2882  /**
2883  Implementation of the hash_scan and update algorithm. It collects
2884  rows positions in a hashtable until the last row is
2885  unpacked. Then it scans the table to update and when a record in
2886  the table matches the one in the hashtable, the update/delete is
2887  performed.
2888  */
2889  int do_hash_scan_and_update(Relay_log_info const *rli);
2890 
2891  /**
2892  Implementation of the legacy table_scan and update algorithm. For
2893  each unpacked row it scans the storage engine table for a
2894  match. When a match is found, the update/delete operations are
2895  performed.
2896  */
2897  int do_table_scan_and_update(Relay_log_info const *rli);
2898 
2899  /**
2900  Seek past the after-image of an update event, in case a row was processed
2901  without reading the after-image.
2902 
2903  An update event may process a row without reading the after-image,
2904  e.g. in case of ignored or idempotent errors. To ensure that the
2905  read position for the next row is correct, we need to seek past
2906  the after-image.
2907 
2908  @param rli The applier context
2909 
2910  @param curr_bi_start The read position of the beginning of the
2911  before-image. (The function compares this with m_curr_row to know
2912  if the after-image has been read or not.)
2913 
2914  @retval 0 Success
2915  @retval ER_* Error code returned by unpack_current_row
2916  */
2918  const Relay_log_info *rli MY_ATTRIBUTE((unused)),
2919  const uchar *curr_bi_start MY_ATTRIBUTE((unused))) {
2920  return 0;
2921  }
2922 
2923  /**
2924  Initializes scanning of rows. Opens an index and initailizes an iterator
2925  over a list of distinct keys (m_distinct_keys) if it is a HASH_SCAN
2926  over an index or the table if its a HASH_SCAN over the table.
2927  */
2928  int open_record_scan();
2929 
2930  /**
2931  Does the cleanup
2932  - closes the index if opened by open_record_scan
2933  - closes the table if opened for scanning.
2934  */
2935  int close_record_scan();
2936 
2937  /**
2938  Fetches next row. If it is a HASH_SCAN over an index, it populates
2939  table->record[0] with the next row corresponding to the index. If
2940  the indexes are in non-contigous ranges it fetches record corresponding
2941  to the key value in the next range.
2942 
2943  @param first_read signifying if this is the first time we are reading a row
2944  over an index.
2945  @return error code when there are no more records to be fetched or some
2946  other error occurred,
2947  - 0 otherwise.
2948  */
2949  int next_record_scan(bool first_read);
2950 
2951  /**
2952  Populates the m_distinct_keys with unique keys to be modified
2953  during HASH_SCAN over keys.
2954  @returns 0 success, or the error code.
2955  */
2957 
2958  /**
2959  Populates the m_hash when using HASH_SCAN. Thence, it:
2960  - unpacks the before image (BI)
2961  - saves the positions
2962  - saves the positions into the hash map, using the
2963  BI checksum as key
2964  - unpacks the after image (AI) if needed, so that
2965  m_curr_row_end gets updated correctly.
2966 
2967  @param rli The reference to the relay log info object.
2968  @returns 0 on success. Otherwise, the error code.
2969  */
2970  int do_hash_row(Relay_log_info const *rli);
2971 
2972  /**
2973  This member function scans the table and applies the changes
2974  that had been previously hashed. As such, m_hash MUST be filled
2975  by do_hash_row before calling this member function.
2976 
2977  @param rli The reference to the relay log info object.
2978  @returns 0 on success. Otherwise, the error code.
2979  */
2980  int do_scan_and_update(Relay_log_info const *rli);
2981 #endif /* defined(MYSQL_SERVER) */
2982 
2983  friend class Old_rows_log_event;
2984 
2985  /**
2986  This bitmap is used as a backup for the write set while we calculate
2987  the values for any hidden generated columns (functional indexes). In order
2988  to calculate the values, the columns must be marked in the write set. After
2989  the values are caluclated, we set the write set back to it's original value.
2990  */
2992 };
2993 
2994 /**
2995  @class Write_rows_log_event
2996 
2997  Log row insertions and updates. The event contain several
2998  insert/update rows for a table. Note that each event contains only
2999  rows for one table.
3000 
3001  @internal
3002  The inheritance structure is as follows
3003 
3004  Binary_log_event
3005  ^
3006  |
3007  |
3008  |
3009  Log_event B_l:Rows_event
3010  ^ /\
3011  | / \
3012  | <<vir>>/ \ <<vir>>
3013  | / \
3014  | / \
3015  | / \
3016  Rows_log_event B_l:W_R_E
3017  \ /
3018  \ /
3019  \ /
3020  \ /
3021  \ /
3022  \/
3023  Write_rows_log_event
3024 
3025  B_l: Namespace Binary_log
3026  W_R_E: class Write_rows_event
3027  @endinternal
3028 
3029 */
3032  public:
3033  enum {
3034  /* Support interface to THD::binlog_prepare_pending_rows_event */
3036  };
3037 
3038 #if defined(MYSQL_SERVER)
3039  Write_rows_log_event(THD *, TABLE *, const Table_id &table_id,
3040  bool is_transactional,
3041  const unsigned char *extra_row_ndb_info);
3042 #endif
3043  Write_rows_log_event(const char *buf,
3044  const Format_description_event *description_event);
3045 #if defined(MYSQL_SERVER)
3046  static bool binlog_row_logging_function(
3047  THD *thd, TABLE *table, bool is_transactional,
3048  const uchar *before_record MY_ATTRIBUTE((unused)),
3049  const uchar *after_record);
3050  bool read_write_bitmaps_cmp(const TABLE *table) const override {
3051  return bitmap_cmp(get_cols(), table->write_set);
3052  }
3053 #endif
3054 
3055  protected:
3056  int write_row(const Relay_log_info *const, const bool);
3057 
3058  private:
3060  return (Log_event_type)TYPE_CODE;
3061  }
3062 
3063 #ifndef MYSQL_SERVER
3064  void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
3065 #endif
3066 
3067 #if defined(MYSQL_SERVER)
3068  virtual int do_before_row_operations(
3069  const Slave_reporting_capability *const) override;
3070  virtual int do_after_row_operations(const Slave_reporting_capability *const,
3071  int) override;
3072  virtual int do_exec_row(const Relay_log_info *const) override;
3073 #endif
3074 };
3075 
3076 /**
3077  @class Update_rows_log_event
3078 
3079  Log row updates with a before image. The event contain several
3080  update rows for a table. Note that each event contains only rows for
3081  one table.
3082 
3083  Also note that the row data consists of pairs of row data: one row
3084  for the old data and one row for the new data.
3085 
3086  @internal
3087  The inheritance structure is as follows
3088 
3089  Binary_log_event
3090  ^
3091  |
3092  |
3093  |
3094  Log_event B_l:Rows_event
3095  ^ /\
3096  | / \
3097  | <<vir>>/ \ <<vir>>
3098  | / \
3099  | / \
3100  | / \
3101  Rows_log_event B_l:U_R_E
3102  \ /
3103  \ /
3104  \ /
3105  \ /
3106  \ /
3107  \/
3108  Update_rows_log_event
3109 
3110 
3111  B_l: Namespace Binary_log
3112  U_R_E: class Update_rows_event
3113  @eninternal
3114 
3115 */
3118  public:
3119  enum {
3120  /* Support interface to THD::binlog_prepare_pending_rows_event */
3122  };
3123 
3124 #ifdef MYSQL_SERVER
3125  Update_rows_log_event(THD *, TABLE *, const Table_id &table_id,
3126  MY_BITMAP const *cols_bi, MY_BITMAP const *cols_ai,
3127  bool is_transactional,
3128  const unsigned char *extra_row_ndb_info);
3129 
3130  Update_rows_log_event(THD *, TABLE *, const Table_id &table_id,
3131  bool is_transactional,
3132  const unsigned char *extra_row_ndb_info);
3133 
3134  void init(MY_BITMAP const *cols, const MY_BITMAP &cols_to_subtract);
3135 #endif
3136 
3137  ~Update_rows_log_event() override;
3138 
3139  Update_rows_log_event(const char *buf,
3140  const Format_description_event *description_event);
3141 
3142 #ifdef MYSQL_SERVER
3143  static bool binlog_row_logging_function(THD *thd, TABLE *table,
3144  bool is_transactional,
3145  const uchar *before_record,
3146  const uchar *after_record);
3147  bool read_write_bitmaps_cmp(const TABLE *table) const override {
3148  return (bitmap_cmp(get_cols(), table->read_set) &&
3149  bitmap_cmp(get_cols_ai(), table->write_set));
3150  }
3151 #endif
3152 
3153  protected:
3155  return (Log_event_type)TYPE_CODE;
3156  }
3157 
3158 #ifndef MYSQL_SERVER
3159  void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
3160 #endif
3161 
3162 #if defined(MYSQL_SERVER)
3163  virtual int do_before_row_operations(
3164  const Slave_reporting_capability *const) override;
3165  virtual int do_after_row_operations(const Slave_reporting_capability *const,
3166  int) override;
3167  virtual int do_exec_row(const Relay_log_info *const) override;
3168 
3170  const Relay_log_info *rli, const uchar *curr_bi_start) override;
3171 
3172  private:
3173  /**
3174  Auxiliary function used in the (THD*, ...) constructor to
3175  determine the type code based on configuration options.
3176 
3177  @param thd_arg The THD object for the session.
3178 
3179  @return One of UPDATE_ROWS_EVENT_V1, PARTIAL_UPDATE_ROWS_EVENT, or
3180  UPDATE_ROWS_EVENT.
3181  */
3183  const THD *thd_arg);
3184 #endif /* defined(MYSQL_SERVER) */
3185 };
3186 
3187 /**
3188  @class Delete_rows_log_event
3189 
3190  Log row deletions. The event contain several delete rows for a
3191  table. Note that each event contains only rows for one table.
3192 
3193  RESPONSIBILITIES
3194 
3195  - Act as a container for rows that has been deleted on the master
3196  and should be deleted on the slave.
3197 
3198  COLLABORATION
3199 
3200  Row_writer
3201  Create the event and add rows to the event.
3202  Row_reader
3203  Extract the rows from the event.
3204 
3205  @internal
3206  The inheritance structure is as follows
3207 
3208  Binary_log_event
3209  ^
3210  |
3211  |
3212  |
3213  Log_event B_l:Rows_event
3214  ^ /\
3215  | / \
3216  | <<vir>>/ \ <<vir>>
3217  | / \
3218  | / \
3219  | / \
3220  Rows_log_event B_l:D_R_E
3221  \ /
3222  \ /
3223  \ /
3224  \ /
3225  \ /
3226  \/
3227  Delete_rows_log_event
3228 
3229  B_l: Namespace Binary_log
3230  D_R_E: class Delete_rows_event
3231  @endinternal
3232 
3233 */
3236  public:
3237  enum {
3238  /* Support interface to THD::binlog_prepare_pending_rows_event */
3240  };
3241 
3242 #ifdef MYSQL_SERVER
3243  Delete_rows_log_event(THD *, TABLE *, const Table_id &, bool is_transactional,
3244  const unsigned char *extra_row_ndb_info);
3245 #endif
3246  Delete_rows_log_event(const char *buf,
3247  const Format_description_event *description_event);
3248 #ifdef MYSQL_SERVER
3249  static bool binlog_row_logging_function(
3250  THD *thd, TABLE *table, bool is_transactional, const uchar *before_record,
3251  const uchar *after_record MY_ATTRIBUTE((unused)));
3252  bool read_write_bitmaps_cmp(const TABLE *table) const override {
3253  return bitmap_cmp(get_cols(), table->read_set);
3254  }
3255 #endif
3256 
3257  protected:
3259  return (Log_event_type)TYPE_CODE;
3260  }
3261 
3262 #ifndef MYSQL_SERVER
3263  void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
3264 #endif
3265 
3266 #if defined(MYSQL_SERVER)
3267  virtual int do_before_row_operations(
3268  const Slave_reporting_capability *const) override;
3269  virtual int do_after_row_operations(const Slave_reporting_capability *const,
3270  int) override;
3271  virtual int do_exec_row(const Relay_log_info *const) override;
3272 #endif
3273 };
3274 
3275 /**
3276  @class Incident_log_event
3277 
3278  Class representing an incident, an occurance out of the ordinary,
3279  that happened on the master.
3280 
3281  The event is used to inform the slave that something out of the
3282  ordinary happened on the master that might cause the database to be
3283  in an inconsistent state.
3284  Its the derived class of Incident_event
3285 
3286  @internal
3287  The inheritance structure is as follows
3288 
3289  Binary_log_event
3290  ^
3291  |
3292  |
3293  B_l:Incident_event Log_event
3294  \ /
3295  \ /
3296  \ /
3297  \ /
3298  Incident_log_event
3299 
3300  B_l: Namespace Binary_log
3301  @endinternal
3302 
3303 */
3305  public:
3306 #ifdef MYSQL_SERVER
3307  Incident_log_event(THD *thd_arg, enum_incident incident_arg)
3308  : binary_log::Incident_event(incident_arg),
3311  DBUG_ENTER("Incident_log_event::Incident_log_event");
3312  DBUG_PRINT("enter", ("incident: %d", incident_arg));
3313  common_header->set_is_valid(incident_arg > INCIDENT_NONE &&
3314  incident_arg < INCIDENT_COUNT);
3315  DBUG_ASSERT(message == NULL && message_length == 0);
3317  }
3318 
3319  Incident_log_event(THD *thd_arg, enum_incident incident_arg,
3320  LEX_STRING const msg)
3321  : binary_log::Incident_event(incident_arg),
3324  DBUG_ENTER("Incident_log_event::Incident_log_event");
3325  DBUG_PRINT("enter", ("incident: %d", incident_arg));
3326  common_header->set_is_valid(incident_arg > INCIDENT_NONE &&
3327  incident_arg < INCIDENT_COUNT);
3328  DBUG_ASSERT(message == NULL && message_length == 0);
3330  msg.length + 1, MYF(MY_WME)))) {
3331  // The allocation failed. Mark this binlog event as invalid.
3332  common_header->set_is_valid(false);
3334  }
3335  strmake(message, msg.str, msg.length);
3336  message_length = msg.length;
3338  }
3339 #endif
3340 
3341 #ifdef MYSQL_SERVER
3342  int pack_info(Protocol *) override;
3343 #endif
3344 
3345  Incident_log_event(const char *buf,
3346  const Format_description_event *description_event);
3347 
3348  ~Incident_log_event() override;
3349 
3350 #ifndef MYSQL_SERVER
3351  virtual void print(FILE *file,
3352  PRINT_EVENT_INFO *print_event_info) const override;
3353 #endif
3354 
3355 #if defined(MYSQL_SERVER)
3356  virtual int do_apply_event(Relay_log_info const *rli) override;
3357  virtual bool write_data_header(Basic_ostream *ostream) override;
3358  virtual bool write_data_body(Basic_ostream *ostream) override;
3359 #endif
3360 
3361  virtual size_t get_data_size() override {
3362  return Binary_log_event::INCIDENT_HEADER_LEN + 1 + message_length;
3363  }
3364 
3365  virtual bool ends_group() const override { return true; }
3366 
3367  private:
3368  const char *description() const;
3369 };
3370 
3371 /**
3372  @class Ignorable_log_event
3373 
3374  Base class for ignorable log events is Ignorable_event.
3375  Events deriving from this class can be safely ignored
3376  by slaves that cannot recognize them.
3377 
3378  Its the derived class of Ignorable_event
3379 
3380  @internal
3381  The inheritance structure is as follows
3382 
3383  Binary_log_event
3384  ^
3385  |
3386  |
3387  B_l:Ignorable_event Log_event
3388  \ /
3389  <<virtual>>\ /
3390  \ /
3391  Ignorable_log_event
3392 
3393  B_l: Namespace Binary_log
3394  @endinternal
3395 */
3397  public Log_event {
3398  public:
3399 #ifdef MYSQL_SERVER
3403  DBUG_ENTER("Ignorable_log_event::Ignorable_log_event");
3404  common_header->set_is_valid(true);
3406  }
3407 #endif
3408 
3409  Ignorable_log_event(const char *buf,
3410  const Format_description_event *descr_event);
3411  ~Ignorable_log_event() override;
3412 
3413 #ifdef MYSQL_SERVER
3414  int pack_info(Protocol *) override;
3415 #endif
3416 
3417 #ifndef MYSQL_SERVER
3418  virtual void print(FILE *file,
3419  PRINT_EVENT_INFO *print_event_info) const override;
3420 #endif
3421 
3422  virtual size_t get_data_size() override {
3423  return Binary_log_event::IGNORABLE_HEADER_LEN;
3424  }
3425 };
3426 
3427 /**
3428  @class Rows_query_log_event
3429  It is used to record the original query for the rows
3430  events in RBR.
3431  It is the subclass of Ignorable_log_event and Rows_query_event
3432 
3433  @internal
3434  The inheritance structure in the current design for the classes is
3435  as follows:
3436  Binary_log_event
3437  ^
3438  |
3439  |
3440  |
3441  Log_event B_l:Ignorable_event
3442  ^ /\
3443  | / \
3444  | <<vir>>/ \ <<vir>>
3445  | / \
3446  | / \
3447  | / \
3448  Ignorable_log_event B_l:Rows_query_event
3449  \ /
3450  \ /
3451  \ /
3452  \ /
3453  \ /
3454  \/
3455  Rows_query_log_event
3456 
3457  B_l : namespace binary_log
3458  @endinternal
3459 */
3462  public:
3463 #ifdef MYSQL_SERVER
3464  Rows_query_log_event(THD *thd_arg, const char *query, size_t query_len)
3465  : Ignorable_log_event(thd_arg) {
3466  DBUG_ENTER("Rows_query_log_event::Rows_query_log_event");
3468  if (!(m_rows_query =
3470  query_len + 1, MYF(MY_WME))))
3471  return;
3472  snprintf(m_rows_query, query_len + 1, "%s", query);
3473  DBUG_PRINT("enter", ("%s", m_rows_query));
3475  }
3476 #endif
3477 
3478 #ifdef MYSQL_SERVER
3479  int pack_info(Protocol *) override;
3480  virtual int do_apply_event(Relay_log_info const *rli) override;
3481  virtual bool write_data_body(Basic_ostream *ostream) override;
3482 #endif
3483 
3484  Rows_query_log_event(const char *buf,
3485  const Format_description_event *descr_event);
3486 
3489  m_rows_query = NULL;
3490  }
3491 #ifndef MYSQL_SERVER
3492  virtual void print(FILE *file,
3493  PRINT_EVENT_INFO *print_event_info) const override;
3494 #endif
3495  virtual size_t get_data_size() override {
3496  return Binary_log_event::IGNORABLE_HEADER_LEN + 1 + strlen(m_rows_query);
3497  }
3498 };
3499 
3501  FILE *file,
3502  bool flush_stream) {
3503  return my_b_copy_to_file(cache, file) ||
3504  (flush_stream ? (fflush(file) || ferror(file)) : 0) ||
3505  reinit_io_cache(cache, WRITE_CACHE, 0, false, true);
3506 }
3507 
3508 #ifdef MYSQL_SERVER
3509 /*****************************************************************************
3510 
3511  Heartbeat Log Event class
3512 
3513  The class is not logged to a binary log, and is not applied on to the slave.
3514  The decoding of the event on the slave side is done by its superclass,
3515  binary_log::Heartbeat_event.
3516 
3517  ****************************************************************************/
3519  public Log_event {
3520  public:
3521  Heartbeat_log_event(const char *buf,
3522  const Format_description_event *description_event);
3523 };
3524 
3525 /**
3526  The function is called by slave applier in case there are
3527  active table filtering rules to force gathering events associated
3528  with Query-log-event into an array to execute
3529  them once the fate of the Query is determined for execution.
3530 */
3532 #endif
3533 
3534 int append_query_string(const THD *thd, const CHARSET_INFO *csinfo,
3535  String const *from, String *to);
3537 
3538 /**
3539  @class Gtid_log_event
3540 
3541  This is a subclass if Gtid_event and Log_event. It contains
3542  per-transaction fields, including the GTID and logical timestamps
3543  used by MTS.
3544 
3545  @internal
3546  The inheritance structure is as follows
3547 
3548  Binary_log_event
3549  ^
3550  |
3551  |
3552  B_l:Gtid_event Log_event
3553  \ /
3554  \ /
3555  \ /
3556  \ /
3557  Gtid_log_event
3558 
3559  B_l: Namespace Binary_log
3560  @endinternal
3561 */
3563  public:
3564 #ifdef MYSQL_SERVER
3565  /**
3566  Create a new event using the GTID owned by the given thread.
3567  */
3568  Gtid_log_event(THD *thd_arg, bool using_trans, int64 last_committed_arg,
3569  int64 sequence_number_arg, bool may_have_sbr_stmts_arg,
3570  ulonglong original_commit_timestamp_arg,
3571  ulonglong immediate_commit_timestamp_arg,
3572  uint32_t original_server_version_arg,
3573  uint32_t immediate_server_version_arg);
3574 
3575  /**
3576  Create a new event using the GTID from the given Gtid_specification
3577  without a THD object.
3578  */
3579  Gtid_log_event(uint32 server_id_arg, bool using_trans,
3580  int64 last_committed_arg, int64 sequence_number_arg,
3581  bool may_have_sbr_stmts_arg,
3582  ulonglong original_commit_timestamp_arg,
3583  ulonglong immediate_commit_timestamp_arg,
3584  const Gtid_specification spec_arg,
3585  uint32_t original_server_version_arg,
3586  uint32_t immediate_server_version_arg);
3587 #endif
3588 
3589 #ifdef MYSQL_SERVER
3590  int pack_info(Protocol *) override;
3591 #endif
3592  Gtid_log_event(const char *buffer,
3593  const Format_description_event *description_event);
3594 
3595  ~Gtid_log_event() override {}
3596 
3597  size_t get_data_size() override {
3598  DBUG_EXECUTE_IF("do_not_write_rpl_timestamps", return POST_HEADER_LENGTH;);
3601  }
3602 
3604 
3605  private:
3606  /// Used internally by both print() and pack_info().
3607  size_t to_string(char *buf) const;
3608 
3609 #ifdef MYSQL_SERVER
3610  /**
3611  Writes the post-header to the given output stream.
3612 
3613  This is an auxiliary function typically used by the write() member
3614  function.
3615 
3616  @param ostream The output stream to write to.
3617 
3618  @retval true Error.
3619  @retval false Success.
3620  */
3621  bool write_data_header(Basic_ostream *ostream) override;
3622  bool write_data_body(Basic_ostream *ostream) override;
3623  /**
3624  Writes the post-header to the given memory buffer.
3625 
3626  This is an auxiliary function used by write_to_memory.
3627 
3628  @param[in,out] buffer Buffer to which the post-header will be written.
3629 
3630  @return The number of bytes written, i.e., always
3631  Gtid_log_event::POST_HEADER_LENGTH.
3632  */
3634 
3635  /**
3636  Writes the body to the given memory buffer.
3637 
3638  This is an auxiliary function used by write_to_memory.
3639 
3640  @param [in,out] buff Buffer to which the data will be written.
3641 
3642  @return The number of bytes written, i.e.,
3643  If the transaction did not originated on this server
3644  Gtid_event::IMMEDIATE_COMMIT_TIMESTAMP_LENGTH.
3645  else
3646  FULL_COMMIT_TIMESTAMP_LENGTH.
3647  */
3648  uint32 write_body_to_memory(uchar *buff);
3649 #endif
3650 
3651  public:
3652 #ifndef MYSQL_SERVER
3653  void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
3654 #endif
3655 #ifdef MYSQL_SERVER
3656  /**
3657  Writes this event to a memory buffer.
3658 
3659  @param buf The event will be written to this buffer.
3660 
3661  @return the number of bytes written, i.e., always
3662  LOG_EVENT_HEADER_LEN + Gtid_log_event::POST_HEADEr_LENGTH.
3663  */
3664  uint32 write_to_memory(uchar *buf) {
3666  uint32 len = write_header_to_memory(buf);
3668  len += write_body_to_memory(buf + len);
3669  return len;
3670  }
3671 #endif
3672 
3673 #if defined(MYSQL_SERVER)
3674  int do_apply_event(Relay_log_info const *rli) override;
3675  int do_update_pos(Relay_log_info *rli) override;
3677 #endif
3678 
3679  /**
3680  Return the gtid type for this Gtid_log_event: this can be
3681  either ANONYMOUS_GTID, AUTOMATIC_GTID, or ASSIGNED_GTID.
3682  */
3683  enum_gtid_type get_type() const { return spec.type; }
3684 
3685  /**
3686  Return the SID for this GTID. The SID is shared with the
3687  Log_event so it should not be modified.
3688  */
3689  const rpl_sid *get_sid() const { return &sid; }
3690  /**
3691  Return the SIDNO relative to the global sid_map for this GTID.
3692 
3693  This requires a lookup and possibly even update of global_sid_map,
3694  hence global_sid_lock must be held. If global_sid_lock is not
3695  held, the caller must pass need_lock=true. If there is an error
3696  (e.g. out of memory) while updating global_sid_map, this function
3697  returns a negative number.
3698 
3699  @param need_lock If true, the read lock on global_sid_lock is
3700  acquired and released inside this function; if false, the read
3701  lock or write lock must be held prior to calling this function.
3702  @retval SIDNO if successful
3703  @retval negative if adding SID to global_sid_map causes an error.
3704  */
3705  rpl_sidno get_sidno(bool need_lock);
3706 
3707  /**
3708  Return the SIDNO relative to the given Sid_map for this GTID.
3709 
3710  This assumes that the Sid_map is local to the thread, and thus
3711  does not use locks.
3712 
3713  @param sid_map The sid_map to use.
3714  @retval SIDNO if successful.
3715  @retval negative if adding SID to sid_map causes an error.
3716  */
3717  rpl_sidno get_sidno(Sid_map *sid_map) { return sid_map->add_sid(sid); }
3718  /// Return the GNO for this GTID.
3719  rpl_gno get_gno() const { return spec.gtid.gno; }
3720 
3721  /// string holding the text "SET @@GLOBAL.GTID_NEXT = '"
3722  static const char *SET_STRING_PREFIX;
3723 
3724  private:
3725  /// Length of SET_STRING_PREFIX
3726  static const size_t SET_STRING_PREFIX_LENGTH = 26;
3727  /// The maximal length of the entire "SET ..." query.
3730  1 + MAX_GNO_TEXT_LENGTH + 1;
3731 
3732  private:
3733  /**
3734  Internal representation of the GTID. The SIDNO will be
3735  uninitialized (value -1) until the first call to get_sidno(bool).
3736  */
3738  /// SID for this GTID.
3740 
3741  public:
3742  /**
3743  Set the transaction length information based on binlog cache size.
3744 
3745  Note that is_checksum_enabled and event_counter are optional parameters.
3746  When not specified, the function will assume that no checksum will be used
3747  and the informed cache_size is the final transaction size without
3748  considering the GTID event size.
3749 
3750  The high level formula that will be used by the function is:
3751 
3752  trx_length = cache_size +
3753  cache_checksum_active * cache_events * CRC32_payload +
3754  gtid_length +
3755  cache_checksum_active * CRC32_payload; // For the GTID.
3756 
3757  @param cache_size The size of the binlog cache in bytes.
3758  @param is_checksum_enabled If checksum will be added to events on flush.
3759  @param event_counter The amount of events in the cache.
3760  */
3761  void set_trx_length_by_cache_size(ulonglong cache_size,
3762  bool is_checksum_enabled = false,
3763  int event_counter = 0);
3764 };
3765 
3766 /**
3767  @class Previous_gtids_log_event
3768 
3769  This is the subclass of Previous_gtids_event and Log_event
3770  It is used to record the gtid_executed in the last binary log file,
3771  for ex after flush logs, or at the starting of the binary log file
3772 
3773  @internal
3774  The inheritance structure is as follows
3775 
3776  Binary_log_event
3777  ^
3778  |
3779  |
3780 B_l:Previous_gtids_event Log_event
3781  \ /
3782  \ /
3783  \ /
3784  \ /
3785  Previous_gtids_log_event
3786 
3787  B_l: Namespace Binary_log
3788  @endinternal
3789 */
3791  public Log_event {
3792  public:
3793 #ifdef MYSQL_SERVER
3794  Previous_gtids_log_event(const Gtid_set *set);
3795 #endif
3796 
3797 #ifdef MYSQL_SERVER
3798  int pack_info(Protocol *) override;
3799 #endif
3800 
3801  Previous_gtids_log_event(const char *buf,
3802  const Format_description_event *description_event);
3804 
3805  size_t get_data_size() override { return buf_size; }
3806 
3807 #ifndef MYSQL_SERVER
3808  void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
3809 #endif
3810 #ifdef MYSQL_SERVER
3811  bool write(Basic_ostream *ostream) override {
3812  if (DBUG_EVALUATE_IF("skip_writing_previous_gtids_log_event", 1, 0) &&
3813  /*
3814  The skip_writing_previous_gtids_log_event debug point was designed
3815  for skipping the writing of the previous_gtids_log_event on binlog
3816  files only.
3817  */
3818  !is_relay_log_event()) {
3819  DBUG_PRINT("info",
3820  ("skip writing Previous_gtids_log_event because of"
3821  "debug option 'skip_writing_previous_gtids_log_event'"));
3822  return false;
3823  }
3824 
3825  if (DBUG_EVALUATE_IF("write_partial_previous_gtids_log_event", 1, 0) &&
3826  /*
3827  The write_partial_previous_gtids_log_event debug point was designed
3828  for writing a partial previous_gtids_log_event on binlog files only.
3829  */
3830  !is_relay_log_event()) {
3831  DBUG_PRINT("info",
3832  ("writing partial Previous_gtids_log_event because of"
3833  "debug option 'write_partial_previous_gtids_log_event'"));
3834  return (Log_event::write_header(ostream, get_data_size()) ||
3835  Log_event::write_data_header(ostream));
3836  }
3837 
3838  return (Log_event::write_header(ostream, get_data_size()) ||
3839  Log_event::write_data_header(ostream) || write_data_body(ostream) ||
3840  Log_event::write_footer(ostream));
3841  }
3842  bool write_data_body(Basic_ostream *ostream) override;
3843 #endif
3844 
3845  /// Return the encoded buffer, or NULL on error.
3846  const uchar *get_buf() { return buf; }
3847  /**
3848  Return the formatted string, or NULL on error.
3849  The string is allocated using my_malloc and it is the
3850  responsibility of the caller to free it.
3851  */
3852  char *get_str(size_t *length,
3853  const Gtid_set::String_format *string_format) const;
3854  /// Add all GTIDs from this event to the given Gtid_set.
3855  int add_to_set(Gtid_set *gtid_set) const;
3856  /*
3857  Previous Gtid Log events should always be skipped
3858  there is nothing to apply there, whether it is
3859  relay log's (generated on Slave) or it is binary log's
3860  (generated on Master, copied to slave as relay log).
3861  Also, we should not increment slave_skip_counter
3862  for this event, hence return EVENT_SKIP_IGNORE.
3863  */
3864 #if defined(MYSQL_SERVER)
3866  {
3867  return EVENT_SKIP_IGNORE;
3868  }
3869 
3870  int do_apply_event(Relay_log_info const *) override { return 0; }
3871  int do_update_pos(Relay_log_info *rli) override;
3872 #endif
3873 };
3874 
3875 /**
3876  @class Transaction_context_log_event
3877 
3878  This is the subclass of Transaction_context_event and Log_event
3879  This class encodes the transaction_context_log_event.
3880 
3881  @internal
3882  The inheritance structure is as follows
3883 
3884  Binary_log_event
3885  ^
3886  |
3887  |
3888 B_l:Transaction_context_event Log_event
3889  \ /
3890  \ /
3891  \ /
3892  \ /
3893  Transaction_context_log_event
3894 
3895  B_l: Namespace Binary_log
3896  @endinternal
3897 */
3900  public Log_event {
3901  private:
3902  /// The Sid_map to use for creating the Gtid_set.
3904  /// A gtid_set which is used to store the transaction set used for
3905  /// conflict detection.
3907 
3908 #ifdef MYSQL_SERVER
3909  bool write_data_header(Basic_ostream *ostream) override;
3910 
3911  bool write_data_body(Basic_ostream *ostream) override;
3912 
3913  bool write_snapshot_version(Basic_ostream *ostream);
3914 
3915  bool write_data_set(Basic_ostream *ostream, std::list<const char *> *set);
3916 #endif
3917 
3918  size_t get_snapshot_version_size();
3919 
3920  static int get_data_set_size(std::list<const char *> *set);
3921 
3922  size_t to_string(char *buf, ulong len) const;
3923 
3924  public:
3925 #ifdef MYSQL_SERVER
3926  Transaction_context_log_event(const char *server_uuid_arg, bool using_trans,
3927  my_thread_id thread_id_arg,
3928  bool is_gtid_specified_arg);
3929 #endif
3930 
3932  const Format_description_event *descr_event);
3933 
3934  ~Transaction_context_log_event() override;
3935 
3936  size_t get_data_size() override;
3937 
3938 #ifdef MYSQL_SERVER
3939  int pack_info(Protocol *protocol) override;
3940 #endif
3941 
3942 #ifndef MYSQL_SERVER
3943  void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
3944 #endif
3945 
3946 #if defined(MYSQL_SERVER)
3947  int do_apply_event(Relay_log_info const *) override { return 0; }
3948  int do_update_pos(Relay_log_info *rli) override;
3949 #endif
3950 
3951  /**
3952  Add a hash which identifies a inserted/updated/deleted row on the
3953  ongoing transaction.
3954 
3955  @param[in] hash row identifier
3956  */
3957  void add_write_set(const char *hash);
3958 
3959  /**
3960  Return a pointer to write-set list.
3961  */
3962  std::list<const char *> *get_write_set() { return &write_set; }
3963 
3964  /**
3965  Add a hash which identifies a read row on the ongoing transaction.
3966 
3967  @param[in] hash row identifier
3968  */
3969  void add_read_set(const char *hash);
3970 
3971  /**
3972  Return a pointer to read-set list.
3973  */
3974  std::list<const char *> *get_read_set() { return &read_set; }
3975 
3976  /**
3977  Read snapshot version from encoded buffers.
3978  Cannot be executed during data read from file (event constructor),
3979  since its required locks will collide with the server gtid state
3980  initialization procedure.
3981  */
3982  bool read_snapshot_version();
3983 
3984  /**
3985  Return the transaction snapshot timestamp.
3986  */
3988 
3989  /**
3990  Return the server uuid.
3991  */
3992  const char *get_server_uuid() { return server_uuid; }
3993 
3994  /**
3995  Return the id of the committing thread.
3996  */
3997  my_thread_id get_thread_id() { return static_cast<my_thread_id>(thread_id); }
3998 
3999  /**
4000  Return true if transaction has GTID_NEXT specified, false otherwise.
4001  */
4002  bool is_gtid_specified() { return gtid_specified == true; }
4003 };
4004 
4005 /**
4006  @class View_change_log_event
4007 
4008  This is the subclass of View_change_log_event and Log_event
4009  This class created the view_change_log_event which is used as a marker in
4010  case a new node joins or leaves the group.
4011 
4012  @internal
4013  The inheritance structure is as follows
4014 
4015  Binary_log_event
4016  ^
4017  |
4018  |
4019 B_l: View_change_event Log_event
4020  \ /
4021  \ /
4022  \ /
4023  \ /
4024  View_change_log_event
4025 
4026  B_l: Namespace Binary_log
4027  @endinternal
4028 */
4029 
4031  public Log_event {
4032  private:
4033  size_t to_string(char *buf, ulong len) const;
4034 
4035 #ifdef MYSQL_SERVER
4036  bool write_data_header(Basic_ostream *ostream) override;
4037 
4038  bool write_data_body(Basic_ostream *ostream) override;
4039 
4040  bool write_data_map(Basic_ostream *ostream,
4041  std::map<std::string, std::string> *map);
4042 #endif
4043 
4044  size_t get_size_data_map(std::map<std::string, std::string> *map);
4045 
4046  public:
4048 
4049  View_change_log_event(const char *buffer,
4050  const Format_description_event *descr_event);
4051 
4052  ~View_change_log_event() override;
4053 
4054  size_t get_data_size() override;
4055 
4056 #ifdef MYSQL_SERVER
4057  int pack_info(Protocol *protocol) override;
4058 #endif
4059 
4060 #ifndef MYSQL_SERVER
4061  void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
4062 #endif
4063 
4064 #if defined(MYSQL_SERVER)
4065  int do_apply_event(Relay_log_info const *rli) override;
4066  int do_update_pos(Relay_log_info *rli) override;
4067 #endif
4068 
4069  /**
4070  Returns the view id.
4071  */
4072  char *get_view_id() { return view_id; }
4073 
4074  /**
4075  Sets the certification info in the event
4076 
4077  @note size is calculated on this method as the size of the data
4078  might render the log even invalid. Also due to its size doing it
4079  here avoid looping over the data multiple times.
4080 
4081  @param[in] info certification info to be written
4082  @param[out] event_size the event size after this operation
4083  */
4084  void set_certification_info(std::map<std::string, std::string> *info,
4085  size_t *event_size);
4086 
4087  /**
4088  Returns the certification info
4089  */
4090  std::map<std::string, std::string> *get_certification_info() {
4091  return &certification_info;
4092  }
4093 
4094  /**
4095  Set the certification sequence number
4096 
4097  @param number the sequence number
4098  */
4099  void set_seq_number(rpl_gno number) { seq_number = number; }
4100 
4101  /**
4102  Returns the certification sequence number
4103  */
4105 };
4106 
4107 inline bool is_gtid_event(Log_event *evt) {
4108  return (evt->get_type_code() == binary_log::GTID_LOG_EVENT ||
4110 }
4111 
4112 /**
4113  The function checks the argument event properties to deduce whether
4114  it represents an atomic DDL.
4115 
4116  @param evt a reference to Log_event
4117  @return true when the DDL properties are found,
4118  false otherwise
4119 */
4120 inline bool is_atomic_ddl_event(Log_event *evt) {
4121  return evt != NULL && evt->get_type_code() == binary_log::QUERY_EVENT &&
4122  static_cast<Query_log_event *>(evt)->ddl_xid !=
4124 }
4125 
4126 /**
4127  The function lists all DDL instances that are supported
4128  for crash-recovery (WL9175).
4129  todo: the supported feature list is supposed to grow. Once
4130  a feature has been readied for 2pc through WL7743,9536(7141/7016) etc
4131  it needs registering in the function.
4132 
4133  @param thd an Query-log-event creator thread handle
4134  @param using_trans
4135  The caller must specify the value accoding to the following
4136  rules:
4137  @c true when
4138  - on master the current statement is not processing
4139  a table in SE which does not support atomic DDL
4140  - on slave the relay-log repository is transactional.
4141  @c false otherwise.
4142  @return true when the being created (master) or handled (slave) event
4143  is 2pc-capable, @c false otherwise.
4144 */
4145 bool is_atomic_ddl(THD *thd, bool using_trans);
4146 
4147 #ifdef MYSQL_SERVER
4148 /**
4149  Serialize an binary event to the given output stream. It is more general
4150  than call ev->write() directly. The caller will not be affected if any
4151  change happens in serialization process. For example, serializing the
4152  event in different format.
4153  */
4154 template <class EVENT>
4155 bool binary_event_serialize(EVENT *ev, Basic_ostream *ostream) {
4156  return ev->write(ostream);
4157 }
4158 
4159 /*
4160  This is an utility function that adds a quoted identifier into the a buffer.
4161  This also escapes any existance of the quote string inside the identifier.
4162  */
4163 size_t my_strmov_quoted_identifier(THD *thd, char *buffer,
4164  const char *identifier, size_t length);
4165 #else
4166 size_t my_strmov_quoted_identifier(char *buffer, const char *identifier);
4167 #endif
4168 size_t my_strmov_quoted_identifier_helper(int q, char *buffer,
4169  const char *identifier,
4170  size_t length);
4171 
4172 /**
4173  Read an integer in net_field_length format, guarding against read out of
4174  bounds and advancing the position.
4175 
4176  @param[in,out] packet Pointer to buffer to read from. On successful
4177  return, the buffer position will be incremented to point to the next
4178  byte after what was read.
4179 
4180  @param[in,out] max_length Pointer to the number of bytes in the
4181  buffer. If the function would need to look at more than *max_length
4182  bytes in order to decode the number, the function will do nothing
4183  and return true.
4184 
4185  @param[out] out Pointer where the value will be stored.
4186 
4187  @retval false Success.
4188  @retval true Failure, i.e., reached end of buffer.
4189 */
4190 template <typename T>
4191 bool net_field_length_checked(const uchar **packet, size_t *max_length, T *out);
4192 
4193 /**
4194  @} (end of group Replication)
4195 */
4196 
4197 #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:719
int do_hash_row(Relay_log_info const *rli)
Populates the m_hash when using HASH_SCAN.
Definition: log_event.cc:8827
bool write_data_set(Basic_ostream *ostream, std::list< const char *> *set)
Definition: log_event.cc:13090
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:5318
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:7015
int pack_info(Protocol *protocol) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:13000
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:12721
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:64
std::list< const char * > * get_read_set()
Return a pointer to read-set list.
Definition: log_event.h:3974
No incident.
Definition: control_events.h:436
unsigned long long log_pos
Definition: binlog_event.h:653
View_change_log_event(char *view_id)
Definition: log_event.cc:13159
unsigned long long int ulonglong
Definition: my_inttypes.h:69
Definition: my_sys.h:278
const uint64_t INVALID_XID
The following constant represents the maximum of MYSQL_XID domain.
Definition: statement_events.h:48
virtual size_t get_data_size() override
Definition: log_event.h:3361
virtual bool ends_group() const
Definition: log_event.h:1057
const char * delimiter
Definition: mysqlslap.cc:152
#define DBUG_RETURN(a1)
Definition: my_dbug.h:84
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:6143
Definition: partition_info.h:208
string string_format(const char *format,...)
Definition: utilities.cc:66
size_t get_data_size() override
Definition: log_event.h:3805
#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:2252
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:1024
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:13285
virtual const char * get_db() override
Definition: log_event.h:2631
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:12869
unsigned char * m_coltype
Definition: rows_event.h:666
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:49
void free_temp_buf()
Definition: log_event.h:833
Table definition does not match.
Definition: log_event.h:2254
char * str
Definition: mysql_lex_string.h:35
Our own string classes, used pervasively throughout the executor.
TABLE * m_table
Definition: log_event.h:2377
virtual int save_field_metadata()
Save the field metadata based on the real_type of the field.
Definition: log_event.cc:10054
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:8769
Definition: log_event.h:2165
Log_event_type get_type_code()
Definition: log_event.h:1738
Previous_gtids_log_event(const Gtid_set *set)
Definition: log_event.cc:12809
This is the subclass of View_change_log_event and Log_event This class created the view_change_log_e...
Definition: log_event.h:4030
int do_hash_scan_and_update(Relay_log_info const *rli)
Implementation of the hash_scan and update algorithm.
Definition: log_event.cc:9042
~View_change_log_event() override
Definition: log_event.cc:13189
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:3400
bool is_gtid_event(Log_event *evt)
Definition: log_event.h:4107
std::map< std::string, std::string > * get_certification_info()
Returns the certification info.
Definition: log_event.h:4090
t pos
Definition: dbug_analyze.cc:148
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:11978
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:12302
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:759
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:9724
enum_event_cache_type
Definition: log_event.h:546
size_t to_string(char *buf, ulong len) const
Definition: log_event.cc:12993
virtual int do_apply_event(Relay_log_info const *rli) override
Primitive to apply an event to the database.
Definition: log_event.cc:5670
Definition: mysql_lex_string.h:34
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:5621
static bool copy_event_cache_to_file_and_reinit(IO_CACHE *cache, FILE *file, bool flush_stream)
Definition: log_event.h:3500
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:3717
Class Gtid_set::String_format defines the separators used by Gtid_set::to_string. ...
Definition: rpl_gtid.h:1578
bool is_gtid_specified()
Return true if transaction has GTID_NEXT specified, false otherwise.
Definition: log_event.h:4002
int do_table_scan_and_update(Relay_log_info const *rli)
Implementation of the legacy table_scan and update algorithm.
Definition: log_event.cc:9063
size_t get_data_size() override
Definition: log_event.h:1909
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:2455
#define MY_WME
Definition: my_sys.h:114
Definition: binlog_event.h:340
bool is_rewrite_empty()
Definition: rpl_filter.cc:568
static char * query
Definition: myisam_ftdump.cc:44
unsigned char * m_field_metadata
Definition: rows_event.h:672
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:3846
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:1261
Delete_rows_log_event(THD *, TABLE *, const Table_id &, bool is_transactional, const unsigned char *extra_row_ndb_info)
Definition: log_event.cc:11775
Gtid_specification spec
Internal representation of the GTID.
Definition: log_event.h:3737
Table_map_log_event(THD *thd_arg, TABLE *tbl, const Table_id &tid, bool is_transactional)
Definition: log_event.cc:10075
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:2507
Failure to open table.
Definition: log_event.h:2565
const char * get_db() override
Definition: log_event.h:1968
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:1859
longlong int64
Definition: my_inttypes.h:71
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:2661
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:10455
This is the subclass of Previous_gtids_event and Log_event It is used to record the gtid_executed in...
Definition: log_event.h:3790
int pack_info(Protocol *protocol) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:5712
virtual int do_update_pos(Relay_log_info *rli)
Advance relay log coordinates.
Definition: log_event.cc:1016
my_thread_id get_thread_id()
Return the id of the committing thread.
Definition: log_event.h:3997
virtual size_t get_data_size() override
Definition: log_event.h:2299
bool is_deferred()
Definition: log_event.h:1805
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:7974
virtual int do_before_row_operations(const Slave_reporting_capability *const) override
Definition: log_event.cc:11948
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:1853
size_t get_data_size() override
Definition: log_event.h:1963
bool has_replace
Definition: log_event.h:2185
virtual bool write_data_header(Basic_ostream *ostream) override
Definition: log_event.cc:9852
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:12907
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:2732
bool init_geometry_type_field()
Definition: log_event.cc:10825
virtual Log_event_type get_general_type_code() override
Definition: log_event.h:3258
flag_set get_flags(flag_set flags_arg) const
Definition: log_event.h:2580
Definition: control_events.h:985
void clear_flags(flag_set flags_arg)
Definition: log_event.h:2579
bool init_set_str_value_field()
Definition: log_event.cc:10777
int do_apply_event(Relay_log_info const *) override
Primitive to apply an event to the database.
Definition: log_event.h:3947
bool binary_event_serialize(EVENT *ev, Basic_ostream *ostream)
Serialize an binary event to the given output stream.
Definition: log_event.h:4155
uchar * m_rows_cur
Definition: log_event.h:2693
static uint verbose
Definition: mysqlcheck.cc:62
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:8563
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:5437
bool my_b_inited(const IO_CACHE *info)
Definition: my_sys.h:494
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:7377
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:7230
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:13402
Base class for ignorable log events is Ignorable_event.
Definition: log_event.h:3396
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:4104
Contains the classes representing events occuring 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:3147
enum_error
Enumeration of the errors that can be returned.
Definition: log_event.h:2564
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:2428
const char * get_type_str() const
Returns the human readable name of this event&#39;s type.
Definition: log_event.cc:918
Stop_log_event(const char *buf, const Format_description_event *description_event)
Definition: log_event.h:1843
virtual uint8 mts_number_dbs() override
Definition: log_event.h:2305
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:2917
int close_record_scan()
Does the cleanup.
Definition: log_event.cc:8423
Definition: log_event.h:2270
Definition: field.h:707
void end_work()
Resets this object.
Definition: log_event.h:2492
unsigned char uint8
Definition: my_inttypes.h:51
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:11898
bool init_signedness_field()
Definition: log_event.cc:10639
const char * get_db() override
Definition: log_event.h:2027
int open_record_scan()
Initializes scanning of rows.
Definition: log_event.cc:8507
size_t get_data_size() override
Definition: log_event.h:1739
#define SERVER_VERSION_LENGTH
Definition: mysql_com.h:72
static int get_data_set_size(std::list< const char *> *set)
Definition: log_event.cc:13130
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:2667
int add_row_data(uchar *data, size_t length)
Definition: log_event.h:2599
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:3562
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:2174
Sergei Dialog Client Authentication NULL
Definition: dialog.cc:352
Definition: rpl_utility.h:106
~User_var_log_event() override
Definition: log_event.h:1797
time_t get_time()
Prints a "session_var=value" string.
Definition: log_event.cc:832
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:4968
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:6971
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:1081
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:11301
bool write_data_body(Basic_ostream *ostream) override
Definition: log_event.cc:13296
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:6998
#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:1134
#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:1414
virtual int do_apply_event(Relay_log_info const *rli) override
Primitive to apply an event to the database.
Definition: log_event.cc:12078
virtual int do_after_row_operations(const Slave_reporting_capability *const, int) override
Definition: log_event.cc:11837
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:13218
No more room for tables.
Definition: log_event.h:2567
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:2569
int get_commit_timestamp_length() const
Definition: control_events.h:892
~Transaction_context_log_event() override
Definition: log_event.cc:12982
Out of memory.
Definition: log_event.h:2568
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:7609
#define DBUG_EVALUATE_IF(keyword, a1, a2)
Definition: my_dbug.h:108
Definition: log_event.h:2558
virtual int pack_info(Protocol *protocol) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:9966
Log_event_header::Byte * data_buf
Definition: log_event.h:1245
std::set< uchar *, Key_compare >::iterator m_itr
Definition: log_event.h:2727
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:6804
virtual bool write_data_header(Basic_ostream *ostream) override
Definition: log_event.cc:12117
virtual size_t get_data_size() override
Definition: log_event.h:3495
DBUG_VOID_RETURN
Definition: dbug_analyze.cc:151
bool write_data_body(Basic_ostream *ostream) override
Definition: log_event.cc:12891
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:5331
~Append_block_log_event() override
Definition: log_event.h:1962
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:1776
bool write(Basic_ostream *ostream) override
Definition: log_event.cc:6171
virtual int do_exec_row(const Relay_log_info *const) override
Definition: log_event.cc:11844
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:2468
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:1062
bool write(Basic_ostream *ostream) override
Definition: log_event.cc:6772
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:4120
MY_BITMAP const * get_cols() const
Definition: log_event.h:2607
protocol
Definition: memcached.h:112
uint m_key_index
Definition: log_event.h:2702
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:8163
Definition: log_event.h:3518
bool write(Basic_ostream *ostream) override
Definition: log_event.cc:5839
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:1072
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:551
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:519
#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:3154
enum_event_logging_type
Definition: log_event.h:571
bool write(Basic_ostream *ostream) override
Definition: log_event.cc:6372
virtual int do_update_pos(Relay_log_info *rli) override
Advance relay log coordinates.
Definition: log_event.cc:5774
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:13046
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:159
bool is_rbr_logging_format() const override
Return true if the event has to be logged using RBR for DMLs.
Definition: log_event.h:2789
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:7062
daisy-chanining RBR to SBR not allowed
Definition: log_event.h:2255
flag_set m_flags
Definition: rows_event.h:656
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:2180
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:5799
Definition: log_event.h:904
Definition: log_event.h:586
unsigned long m_width
Flags for row-level events.
Definition: rows_event.h:934
#define DBUG_EXECUTE_IF(keyword, a1)
Definition: my_dbug.h:100
Rows_applier_psi_stage()
Definition: log_event.h:2446
Definition: table.h:1294
LEX_STRING db
Definition: table.h:724
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:1971
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:862
char * temp_buf
Definition: log_event.h:627
int next_record_scan(bool first_read)
Fetches next row.
Definition: log_event.cc:8448
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:10314
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:3587
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:2156
const Table_id & get_table_id() const
Definition: log_event.h:2610
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:3307
virtual int do_apply_event(Relay_log_info const *rli) override
Primitive to apply an event to the database.
Definition: log_event.cc:6956
const char * get_db_name() const
Definition: log_event.h:2297
int pack_info(Protocol *) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:12394
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:2030
uint16_t m_flags
Definition: rows_event.h:931
bool write(Basic_ostream *ostream) override
Definition: log_event.cc:5190
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:5066
Definition: binlog_event.h:279
#define DBUG_PRINT(keyword, arglist)
Definition: my_dbug.h:110
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:9829
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:5569
Skip event and decrease skip counter.
Definition: log_event.h:542
Log_event_type get_type_code()
Definition: log_event.h:1854
uint32_t thread_id
Definition: control_events.h:1109
bool write(Basic_ostream *ostream) override
Definition: log_event.cc:6916
Contains the classes representing events which are used for row based replication.
KEY * m_key_info
Definition: log_event.h:2703
bool is_relay_log_event() const
Definition: log_event.h:802
#define DBUG_ASSERT(A)
Definition: my_dbug.h:128
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:13142
Definition: log_event.h:2556
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:2443
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:1117
virtual int do_after_row_operations(const Slave_reporting_capability *const, int) override
Definition: log_event.cc:11436
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:2692
~Gtid_log_event() override
Definition: log_event.h:3595
void close_cached_file(IO_CACHE *cache)
Definition: mf_cache.cc:91
Legends running throughout the module:
Definition: rpl_rli_pdb.h:72
~Table_map_log_event() override
Definition: log_event.cc:10202
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:3600
bool write_data_body(Basic_ostream *ostream) override
Definition: log_event.cc:13062
#define DBUG_ENTER(a)
Definition: my_dbug.h:80
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:5245
ulong get_post_header_size_for_derived() override
Definition: log_event.cc:7057
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:5365
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:565
int do_apply_event(Relay_log_info const *) override
Primitive to apply an event to the database.
Definition: log_event.h:3870
std::list< const char * > * get_write_set()
Return a pointer to write-set list.
Definition: log_event.h:3962
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:12244
virtual int do_apply_event(Relay_log_info const *rli) override
Primitive to apply an event to the database.
Definition: log_event.cc:6825
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:12051
const uchar * m_curr_row
Definition: log_event.h:2699
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:2553
bool write(Basic_ostream *ostream) override
Definition: log_event.cc:5734
Definition: log_event.h:2271
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:1144
Definition: log_event.h:564
virtual size_t get_data_size() override
Definition: log_event.cc:7669
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:930
size_t my_strmov_quoted_identifier(THD *thd, char *buffer, const char *identifier, size_t length)
Definition: log_event.cc:13425
Definition: aggregate_check.h:523
Rows_query_log_event(THD *thd_arg, const char *query, size_t query_len)
Definition: log_event.h:3464
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:3811
Definition: log_event.h:547
flag_set get_flags(flag_set flag) const
Definition: log_event.h:2275
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:7002
Gtid gtid
The GTID: { SIDNO, GNO } if type == GTID; { 0, 0 } if type == AUTOMATIC or ANONYMOUS.
Definition: rpl_gtid.h:3595
unsigned long m_field_metadata_size
The size of field metadata buffer set by calling save_field_metadata()
Definition: rows_event.h:671
Definition: log_event.h:1655
bool read_snapshot_version()
Read snapshot version from encoded buffers.
Definition: log_event.cc:13110
Cursor end()
A past-the-end Cursor.
Definition: rules_table_service.cc:191
ulonglong my_xid
recover() step of xa.
Definition: handler.h:6572
virtual bool write_data_body(Basic_ostream *ostream) override
Definition: log_event.cc:10469
std::string m_tblnam
Definition: rows_event.h:663
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:7213
int do_apply_event(Relay_log_info const *rli) override
Primitive to apply an event to the database.
Definition: log_event.cc:12610
Sid_map * sid_map
The Sid_map to use for creating the Gtid_set.
Definition: log_event.h:3903
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:12735
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:4305
TABLE_SHARE * s
Definition: table.h:1295
static bool ignore
Definition: mysqlimport.cc:64
Key_compare(KEY **ki=NULL)
Definition: log_event.h:2717
uint m_rows_lookup_algorithm
The algorithm to use while searching for rows using the before image.
Definition: log_event.h:2673
query_id_t query_id
Definition: log_event.h:1777
std::set< uchar *, Key_compare > m_distinct_keys
Definition: log_event.h:2726
virtual int do_update_pos(Relay_log_info *rli) override
Advance relay log coordinates.
Definition: log_event.cc:6650
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:12254
Definition: my_sys.h:354
Event for the first block of file to be loaded, its only difference from Append_block event is that t...
Definition: log_event.h:2075
virtual Log_event_type get_general_type_code() override
Definition: log_event.h:3059
bool is_query_prefix_match(const char *pattern, uint p_len)
Definition: log_event.h:1419
This is the abstract base class for binary log events.
Definition: log_event.h:517
const char * table_name
Definition: log_event.h:2181
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:499
int do_update_pos(Relay_log_info *rli) override
Advance relay log coordinates.
Definition: log_event.cc:12898
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:777
virtual bool ends_group() const override
Definition: log_event.h:3365
void set_deferred(query_id_t qid)
Definition: log_event.h:1810
enum_gtid_type
Enumeration of different types of values for Gtid_specification, i.e, the different internal states t...
Definition: rpl_gtid.h:3483
In row-based mode, every row operation event is preceded by a Table_map_event which maps a table defi...
Definition: rows_event.h:510
size_t get_data_size() override
Definition: log_event.h:2022
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:2317
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:3987
Common base class for all row-containing log events.
Definition: log_event.h:2544
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:10441
void * xid
Definition: control_events.h:596
Log row updates with a before image.
Definition: log_event.h:3116
No error.
Definition: log_event.h:2566
rpl_sid sid
SID for this GTID.
Definition: log_event.h:3739
rpl_sidno get_sidno(bool need_lock)
Return the SIDNO relative to the global sid_map for this GTID.
Definition: log_event.cc:12788
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:6655
char * message
Definition: control_events.h:480
MY_BITMAP * write_set
Definition: table.h:1414
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:10804
unsigned int len
Definition: dbug_analyze.cc:216
void set_progress(PSI_stage_progress *progress)
Definition: log_event.h:2448
Definition: item.h:666
virtual int do_update_pos(Relay_log_info *rli) override
Advance relay log coordinates.
Definition: log_event.cc:6712
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:13304
~Update_rows_log_event() override
Definition: log_event.cc:11921
bool write_data_body(Basic_ostream *ostream) override
Definition: log_event.cc:12601
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:5974
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:10671
bool is_valid()
Definition: log_event.cc:1314
#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:4292
bool is_sbr_logging_format() const override
Return true if the event has to be logged using SBR for DMLs.
Definition: log_event.h:1816
Gtid_set * snapshot_version
A gtid_set which is used to store the transaction set used for conflict detection.
Definition: log_event.h:3906
virtual void set_mts_isolate_group()
Definition: log_event.h:994
~Rotate_log_event() override
Definition: log_event.h:1908
~Rows_log_event() override
Definition: log_event.cc:7596
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:533
#define MYF(v)
Definition: my_inttypes.h:131
std::list< const char * > write_set
Definition: control_events.h:1113
const uchar * m_curr_row_end
Definition: log_event.h:2700
int pack_info(Protocol *) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:12168
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:2724
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:212
int pack_info(Protocol *protocol) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:5180
const char * description() const
Definition: log_event.cc:12041
Table_map_log_event which maps a table definition to a number.
Definition: log_event.h:2240
virtual int do_exec_row(const Relay_log_info *const) override
Definition: log_event.cc:11743
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:910
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:8895
Log row insertions and updates.
Definition: log_event.h:3030
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:7120
size_t get_event_length()
Definition: log_event.h:3603
char msg[1024]
Definition: test_sql_9_sessions.cc:282
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:11315
Nothing here right now, but the flags support is there in preparation for changes that are coming...
Definition: log_event.h:2265
virtual int get_create_or_append() const
Definition: log_event.cc:6817
This will be deprecated when we move to using sequence ids.
Definition: log_event.h:1896
const char * get_table_name() const
Definition: log_event.h:2296
GTID stands for Global Transaction IDentifier It is composed of two parts:
Definition: control_events.h:795
char * buf[2048]
Definition: log_event.h:2176
Definition: m_ctype.h:358
#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:2554
virtual bool write_data_body(Basic_ostream *ostream) override
Definition: log_event.cc:9933
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:12202
~Previous_gtids_log_event() override
Definition: log_event.h:3803
Definition: log_event.h:2244
const int MAX_GNO_TEXT_LENGTH
The length of MAX_GNO when printed in decimal.
Definition: rpl_gtid.h:391
Incident_log_event(THD *thd_arg, enum_incident incident_arg, LEX_STRING const msg)
Definition: log_event.h:3319
TABLE * m_table
Definition: log_event.h:2659
uint32 write_header_to_memory(uchar *buf)
Writes the common header of this event to the given memory buffer.
Definition: log_event.cc:1225
size_t get_size_data_map(std::map< std::string, std::string > *map)
Definition: log_event.cc:13204
bool contains_partition_info(bool)
Definition: log_event.cc:2468
PSI_memory_key key_memory_Incident_log_event_message
Definition: log_event.cc:167
void init(MY_BITMAP const *cols, const MY_BITMAP &cols_to_subtract)
Definition: log_event.cc:11905
uint32 m_bitbuf_ai[128/(sizeof(uint32) *8)]
Definition: log_event.h:2686
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:5593
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:10615
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:8398
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:3422
Definition: log_event.h:2555
virtual int do_update_pos(Relay_log_info *rli) override
Advance relay log coordinates.
Definition: log_event.cc:4954
Append_block_log_event(THD *thd, const char *db_arg, uchar *block_arg, uint block_len_arg, bool using_trans)
Definition: log_event.cc:6741
static const size_t MAX_SET_STRING_LENGTH
The maximal length of the entire "SET ..." query.
Definition: log_event.h:3728
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:3992
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:3865
uint32 write_body_to_memory(uchar *buff)
Writes the body to the given memory buffer.
Definition: log_event.cc:12544
Definition: typelib.h:34
size_t get_width() const
Definition: log_event.h:2609
~Intvar_log_event() override
Definition: log_event.h:1548
~Begin_load_query_log_event() override
Definition: log_event.h:2086
int pack_info(Protocol *protocol) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:5818
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:6227
Log row deletions.
Definition: log_event.h:3234
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:5779
uint16 flag_set
Definition: log_event.h:2551
#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:954
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
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:319
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:3050
unsigned long my_off_t
Definition: my_inttypes.h:88
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:2179
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:11868
Definition: log_event.h:559
unsigned long m_colcnt
Definition: rows_event.h:665
uint32 my_thread_id
Definition: my_thread_local.h:33
String str
Definition: log_event.h:2175
const char * fname
Definition: log_event.h:2182
void inc_n_rows_applied(ulonglong delta)
Updates the counter of processed rows.
Definition: log_event.h:2501
const char * get_rewrite_db(const char *db, size_t *new_len)
Definition: rpl_filter.cc:1184
virtual int do_apply_event(Relay_log_info const *rli) override
Primitive to apply an event to the database.
Definition: log_event.cc:6543
THD * thd
Definition: log_event.h:2178
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:5695
Definition: protocol.h:34
Performance schema instrumentation interface.
~Delete_file_log_event() override
Definition: log_event.h:2021
#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:1002
friend class Old_rows_log_event
Definition: log_event.h:2983
static int flag
Definition: hp_test1.cc:39
bool init_column_name_field()
Definition: log_event.cc:10765
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:13279
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:2436
enum_gtid_type type
The type of this GTID.
Definition: rpl_gtid.h:3589
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:7708
virtual const char * get_db()
Definition: log_event.cc:1077
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:2295
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:1773
int pack_info(Protocol *protocol) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:13224
virtual int do_apply_event(Relay_log_info const *rli) override
Primitive to apply an event to the database.
Definition: log_event.cc:7151
void set_seq_number(rpl_gno number)
Set the certification sequence number.
Definition: log_event.h:4099
size_t get_data_size() override
Definition: log_event.h:3597
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:11507
Definition: key.h:111
uint64_t xid
Definition: control_events.h:529
bool operator()(uchar *k1, uchar *k2) const
Definition: log_event.h:2718
static const size_t SET_STRING_PREFIX_LENGTH
Length of SET_STRING_PREFIX.
Definition: log_event.h:3726
bool is_artificial_event() const
Definition: log_event.h:799
Definition: binlog_event.h:284
~Rows_query_log_event() override
Definition: log_event.h:3487
size_t to_string(char *buf) const
Used internally by both print() and pack_info().
Definition: log_event.cc:12402
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:12740
Definition: log_event.h:2574
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:8280
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:11814
char * get_view_id()
Returns the view id.
Definition: log_event.h:4072
~Ignorable_log_event() override
Definition: log_event.cc:12164
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:11791
int net_send(Protocol *protocol, const char *log_name, my_off_t pos)
Only called by SHOW BINLOG EVENTS.
Definition: log_event.cc:1082
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:3252
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
int row_operations_scan_and_key_teardown