MySQL  8.0.28
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 [[maybe_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 [[maybe_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 
2972  /**
2973  Helper function to check whether the storage engine error
2974  allows for the transaction to be retried or not.
2975 
2976  @param error Storage engine error
2977  @retval true if the error is retryable.
2978  @retval false if the error is non-retryable.
2979  */
2980  static bool is_trx_retryable_upon_engine_error(int error);
2981 #endif
2983  bool is_rbr_logging_format() const override { return true; }
2984 
2985  private:
2986 #if defined(MYSQL_SERVER)
2987  int do_apply_event(Relay_log_info const *rli) override;
2988  int do_update_pos(Relay_log_info *rli) override;
2990 
2991  /*
2992  Primitive to prepare for a sequence of row executions.
2993 
2994  DESCRIPTION
2995 
2996  Before doing a sequence of do_prepare_row() and do_exec_row()
2997  calls, this member function should be called to prepare for the
2998  entire sequence. Typically, this member function will allocate
2999  space for any buffers that are needed for the two member
3000  functions mentioned above.
3001 
3002  RETURN VALUE
3003 
3004  The member function will return 0 if all went OK, or a non-zero
3005  error code otherwise.
3006  */
3007  virtual int do_before_row_operations(
3008  const Slave_reporting_capability *const log) = 0;
3009 
3010  /*
3011  Primitive to clean up after a sequence of row executions.
3012 
3013  DESCRIPTION
3014 
3015  After doing a sequence of do_prepare_row() and do_exec_row(),
3016  this member function should be called to clean up and release
3017  any allocated buffers.
3018 
3019  The error argument, if non-zero, indicates an error which happened during
3020  row processing before this function was called. In this case, even if
3021  function is successful, it should return the error code given in the
3022  argument.
3023  */
3024  virtual int do_after_row_operations(
3025  const Slave_reporting_capability *const log, int error) = 0;
3026 
3027  /*
3028  Primitive to do the actual execution necessary for a row.
3029 
3030  DESCRIPTION
3031  The member function will do the actual execution needed to handle a row.
3032  The row is located at m_curr_row. When the function returns,
3033  m_curr_row_end should point at the next row (one byte after the end
3034  of the current row).
3035 
3036  RETURN VALUE
3037  0 if execution succeeded, 1 if execution failed.
3038 
3039  */
3040  virtual int do_exec_row(const Relay_log_info *const rli) = 0;
3041 
3042  /**
3043  Private member function called while handling idempotent errors.
3044 
3045  @param rli Pointer to relay log info structure.
3046  @param [in,out] err the error to handle. If it is listed as
3047  idempotent/ignored related error, then it is cleared.
3048  @returns true if the slave should stop executing rows.
3049  */
3051 
3052  /**
3053  Private member function called after updating/deleting a row. It
3054  performs some assertions and more importantly, it updates
3055  m_curr_row so that the next row is processed during the row
3056  execution main loop (@c Rows_log_event::do_apply_event()).
3057 
3058  @param rli Pointer to relay log info structure.
3059  @param err the current error code.
3060  */
3061  void do_post_row_operations(Relay_log_info const *rli, int err);
3062 
3063  /**
3064  Commodity wrapper around do_exec_row(), that deals with resetting
3065  the thd reference in the table.
3066  */
3067  int do_apply_row(Relay_log_info const *rli);
3068 
3069  /**
3070  Implementation of the index scan and update algorithm. It uses
3071  PK, UK or regular Key to search for the record to update. When
3072  found it updates it.
3073  */
3074  int do_index_scan_and_update(Relay_log_info const *rli);
3075 
3076  /**
3077  Implementation of the hash_scan and update algorithm. It collects
3078  rows positions in a hashtable until the last row is
3079  unpacked. Then it scans the table to update and when a record in
3080  the table matches the one in the hashtable, the update/delete is
3081  performed.
3082  */
3083  int do_hash_scan_and_update(Relay_log_info const *rli);
3084 
3085  /**
3086  Implementation of the legacy table_scan and update algorithm. For
3087  each unpacked row it scans the storage engine table for a
3088  match. When a match is found, the update/delete operations are
3089  performed.
3090  */
3091  int do_table_scan_and_update(Relay_log_info const *rli);
3092 
3093  /**
3094  Seek past the after-image of an update event, in case a row was processed
3095  without reading the after-image.
3096 
3097  An update event may process a row without reading the after-image,
3098  e.g. in case of ignored or idempotent errors. To ensure that the
3099  read position for the next row is correct, we need to seek past
3100  the after-image.
3101 
3102  @param rli The applier context
3103 
3104  @param curr_bi_start The read position of the beginning of the
3105  before-image. (The function compares this with m_curr_row to know
3106  if the after-image has been read or not.)
3107 
3108  @retval 0 Success
3109  @retval ER_* Error code returned by unpack_current_row
3110  */
3111  virtual int skip_after_image_for_update_event(const Relay_log_info *rli
3112  [[maybe_unused]],
3113  const uchar *curr_bi_start
3114  [[maybe_unused]]) {
3115  return 0;
3116  }
3117 
3118  /**
3119  Initializes scanning of rows. Opens an index and initailizes an iterator
3120  over a list of distinct keys (m_distinct_keys) if it is a HASH_SCAN
3121  over an index or the table if its a HASH_SCAN over the table.
3122  */
3123  int open_record_scan();
3124 
3125  /**
3126  Does the cleanup
3127  - closes the index if opened by open_record_scan
3128  - closes the table if opened for scanning.
3129  */
3130  int close_record_scan();
3131 
3132  /**
3133  Fetches next row. If it is a HASH_SCAN over an index, it populates
3134  table->record[0] with the next row corresponding to the index. If
3135  the indexes are in non-contigous ranges it fetches record corresponding
3136  to the key value in the next range.
3137 
3138  @param first_read signifying if this is the first time we are reading a row
3139  over an index.
3140  @return error code when there are no more records to be fetched or some
3141  other error occurred,
3142  - 0 otherwise.
3143  */
3144  int next_record_scan(bool first_read);
3145 
3146  /**
3147  Populates the m_distinct_keys with unique keys to be modified
3148  during HASH_SCAN over keys.
3149  @returns 0 success, or the error code.
3150  */
3152 
3153  /**
3154  Populates the m_hash when using HASH_SCAN. Thence, it:
3155  - unpacks the before image (BI)
3156  - saves the positions
3157  - saves the positions into the hash map, using the
3158  BI checksum as key
3159  - unpacks the after image (AI) if needed, so that
3160  m_curr_row_end gets updated correctly.
3161 
3162  @param rli The reference to the relay log info object.
3163  @returns 0 on success. Otherwise, the error code.
3164  */
3165  int do_hash_row(Relay_log_info const *rli);
3166 
3167  /**
3168  This member function scans the table and applies the changes
3169  that had been previously hashed. As such, m_hash MUST be filled
3170  by do_hash_row before calling this member function.
3171 
3172  @param rli The reference to the relay log info object.
3173  @returns 0 on success. Otherwise, the error code.
3174  */
3175  int do_scan_and_update(Relay_log_info const *rli);
3176 #endif /* defined(MYSQL_SERVER) */
3178  friend class Old_rows_log_event;
3179 
3180  /**
3181  This bitmap is used as a backup for the write set while we calculate
3182  the values for any hidden generated columns (functional indexes). In order
3183  to calculate the values, the columns must be marked in the write set. After
3184  the values are caluclated, we set the write set back to it's original value.
3185  */
3187 };
3188 
3189 /**
3190  @class Write_rows_log_event
3191 
3192  Log row insertions and updates. The event contain several
3193  insert/update rows for a table. Note that each event contains only
3194  rows for one table.
3195 
3196  @internal
3197  The inheritance structure is as follows
3198 
3199  Binary_log_event
3200  ^
3201  |
3202  |
3203  |
3204  Log_event B_l:Rows_event
3205  ^ /\
3206  | / \
3207  | <<vir>>/ \ <<vir>>
3208  | / \
3209  | / \
3210  | / \
3211  Rows_log_event B_l:W_R_E
3212  \ /
3213  \ /
3214  \ /
3215  \ /
3216  \ /
3217  \/
3218  Write_rows_log_event
3219 
3220  B_l: Namespace Binary_log
3221  W_R_E: class Write_rows_event
3222  @endinternal
3223 
3224 */
3225 class Write_rows_log_event : public Rows_log_event,
3227  public:
3228  enum {
3229  /* Support interface to THD::binlog_prepare_pending_rows_event */
3231  };
3232 
3233 #if defined(MYSQL_SERVER)
3234  Write_rows_log_event(THD *, TABLE *, const Table_id &table_id,
3235  bool is_transactional,
3236  const unsigned char *extra_row_ndb_info);
3237 #endif
3238  Write_rows_log_event(const char *buf,
3239  const Format_description_event *description_event);
3240 #if defined(MYSQL_SERVER)
3241  static bool binlog_row_logging_function(THD *thd, TABLE *table,
3242  bool is_transactional,
3243  const uchar *before_record
3244  [[maybe_unused]],
3245  const uchar *after_record);
3246  bool read_write_bitmaps_cmp(const TABLE *table) const override {
3247  return bitmap_cmp(get_cols(), table->write_set);
3248  }
3249 #endif
3250 
3251  protected:
3252  int write_row(const Relay_log_info *const, const bool);
3253 
3254  private:
3256  return (Log_event_type)TYPE_CODE;
3257  }
3258 
3259 #ifndef MYSQL_SERVER
3260  void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
3261 #endif
3262 
3263 #if defined(MYSQL_SERVER)
3265  const Slave_reporting_capability *const) override;
3267  int) override;
3268  int do_exec_row(const Relay_log_info *const) override;
3269 #endif
3270 };
3271 
3272 /**
3273  @class Update_rows_log_event
3274 
3275  Log row updates with a before image. The event contain several
3276  update rows for a table. Note that each event contains only rows for
3277  one table.
3278 
3279  Also note that the row data consists of pairs of row data: one row
3280  for the old data and one row for the new data.
3281 
3282  @internal
3283  The inheritance structure is as follows
3284 
3285  Binary_log_event
3286  ^
3287  |
3288  |
3289  |
3290  Log_event B_l:Rows_event
3291  ^ /\
3292  | / \
3293  | <<vir>>/ \ <<vir>>
3294  | / \
3295  | / \
3296  | / \
3297  Rows_log_event B_l:U_R_E
3298  \ /
3299  \ /
3300  \ /
3301  \ /
3302  \ /
3303  \/
3304  Update_rows_log_event
3305 
3306 
3307  B_l: Namespace Binary_log
3308  U_R_E: class Update_rows_event
3309  @eninternal
3310 
3311 */
3312 class Update_rows_log_event : public Rows_log_event,
3314  public:
3315  enum {
3316  /* Support interface to THD::binlog_prepare_pending_rows_event */
3318  };
3319 
3320 #ifdef MYSQL_SERVER
3321  Update_rows_log_event(THD *, TABLE *, const Table_id &table_id,
3322  MY_BITMAP const *cols_bi, MY_BITMAP const *cols_ai,
3323  bool is_transactional,
3324  const unsigned char *extra_row_ndb_info);
3325 
3326  Update_rows_log_event(THD *, TABLE *, const Table_id &table_id,
3327  bool is_transactional,
3328  const unsigned char *extra_row_ndb_info);
3329 
3330  void init(MY_BITMAP const *cols);
3331 #endif
3332 
3333  ~Update_rows_log_event() override;
3334 
3335  Update_rows_log_event(const char *buf,
3336  const Format_description_event *description_event);
3337 
3338 #ifdef MYSQL_SERVER
3339  static bool binlog_row_logging_function(THD *thd, TABLE *table,
3340  bool is_transactional,
3341  const uchar *before_record,
3342  const uchar *after_record);
3343  bool read_write_bitmaps_cmp(const TABLE *table) const override {
3344  return (bitmap_cmp(get_cols(), table->read_set) &&
3345  bitmap_cmp(get_cols_ai(), table->write_set));
3346  }
3347 #endif
3348 
3349  protected:
3351  return (Log_event_type)TYPE_CODE;
3352  }
3353 
3354 #ifndef MYSQL_SERVER
3355  void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
3356 #endif
3357 
3358 #if defined(MYSQL_SERVER)
3360  const Slave_reporting_capability *const) override;
3362  int) override;
3363  int do_exec_row(const Relay_log_info *const) override;
3364 
3366  const uchar *curr_bi_start) override;
3367 
3368  private:
3369  /**
3370  Auxiliary function used in the (THD*, ...) constructor to
3371  determine the type code based on configuration options.
3372 
3373  @param thd_arg The THD object for the session.
3374 
3375  @return One of UPDATE_ROWS_EVENT_V1, PARTIAL_UPDATE_ROWS_EVENT, or
3376  UPDATE_ROWS_EVENT.
3377  */
3379  const THD *thd_arg);
3380 #endif /* defined(MYSQL_SERVER) */
3381 };
3382 
3383 /**
3384  @class Delete_rows_log_event
3385 
3386  Log row deletions. The event contain several delete rows for a
3387  table. Note that each event contains only rows for one table.
3388 
3389  RESPONSIBILITIES
3390 
3391  - Act as a container for rows that has been deleted on the master
3392  and should be deleted on the slave.
3393 
3394  COLLABORATION
3395 
3396  Row_writer
3397  Create the event and add rows to the event.
3398  Row_reader
3399  Extract the rows from the event.
3400 
3401  @internal
3402  The inheritance structure is as follows
3403 
3404  Binary_log_event
3405  ^
3406  |
3407  |
3408  |
3409  Log_event B_l:Rows_event
3410  ^ /\
3411  | / \
3412  | <<vir>>/ \ <<vir>>
3413  | / \
3414  | / \
3415  | / \
3416  Rows_log_event B_l:D_R_E
3417  \ /
3418  \ /
3419  \ /
3420  \ /
3421  \ /
3422  \/
3423  Delete_rows_log_event
3424 
3425  B_l: Namespace Binary_log
3426  D_R_E: class Delete_rows_event
3427  @endinternal
3428 
3429 */
3430 class Delete_rows_log_event : public Rows_log_event,
3432  public:
3433  enum {
3434  /* Support interface to THD::binlog_prepare_pending_rows_event */
3436  };
3437 
3438 #ifdef MYSQL_SERVER
3439  Delete_rows_log_event(THD *, TABLE *, const Table_id &, bool is_transactional,
3440  const unsigned char *extra_row_ndb_info);
3441 #endif
3442  Delete_rows_log_event(const char *buf,
3443  const Format_description_event *description_event);
3444 #ifdef MYSQL_SERVER
3445  static bool binlog_row_logging_function(THD *thd, TABLE *table,
3446  bool is_transactional,
3447  const uchar *before_record,
3448  const uchar *after_record
3449  [[maybe_unused]]);
3450  bool read_write_bitmaps_cmp(const TABLE *table) const override {
3451  return bitmap_cmp(get_cols(), table->read_set);
3452  }
3453 #endif
3454 
3455  protected:
3457  return (Log_event_type)TYPE_CODE;
3458  }
3459 
3460 #ifndef MYSQL_SERVER
3461  void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
3462 #endif
3463 
3464 #if defined(MYSQL_SERVER)
3466  const Slave_reporting_capability *const) override;
3468  int) override;
3469  int do_exec_row(const Relay_log_info *const) override;
3470 #endif
3471 };
3472 
3473 /**
3474  @class Incident_log_event
3475 
3476  Class representing an incident, an occurance out of the ordinary,
3477  that happened on the master.
3478 
3479  The event is used to inform the slave that something out of the
3480  ordinary happened on the master that might cause the database to be
3481  in an inconsistent state.
3482  Its the derived class of Incident_event
3483 
3484  @internal
3485  The inheritance structure is as follows
3486 
3487  Binary_log_event
3488  ^
3489  |
3490  |
3491  B_l:Incident_event Log_event
3492  \ /
3493  \ /
3494  \ /
3495  \ /
3496  Incident_log_event
3497 
3498  B_l: Namespace Binary_log
3499  @endinternal
3500 
3501 */
3503  public:
3504 #ifdef MYSQL_SERVER
3505  Incident_log_event(THD *thd_arg, enum_incident incident_arg)
3506  : binary_log::Incident_event(incident_arg),
3509  DBUG_TRACE;
3510  DBUG_PRINT("enter", ("incident: %d", incident_arg));
3511  common_header->set_is_valid(incident_arg > INCIDENT_NONE &&
3512  incident_arg < INCIDENT_COUNT);
3513  assert(message == nullptr && message_length == 0);
3514  return;
3515  }
3517  Incident_log_event(THD *thd_arg, enum_incident incident_arg,
3518  LEX_CSTRING const msg)
3519  : binary_log::Incident_event(incident_arg),
3522  DBUG_TRACE;
3523  DBUG_PRINT("enter", ("incident: %d", incident_arg));
3524  common_header->set_is_valid(incident_arg > INCIDENT_NONE &&
3525  incident_arg < INCIDENT_COUNT);
3526  assert(message == nullptr && message_length == 0);
3528  msg.length + 1, MYF(MY_WME)))) {
3529  // The allocation failed. Mark this binlog event as invalid.
3530  common_header->set_is_valid(false);
3531  return;
3532  }
3533  strmake(message, msg.str, msg.length);
3534  message_length = msg.length;
3535  return;
3536  }
3537 #endif
3538 
3539 #ifdef MYSQL_SERVER
3540  int pack_info(Protocol *) override;
3541 #endif
3542 
3543  Incident_log_event(const char *buf,
3544  const Format_description_event *description_event);
3545 
3546  ~Incident_log_event() override;
3547 
3548 #ifndef MYSQL_SERVER
3549  void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
3550 #endif
3551 
3552 #if defined(MYSQL_SERVER)
3553  int do_apply_event(Relay_log_info const *rli) override;
3554  bool write_data_header(Basic_ostream *ostream) override;
3555  bool write_data_body(Basic_ostream *ostream) override;
3556 #endif
3558  size_t get_data_size() override {
3559  return Binary_log_event::INCIDENT_HEADER_LEN + 1 + message_length;
3560  }
3562  bool ends_group() const override { return true; }
3563 
3564  private:
3565  const char *description() const;
3566 };
3567 
3568 /**
3569  @class Ignorable_log_event
3570 
3571  Base class for ignorable log events is Ignorable_event.
3572  Events deriving from this class can be safely ignored
3573  by slaves that cannot recognize them.
3574 
3575  Its the derived class of Ignorable_event
3576 
3577  @internal
3578  The inheritance structure is as follows
3579 
3580  Binary_log_event
3581  ^
3582  |
3583  |
3584  B_l:Ignorable_event Log_event
3585  \ /
3586  <<virtual>>\ /
3587  \ /
3588  Ignorable_log_event
3589 
3590  B_l: Namespace Binary_log
3591  @endinternal
3592 */
3593 class Ignorable_log_event : public virtual binary_log::Ignorable_event,
3594  public Log_event {
3595  public:
3596 #ifdef MYSQL_SERVER
3597  Ignorable_log_event(THD *thd_arg)
3600  DBUG_TRACE;
3601  common_header->set_is_valid(true);
3602  return;
3603  }
3604 #endif
3605 
3606  Ignorable_log_event(const char *buf,
3607  const Format_description_event *descr_event);
3608  ~Ignorable_log_event() override;
3609 
3610 #ifdef MYSQL_SERVER
3611  int pack_info(Protocol *) override;
3612 #endif
3613 
3614 #ifndef MYSQL_SERVER
3615  void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
3616 #endif
3618  size_t get_data_size() override {
3619  return Binary_log_event::IGNORABLE_HEADER_LEN;
3620  }
3621 };
3622 
3623 /**
3624  @class Rows_query_log_event
3625  It is used to record the original query for the rows
3626  events in RBR.
3627  It is the subclass of Ignorable_log_event and Rows_query_event
3628 
3629  @internal
3630  The inheritance structure in the current design for the classes is
3631  as follows:
3632  Binary_log_event
3633  ^
3634  |
3635  |
3636  |
3637  Log_event B_l:Ignorable_event
3638  ^ /\
3639  | / \
3640  | <<vir>>/ \ <<vir>>
3641  | / \
3642  | / \
3643  | / \
3644  Ignorable_log_event B_l:Rows_query_event
3645  \ /
3646  \ /
3647  \ /
3648  \ /
3649  \ /
3650  \/
3651  Rows_query_log_event
3652 
3653  B_l : namespace binary_log
3654  @endinternal
3655 */
3658  public:
3659 #ifdef MYSQL_SERVER
3660  Rows_query_log_event(THD *thd_arg, const char *query, size_t query_len)
3661  : Ignorable_log_event(thd_arg) {
3662  DBUG_TRACE;
3664  if (!(m_rows_query =
3666  query_len + 1, MYF(MY_WME))))
3667  return;
3668  snprintf(m_rows_query, query_len + 1, "%s", query);
3669  DBUG_PRINT("enter", ("%s", m_rows_query));
3670  return;
3671  }
3672 #endif
3673 
3674 #ifdef MYSQL_SERVER
3675  int pack_info(Protocol *) override;
3676  int do_apply_event(Relay_log_info const *rli) override;
3677  bool write_data_body(Basic_ostream *ostream) override;
3678 #endif
3679 
3680  Rows_query_log_event(const char *buf,
3681  const Format_description_event *descr_event);
3683  ~Rows_query_log_event() override {
3685  m_rows_query = nullptr;
3686  }
3687 #ifndef MYSQL_SERVER
3688  void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
3689 #endif
3690  size_t get_data_size() override {
3691  return Binary_log_event::IGNORABLE_HEADER_LEN + 1 + strlen(m_rows_query);
3692  }
3693 };
3695 static inline bool copy_event_cache_to_file_and_reinit(IO_CACHE *cache,
3696  FILE *file,
3697  bool flush_stream) {
3698  return my_b_copy_to_file(cache, file) ||
3699  (flush_stream ? (fflush(file) || ferror(file)) : 0) ||
3700  reinit_io_cache(cache, WRITE_CACHE, 0, false, true);
3701 }
3702 
3703 #ifdef MYSQL_SERVER
3704 /*****************************************************************************
3705 
3706  Heartbeat Log Event class
3707 
3708  The class is not logged to a binary log, and is not applied on to the slave.
3709  The decoding of the event on the slave side is done by its superclass,
3710  binary_log::Heartbeat_event.
3711 
3712  ****************************************************************************/
3714  public Log_event {
3715  public:
3716  Heartbeat_log_event(const char *buf,
3717  const Format_description_event *description_event);
3718 };
3721  public Log_event {
3722  public:
3723  Heartbeat_log_event_v2(const char *buf,
3724  const Format_description_event *description_event);
3725 };
3726 /**
3727  The function is called by slave applier in case there are
3728  active table filtering rules to force gathering events associated
3729  with Query-log-event into an array to execute
3730  them once the fate of the Query is determined for execution.
3731 */
3733 #endif
3734 
3735 int append_query_string(const THD *thd, const CHARSET_INFO *csinfo,
3736  String const *from, String *to);
3741  public Log_event {
3742  public:
3743 #ifdef MYSQL_SERVER
3745  class Applier_context {
3746  private:
3747  // context for the applier (to remove if we remove the DATABASE scheduler)
3749 
3750  public:
3751  Applier_context() = default;
3752  virtual ~Applier_context() { reset(); }
3755  };
3757  Transaction_payload_log_event(THD *thd_arg, const char *payload,
3758  uint64_t payload_size,
3759  uint16_t compression_type,
3760  uint64_t uncompressed_size)
3761  : Transaction_payload_event(payload, payload_size, compression_type,
3762  uncompressed_size),
3763  Log_event(thd_arg, 0 /* flags */, Log_event::EVENT_TRANSACTIONAL_CACHE,
3766  Transaction_payload_log_event(THD *thd_arg, const char *payload,
3767  uint64_t payload_size)
3769  thd_arg, payload, payload_size,
3770  binary_log::transaction::compression::type::NONE, payload_size) {}
3773  : Transaction_payload_log_event(thd_arg, nullptr, (uint64_t)0) {}
3774 #endif
3776  Transaction_payload_log_event(const char *buf,
3777  const Format_description_event *fde)
3780  ~Transaction_payload_log_event() override = default;
3781 
3782 #ifndef MYSQL_SERVER
3783  void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
3784 #endif
3786  size_t get_event_length() { return LOG_EVENT_HEADER_LEN + get_data_size(); }
3787  size_t get_data_size() override;
3788 
3789 #if defined(MYSQL_SERVER)
3790  private:
3792 
3793  public:
3794  int do_apply_event(Relay_log_info const *rli) override;
3795  bool apply_payload_event(Relay_log_info const *rli, const uchar *event_buf);
3797  int pack_info(Protocol *protocol) override;
3798  bool ends_group() const override;
3799  bool write(Basic_ostream *ostream) override;
3801  void set_mts_dbs(Mts_db_names &arg);
3802  uint8 mts_number_dbs() override;
3803 #endif
3804 };
3805 
3806 /**
3807  @class Gtid_log_event
3808 
3809  This is a subclass if Gtid_event and Log_event. It contains
3810  per-transaction fields, including the GTID and logical timestamps
3811  used by MTS.
3812 
3813  @internal
3814  The inheritance structure is as follows
3815 
3816  Binary_log_event
3817  ^
3818  |
3819  |
3820  B_l:Gtid_event Log_event
3821  \ /
3822  \ /
3823  \ /
3824  \ /
3825  Gtid_log_event
3826 
3827  B_l: Namespace Binary_log
3828  @endinternal
3829 */
3830 class Gtid_log_event : public binary_log::Gtid_event, public Log_event {
3831  public:
3832 #ifdef MYSQL_SERVER
3833  /**
3834  Create a new event using the GTID owned by the given thread.
3835  */
3836  Gtid_log_event(THD *thd_arg, bool using_trans, int64 last_committed_arg,
3837  int64 sequence_number_arg, bool may_have_sbr_stmts_arg,
3838  ulonglong original_commit_timestamp_arg,
3839  ulonglong immediate_commit_timestamp_arg,
3840  uint32_t original_server_version_arg,
3841  uint32_t immediate_server_version_arg);
3842 
3843  /**
3844  Create a new event using the GTID from the given Gtid_specification
3845  without a THD object.
3846  */
3847  Gtid_log_event(uint32 server_id_arg, bool using_trans,
3848  int64 last_committed_arg, int64 sequence_number_arg,
3849  bool may_have_sbr_stmts_arg,
3850  ulonglong original_commit_timestamp_arg,
3851  ulonglong immediate_commit_timestamp_arg,
3852  const Gtid_specification spec_arg,
3853  uint32_t original_server_version_arg,
3854  uint32_t immediate_server_version_arg);
3855 #endif
3856 
3857 #ifdef MYSQL_SERVER
3858  int pack_info(Protocol *) override;
3859 #endif
3860  Gtid_log_event(const char *buffer,
3861  const Format_description_event *description_event);
3863  ~Gtid_log_event() override = default;
3865  size_t get_data_size() override {
3866  DBUG_EXECUTE_IF("do_not_write_rpl_timestamps", return POST_HEADER_LENGTH;);
3869  }
3871  size_t get_event_length() { return LOG_EVENT_HEADER_LEN + get_data_size(); }
3872 
3873  private:
3874  /// Used internally by both print() and pack_info().
3875  size_t to_string(char *buf) const;
3876 
3877 #ifdef MYSQL_SERVER
3878  /**
3879  Writes the post-header to the given output stream.
3880 
3881  This is an auxiliary function typically used by the write() member
3882  function.
3883 
3884  @param ostream The output stream to write to.
3885 
3886  @retval true Error.
3887  @retval false Success.
3888  */
3889  bool write_data_header(Basic_ostream *ostream) override;
3890  bool write_data_body(Basic_ostream *ostream) override;
3891  /**
3892  Writes the post-header to the given memory buffer.
3893 
3894  This is an auxiliary function used by write_to_memory.
3895 
3896  @param[in,out] buffer Buffer to which the post-header will be written.
3897 
3898  @return The number of bytes written, i.e., always
3899  Gtid_log_event::POST_HEADER_LENGTH.
3900  */
3902 
3903  /**
3904  Writes the body to the given memory buffer.
3905 
3906  This is an auxiliary function used by write_to_memory.
3907 
3908  @param [in,out] buff Buffer to which the data will be written.
3909 
3910  @return The number of bytes written, i.e.,
3911  If the transaction did not originated on this server
3912  Gtid_event::IMMEDIATE_COMMIT_TIMESTAMP_LENGTH.
3913  else
3914  FULL_COMMIT_TIMESTAMP_LENGTH.
3915  */
3917 #endif
3918 
3919  public:
3920 #ifndef MYSQL_SERVER
3921  void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
3922 #endif
3923 
3924 #if defined(MYSQL_SERVER)
3925  int do_apply_event(Relay_log_info const *rli) override;
3926  int do_update_pos(Relay_log_info *rli) override;
3928 #endif
3929 
3930  /**
3931  Return the gtid type for this Gtid_log_event: this can be
3932  either ANONYMOUS_GTID, AUTOMATIC_GTID, or ASSIGNED_GTID.
3933  */
3934  enum_gtid_type get_type() const { return spec.type; }
3935 
3936  /**
3937  Return the SID for this GTID. The SID is shared with the
3938  Log_event so it should not be modified.
3939  */
3940  const rpl_sid *get_sid() const { return &sid; }
3941  /**
3942  Return the SIDNO relative to the global sid_map for this GTID.
3943 
3944  This requires a lookup and possibly even update of global_sid_map,
3945  hence global_sid_lock must be held. If global_sid_lock is not
3946  held, the caller must pass need_lock=true. If there is an error
3947  (e.g. out of memory) while updating global_sid_map, this function
3948  returns a negative number.
3949 
3950  @param need_lock If true, the read lock on global_sid_lock is
3951  acquired and released inside this function; if false, the read
3952  lock or write lock must be held prior to calling this function.
3953  @retval SIDNO if successful
3954  @retval negative if adding SID to global_sid_map causes an error.
3955  */
3956  rpl_sidno get_sidno(bool need_lock);
3957 
3958  /**
3959  Return the SIDNO relative to the given Sid_map for this GTID.
3960 
3961  This assumes that the Sid_map is local to the thread, and thus
3962  does not use locks.
3963 
3964  @param sid_map The sid_map to use.
3965  @retval SIDNO if successful.
3966  @retval negative if adding SID to sid_map causes an error.
3967  */
3968  rpl_sidno get_sidno(Sid_map *sid_map) { return sid_map->add_sid(sid); }
3969  /// Return the GNO for this GTID.
3970  rpl_gno get_gno() const { return spec.gtid.gno; }
3971 
3972  /// string holding the text "SET @@GLOBAL.GTID_NEXT = '"
3973  static const char *SET_STRING_PREFIX;
3974 
3975  private:
3976  /// Length of SET_STRING_PREFIX
3977  static const size_t SET_STRING_PREFIX_LENGTH = 26;
3978  /// The maximal length of the entire "SET ..." query.
3979  static const size_t MAX_SET_STRING_LENGTH = SET_STRING_PREFIX_LENGTH +
3981  1 + MAX_GNO_TEXT_LENGTH + 1;
3982 
3983  private:
3984  /**
3985  Internal representation of the GTID. The SIDNO will be
3986  uninitialized (value -1) until the first call to get_sidno(bool).
3987  */
3989  /// SID for this GTID.
3990  rpl_sid sid;
3991 
3992  public:
3993  /**
3994  Set the transaction length information based on binlog cache size.
3995 
3996  Note that is_checksum_enabled and event_counter are optional parameters.
3997  When not specified, the function will assume that no checksum will be used
3998  and the informed cache_size is the final transaction size without
3999  considering the GTID event size.
4000 
4001  The high level formula that will be used by the function is:
4002 
4003  trx_length = cache_size +
4004  cache_checksum_active * cache_events * CRC32_payload +
4005  gtid_length +
4006  cache_checksum_active * CRC32_payload; // For the GTID.
4007 
4008  @param cache_size The size of the binlog cache in bytes.
4009  @param is_checksum_enabled If checksum will be added to events on flush.
4010  @param event_counter The amount of events in the cache.
4011  */
4013  bool is_checksum_enabled = false,
4014  int event_counter = 0);
4015 };
4016 
4017 /**
4018  @class Previous_gtids_log_event
4019 
4020  This is the subclass of Previous_gtids_event and Log_event
4021  It is used to record the gtid_executed in the last binary log file,
4022  for ex after flush logs, or at the starting of the binary log file
4023 
4024  @internal
4025  The inheritance structure is as follows
4026 
4027  Binary_log_event
4028  ^
4029  |
4030  |
4031 B_l:Previous_gtids_event Log_event
4032  \ /
4033  \ /
4034  \ /
4035  \ /
4036  Previous_gtids_log_event
4037 
4038  B_l: Namespace Binary_log
4039  @endinternal
4040 */
4042  public Log_event {
4043  public:
4044 #ifdef MYSQL_SERVER
4046 #endif
4047 
4048 #ifdef MYSQL_SERVER
4049  int pack_info(Protocol *) override;
4050 #endif
4051 
4052  Previous_gtids_log_event(const char *buf,
4053  const Format_description_event *description_event);
4054  ~Previous_gtids_log_event() override = default;
4056  size_t get_data_size() override { return buf_size; }
4057 
4058 #ifndef MYSQL_SERVER
4059  void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
4060 #endif
4061 #ifdef MYSQL_SERVER
4062  bool write(Basic_ostream *ostream) override {
4063  if (DBUG_EVALUATE_IF("skip_writing_previous_gtids_log_event", 1, 0) &&
4064  /*
4065  The skip_writing_previous_gtids_log_event debug point was designed
4066  for skipping the writing of the previous_gtids_log_event on binlog
4067  files only.
4068  */
4069  !is_relay_log_event()) {
4070  DBUG_PRINT("info",
4071  ("skip writing Previous_gtids_log_event because of"
4072  "debug option 'skip_writing_previous_gtids_log_event'"));
4073  return false;
4074  }
4075 
4076  if (DBUG_EVALUATE_IF("write_partial_previous_gtids_log_event", 1, 0) &&
4077  /*
4078  The write_partial_previous_gtids_log_event debug point was designed
4079  for writing a partial previous_gtids_log_event on binlog files only.
4080  */
4081  !is_relay_log_event()) {
4082  DBUG_PRINT("info",
4083  ("writing partial Previous_gtids_log_event because of"
4084  "debug option 'write_partial_previous_gtids_log_event'"));
4085  return (Log_event::write_header(ostream, get_data_size()) ||
4086  Log_event::write_data_header(ostream));
4087  }
4088 
4089  return (Log_event::write_header(ostream, get_data_size()) ||
4090  Log_event::write_data_header(ostream) || write_data_body(ostream) ||
4091  Log_event::write_footer(ostream));
4092  }
4093  bool write_data_body(Basic_ostream *ostream) override;
4094 #endif
4095 
4096  /// Return the encoded buffer, or NULL on error.
4097  const uchar *get_buf() { return buf; }
4098  /**
4099  Return the formatted string, or NULL on error.
4100  The string is allocated using my_malloc and it is the
4101  responsibility of the caller to free it.
4102  */
4103  char *get_str(size_t *length,
4104  const Gtid_set::String_format *string_format) const;
4105  /// Add all GTIDs from this event to the given Gtid_set.
4106  int add_to_set(Gtid_set *gtid_set) const;
4107  /*
4108  Previous Gtid Log events should always be skipped
4109  there is nothing to apply there, whether it is
4110  relay log's (generated on Slave) or it is binary log's
4111  (generated on Master, copied to slave as relay log).
4112  Also, we should not increment slave_skip_counter
4113  for this event, hence return EVENT_SKIP_IGNORE.
4114  */
4115 #if defined(MYSQL_SERVER)
4116  enum_skip_reason do_shall_skip(Relay_log_info *) override // 1358
4117  {
4118  return EVENT_SKIP_IGNORE;
4119  }
4121  int do_apply_event(Relay_log_info const *) override { return 0; }
4122  int do_update_pos(Relay_log_info *rli) override;
4123 #endif
4124 };
4125 
4126 /**
4127  @class Transaction_context_log_event
4128 
4129  This is the subclass of Transaction_context_event and Log_event
4130  This class encodes the transaction_context_log_event.
4131 
4132  @internal
4133  The inheritance structure is as follows
4134 
4135  Binary_log_event
4136  ^
4137  |
4138  |
4139 B_l:Transaction_context_event Log_event
4140  \ /
4141  \ /
4142  \ /
4143  \ /
4144  Transaction_context_log_event
4145 
4146  B_l: Namespace Binary_log
4147  @endinternal
4148 */
4151  public Log_event {
4152  private:
4153  /// The Sid_map to use for creating the Gtid_set.
4154  Sid_map *sid_map;
4155  /// A gtid_set which is used to store the transaction set used for
4156  /// conflict detection.
4158 
4159 #ifdef MYSQL_SERVER
4160  bool write_data_header(Basic_ostream *ostream) override;
4161 
4162  bool write_data_body(Basic_ostream *ostream) override;
4163 
4164  bool write_snapshot_version(Basic_ostream *ostream);
4165 
4166  bool write_data_set(Basic_ostream *ostream, std::list<const char *> *set);
4167 #endif
4168 
4169  size_t get_snapshot_version_size();
4170 
4171  static int get_data_set_size(std::list<const char *> *set);
4172 
4173  size_t to_string(char *buf, ulong len) const;
4174 
4175  public:
4176 #ifdef MYSQL_SERVER
4177  Transaction_context_log_event(const char *server_uuid_arg, bool using_trans,
4178  my_thread_id thread_id_arg,
4179  bool is_gtid_specified_arg);
4180 #endif
4181 
4183  const Format_description_event *descr_event);
4184 
4185  ~Transaction_context_log_event() override;
4186 
4187  size_t get_data_size() override;
4188 
4189  size_t get_event_length();
4190 
4191 #ifdef MYSQL_SERVER
4192  int pack_info(Protocol *protocol) override;
4193 #endif
4194 
4195 #ifndef MYSQL_SERVER
4196  void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
4197 #endif
4198 
4199 #if defined(MYSQL_SERVER)
4200  int do_apply_event(Relay_log_info const *) override { return 0; }
4201  int do_update_pos(Relay_log_info *rli) override;
4202 #endif
4203 
4204  /**
4205  Add a hash which identifies a inserted/updated/deleted row on the
4206  ongoing transaction.
4207 
4208  @param[in] hash row identifier
4209  */
4210  void add_write_set(const char *hash);
4211 
4212  /**
4213  Return a pointer to write-set list.
4214  */
4215  std::list<const char *> *get_write_set() { return &write_set; }
4216 
4217  /**
4218  Add a hash which identifies a read row on the ongoing transaction.
4219 
4220  @param[in] hash row identifier
4221  */
4222  void add_read_set(const char *hash);
4223 
4224  /**
4225  Return a pointer to read-set list.
4226  */
4227  std::list<const char *> *get_read_set() { return &read_set; }
4228 
4229  /**
4230  Read snapshot version from encoded buffers.
4231  Cannot be executed during data read from file (event constructor),
4232  since its required locks will collide with the server gtid state
4233  initialization procedure.
4234  */
4235  bool read_snapshot_version();
4236 
4237  /**
4238  Return the transaction snapshot timestamp.
4239  */
4241 
4242  /**
4243  Return the server uuid.
4244  */
4245  const char *get_server_uuid() { return server_uuid; }
4246 
4247  /**
4248  Return the id of the committing thread.
4249  */
4250  my_thread_id get_thread_id() { return static_cast<my_thread_id>(thread_id); }
4251 
4252  /**
4253  Return true if transaction has GTID_NEXT specified, false otherwise.
4254  */
4255  bool is_gtid_specified() { return gtid_specified == true; }
4256 };
4257 
4258 /**
4259  @class View_change_log_event
4260 
4261  This is the subclass of View_change_log_event and Log_event
4262  This class created the view_change_log_event which is used as a marker in
4263  case a new node joins or leaves the group.
4264 
4265  @internal
4266  The inheritance structure is as follows
4267 
4268  Binary_log_event
4269  ^
4270  |
4271  |
4272 B_l: View_change_event Log_event
4273  \ /
4274  \ /
4275  \ /
4276  \ /
4277  View_change_log_event
4278 
4279  B_l: Namespace Binary_log
4280  @endinternal
4281 */
4284  public Log_event {
4285  private:
4286  size_t to_string(char *buf, ulong len) const;
4287 
4288 #ifdef MYSQL_SERVER
4289  bool write_data_header(Basic_ostream *ostream) override;
4290 
4291  bool write_data_body(Basic_ostream *ostream) override;
4292 
4293  bool write_data_map(Basic_ostream *ostream,
4294  std::map<std::string, std::string> *map);
4295 #endif
4296 
4297  size_t get_size_data_map(std::map<std::string, std::string> *map);
4298 
4299  public:
4300  View_change_log_event(const char *view_id);
4301 
4302  View_change_log_event(const char *buffer,
4303  const Format_description_event *descr_event);
4304 
4305  ~View_change_log_event() override;
4306 
4307  size_t get_data_size() override;
4308 
4309 #ifdef MYSQL_SERVER
4310  int pack_info(Protocol *protocol) override;
4311 #endif
4312 
4313 #ifndef MYSQL_SERVER
4314  void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
4315 #endif
4316 
4317 #if defined(MYSQL_SERVER)
4318  int do_apply_event(Relay_log_info const *rli) override;
4319  int do_update_pos(Relay_log_info *rli) override;
4320 #endif
4321 
4322  /**
4323  Returns the view id.
4324  */
4325  char *get_view_id() { return view_id; }
4326 
4327  /**
4328  Sets the certification info in the event
4329 
4330  @note size is calculated on this method as the size of the data
4331  might render the log even invalid. Also due to its size doing it
4332  here avoid looping over the data multiple times.
4333 
4334  @param[in] info certification info to be written
4335  @param[out] event_size the event size after this operation
4336  */
4337  void set_certification_info(std::map<std::string, std::string> *info,
4338  size_t *event_size);
4339 
4340  /**
4341  Returns the certification info
4342  */
4343  std::map<std::string, std::string> *get_certification_info() {
4344  return &certification_info;
4345  }
4346 
4347  /**
4348  Set the certification sequence number
4349 
4350  @param number the sequence number
4351  */
4352  void set_seq_number(rpl_gno number) { seq_number = number; }
4353 
4354  /**
4355  Returns the certification sequence number
4356  */
4357  rpl_gno get_seq_number() { return seq_number; }
4358 };
4360 inline bool is_gtid_event(Log_event *evt) {
4361  return (evt->get_type_code() == binary_log::GTID_LOG_EVENT ||
4363 }
4364 
4365 /**
4366  The function checks the argument event properties to deduce whether
4367  it represents an atomic DDL.
4368 
4369  @param evt a reference to Log_event
4370  @return true when the DDL properties are found,
4371  false otherwise
4372 */
4373 inline bool is_atomic_ddl_event(Log_event *evt) {
4374  return evt != nullptr && evt->get_type_code() == binary_log::QUERY_EVENT &&
4375  static_cast<Query_log_event *>(evt)->ddl_xid !=
4377 }
4378 
4379 /**
4380  The function lists all DDL instances that are supported
4381  for crash-recovery (WL9175).
4382  todo: the supported feature list is supposed to grow. Once
4383  a feature has been readied for 2pc through WL7743,9536(7141/7016) etc
4384  it needs registering in the function.
4385 
4386  @param thd an Query-log-event creator thread handle
4387  @param using_trans
4388  The caller must specify the value accoding to the following
4389  rules:
4390  @c true when
4391  - on master the current statement is not processing
4392  a table in SE which does not support atomic DDL
4393  - on slave the relay-log repository is transactional.
4394  @c false otherwise.
4395  @return true when the being created (master) or handled (slave) event
4396  is 2pc-capable, @c false otherwise.
4397 */
4398 bool is_atomic_ddl(THD *thd, bool using_trans);
4399 
4400 #ifdef MYSQL_SERVER
4401 /**
4402  Serialize an binary event to the given output stream. It is more general
4403  than call ev->write() directly. The caller will not be affected if any
4404  change happens in serialization process. For example, serializing the
4405  event in different format.
4406  */
4407 template <class EVENT>
4408 bool binary_event_serialize(EVENT *ev, Basic_ostream *ostream) {
4409  return ev->write(ostream);
4410 }
4411 
4412 /*
4413  This is an utility function that adds a quoted identifier into the a buffer.
4414  This also escapes any existance of the quote string inside the identifier.
4415  */
4416 size_t my_strmov_quoted_identifier(THD *thd, char *buffer,
4417  const char *identifier, size_t length);
4418 #else
4419 size_t my_strmov_quoted_identifier(char *buffer, const char *identifier);
4420 #endif
4421 size_t my_strmov_quoted_identifier_helper(int q, char *buffer,
4422  const char *identifier,
4423  size_t length);
4424 
4425 /**
4426  Read an integer in net_field_length format, guarding against read out of
4427  bounds and advancing the position.
4428 
4429  @param[in,out] packet Pointer to buffer to read from. On successful
4430  return, the buffer position will be incremented to point to the next
4431  byte after what was read.
4432 
4433  @param[in,out] max_length Pointer to the number of bytes in the
4434  buffer. If the function would need to look at more than *max_length
4435  bytes in order to decode the number, the function will do nothing
4436  and return true.
4437 
4438  @param[out] out Pointer where the value will be stored.
4439 
4440  @retval false Success.
4441  @retval true Failure, i.e., reached end of buffer.
4442 */
4443 template <typename T>
4444 bool net_field_length_checked(const uchar **packet, size_t *max_length, T *out);
4445 
4446 /**
4447  Extract basic info about an event: type, query, is it ignorable
4448 
4449  @param log_event the event to extract info from
4450  @return a pair first param is true if an error occurred, false otherwise
4451  second param is the event info
4452  */
4453 std::pair<bool, binary_log::Log_event_basic_info> extract_log_event_basic_info(
4454  Log_event *log_event);
4455 
4456 /**
4457  Extract basic info about an event: type, query, is it ignorable
4458 
4459  @param buf The event info buffer
4460  @param length The length of the buffer
4461  @param fd_event The Format description event associated
4462  @return a pair first param is true if an error occurred, false otherwise
4463  second param is the event info
4464  */
4465 std::pair<bool, binary_log::Log_event_basic_info> extract_log_event_basic_info(
4466  const char *buf, size_t length,
4467  const binary_log::Format_description_event *fd_event);
4468 
4469 /**
4470  @} (end of group Replication)
4471 */
4472 
4473 #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:398
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:6967
bool write(Basic_ostream *ostream) override
Definition: log_event.cc:6997
virtual int get_create_or_append() const
Definition: log_event.cc:7042
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:7029
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
Definition: log_event.cc:7050
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:7256
~Begin_load_query_log_event() override=default
int get_create_or_append() const override
Definition: log_event.cc:7252
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:7228
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
Definition: log_event.cc:7201
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:7161
Delete_file_log_event(THD *thd, const char *db_arg, bool using_trans)
Definition: log_event.cc:7134
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:7189
Log row deletions.
Definition: log_event.h:3430
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:3449
Delete_rows_log_event(THD *, TABLE *, const Table_id &, bool is_transactional, const unsigned char *extra_row_ndb_info)
Definition: log_event.cc:12237
Log_event_type get_general_type_code() override
Definition: log_event.h:3455
@ TYPE_CODE
Definition: log_event.h:3434
int do_exec_row(const Relay_log_info *const) override
Definition: log_event.cc:12305
static bool binlog_row_logging_function(THD *thd, TABLE *table, bool is_transactional, const uchar *before_record, const uchar *after_record[[maybe_unused]])
Definition: log_event.cc:12253
int do_before_row_operations(const Slave_reporting_capability *const) override
Definition: log_event.cc:12275
int do_after_row_operations(const Slave_reporting_capability *const, int) override
Definition: log_event.cc:12298
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
Definition: log_event.cc:7403
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:7313
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:7269
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:7372
ulong get_post_header_size_for_derived() override
Definition: log_event.cc:7308
~Execute_load_query_log_event() override=default
Definition: field.h:590
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:5361
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:5526
size_t get_data_size() override
Definition: log_event.h:1643
bool write(Basic_ostream *ostream) override
Definition: log_event.cc:5371
int do_update_pos(Relay_log_info *rli) override
Advance relay log coordinates.
Definition: log_event.cc:5504
int do_apply_event(Relay_log_info const *rli) override
Definition: log_event.cc:5453
Format_description_log_event()
Format_description_log_event 1st ctor.
Definition: log_event.cc:5251
This is a subclass if Gtid_event and Log_event.
Definition: log_event.h:3829
rpl_sidno get_sidno(bool need_lock)
Return the SIDNO relative to the global sid_map for this GTID.
Definition: log_event.cc:13253
rpl_sid sid
SID for this GTID.
Definition: log_event.h:3989
~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:12993
size_t get_event_length()
Definition: log_event.h:3870
int do_update_pos(Relay_log_info *rli) override
Advance relay log coordinates.
Definition: log_event.cc:13185
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:3933
uint32 write_body_to_memory(uchar *buff)
Writes the body to the given memory buffer.
Definition: log_event.cc:13000
int do_apply_event(Relay_log_info const *rli) override
Definition: log_event.cc:13066
uint32 write_post_header_to_memory(uchar *buffer)
Writes the post-header to the given memory buffer.
Definition: log_event.cc:12940
static const size_t SET_STRING_PREFIX_LENGTH
Length of SET_STRING_PREFIX.
Definition: log_event.h:3976
rpl_gno get_gno() const
Return the GNO for this GTID.
Definition: log_event.h:3969
const rpl_sid * get_sid() const
Return the SID for this GTID.
Definition: log_event.h:3939
bool write_data_body(Basic_ostream *ostream) override
Definition: log_event.cc:13057
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:13204
static const size_t MAX_SET_STRING_LENGTH
The maximal length of the entire "SET ..." query.
Definition: log_event.h:3978
static const char * SET_STRING_PREFIX
string holding the text "SET @@GLOBAL.GTID_NEXT = '"
Definition: log_event.h:3972
Gtid_specification spec
Internal representation of the GTID.
Definition: log_event.h:3987
int pack_info(Protocol *) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:12846
size_t get_data_size() override
Definition: log_event.h:3864
size_t to_string(char *buf) const
Used internally by both print() and pack_info().
Definition: log_event.cc:12854
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:12754
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:13199
Represents a set of GTIDs.
Definition: rpl_gtid.h:1454
Definition: rpl_utility.h:108
Definition: log_event.h:3720
Heartbeat_log_event_v2(const char *buf, const Format_description_event *description_event)
Definition: log_event.cc:14085
Definition: log_event.h:3713
Heartbeat_log_event(const char *buf, const Format_description_event *description_event)
Definition: log_event.cc:14078
Base class for ignorable log events is Ignorable_event.
Definition: log_event.h:3593
Ignorable_log_event(THD *thd_arg)
Definition: log_event.h:3596
int pack_info(Protocol *) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:12623
size_t get_data_size() override
Definition: log_event.h:3617
~Ignorable_log_event() override
Class representing an incident, an occurance out of the ordinary, that happened on the master.
Definition: log_event.h:3501
bool write_data_header(Basic_ostream *ostream) override
Definition: log_event.cc:12573
size_t get_data_size() override
Definition: log_event.h:3557
Incident_log_event(THD *thd_arg, enum_incident incident_arg)
Definition: log_event.h:3504
bool write_data_body(Basic_ostream *ostream) override
Definition: log_event.cc:12599
~Incident_log_event() override
Definition: log_event.cc:12493
int do_apply_event(Relay_log_info const *rli) override
Definition: log_event.cc:12534
int pack_info(Protocol *) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:12507
const char * description() const
Definition: log_event.cc:12497
bool ends_group() const override
Definition: log_event.h:3561
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:5837
~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:5911
int pack_info(Protocol *protocol) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:5812
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
Definition: log_event.cc:5886
int do_update_pos(Relay_log_info *rli) override
Advance relay log coordinates.
Definition: log_event.cc:5906
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:802
Definition: key.h:112
Definition: sql_list.h:433
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:7493
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:7476
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 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
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:899
bool write_footer(Basic_ostream *ostream)
Definition: log_event.cc:1286
virtual int do_apply_event(Relay_log_info const *rli[[maybe_unused]])
Primitive to apply an event to the database.
Definition: log_event.h:1262
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 uint8 get_mts_dbs(Mts_db_names *arg, Rpl_filter *rpl_filter[[maybe_unused]])
The method fills in pointers to event's database name c-strings to a supplied array.
Definition: log_event.h:1156
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:4041
bool write_data_body(Basic_ostream *ostream) override
Definition: log_event.cc:13349
int do_update_pos(Relay_log_info *rli) override
Advance relay log coordinates.
Definition: log_event.cc:13356
const uchar * get_buf()
Return the encoded buffer, or NULL on error.
Definition: log_event.h:4096
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:13330
int pack_info(Protocol *) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:13293
int do_apply_event(Relay_log_info const *) override
Definition: log_event.h:4120
int add_to_set(Gtid_set *gtid_set) const
Add all GTIDs from this event to the given Gtid_set.
Definition: log_event.cc:13319
size_t get_data_size() override
Definition: log_event.h:4055
Previous_gtids_log_event(const Gtid_set *set)
Definition: log_event.cc:13273
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:4115
bool write(Basic_ostream *ostream) override
Definition: log_event.h:4061
~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:5140
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:5154
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
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:5190
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:5947
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:5992
int do_apply_event(Relay_log_info const *rli) override
Definition: log_event.cc:5973
int pack_info(Protocol *protocol) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:5928
int do_update_pos(Relay_log_info *rli) override
Advance relay log coordinates.
Definition: log_event.cc:5987
Definition: rpl_rli.h:200
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:862
bool is_inbound_filtering_enabled()
Returns whether or not filtering should be enabled, given the current THD instance in use.
Definition: log_event.cc:868
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:838
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:884
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:875
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:5646
int pack_info(Protocol *protocol) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:5539
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:5788
~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:5575
bool write(Basic_ostream *ostream) override
Definition: log_event.cc:5617
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:3185
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:8752
MY_BITMAP const * get_cols() const
Definition: log_event.h:2761
size_t get_width() const
Definition: log_event.h:2763
virtual int skip_after_image_for_update_event(const Relay_log_info *rli[[maybe_unused]], const uchar *curr_bi_start[[maybe_unused]])
Seek past the after-image of an update event, in case a row was processed without reading the after-i...
Definition: log_event.h:3110
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:8697
bool write_data_header(Basic_ostream *ostream) override
Definition: log_event.cc:10256
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:2982
int do_hash_row(Relay_log_info const *rli)
Populates the m_hash when using HASH_SCAN.
Definition: log_event.cc:9147
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:9382
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:8302
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:8727
int row_operations_scan_and_key_setup()
Definition: log_event.cc:8414
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:7660
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:10127
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:8903
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:9215
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:8031
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
static bool is_trx_retryable_upon_engine_error(int error)
Helper function to check whether the storage engine error allows for the transaction to be retried or...
Definition: log_event.cc:8494
size_t get_data_size() override
Definition: log_event.cc:7992
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
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
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:8487
int do_apply_event(Relay_log_info const *rli) override
Definition: log_event.cc:9486
int next_record_scan(bool first_read)
Fetches next row.
Definition: log_event.cc:8765
int pack_info(Protocol *protocol) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:10370
int do_table_scan_and_update(Relay_log_info const *rli)
Implementation of the legacy table_scan and update algorithm.
Definition: log_event.cc:9403
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:8827
@ RLE_NO_FLAGS
Definition: log_event.h:2728
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:8457
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:7969
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:8609
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:8883
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:7886
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:10233
~Rows_log_event() override
Definition: log_event.cc:7866
void set_flags(flag_set flags_arg)
Definition: log_event.h:2732
friend class Old_rows_log_event
Definition: log_event.h:3177
const uchar * m_curr_row_end
Definition: log_event.h:2868
bool write_data_body(Basic_ostream *ostream) override
Definition: log_event.cc:10337
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:3656
size_t get_data_size() override
Definition: log_event.h:3689
~Rows_query_log_event() override
Definition: log_event.h:3682
int do_apply_event(Relay_log_info const *rli) override
Definition: log_event.cc:12706
bool write_data_body(Basic_ostream *ostream) override
Definition: log_event.cc:12696
int pack_info(Protocol *) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:12654
Rows_query_log_event(THD *thd_arg, const char *query, size_t query_len)
Definition: log_event.h:3659
Rpl_filter.
Definition: rpl_filter.h:213
const char * get_rewrite_db(const char *db, size_t *new_len)
Definition: rpl_filter.cc:1173
bool is_rewrite_empty()
Definition: rpl_filter.cc:568
Represents a bidirectional map between SID and SIDNO.
Definition: rpl_gtid.h:723
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:6938
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:945
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
@ TYPE_CODE
Definition: log_event.h:2392
const Table_id & get_table_id() const
Definition: log_event.h:2443
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:10866
int do_apply_event(Relay_log_info const *rli) override
Definition: log_event.cc:10739
@ 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
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:10875
virtual int save_field_metadata()
Save the field metadata based on the real_type of the field.
Definition: log_event.cc:10458
bool init_set_str_value_field()
Definition: log_event.cc:11182
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:11230
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:11076
bool init_primary_key_field()
Definition: log_event.cc:11247
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:11295
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:10880
bool write_data_body(Basic_ostream *ostream) override
Definition: log_event.cc:10894
bool init_enum_str_value_field()
Definition: log_event.cc:11209
bool init_column_name_field()
Definition: log_event.cc:11170
Table_map_log_event(THD *thd_arg, TABLE *tbl, const Table_id &tid, bool is_transactional)
Definition: log_event.cc:10480
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:11327
TABLE * m_table
Definition: log_event.h:2523
const char * get_db() override
Definition: log_event.h:2452
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:11022
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:11045
This is the subclass of Transaction_context_event and Log_event This class encodes the transaction_co...
Definition: log_event.h:4150
bool is_gtid_specified()
Return true if transaction has GTID_NEXT specified, false otherwise.
Definition: log_event.h:4254
Gtid_set * get_snapshot_version()
Return the transaction snapshot timestamp.
Definition: log_event.h:4239
std::list< const char * > * get_write_set()
Return a pointer to write-set list.
Definition: log_event.h:4214
static int get_data_set_size(std::list< const char * > *set)
Definition: log_event.cc:13584
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:13596
void add_read_set(const char *hash)
Add a hash which identifies a read row on the ongoing transaction.
Definition: log_event.cc:13601
std::list< const char * > * get_read_set()
Return a pointer to read-set list.
Definition: log_event.h:4226
int do_update_pos(Relay_log_info *rli) override
Advance relay log coordinates.
Definition: log_event.cc:13476
size_t get_data_size() override
Definition: log_event.cc:13483
int do_apply_event(Relay_log_info const *) override
Definition: log_event.h:4199
Sid_map * sid_map
The Sid_map to use for creating the Gtid_set.
Definition: log_event.h:4153
int pack_info(Protocol *protocol) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:13451
bool read_snapshot_version()
Read snapshot version from encoded buffers.
Definition: log_event.cc:13564
Gtid_set * snapshot_version
A gtid_set which is used to store the transaction set used for conflict detection.
Definition: log_event.h:4156
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:13365
const char * get_server_uuid()
Return the server uuid.
Definition: log_event.h:4244
size_t get_event_length()
Definition: log_event.cc:13495
size_t get_snapshot_version_size()
Definition: log_event.cc:13578
bool write_data_header(Basic_ostream *ostream) override
Definition: log_event.cc:13500
~Transaction_context_log_event() override
Definition: log_event.cc:13433
bool write_data_set(Basic_ostream *ostream, std::list< const char * > *set)
Definition: log_event.cc:13544