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