MySQL 8.0.30
Source Code Documentation
log_event.h
Go to the documentation of this file.
1/* Copyright (c) 2000, 2022, 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
73class THD;
74class Table_id;
75struct CHARSET_INFO;
76
77enum class enum_row_image_type;
78class 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
103#endif
104
105#ifndef MYSQL_SERVER
107#endif
108
112
113/* Forward declarations */
121
124
126#if defined(MYSQL_SERVER)
127int 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.
202#define MAX_MAX_ALLOWED_PACKET 1024 * 1024 * 1024
203
204/* slave event post-header (this event is never written) */
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).
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 arbitrarily 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.
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
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.
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.
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.
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).
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.
361const 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*/
374int get_rpl_part_id(partition_info *part_info);
375
376#ifdef MYSQL_SERVER
377class Item;
378class Protocol;
380class Slave_worker;
381class sql_exchange;
382template <class T>
383class List;
384#endif
385
386class Relay_log_info;
387class Gtid_log_event;
388
389#ifndef MYSQL_SERVER
390enum 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*/
411struct 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
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 statement.
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.
509 const char *name[MAX_DBS_IN_EVENT_MTS]{nullptr};
510 int num{0};
512 Mts_db_names() = default;
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 */
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
660class 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 };
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 immediately 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);
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();
913 virtual bool write_data_header(Basic_ostream *) { return false; }
914 virtual bool write_data_body(Basic_ostream *) { return false; }
915#endif
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 */
942 bool is_artificial_event() const {
945 bool is_relay_log_event() const {
948 bool is_ignorable_event() const {
951 bool is_no_filter_event() const {
954 inline bool is_using_trans_cache() const {
957 inline bool is_using_stmt_cache() const {
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 */
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;
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 against 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
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.
1032 /*
1033 Event is run by a Worker.
1036 /*
1037 Event is run by Coordinator.
1040 /*
1041 Event is run by Coordinator and requires synchronization with Workers.
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
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.
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 instances indicating how many
1155 databases the event accesses.
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.
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
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
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
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
1239 DBUG_TRACE;
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
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
1385class 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).
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.
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().
1417 bool has_ddl_committed;
1418
1419#ifdef MYSQL_SERVER
1420
1421 /**
1422 Instructs the applier to skip temporary tables handling.
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.
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
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
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 {
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).
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
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")) ||
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.
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 occurs 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. */
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.
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
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()) {
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
1747class 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()) {
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
1807typedef ulonglong my_xid; // this line is the same as in handler.h
1808#endif
1810class 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()) {
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;
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
1927 public:
1928#ifdef MYSQL_SERVER
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.
1958 bool is_deferred() { return deferred; }
1959 /*
1960 In case of the deferred applying the variable instance is flagged
1961 and the parsing time query id is stored to be used at applying time.
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
1983class Stop_log_event : public binary_log::Stop_event, public Log_event {
1984 public:
1985#ifdef MYSQL_SERVER
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
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
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
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
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
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
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*/
2345class 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
2367char *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
2390 public Log_event {
2391 public:
2392 /** Constants */
2394
2395 /**
2396 Enumeration of the errors that can be returned.
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 {
2421 TM_REFERRED_FK_DB_F = (1U << 1),
2422 /**
2423 Table has generated invisible primary key. MySQL generates primary key
2424 while creating a table if sql_generate_invisible_primary_key is "ON" and
2425 table is PK-less.
2426 */
2428 };
2430 flag_set get_flags(flag_set flag) const { return m_flags & flag; }
2431
2432#ifdef MYSQL_SERVER
2433 Table_map_log_event(THD *thd_arg, TABLE *tbl, const Table_id &tid,
2434 bool is_transactional);
2435#endif
2436 Table_map_log_event(const char *buf,
2437 const Format_description_event *description_event);
2439 ~Table_map_log_event() override;
2440
2441#ifndef MYSQL_SERVER
2442 table_def *create_table_def() {
2443 assert(m_colcnt > 0);
2446 }
2447 static bool rewrite_db_in_buffer(char **buf, ulong *event_len,
2448 const Format_description_event &fde);
2449#endif
2450 const Table_id &get_table_id() const { return m_table_id; }
2451 const char *get_table_name() const { return m_tblnam.c_str(); }
2452 const char *get_db_name() const { return m_dbnam.c_str(); }
2454 size_t get_data_size() override { return m_data_size; }
2455#ifdef MYSQL_SERVER
2456 virtual int save_field_metadata();
2457 bool write_data_header(Basic_ostream *ostream) override;
2458 bool write_data_body(Basic_ostream *ostream) override;
2459 const char *get_db() override { return m_dbnam.c_str(); }
2460 uint8 mts_number_dbs() override {
2462 }
2463 /**
2464 @param[out] arg pointer to a struct containing char* array
2465 pointers be filled in and the number of filled instances.
2466 @param rpl_filter pointer to a replication filter.
2467
2468 @return number of databases in the array: either one or
2469 OVER_MAX_DBS_IN_EVENT_MTS, when the Table map event reports
2470 foreign keys constraint.
2473 const char *db_name = get_db();
2474
2476 size_t dummy_len;
2477 const char *db_filtered = rpl_filter->get_rewrite_db(db_name, &dummy_len);
2478 // db_name != db_filtered means that db_name is rewritten.
2479 if (strcmp(db_name, db_filtered)) db_name = db_filtered;
2480 }
2481
2482 if (!get_flags(TM_REFERRED_FK_DB_F)) arg->name[0] = db_name;
2483
2484 return arg->num = mts_number_dbs();
2485 }
2486
2487#endif
2488
2489#if defined(MYSQL_SERVER)
2490 int pack_info(Protocol *protocol) override;
2491#endif
2492
2493#ifndef MYSQL_SERVER
2494 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
2495
2496 /**
2497 Print column metadata. Its format looks like:
2498 # Columns(colume_name type, colume_name type, ...)
2499 if colume_name field is not logged into table_map_log_event, then
2500 only type is printed.
2501
2502 @@param[out] file the place where colume metadata is printed
2503 @@param[in] The metadata extracted from optional metadata fields
2504 */
2505 void print_columns(IO_CACHE *file,
2506 const Optional_metadata_fields &fields) const;
2507 /**
2508 Print primary information. Its format looks like:
2509 # Primary Key(colume_name, column_name(prifix), ...)
2510 if colume_name field is not logged into table_map_log_event, then
2511 colume index is printed.
2512
2513 @@param[out] file the place where primary key is printed
2514 @@param[in] The metadata extracted from optional metadata fields
2515 */
2516 void print_primary_key(IO_CACHE *file,
2517 const Optional_metadata_fields &fields) const;
2518#endif
2520 bool is_rbr_logging_format() const override { return true; }
2521
2522 private:
2523#if defined(MYSQL_SERVER)
2524 int do_apply_event(Relay_log_info const *rli) override;
2525 int do_update_pos(Relay_log_info *rli) override;
2527#endif
2528
2529#ifdef MYSQL_SERVER
2530 TABLE *m_table;
2531
2532 // Metadata fields buffer
2534
2535 /**
2536 Wrapper around `TABLE *m_table` that abstracts the table field set iteration
2537 logic, since it is not mandatory that all table fields are to be
2538 replicated. For details, @see Replicated_columns_view class documentation.
2541
2542 /**
2543 Capture the optional metadata fields which should be logged into
2544 table_map_log_event and serialize them into m_metadata_buf.
2545 */
2546 void init_metadata_fields();
2547 bool init_signedness_field();
2548 /**
2549 Capture and serialize character sets. Character sets for
2550 character columns (TEXT etc) and character sets for ENUM and SET
2551 columns are stored in different metadata fields. The reason is
2552 that TEXT character sets are included even when
2553 binlog_row_metadata=MINIMAL, whereas ENUM and SET character sets
2554 are included only when binlog_row_metadata=FULL.
2555
2556 @param include_type Predicate to determine if a given Field object
2557 is to be included in the metadata field.
2558
2559 @param default_charset_type Type code when storing in "default
2560 charset" format. (See comment above Table_maps_log_event in
2561 libbinlogevents/include/rows_event.h)
2562
2563 @param column_charset_type Type code when storing in "column
2564 charset" format. (See comment above Table_maps_log_event in
2565 libbinlogevents/include/rows_event.h)
2566 */
2567 bool init_charset_field(std::function<bool(const Field *)> include_type,
2568 Optional_metadata_field_type default_charset_type,
2569 Optional_metadata_field_type column_charset_type);
2576#endif
2577
2578#ifndef MYSQL_SERVER
2579 class Charset_iterator;
2580 class Default_charset_iterator;
2581 class Column_charset_iterator;
2582#endif
2583};
2584
2585#ifdef HAVE_PSI_STAGE_INTERFACE
2586/*
2587 Helper class for PSI context while applying a Rows_log_event.
2590 private:
2593
2594 /**
2595 A cached pointer to this stage PSI_stage_progress.
2598
2599 /**
2600 Counter that is unconditionally incremented on each row that is processed.
2601 This is helpful in case estimation is needed after started processing
2602 a Rows_log_event.
2605
2606 public:
2609 void set_progress(PSI_stage_progress *progress) { m_progress = progress; }
2610
2611 /**
2612 If instrumentation is enabled this member function SHALL return true.
2613 @return true if instrumentation is enabled for the given stage, false
2614 otherwise.
2616 bool is_enabled() { return m_progress != nullptr; }
2617
2618 /**
2619 This member function shall update the progress and reestimate the remaining
2620 work needed. This MUST be called after setting n_rows_applied correctly
2621 by calling inc_n_rows_applied beforehand.
2622
2623 Cursor, begin and end are used in case estimation is needed.
2624
2625 @param cursor Pointer to where we are in the buffer of rows to be processed.
2626 @param begin Pointer to the beginning of the rows buffer.
2627 @param end Pointer to the end of the rows buffer.
2629 void update_work_estimated_and_completed(const uchar *cursor,
2630 const uchar *begin,
2631 const uchar *end) {
2632 if (!is_enabled()) return;
2633
2635
2636 /* Estimate if need be. */
2637 if (estimated == 0) {
2638 assert(cursor > begin);
2639 ulonglong avg_row_change_size = (cursor - begin) / m_n_rows_applied;
2640 estimated = (end - begin) / avg_row_change_size;
2642 }
2643
2644 /* reset estimated if done more work than estimated */
2645 if (m_n_rows_applied > estimated)
2648 }
2649
2650 /**
2651 Resets this object.
2653 void end_work() {
2654 m_progress = nullptr;
2655 m_n_rows_applied = 0;
2656 }
2657
2658 /**
2659 Updates the counter of processed rows.
2660 @param delta the amount of increment to be done.
2662 void inc_n_rows_applied(ulonglong delta) { m_n_rows_applied += delta; }
2663
2664 /**
2665 Gets the value of the counter of rows that have been processed.
2666 @return the value of the counter of rows processed so far.
2669};
2670#endif
2671
2672/**
2673 @class Rows_log_event
2674
2675 Common base class for all row-containing log events.
2676
2677 RESPONSIBILITIES
2678
2679 Encode the common parts of all events containing rows, which are:
2680 - Write data header and data body to an IO_CACHE.
2681
2682 Virtual inheritance is required here to handle the diamond problem in
2683 the class Write_rows_log_event, Update_rows_log_event and
2684 Delete_rows_log_event.
2685 The diamond structure is explained in @c Write_rows_log_event,
2686 @c Update_rows_log_event,
2687 @c Delete_rows_log_event
2688
2689 @internal
2690 The inheritance structure in the current design for the classes is
2691 as follows:
2692
2693 Binary_log_event
2694 ^
2695 |
2696 |
2697 Rows_event Log_event
2698 \ /
2699 <<vir>>\ /
2700 \ /
2701 Rows_log_event
2702 @endinternal
2703
2705class Rows_log_event : public virtual binary_log::Rows_event, public Log_event {
2706#ifdef HAVE_PSI_STAGE_INTERFACE
2707 protected:
2709#endif
2710
2711 public:
2712 typedef uint16 flag_set;
2720 };
2721
2722 /**
2723 Enumeration of the errors that can be returned.
2726 ERR_OPEN_FAILURE = -1, /**< Failure to open table */
2727 ERR_OK = 0, /**< No error */
2728 ERR_TABLE_LIMIT_EXCEEDED = 1, /**< No more room for tables */
2729 ERR_OUT_OF_MEM = 2, /**< Out of memory */
2730 ERR_BAD_TABLE_DEF = 3, /**< Table definition does not match */
2731 ERR_RBR_TO_SBR = 4 /**< daisy-chanining RBR to SBR not allowed */
2732 };
2733
2734 /* Special constants representing sets of flags */
2735 enum { RLE_NO_FLAGS = 0U };
2736
2737 ~Rows_log_event() override;
2739 void set_flags(flag_set flags_arg) { m_flags |= flags_arg; }
2740 void clear_flags(flag_set flags_arg) { m_flags &= ~flags_arg; }
2741 flag_set get_flags(flag_set flags_arg) const { return m_flags & flags_arg; }
2742
2744 get_general_type_code() = 0; /* General rows op type, no version */
2745
2746#if defined(MYSQL_SERVER)
2747 int pack_info(Protocol *protocol) override;
2748#endif
2749
2750#ifndef MYSQL_SERVER
2751 void print_verbose(IO_CACHE *file, PRINT_EVENT_INFO *print_event_info);
2752 size_t print_verbose_one_row(IO_CACHE *file, table_def *td,
2753 PRINT_EVENT_INFO *print_event_info,
2754 MY_BITMAP *cols_bitmap, const uchar *ptr,
2755 const uchar *prefix,
2756 enum_row_image_type row_image_type);
2757#endif
2758
2759#ifdef MYSQL_SERVER
2760 int add_row_data(uchar *data, size_t length) {
2761 return do_add_row_data(data, length);
2762 }
2763#endif
2764
2765 /* Member functions to implement superclass interface */
2766 size_t get_data_size() override;
2768 MY_BITMAP const *get_cols() const { return &m_cols; }
2769 MY_BITMAP const *get_cols_ai() const { return &m_cols_ai; }
2770 size_t get_width() const { return m_width; }
2771 const Table_id &get_table_id() const { return m_table_id; }
2772
2773#if defined(MYSQL_SERVER)
2774 /**
2775 Compares the table's read/write_set with the columns included in
2776 this event's before-image and/or after-image. Each subclass
2777 (Write/Update/Delete) implements this function by comparing on the
2778 image(s) pertinent to the subclass.
2779
2780 @param[in] table The table to compare this events bitmaps
2781 against.
2782
2783 @retval true if sets match
2784 @retval false otherwise (following bitmap_cmp return logic).
2786 virtual bool read_write_bitmaps_cmp(const TABLE *table) const = 0;
2787#endif
2788
2789#ifdef MYSQL_SERVER
2790 bool write_data_header(Basic_ostream *ostream) override;
2791 bool write_data_body(Basic_ostream *ostream) override;
2792 const char *get_db() override { return m_table->s->db.str; }
2793#endif
2795 uint m_row_count; /* The number of rows added to the event */
2796
2797 protected:
2798 /*
2799 The constructors are protected since you're supposed to inherit
2800 this class, not create instances of this class.
2801 */
2802#ifdef MYSQL_SERVER
2803 Rows_log_event(THD *, TABLE *, const Table_id &table_id,
2804 MY_BITMAP const *cols, bool is_transactional,
2805 Log_event_type event_type,
2806 const unsigned char *extra_row_ndb_info);
2807#endif
2808 Rows_log_event(const char *row_data,
2809 const Format_description_event *description_event);
2810
2811#ifndef MYSQL_SERVER
2812 void print_helper(FILE *, PRINT_EVENT_INFO *) const;
2813#endif
2814
2815#ifdef MYSQL_SERVER
2816 virtual int do_add_row_data(uchar *data, size_t length);
2817#endif
2818
2819#ifdef MYSQL_SERVER
2820 TABLE *m_table; /* The table the rows belong to */
2821#endif
2822 MY_BITMAP m_cols; /* Bitmap denoting columns available */
2823 /**
2824 Bitmap denoting columns available in the image as they appear in the table
2825 setup. On some setups, the number and order of columns may differ from
2826 master to slave so, a bitmap for local available columns is computed using
2827 `Replicated_columns_view` utility class.
2830#ifdef MYSQL_SERVER
2831 /**
2832 Hash table that will hold the entries for while using HASH_SCAN
2833 algorithm to search and update/delete rows.
2836
2837 /**
2838 The algorithm to use while searching for rows using the before
2839 image.
2842#endif
2843 /**
2844 Bitmap for columns available in the after image, if present. These
2845 fields are only available for Update_rows events. Observe that the
2846 width of both the before image COLS vector and the after image
2847 COLS vector is the same: the number of columns of the table on the
2848 master.
2851 /**
2852 Bitmap denoting columns available in the after-image as they appear in the
2853 table setup. On some setups, the number and order of columns may differ from
2854 master to slave so, a bitmap for local available columns is computed using
2855 `Replicated_columns_view` utility class.
2858
2859 /* Bit buffers in the same memory as the class */
2860 uint32 m_bitbuf[128 / (sizeof(uint32) * 8)];
2861 uint32 m_bitbuf_ai[128 / (sizeof(uint32) * 8)];
2862
2863 /*
2864 is_valid depends on the value of m_rows_buf, so while changing the value
2865 of m_rows_buf check if is_valid also needs to be modified
2867 uchar *m_rows_buf; /* The rows in packed format */
2868 uchar *m_rows_cur; /* One-after the end of the data */
2869 uchar *m_rows_end; /* One-after the end of the allocated space */
2870
2871 /* helper functions */
2872
2873#if defined(MYSQL_SERVER)
2874 const uchar *m_curr_row; /* Start of the row being processed */
2875 const uchar *m_curr_row_end; /* One-after the end of the current row */
2876 uchar *m_key; /* Buffer to keep key value during searches */
2878 KEY *m_key_info; /* Points to description of index #m_key_index */
2879 class Key_compare {
2880 public:
2881 /**
2882 @param ki Where to find KEY description
2883 @note m_distinct_keys is instantiated when Rows_log_event is constructed;
2884 it stores a Key_compare object internally. However at that moment, the
2885 index (KEY*) to use for comparisons, is not yet known. So, at
2886 instantiation, we indicate the Key_compare the place where it can
2887 find the KEY* when needed (this place is Rows_log_event::m_key_info),
2888 Key_compare remembers the place in member m_key_info.
2889 Before we need to do comparisons - i.e. before we need to insert
2890 elements, we update Rows_log_event::m_key_info once for all.
2892 Key_compare(KEY **ki = nullptr) : m_key_info(ki) {}
2893 bool operator()(uchar *k1, uchar *k2) const {
2894 return key_cmp2((*m_key_info)->key_part, k1, (*m_key_info)->key_length,
2895 k2, (*m_key_info)->key_length) < 0;
2896 }
2897
2898 private:
2899 KEY **m_key_info;
2901 std::set<uchar *, Key_compare> m_distinct_keys;
2902 std::set<uchar *, Key_compare>::iterator m_itr;
2903 /**
2904 A spare buffer which will be used when saving the distinct keys
2905 for doing an index scan with HASH_SCAN search algorithm.
2908 /**
2909 Container to hold and manage the relevant TABLE fields
2912
2913 /**
2914 Unpack the current row image from the event into m_table->record[0].
2915
2916 @param rli The applier context.
2917
2918 @param cols The bitmap of columns included in the update.
2919
2920 @param is_after_image Should be true if this is an after-image,
2921 false if it is a before-image.
2922
2923 @param only_seek unpack_row()
2924
2925 @retval 0 Success
2926
2927 @retval ER_* On error, it is guaranteed that the error has been
2928 reported through my_error, and the corresponding ER_* code is
2929 returned. Currently the error codes are: EE_OUTOFMEMORY,
2930 ER_SLAVE_CORRUPT_EVENT, or various JSON errors when applying JSON
2931 diffs (ER_COULD_NOT_APPLY_JSON_DIFF, ER_INVALID_JSON_BINARY_DATA,
2932 and maybe others).
2933 */
2934 int unpack_current_row(const Relay_log_info *const rli, MY_BITMAP const *cols,
2935 bool is_after_image, bool only_seek = false);
2936 /**
2937 Updates the generated columns of the `TABLE` object referenced by
2938 `m_table`, that have an active bit in the parameter bitset
2939 `fields_to_update`.
2940
2941 @param fields_to_update A bitset where the bit at the index of
2942 generated columns to update must be set to `1`
2943
2944 @return 0 if the operation terminated successfully, 1 otherwise.
2945 */
2946 int update_generated_columns(MY_BITMAP const &fields_to_update);
2947 /*
2948 This member function is called when deciding the algorithm to be used to
2949 find the rows to be updated on the slave during row based replication.
2950 This this functions sets the m_rows_lookup_algorithm and also the
2951 m_key_index with the key index to be used if the algorithm is dependent on
2952 an index.
2953 TODO(Bug#31173056): Remove SUPPRESS_UBSAN_CLANG10
2954 */
2956
2957 /*
2958 Encapsulates the operations to be done before applying
2959 row event for update and delete.
2960 */
2962
2963 /*
2964 Encapsulates the operations to be done after applying
2965 row event for update and delete.
2966 */
2968
2969 /**
2970 Helper function to check whether there is an auto increment
2971 column on the table where the event is to be applied.
2972
2973 @return true if there is an autoincrement field on the extra
2974 columns, false otherwise.
2975 */
2977
2978 /**
2979 Helper function to check whether the storage engine error
2980 allows for the transaction to be retried or not.
2981
2982 @param error Storage engine error
2983 @retval true if the error is retryable.
2984 @retval false if the error is non-retryable.
2985 */
2987#endif
2989 bool is_rbr_logging_format() const override { return true; }
2990
2991 private:
2992#if defined(MYSQL_SERVER)
2993 int do_apply_event(Relay_log_info const *rli) override;
2994 int do_update_pos(Relay_log_info *rli) override;
2996
2997 /*
2998 Primitive to prepare for a sequence of row executions.
2999
3000 DESCRIPTION
3001
3002 Before doing a sequence of do_prepare_row() and do_exec_row()
3003 calls, this member function should be called to prepare for the
3004 entire sequence. Typically, this member function will allocate
3005 space for any buffers that are needed for the two member
3006 functions mentioned above.
3007
3008 RETURN VALUE
3009
3010 The member function will return 0 if all went OK, or a non-zero
3011 error code otherwise.
3013 virtual int do_before_row_operations(
3014 const Slave_reporting_capability *const log) = 0;
3015
3016 /*
3017 Primitive to clean up after a sequence of row executions.
3018
3019 DESCRIPTION
3020
3021 After doing a sequence of do_prepare_row() and do_exec_row(),
3022 this member function should be called to clean up and release
3023 any allocated buffers.
3024
3025 The error argument, if non-zero, indicates an error which happened during
3026 row processing before this function was called. In this case, even if
3027 function is successful, it should return the error code given in the
3028 argument.
3030 virtual int do_after_row_operations(
3031 const Slave_reporting_capability *const log, int error) = 0;
3032
3033 /*
3034 Primitive to do the actual execution necessary for a row.
3035
3036 DESCRIPTION
3037 The member function will do the actual execution needed to handle a row.
3038 The row is located at m_curr_row. When the function returns,
3039 m_curr_row_end should point at the next row (one byte after the end
3040 of the current row).
3041
3042 RETURN VALUE
3043 0 if execution succeeded, 1 if execution failed.
3044
3046 virtual int do_exec_row(const Relay_log_info *const rli) = 0;
3047
3048 /**
3049 Private member function called while handling idempotent errors.
3050
3051 @param rli Pointer to relay log info structure.
3052 @param [in,out] err the error to handle. If it is listed as
3053 idempotent/ignored related error, then it is cleared.
3054 @returns true if the slave should stop executing rows.
3055 */
3057
3058 /**
3059 Private member function called after updating/deleting a row. It
3060 performs some assertions and more importantly, it updates
3061 m_curr_row so that the next row is processed during the row
3062 execution main loop (@c Rows_log_event::do_apply_event()).
3063
3064 @param rli Pointer to relay log info structure.
3065 @param err the current error code.
3066 */
3067 void do_post_row_operations(Relay_log_info const *rli, int err);
3068
3069 /**
3070 Commodity wrapper around do_exec_row(), that deals with resetting
3071 the thd reference in the table.
3072 */
3073 int do_apply_row(Relay_log_info const *rli);
3074
3075 /**
3076 Implementation of the index scan and update algorithm. It uses
3077 PK, UK or regular Key to search for the record to update. When
3078 found it updates it.
3079 */
3081
3082 /**
3083 Implementation of the hash_scan and update algorithm. It collects
3084 rows positions in a hashtable until the last row is
3085 unpacked. Then it scans the table to update and when a record in
3086 the table matches the one in the hashtable, the update/delete is
3087 performed.
3088 */
3090
3091 /**
3092 Implementation of the legacy table_scan and update algorithm. For
3093 each unpacked row it scans the storage engine table for a
3094 match. When a match is found, the update/delete operations are
3095 performed.
3096 */
3098
3099 /**
3100 Seek past the after-image of an update event, in case a row was processed
3101 without reading the after-image.
3102
3103 An update event may process a row without reading the after-image,
3104 e.g. in case of ignored or idempotent errors. To ensure that the
3105 read position for the next row is correct, we need to seek past
3106 the after-image.
3107
3108 @param rli The applier context
3109
3110 @param curr_bi_start The read position of the beginning of the
3111 before-image. (The function compares this with m_curr_row to know
3112 if the after-image has been read or not.)
3113
3114 @retval 0 Success
3115 @retval ER_* Error code returned by unpack_current_row
3118 [[maybe_unused]],
3119 const uchar *curr_bi_start
3120 [[maybe_unused]]) {
3121 return 0;
3122 }
3123
3124 /**
3125 Initializes scanning of rows. Opens an index and initializes an iterator
3126 over a list of distinct keys (m_distinct_keys) if it is a HASH_SCAN
3127 over an index or the table if its a HASH_SCAN over the table.
3128 */
3129 int open_record_scan();
3130
3131 /**
3132 Does the cleanup
3133 - closes the index if opened by open_record_scan
3134 - closes the table if opened for scanning.
3135 */
3136 int close_record_scan();
3137
3138 /**
3139 Fetches next row. If it is a HASH_SCAN over an index, it populates
3140 table->record[0] with the next row corresponding to the index. If
3141 the indexes are in non-contigous ranges it fetches record corresponding
3142 to the key value in the next range.
3143
3144 @param first_read signifying if this is the first time we are reading a row
3145 over an index.
3146 @return error code when there are no more records to be fetched or some
3147 other error occurred,
3148 - 0 otherwise.
3149 */
3150 int next_record_scan(bool first_read);
3151
3152 /**
3153 Populates the m_distinct_keys with unique keys to be modified
3154 during HASH_SCAN over keys.
3155 @returns 0 success, or the error code.
3156 */
3158
3159 /**
3160 Populates the m_hash when using HASH_SCAN. Thence, it:
3161 - unpacks the before image (BI)
3162 - saves the positions
3163 - saves the positions into the hash map, using the
3164 BI checksum as key
3165 - unpacks the after image (AI) if needed, so that
3166 m_curr_row_end gets updated correctly.
3167
3168 @param rli The reference to the relay log info object.
3169 @returns 0 on success. Otherwise, the error code.
3170 */
3171 int do_hash_row(Relay_log_info const *rli);
3172
3173 /**
3174 This member function scans the table and applies the changes
3175 that had been previously hashed. As such, m_hash MUST be filled
3176 by do_hash_row before calling this member function.
3177
3178 @param rli The reference to the relay log info object.
3179 @returns 0 on success. Otherwise, the error code.
3180 */
3181 int do_scan_and_update(Relay_log_info const *rli);
3182#endif /* defined(MYSQL_SERVER) */
3184 friend class Old_rows_log_event;
3185
3186 /**
3187 This bitmap is used as a backup for the write set while we calculate
3188 the values for any hidden generated columns (functional indexes). In order
3189 to calculate the values, the columns must be marked in the write set. After
3190 the values are calculated, we set the write set back to its original value.
3193};
3194
3195/**
3196 @class Write_rows_log_event
3197
3198 Log row insertions and updates. The event contain several
3199 insert/update rows for a table. Note that each event contains only
3200 rows for one table.
3201
3202 @internal
3203 The inheritance structure is as follows
3204
3205 Binary_log_event
3206 ^
3207 |
3208 |
3209 |
3210 Log_event B_l:Rows_event
3211 ^ /\
3212 | / \
3213 | <<vir>>/ \ <<vir>>
3214 | / \
3215 | / \
3216 | / \
3217 Rows_log_event B_l:W_R_E
3218 \ /
3219 \ /
3220 \ /
3221 \ /
3222 \ /
3223 \/
3224 Write_rows_log_event
3225
3226 B_l: Namespace Binary_log
3227 W_R_E: class Write_rows_event
3228 @endinternal
3229
3233 public:
3234 enum {
3235 /* Support interface to THD::binlog_prepare_pending_rows_event */
3237 };
3238
3239#if defined(MYSQL_SERVER)
3240 Write_rows_log_event(THD *, TABLE *, const Table_id &table_id,
3241 bool is_transactional,
3242 const unsigned char *extra_row_ndb_info);
3243#endif
3244 Write_rows_log_event(const char *buf,
3245 const Format_description_event *description_event);
3246#if defined(MYSQL_SERVER)
3247 static bool binlog_row_logging_function(THD *thd, TABLE *table,
3248 bool is_transactional,
3249 const uchar *before_record
3250 [[maybe_unused]],
3251 const uchar *after_record);
3252 bool read_write_bitmaps_cmp(const TABLE *table) const override {
3253 return bitmap_cmp(get_cols(), table->write_set);
3254 }
3255#endif
3256
3257 protected:
3258 int write_row(const Relay_log_info *const, const bool);
3259
3260 private:
3262 return (Log_event_type)TYPE_CODE;
3263 }
3264
3265#ifndef MYSQL_SERVER
3266 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
3267#endif
3268
3269#if defined(MYSQL_SERVER)
3271 const Slave_reporting_capability *const) override;
3273 int) override;
3274 int do_exec_row(const Relay_log_info *const) override;
3275#endif
3276};
3277
3278/**
3279 @class Update_rows_log_event
3280
3281 Log row updates with a before image. The event contain several
3282 update rows for a table. Note that each event contains only rows for
3283 one table.
3284
3285 Also note that the row data consists of pairs of row data: one row
3286 for the old data and one row for the new data.
3287
3288 @internal
3289 The inheritance structure is as follows
3290
3291 Binary_log_event
3292 ^
3293 |
3294 |
3295 |
3296 Log_event B_l:Rows_event
3297 ^ /\
3298 | / \
3299 | <<vir>>/ \ <<vir>>
3300 | / \
3301 | / \
3302 | / \
3303 Rows_log_event B_l:U_R_E
3304 \ /
3305 \ /
3306 \ /
3307 \ /
3308 \ /
3309 \/
3310 Update_rows_log_event
3311
3312
3313 B_l: Namespace Binary_log
3314 U_R_E: class Update_rows_event
3315 @eninternal
3316
3320 public:
3321 enum {
3322 /* Support interface to THD::binlog_prepare_pending_rows_event */
3324 };
3325
3326#ifdef MYSQL_SERVER
3327 Update_rows_log_event(THD *, TABLE *, const Table_id &table_id,
3328 MY_BITMAP const *cols_bi, MY_BITMAP const *cols_ai,
3329 bool is_transactional,
3330 const unsigned char *extra_row_ndb_info);
3331
3332 Update_rows_log_event(THD *, TABLE *, const Table_id &table_id,
3333 bool is_transactional,
3334 const unsigned char *extra_row_ndb_info);
3335
3336 void init(MY_BITMAP const *cols);
3337#endif
3338
3339 ~Update_rows_log_event() override;
3340
3341 Update_rows_log_event(const char *buf,
3342 const Format_description_event *description_event);
3343
3344#ifdef MYSQL_SERVER
3345 static bool binlog_row_logging_function(THD *thd, TABLE *table,
3346 bool is_transactional,
3347 const uchar *before_record,
3348 const uchar *after_record);
3349 bool read_write_bitmaps_cmp(const TABLE *table) const override {
3350 return (bitmap_cmp(get_cols(), table->read_set) &&
3351 bitmap_cmp(get_cols_ai(), table->write_set));
3352 }
3353#endif
3354
3355 protected:
3357 return (Log_event_type)TYPE_CODE;
3358 }
3359
3360#ifndef MYSQL_SERVER
3361 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
3362#endif
3363
3364#if defined(MYSQL_SERVER)
3366 const Slave_reporting_capability *const) override;
3368 int) override;
3369 int do_exec_row(const Relay_log_info *const) override;
3370
3372 const uchar *curr_bi_start) override;
3373
3374 private:
3375 /**
3376 Auxiliary function used in the (THD*, ...) constructor to
3377 determine the type code based on configuration options.
3378
3379 @param thd_arg The THD object for the session.
3380
3381 @return One of UPDATE_ROWS_EVENT_V1, PARTIAL_UPDATE_ROWS_EVENT, or
3382 UPDATE_ROWS_EVENT.
3383 */
3385 const THD *thd_arg);
3386#endif /* defined(MYSQL_SERVER) */
3387};
3388
3389/**
3390 @class Delete_rows_log_event
3391
3392 Log row deletions. The event contain several delete rows for a
3393 table. Note that each event contains only rows for one table.
3394
3395 RESPONSIBILITIES
3396
3397 - Act as a container for rows that has been deleted on the master
3398 and should be deleted on the slave.
3399
3400 COLLABORATION
3401
3402 Row_writer
3403 Create the event and add rows to the event.
3404 Row_reader
3405 Extract the rows from the event.
3406
3407 @internal
3408 The inheritance structure is as follows
3409
3410 Binary_log_event
3411 ^
3412 |
3413 |
3414 |
3415 Log_event B_l:Rows_event
3416 ^ /\
3417 | / \
3418 | <<vir>>/ \ <<vir>>
3419 | / \
3420 | / \
3421 | / \
3422 Rows_log_event B_l:D_R_E
3423 \ /
3424 \ /
3425 \ /
3426 \ /
3427 \ /
3428 \/
3429 Delete_rows_log_event
3430
3431 B_l: Namespace Binary_log
3432 D_R_E: class Delete_rows_event
3433 @endinternal
3434
3438 public:
3439 enum {
3440 /* Support interface to THD::binlog_prepare_pending_rows_event */
3442 };
3443
3444#ifdef MYSQL_SERVER
3445 Delete_rows_log_event(THD *, TABLE *, const Table_id &, bool is_transactional,
3446 const unsigned char *extra_row_ndb_info);
3447#endif
3448 Delete_rows_log_event(const char *buf,
3449 const Format_description_event *description_event);
3450#ifdef MYSQL_SERVER
3451 static bool binlog_row_logging_function(THD *thd, TABLE *table,
3452 bool is_transactional,
3453 const uchar *before_record,
3454 const uchar *after_record
3455 [[maybe_unused]]);
3456 bool read_write_bitmaps_cmp(const TABLE *table) const override {
3457 return bitmap_cmp(get_cols(), table->read_set);
3458 }
3459#endif
3460
3461 protected:
3463 return (Log_event_type)TYPE_CODE;
3464 }
3465
3466#ifndef MYSQL_SERVER
3467 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
3468#endif
3469
3470#if defined(MYSQL_SERVER)
3472 const Slave_reporting_capability *const) override;
3474 int) override;
3475 int do_exec_row(const Relay_log_info *const) override;
3476#endif
3477};
3478
3479/**
3480 @class Incident_log_event
3481
3482 Class representing an incident, an occurrence out of the ordinary,
3483 that happened on the master.
3484
3485 The event is used to inform the slave that something out of the
3486 ordinary happened on the master that might cause the database to be
3487 in an inconsistent state.
3488
3489 It's the derived class of Incident_event
3490
3491 @internal
3492 The inheritance structure is as follows
3493
3494 Binary_log_event
3495 ^
3496 |
3497 |
3498 B_l:Incident_event Log_event
3499 \ /
3500 \ /
3501 \ /
3502 \ /
3503 Incident_log_event
3504
3505 B_l: Namespace Binary_log
3506 @endinternal
3507
3510 public:
3511#ifdef MYSQL_SERVER
3512 Incident_log_event(THD *thd_arg, enum_incident incident_arg)
3513 : binary_log::Incident_event(incident_arg),
3516 DBUG_TRACE;
3517 DBUG_PRINT("enter", ("incident: %d", incident_arg));
3518 common_header->set_is_valid(incident_arg > INCIDENT_NONE &&
3519 incident_arg < INCIDENT_COUNT);
3520 assert(message == nullptr && message_length == 0);
3521 return;
3522 }
3524 Incident_log_event(THD *thd_arg, enum_incident incident_arg,
3525 LEX_CSTRING const msg)
3526 : binary_log::Incident_event(incident_arg),
3529 DBUG_TRACE;
3530 DBUG_PRINT("enter", ("incident: %d", incident_arg));
3531 common_header->set_is_valid(incident_arg > INCIDENT_NONE &&
3532 incident_arg < INCIDENT_COUNT);
3533 assert(message == nullptr && message_length == 0);
3535 msg.length + 1, MYF(MY_WME)))) {
3536 // The allocation failed. Mark this binlog event as invalid.
3538 return;
3539 }
3540 strmake(message, msg.str, msg.length);
3541 message_length = msg.length;
3542 return;
3543 }
3544#endif
3545
3546#ifdef MYSQL_SERVER
3547 int pack_info(Protocol *) override;
3548#endif
3549
3550 Incident_log_event(const char *buf,
3551 const Format_description_event *description_event);
3552
3553 ~Incident_log_event() override;
3554
3555#ifndef MYSQL_SERVER
3556 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
3557#endif
3558
3559#if defined(MYSQL_SERVER)
3560 int do_apply_event(Relay_log_info const *rli) override;
3561 bool write_data_header(Basic_ostream *ostream) override;
3562 bool write_data_body(Basic_ostream *ostream) override;
3563#endif
3565 size_t get_data_size() override {
3566 return Binary_log_event::INCIDENT_HEADER_LEN + 1 + message_length;
3567 }
3569 bool ends_group() const override { return true; }
3570
3571 private:
3572 const char *description() const;
3573};
3574
3575/**
3576 @class Ignorable_log_event
3577
3578 Base class for ignorable log events is Ignorable_event.
3579 Events deriving from this class can be safely ignored
3580 by slaves that cannot recognize them.
3581
3582 Its the derived class of Ignorable_event
3583
3584 @internal
3585 The inheritance structure is as follows
3586
3587 Binary_log_event
3588 ^
3589 |
3590 |
3591 B_l:Ignorable_event Log_event
3592 \ /
3593 <<virtual>>\ /
3594 \ /
3595 Ignorable_log_event
3596
3597 B_l: Namespace Binary_log
3598 @endinternal
3601 public Log_event {
3602 public:
3603#ifdef MYSQL_SERVER
3604 Ignorable_log_event(THD *thd_arg)
3607 DBUG_TRACE;
3609 return;
3610 }
3611#endif
3612
3613 Ignorable_log_event(const char *buf,
3614 const Format_description_event *descr_event);
3615 ~Ignorable_log_event() override;
3616
3617#ifdef MYSQL_SERVER
3618 int pack_info(Protocol *) override;
3619#endif
3620
3621#ifndef MYSQL_SERVER
3622 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
3623#endif
3625 size_t get_data_size() override {
3626 return Binary_log_event::IGNORABLE_HEADER_LEN;
3627 }
3628};
3629
3630/**
3631 @class Rows_query_log_event
3632 It is used to record the original query for the rows
3633 events in RBR.
3634 It is the subclass of Ignorable_log_event and Rows_query_event
3635
3636 @internal
3637 The inheritance structure in the current design for the classes is
3638 as follows:
3639 Binary_log_event
3640 ^
3641 |
3642 |
3643 |
3644 Log_event B_l:Ignorable_event
3645 ^ /\
3646 | / \
3647 | <<vir>>/ \ <<vir>>
3648 | / \
3649 | / \
3650 | / \
3651 Ignorable_log_event B_l:Rows_query_event
3652 \ /
3653 \ /
3654 \ /
3655 \ /
3656 \ /
3657 \/
3658 Rows_query_log_event
3659
3660 B_l : namespace binary_log
3661 @endinternal
3665 public:
3666#ifdef MYSQL_SERVER
3667 Rows_query_log_event(THD *thd_arg, const char *query, size_t query_len)
3668 : Ignorable_log_event(thd_arg) {
3669 DBUG_TRACE;
3671 if (!(m_rows_query =
3673 query_len + 1, MYF(MY_WME))))
3674 return;
3675 snprintf(m_rows_query, query_len + 1, "%s", query);
3676 DBUG_PRINT("enter", ("%s", m_rows_query));
3677 return;
3678 }
3679#endif
3680
3681#ifdef MYSQL_SERVER
3682 int pack_info(Protocol *) override;
3683 int do_apply_event(Relay_log_info const *rli) override;
3684 bool write_data_body(Basic_ostream *ostream) override;
3685#endif
3686
3687 Rows_query_log_event(const char *buf,
3688 const Format_description_event *descr_event);
3690 ~Rows_query_log_event() override {
3692 m_rows_query = nullptr;
3693 }
3694#ifndef MYSQL_SERVER
3695 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
3696#endif
3697 size_t get_data_size() override {
3698 return Binary_log_event::IGNORABLE_HEADER_LEN + 1 + strlen(m_rows_query);
3699 }
3700};
3702static inline bool copy_event_cache_to_file_and_reinit(IO_CACHE *cache,
3703 FILE *file,
3704 bool flush_stream) {
3705 return my_b_copy_to_file(cache, file) ||
3706 (flush_stream ? (fflush(file) || ferror(file)) : 0) ||
3707 reinit_io_cache(cache, WRITE_CACHE, 0, false, true);
3708}
3709
3710#ifdef MYSQL_SERVER
3711/*****************************************************************************
3712
3713 Heartbeat Log Event class
3714
3715 The class is not logged to a binary log, and is not applied on to the slave.
3716 The decoding of the event on the slave side is done by its superclass,
3717 binary_log::Heartbeat_event.
3718
3719 ****************************************************************************/
3721 public Log_event {
3722 public:
3723 Heartbeat_log_event(const char *buf,
3724 const Format_description_event *description_event);
3725};
3728 public Log_event {
3729 public:
3730 Heartbeat_log_event_v2(const char *buf,
3731 const Format_description_event *description_event);
3732};
3733/**
3734 The function is called by slave applier in case there are
3735 active table filtering rules to force gathering events associated
3736 with Query-log-event into an array to execute
3737 them once the fate of the Query is determined for execution.
3738*/
3740#endif
3741
3742int append_query_string(const THD *thd, const CHARSET_INFO *csinfo,
3743 String const *from, String *to);
3748 public Log_event {
3749 public:
3750#ifdef MYSQL_SERVER
3752 class Applier_context {
3753 private:
3754 // context for the applier (to remove if we remove the DATABASE scheduler)
3756
3757 public:
3758 Applier_context() = default;
3759 virtual ~Applier_context() { reset(); }
3762 };
3764 Transaction_payload_log_event(THD *thd_arg, const char *payload,
3765 uint64_t payload_size,
3766 uint16_t compression_type,
3767 uint64_t uncompressed_size)
3768 : Transaction_payload_event(payload, payload_size, compression_type,
3769 uncompressed_size),
3770 Log_event(thd_arg, 0 /* flags */, Log_event::EVENT_TRANSACTIONAL_CACHE,
3773 Transaction_payload_log_event(THD *thd_arg, const char *payload,
3774 uint64_t payload_size)
3776 thd_arg, payload, payload_size,
3777 binary_log::transaction::compression::type::NONE, payload_size) {}
3780 : Transaction_payload_log_event(thd_arg, nullptr, (uint64_t)0) {}
3781#endif
3784 const Format_description_event *fde)
3787 ~Transaction_payload_log_event() override = default;
3788
3789#ifndef MYSQL_SERVER
3790 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
3791#endif
3793 size_t get_event_length() { return LOG_EVENT_HEADER_LEN + get_data_size(); }
3794 size_t get_data_size() override;
3795
3796#if defined(MYSQL_SERVER)
3797 private:
3799
3800 public:
3801 int do_apply_event(Relay_log_info const *rli) override;
3802 bool apply_payload_event(Relay_log_info const *rli, const uchar *event_buf);
3804 int pack_info(Protocol *protocol) override;
3805 bool ends_group() const override;
3806 bool write(Basic_ostream *ostream) override;
3808 void set_mts_dbs(Mts_db_names &arg);
3809 uint8 mts_number_dbs() override;
3810#endif
3811};
3812
3813/**
3814 @class Gtid_log_event
3815
3816 This is a subclass if Gtid_event and Log_event. It contains
3817 per-transaction fields, including the GTID and logical timestamps
3818 used by MTS.
3819
3820 @internal
3821 The inheritance structure is as follows
3822
3823 Binary_log_event
3824 ^
3825 |
3826 |
3827 B_l:Gtid_event Log_event
3828 \ /
3829 \ /
3830 \ /
3831 \ /
3832 Gtid_log_event
3833
3834 B_l: Namespace Binary_log
3835 @endinternal
3837class Gtid_log_event : public binary_log::Gtid_event, public Log_event {
3838 public:
3839#ifdef MYSQL_SERVER
3840 /**
3841 Create a new event using the GTID owned by the given thread.
3842 */
3843 Gtid_log_event(THD *thd_arg, bool using_trans, int64 last_committed_arg,
3844 int64 sequence_number_arg, bool may_have_sbr_stmts_arg,
3845 ulonglong original_commit_timestamp_arg,
3846 ulonglong immediate_commit_timestamp_arg,
3847 uint32_t original_server_version_arg,
3848 uint32_t immediate_server_version_arg);
3849
3850 /**
3851 Create a new event using the GTID from the given Gtid_specification
3852 without a THD object.
3853 */
3854 Gtid_log_event(uint32 server_id_arg, bool using_trans,
3855 int64 last_committed_arg, int64 sequence_number_arg,
3856 bool may_have_sbr_stmts_arg,
3857 ulonglong original_commit_timestamp_arg,
3858 ulonglong immediate_commit_timestamp_arg,
3859 const Gtid_specification spec_arg,
3860 uint32_t original_server_version_arg,
3861 uint32_t immediate_server_version_arg);
3862#endif
3863
3864#ifdef MYSQL_SERVER
3865 int pack_info(Protocol *) override;
3866#endif
3867 Gtid_log_event(const char *buffer,
3868 const Format_description_event *description_event);
3870 ~Gtid_log_event() override = default;
3872 size_t get_data_size() override {
3873 DBUG_EXECUTE_IF("do_not_write_rpl_timestamps", return POST_HEADER_LENGTH;);
3876 }
3878 size_t get_event_length() { return LOG_EVENT_HEADER_LEN + get_data_size(); }
3879
3880 private:
3881 /// Used internally by both print() and pack_info().
3882 size_t to_string(char *buf) const;
3883
3884#ifdef MYSQL_SERVER
3885 /**
3886 Writes the post-header to the given output stream.
3887
3888 This is an auxiliary function typically used by the write() member
3889 function.
3890
3891 @param ostream The output stream to write to.
3892
3893 @retval true Error.
3894 @retval false Success.
3895 */
3896 bool write_data_header(Basic_ostream *ostream) override;
3897 bool write_data_body(Basic_ostream *ostream) override;
3898 /**
3899 Writes the post-header to the given memory buffer.
3900
3901 This is an auxiliary function used by write_to_memory.
3902
3903 @param[in,out] buffer Buffer to which the post-header will be written.
3904
3905 @return The number of bytes written, i.e., always
3906 Gtid_log_event::POST_HEADER_LENGTH.
3907 */
3909
3910 /**
3911 Writes the body to the given memory buffer.
3912
3913 This is an auxiliary function used by write_to_memory.
3914
3915 @param [in,out] buff Buffer to which the data will be written.
3916
3917 @return The number of bytes written, i.e.,
3918 If the transaction did not originated on this server
3919 Gtid_event::IMMEDIATE_COMMIT_TIMESTAMP_LENGTH.
3920 else
3921 FULL_COMMIT_TIMESTAMP_LENGTH.
3922 */
3924#endif
3925
3926 public:
3927#ifndef MYSQL_SERVER
3928 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
3929#endif
3930
3931#if defined(MYSQL_SERVER)
3932 int do_apply_event(Relay_log_info const *rli) override;
3933 int do_update_pos(Relay_log_info *rli) override;
3935#endif
3936
3937 /**
3938 Return the gtid type for this Gtid_log_event: this can be
3939 either ANONYMOUS_GTID, AUTOMATIC_GTID, or ASSIGNED_GTID.
3941 enum_gtid_type get_type() const { return spec.type; }
3942
3943 /**
3944 Return the SID for this GTID. The SID is shared with the
3945 Log_event so it should not be modified.
3947 const rpl_sid *get_sid() const { return &sid; }
3948 /**
3949 Return the SIDNO relative to the global sid_map for this GTID.
3950
3951 This requires a lookup and possibly even update of global_sid_map,
3952 hence global_sid_lock must be held. If global_sid_lock is not
3953 held, the caller must pass need_lock=true. If there is an error
3954 (e.g. out of memory) while updating global_sid_map, this function
3955 returns a negative number.
3956
3957 @param need_lock If true, the read lock on global_sid_lock is
3958 acquired and released inside this function; if false, the read
3959 lock or write lock must be held prior to calling this function.
3960 @retval SIDNO if successful
3961 @retval negative if adding SID to global_sid_map causes an error.
3962 */
3963 rpl_sidno get_sidno(bool need_lock);
3964
3965 /**
3966 Return the SIDNO relative to the given Sid_map for this GTID.
3967
3968 This assumes that the Sid_map is local to the thread, and thus
3969 does not use locks.
3970
3971 @param sid_map The sid_map to use.
3972 @retval SIDNO if successful.
3973 @retval negative if adding SID to sid_map causes an error.
3975 rpl_sidno get_sidno(Sid_map *sid_map) { return sid_map->add_sid(sid); }
3976 /// Return the GNO for this GTID.
3977 rpl_gno get_gno() const { return spec.gtid.gno; }
3978
3979 /// string holding the text "SET @@GLOBAL.GTID_NEXT = '"
3980 static const char *SET_STRING_PREFIX;
3981
3982 private:
3983 /// Length of SET_STRING_PREFIX
3984 static const size_t SET_STRING_PREFIX_LENGTH = 26;
3985 /// The maximal length of the entire "SET ..." query.
3986 static const size_t MAX_SET_STRING_LENGTH = SET_STRING_PREFIX_LENGTH +
3988 1 + MAX_GNO_TEXT_LENGTH + 1;
3989
3990 private:
3991 /**
3992 Internal representation of the GTID. The SIDNO will be
3993 uninitialized (value -1) until the first call to get_sidno(bool).
3996 /// SID for this GTID.
3997 rpl_sid sid;
3998
3999 public:
4000 /**
4001 Set the transaction length information based on binlog cache size.
4002
4003 Note that is_checksum_enabled and event_counter are optional parameters.
4004 When not specified, the function will assume that no checksum will be used
4005 and the informed cache_size is the final transaction size without
4006 considering the GTID event size.
4007
4008 The high level formula that will be used by the function is:
4009
4010 trx_length = cache_size +
4011 cache_checksum_active * cache_events * CRC32_payload +
4012 gtid_length +
4013 cache_checksum_active * CRC32_payload; // For the GTID.
4014
4015 @param cache_size The size of the binlog cache in bytes.
4016 @param is_checksum_enabled If checksum will be added to events on flush.
4017 @param event_counter The amount of events in the cache.
4018 */
4020 bool is_checksum_enabled = false,
4021 int event_counter = 0);
4022};
4023
4024/**
4025 @class Previous_gtids_log_event
4026
4027 This is the subclass of Previous_gtids_event and Log_event
4028 It is used to record the gtid_executed in the last binary log file,
4029 for ex after flush logs, or at the starting of the binary log file
4030
4031 @internal
4032 The inheritance structure is as follows
4033
4034 Binary_log_event
4035 ^
4036 |
4037 |
4038B_l:Previous_gtids_event Log_event
4039 \ /
4040 \ /
4041 \ /
4042 \ /
4043 Previous_gtids_log_event
4044
4045 B_l: Namespace Binary_log
4046 @endinternal
4049 public Log_event {
4050 public:
4051#ifdef MYSQL_SERVER
4053#endif
4054
4055#ifdef MYSQL_SERVER
4056 int pack_info(Protocol *) override;
4057#endif
4058
4059 Previous_gtids_log_event(const char *buf,
4060 const Format_description_event *description_event);
4061 ~Previous_gtids_log_event() override = default;
4063 size_t get_data_size() override { return buf_size; }
4064
4065#ifndef MYSQL_SERVER
4066 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
4067#endif
4068#ifdef MYSQL_SERVER
4069 bool write(Basic_ostream *ostream) override {
4070#ifndef NDEBUG
4071 if (DBUG_EVALUATE_IF("skip_writing_previous_gtids_log_event", 1, 0) &&
4072 /*
4073 The skip_writing_previous_gtids_log_event debug point was designed
4074 for skipping the writing of the previous_gtids_log_event on binlog
4075 files only.
4076 */
4077 !is_relay_log_event()) {
4078 DBUG_PRINT("info",
4079 ("skip writing Previous_gtids_log_event because of"
4080 "debug option 'skip_writing_previous_gtids_log_event'"));
4081 return false;
4082 }
4083
4084 if (DBUG_EVALUATE_IF("write_partial_previous_gtids_log_event", 1, 0) &&
4085 /*
4086 The write_partial_previous_gtids_log_event debug point was designed
4087 for writing a partial previous_gtids_log_event on binlog files only.
4088 */
4089 !is_relay_log_event()) {
4090 DBUG_PRINT("info",
4091 ("writing partial Previous_gtids_log_event because of"
4092 "debug option 'write_partial_previous_gtids_log_event'"));
4093 return (Log_event::write_header(ostream, get_data_size()) ||
4095 }
4096#endif
4097
4098 return (Log_event::write_header(ostream, get_data_size()) ||
4099 Log_event::write_data_header(ostream) || write_data_body(ostream) ||
4100 Log_event::write_footer(ostream));
4101 }
4102 bool write_data_body(Basic_ostream *ostream) override;
4103#endif
4104
4105 /// Return the encoded buffer, or NULL on error.
4106 const uchar *get_buf() { return buf; }
4107 /**
4108 Return the formatted string, or NULL on error.
4109 The string is allocated using my_malloc and it is the
4110 responsibility of the caller to free it.
4111 */
4112 char *get_str(size_t *length,
4114 /// Add all GTIDs from this event to the given Gtid_set.
4115 int add_to_set(Gtid_set *gtid_set) const;
4116 /*
4117 Previous Gtid Log events should always be skipped
4118 there is nothing to apply there, whether it is
4119 relay log's (generated on Slave) or it is binary log's
4120 (generated on Master, copied to slave as relay log).
4121 Also, we should not increment slave_skip_counter
4122 for this event, hence return EVENT_SKIP_IGNORE.
4123 */
4124#if defined(MYSQL_SERVER)
4126 {
4127 return EVENT_SKIP_IGNORE;
4128 }
4130 int do_apply_event(Relay_log_info const *) override { return 0; }
4131 int do_update_pos(Relay_log_info *rli) override;
4132#endif
4133};
4134
4135/**
4136 @class Transaction_context_log_event
4137
4138 This is the subclass of Transaction_context_event and Log_event
4139 This class encodes the transaction_context_log_event.
4140
4141 @internal
4142 The inheritance structure is as follows
4143
4144 Binary_log_event
4145 ^
4146 |
4147 |
4148B_l:Transaction_context_event Log_event
4149 \ /
4150 \ /
4151 \ /
4152 \ /
4153 Transaction_context_log_event
4154
4155 B_l: Namespace Binary_log
4156 @endinternal
4160 public Log_event {
4161 private:
4162 /// The Sid_map to use for creating the Gtid_set.
4164 /// A gtid_set which is used to store the transaction set used for
4165 /// conflict detection.
4167
4168#ifdef MYSQL_SERVER
4169 bool write_data_header(Basic_ostream *ostream) override;
4170
4171 bool write_data_body(Basic_ostream *ostream) override;
4172
4174
4175 bool write_data_set(Basic_ostream *ostream, std::list<const char *> *set);
4176#endif
4177
4179
4180 static int get_data_set_size(std::list<const char *> *set);
4181
4182 size_t to_string(char *buf, ulong len) const;
4183
4184 public:
4185#ifdef MYSQL_SERVER
4186 Transaction_context_log_event(const char *server_uuid_arg, bool using_trans,
4187 my_thread_id thread_id_arg,
4188 bool is_gtid_specified_arg);
4189#endif
4190
4192 const Format_description_event *descr_event);
4193
4195
4196 size_t get_data_size() override;
4197
4198 size_t get_event_length();
4199
4200#ifdef MYSQL_SERVER
4201 int pack_info(Protocol *protocol) override;
4202#endif
4203
4204#ifndef MYSQL_SERVER
4205 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
4206#endif
4207
4208#if defined(MYSQL_SERVER)
4209 int do_apply_event(Relay_log_info const *) override { return 0; }
4210 int do_update_pos(Relay_log_info *rli) override;
4211#endif
4212
4213 /**
4214 Add a hash which identifies a inserted/updated/deleted row on the
4215 ongoing transaction.
4216
4217 @param[in] hash row identifier
4218 */
4219 void add_write_set(const char *hash);
4220
4221 /**
4222 Return a pointer to write-set list.
4224 std::list<const char *> *get_write_set() { return &write_set; }
4225
4226 /**
4227 Add a hash which identifies a read row on the ongoing transaction.
4228
4229 @param[in] hash row identifier
4230 */
4231 void add_read_set(const char *hash);
4232
4233 /**
4234 Return a pointer to read-set list.
4236 std::list<const char *> *get_read_set() { return &read_set; }
4237
4238 /**
4239 Read snapshot version from encoded buffers.
4240 Cannot be executed during data read from file (event constructor),
4241 since its required locks will collide with the server gtid state
4242 initialization procedure.
4243 */
4244 bool read_snapshot_version();
4245
4246 /**
4247 Return the transaction snapshot timestamp.
4250
4251 /**
4252 Return the server uuid.
4254 const char *get_server_uuid() { return server_uuid; }
4255
4256 /**
4257 Return the id of the committing thread.
4259 my_thread_id get_thread_id() { return static_cast<my_thread_id>(thread_id); }
4260
4261 /**
4262 Return true if transaction has GTID_NEXT specified, false otherwise.
4264 bool is_gtid_specified() { return gtid_specified == true; }
4265};
4266
4267/**
4268 @class View_change_log_event
4269
4270 This is the subclass of View_change_log_event and Log_event
4271 This class created the view_change_log_event which is used as a marker in
4272 case a new node joins or leaves the group.
4273
4274 @internal
4275 The inheritance structure is as follows
4276
4277 Binary_log_event
4278 ^
4279 |
4280 |
4281B_l: View_change_event Log_event
4282 \ /
4283 \ /
4284 \ /
4285 \ /
4286 View_change_log_event
4287
4288 B_l: Namespace Binary_log
4289 @endinternal
4290*/
4293 public Log_event {
4294 private:
4295 size_t to_string(char *buf, ulong len) const;
4296
4297#ifdef MYSQL_SERVER
4298 bool write_data_header(Basic_ostream *ostream) override;
4299
4300 bool write_data_body(Basic_ostream *ostream) override;
4301
4302 bool write_data_map(Basic_ostream *ostream,
4303 std::map<std::string, std::string> *map);
4304#endif
4305
4306 size_t get_size_data_map(std::map<std::string, std::string> *map);
4307
4308 public:
4309 View_change_log_event(const char *view_id);
4310
4311 View_change_log_event(const char *buffer,
4312 const Format_description_event *descr_event);
4313
4314 ~View_change_log_event() override;
4315
4316 size_t get_data_size() override;
4317
4318#ifdef MYSQL_SERVER
4319 int pack_info(Protocol *protocol) override;
4320#endif
4321
4322#ifndef MYSQL_SERVER
4323 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
4324#endif
4325
4326#if defined(MYSQL_SERVER)
4327 int do_apply_event(Relay_log_info const *rli) override;
4328 int do_update_pos(Relay_log_info *rli) override;
4329#endif
4330
4331 /**
4332 Returns the view id.
4334 char *get_view_id() { return view_id; }
4335
4336 /**
4337 Sets the certification info in the event
4338
4339 @note size is calculated on this method as the size of the data
4340 might render the log even invalid. Also due to its size doing it
4341 here avoid looping over the data multiple times.
4342
4343 @param[in] info certification info to be written
4344 @param[out] event_size the event size after this operation
4345 */
4346 void set_certification_info(std::map<std::string, std::string> *info,
4347 size_t *event_size);
4348
4349 /**
4350 Returns the certification info
4352 std::map<std::string, std::string> *get_certification_info() {
4353 return &certification_info;
4354 }
4355
4356 /**
4357 Set the certification sequence number
4358
4359 @param number the sequence number
4361 void set_seq_number(rpl_gno number) { seq_number = number; }
4362
4363 /**
4364 Returns the certification sequence number
4366 rpl_gno get_seq_number() { return seq_number; }
4367};
4369inline bool is_gtid_event(Log_event *evt) {
4370 return (evt->get_type_code() == binary_log::GTID_LOG_EVENT ||
4372}
4373
4374/**
4375 Check if the given event is a session control event, one of
4376 `User_var_event`, `Intvar_event` or `Rand_event`.
4377
4378 @param evt The event to check.
4379
4380 @return true if the given event is of type `User_var_event`,
4381 `Intvar_event` or `Rand_event`, false otherwise.
4383inline bool is_session_control_event(Log_event *evt) {
4384 return (evt->get_type_code() == binary_log::USER_VAR_EVENT ||
4387}
4388
4389/**
4390 The function checks the argument event properties to deduce whether
4391 it represents an atomic DDL.
4392
4393 @param evt a reference to Log_event
4394 @return true when the DDL properties are found,
4395 false otherwise
4397inline bool is_atomic_ddl_event(Log_event const *evt) {
4398 return evt != nullptr && evt->get_type_code() == binary_log::QUERY_EVENT &&
4399 static_cast<Query_log_event const *>(evt)->ddl_xid !=
4401}
4402
4403/**
4404 The function lists all DDL instances that are supported
4405 for crash-recovery (WL9175).
4406 todo: the supported feature list is supposed to grow. Once
4407 a feature has been readied for 2pc through WL7743,9536(7141/7016) etc
4408 it needs registering in the function.
4409
4410 @param thd an Query-log-event creator thread handle
4411 @param using_trans
4412 The caller must specify the value according to the following
4413 rules:
4414 @c true when
4415 - on master the current statement is not processing
4416 a table in SE which does not support atomic DDL
4417 - on slave the relay-log repository is transactional.
4418 @c false otherwise.
4419 @return true when the being created (master) or handled (slave) event
4420 is 2pc-capable, @c false otherwise.
4421*/
4422bool is_atomic_ddl(THD *thd, bool using_trans);
4423
4424#ifdef MYSQL_SERVER
4425/**
4426 Serialize an binary event to the given output stream. It is more general
4427 than call ev->write() directly. The caller will not be affected if any
4428 change happens in serialization process. For example, serializing the
4429 event in different format.
4430 */
4431template <class EVENT>
4432bool binary_event_serialize(EVENT *ev, Basic_ostream *ostream) {
4433 return ev->write(ostream);
4434}
4435
4436/*
4437 This is an utility function that adds a quoted identifier into the a buffer.
4438 This also escapes any existence of the quote string inside the identifier.
4439 */
4440size_t my_strmov_quoted_identifier(THD *thd, char *buffer,
4441 const char *identifier, size_t length);
4442#else
4443size_t my_strmov_quoted_identifier(char *buffer, const char *identifier);
4444#endif
4446 const char *identifier,
4447 size_t length);
4448
4449/**
4450 Read an integer in net_field_length format, guarding against read out of
4451 bounds and advancing the position.
4452
4453 @param[in,out] packet Pointer to buffer to read from. On successful
4454 return, the buffer position will be incremented to point to the next
4455 byte after what was read.
4456
4457 @param[in,out] max_length Pointer to the number of bytes in the
4458 buffer. If the function would need to look at more than *max_length
4459 bytes in order to decode the number, the function will do nothing
4460 and return true.
4461
4462 @param[out] out Pointer where the value will be stored.
4463
4464 @retval false Success.
4465 @retval true Failure, i.e., reached end of buffer.
4466*/
4467template <typename T>
4468bool net_field_length_checked(const uchar **packet, size_t *max_length, T *out);
4469
4470/**
4471 Extract basic info about an event: type, query, is it ignorable
4472
4473 @param log_event the event to extract info from
4474 @return a pair first param is true if an error occurred, false otherwise
4475 second param is the event info
4476 */
4477std::pair<bool, binary_log::Log_event_basic_info> extract_log_event_basic_info(
4478 Log_event *log_event);
4479
4480/**
4481 Extract basic info about an event: type, query, is it ignorable
4482
4483 @param buf The event info buffer
4484 @param length The length of the buffer
4485 @param fd_event The Format description event associated
4486 @return a pair first param is true if an error occurred, false otherwise
4487 second param is the event info
4488 */
4489std::pair<bool, binary_log::Log_event_basic_info> extract_log_event_basic_info(
4490 const char *buf, size_t length,
4491 const binary_log::Format_description_event *fd_event);
4492
4493/**
4494 @} (end of group Replication)
4495*/
4496
4497#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:6972
bool write(Basic_ostream *ostream) override
Definition: log_event.cc:7002
virtual int get_create_or_append() const
Definition: log_event.cc:7047
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:7034
~Append_block_log_event() override=default
const char * get_db() override
Definition: log_event.h:2118
int do_apply_event(Relay_log_info const *rli) override
Primitive to apply an event to the database.
Definition: log_event.cc:7055
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:7261
~Begin_load_query_log_event() override=default
int get_create_or_append() const override
Definition: log_event.cc:7257
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:7233
Delete_file_log_event is created when the LOAD_DATA query fails on the master for some reason,...
Definition: log_event.h:2159
int do_apply_event(Relay_log_info const *rli) override
Primitive to apply an event to the database.
Definition: log_event.cc:7206
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:7166
const char * get_db() override
Definition: log_event.h:2177
Delete_file_log_event(THD *thd, const char *db_arg, bool using_trans)
Definition: log_event.cc:7139
int pack_info(Protocol *protocol) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:7194
Log row deletions.
Definition: log_event.h:3436
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:3455
Delete_rows_log_event(THD *, TABLE *, const Table_id &, bool is_transactional, const unsigned char *extra_row_ndb_info)
Definition: log_event.cc:12244
static bool binlog_row_logging_function(THD *thd, TABLE *table, bool is_transactional, const uchar *before_record, const uchar *after_record)
Definition: log_event.cc:12260
Log_event_type get_general_type_code() override
Definition: log_event.h:3461
@ TYPE_CODE
Definition: log_event.h:3440
int do_exec_row(const Relay_log_info *const) override
Definition: log_event.cc:12312
int do_before_row_operations(const Slave_reporting_capability *const) override
Definition: log_event.cc:12282
int do_after_row_operations(const Slave_reporting_capability *const, int) override
Definition: log_event.cc:12305
Event responsible for LOAD DATA execution, it similar to Query_log_event but before executing the que...
Definition: log_event.h:2282
int do_apply_event(Relay_log_info const *rli) override
Primitive to apply an event to the database.
Definition: log_event.cc:7408
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:7318
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:7274
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:7377
ulong get_post_header_size_for_derived() override
Definition: log_event.cc:7313
~Execute_load_query_log_event() override=default
Definition: field.h:573
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:5367
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:5532
size_t get_data_size() override
Definition: log_event.h:1643
bool write(Basic_ostream *ostream) override
Definition: log_event.cc:5377
int do_update_pos(Relay_log_info *rli) override
Advance relay log coordinates.
Definition: log_event.cc:5510
int do_apply_event(Relay_log_info const *rli) override
Primitive to apply an event to the database.
Definition: log_event.cc:5459
Format_description_log_event()
Format_description_log_event 1st ctor.
Definition: log_event.cc:5257
This is a subclass if Gtid_event and Log_event.
Definition: log_event.h:3836
rpl_sidno get_sidno(bool need_lock)
Return the SIDNO relative to the global sid_map for this GTID.
Definition: log_event.cc:13260
const rpl_sid * get_sid() const
Return the SID for this GTID.
Definition: log_event.h:3946
rpl_sid sid
SID for this GTID.
Definition: log_event.h:3996
~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:13000
size_t get_event_length()
Definition: log_event.h:3877
int do_update_pos(Relay_log_info *rli) override
Advance relay log coordinates.
Definition: log_event.cc:13192
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:3940
uint32 write_body_to_memory(uchar *buff)
Writes the body to the given memory buffer.
Definition: log_event.cc:13007
int do_apply_event(Relay_log_info const *rli) override
Primitive to apply an event to the database.
Definition: log_event.cc:13073
uint32 write_post_header_to_memory(uchar *buffer)
Writes the post-header to the given memory buffer.
Definition: log_event.cc:12947
static const size_t SET_STRING_PREFIX_LENGTH
Length of SET_STRING_PREFIX.
Definition: log_event.h:3983
rpl_gno get_gno() const
Return the GNO for this GTID.
Definition: log_event.h:3976
bool write_data_body(Basic_ostream *ostream) override
Definition: log_event.cc:13064
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:13211
static const size_t MAX_SET_STRING_LENGTH
The maximal length of the entire "SET ..." query.
Definition: log_event.h:3985
static const char * SET_STRING_PREFIX
string holding the text "SET @@GLOBAL.GTID_NEXT = '"
Definition: log_event.h:3979
Gtid_specification spec
Internal representation of the GTID.
Definition: log_event.h:3994
int pack_info(Protocol *) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:12853
size_t get_data_size() override
Definition: log_event.h:3871
size_t to_string(char *buf) const
Used internally by both print() and pack_info().
Definition: log_event.cc:12861
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:12761
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:13206
Represents a set of GTIDs.
Definition: rpl_gtid.h:1454
Definition: rpl_utility.h:108
Definition: log_event.h:3727
Heartbeat_log_event_v2(const char *buf, const Format_description_event *description_event)
Definition: log_event.cc:14092
Definition: log_event.h:3720
Heartbeat_log_event(const char *buf, const Format_description_event *description_event)
Definition: log_event.cc:14085
Base class for ignorable log events is Ignorable_event.
Definition: log_event.h:3600
Ignorable_log_event(THD *thd_arg)
Definition: log_event.h:3603
int pack_info(Protocol *) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:12630
size_t get_data_size() override
Definition: log_event.h:3624
~Ignorable_log_event() override
Class representing an incident, an occurrence out of the ordinary, that happened on the master.
Definition: log_event.h:3508
bool write_data_header(Basic_ostream *ostream) override
Definition: log_event.cc:12580
size_t get_data_size() override
Definition: log_event.h:3564
Incident_log_event(THD *thd_arg, enum_incident incident_arg)
Definition: log_event.h:3511
bool write_data_body(Basic_ostream *ostream) override
Definition: log_event.cc:12606
~Incident_log_event() override
Definition: log_event.cc:12500
int do_apply_event(Relay_log_info const *rli) override
Primitive to apply an event to the database.
Definition: log_event.cc:12541
int pack_info(Protocol *) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:12514
const char * description() const
Definition: log_event.cc:12504
bool ends_group() const override
Definition: log_event.h:3568
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:5844
~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:5918
int pack_info(Protocol *protocol) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:5819
bool is_sbr_logging_format() const override
Return true if the event has to be logged using SBR for DMLs.
Definition: log_event.h:1711
int do_apply_event(Relay_log_info const *rli) override
Primitive to apply an event to the database.
Definition: log_event.cc:5893
int do_update_pos(Relay_log_info *rli) override
Advance relay log coordinates.
Definition: log_event.cc:5913
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:7498
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:7481
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:1339
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:2524
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:3119
virtual int do_apply_event(Relay_log_info const *rli)
Primitive to apply an event to the database.
Definition: log_event.h:1262
virtual const char * get_db()
Definition: log_event.cc:1151
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:1156
uint32 write_header_to_memory(uchar *buf)
Writes the common header of this event to the given memory buffer.
Definition: log_event.cc:1303
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:1392
virtual uint8 get_mts_dbs(Mts_db_names *arg, Rpl_filter *rpl_filter)
The method fills in pointers to event's database name c-strings to a supplied array.
Definition: log_event.h:1156
ha_checksum crc
Placeholder for event checksum while writing to binlog.
Definition: log_event.h:807
virtual size_t get_data_size()
Definition: log_event.h:985
bool wrapper_my_b_safe_write(Basic_ostream *ostream, const uchar *buf, size_t data_length)
Write the given buffer to the given output stream, updating the checksum if checksums are enabled.
Definition: log_event.cc:1281
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:2544
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:1028
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:1076
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:992
time_t get_time()
Definition: log_event.cc:903
bool write_footer(Basic_ostream *ostream)
Definition: log_event.cc:1290
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:1098
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:3075
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:1146
bool is_using_immediate_logging() const
Definition: log_event.h:959
void set_relay_log_event()
Definition: log_event.h:940
virtual bool write_data_header(Basic_ostream *)
Definition: log_event.h:912
static void init_show_field_list(mem_root_deque< Item * > *field_list)
init_show_field_list() prepares the column names and types for the output of SHOW BINLOG EVENTS; it i...
Definition: log_event.cc:1179
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:1090
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:1208
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:2672
This is the subclass of Previous_gtids_event and Log_event It is used to record the gtid_executed in ...
Definition: log_event.h:4048
bool write_data_body(Basic_ostream *ostream) override
Definition: log_event.cc:13356
int do_update_pos(Relay_log_info *rli) override
Advance relay log coordinates.
Definition: log_event.cc:13363
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:13337
int pack_info(Protocol *) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:13300
int do_apply_event(Relay_log_info const *) override
Primitive to apply an event to the database.
Definition: log_event.h:4129
int add_to_set(Gtid_set *gtid_set) const
Add all GTIDs from this event to the given Gtid_set.
Definition: log_event.cc:13326
size_t get_data_size() override
Definition: log_event.h:4062
Previous_gtids_log_event(const Gtid_set *set)
Definition: log_event.cc:13280
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:4124
bool write(Basic_ostream *ostream) override
Definition: log_event.h:4068
~Previous_gtids_log_event() override=default
const uchar * get_buf()
Return the encoded buffer, or NULL on error.
Definition: log_event.h:4105
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:5146
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
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:3700
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:5160
virtual ulong get_post_header_size_for_derived()
Definition: log_event.h:1502
bool starts_group() const override
Notice, DDL queries are logged without BEGIN/COMMIT parentheses and identification of such single-que...
Definition: log_event.h:1558
uchar mts_number_dbs() override
Definition: log_event.h:1474
my_thread_id slave_proxy_id
Definition: log_event.h:1396
void set_skip_temp_tables_handling_by_worker()
Definition: log_event.h:1425
bool has_ddl_committed
The flag indicates whether the DDL query has been (already) committed or not.
Definition: log_event.h:1416
int do_apply_event(Relay_log_info const *rli) override
Primitive to apply an event to the database.
Definition: log_event.cc:4446
~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:4423
bool write(Basic_ostream *ostream) override
Query_log_event::write().
Definition: log_event.cc:3408
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:5196
const char * get_db() override
Definition: log_event.h:1436
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:3357
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:4437
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:5954
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:5999
int do_apply_event(Relay_log_info const *rli) override
Primitive to apply an event to the database.
Definition: log_event.cc:5980
int pack_info(Protocol *protocol) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:5935
int do_update_pos(Relay_log_info *rli) override
Advance relay log coordinates.
Definition: log_event.cc:5994
Definition: rpl_rli.h:201
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:866
bool is_inbound_filtering_enabled()
Returns whether or not filtering should be enabled, given the current THD instance in use.
Definition: log_event.cc:872
Replicated_columns_view & operator=(const Replicated_columns_view &rhs)=delete
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(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:842
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:888
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:879
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:5652
int pack_info(Protocol *protocol) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:5545
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:5795
~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:5581
bool write(Basic_ostream *ostream) override
Definition: log_event.cc:5623
size_t get_data_size() override
Definition: log_event.h:2059
Definition: log_event.h:2588
bool is_enabled()
If instrumentation is enabled this member function SHALL return true.
Definition: log_event.h:2615
Rows_applier_psi_stage & operator=(const Rows_applier_psi_stage &rhs)
void inc_n_rows_applied(ulonglong delta)
Updates the counter of processed rows.
Definition: log_event.h:2661
ulonglong m_n_rows_applied
Counter that is unconditionally incremented on each row that is processed.
Definition: log_event.h:2603
ulonglong get_n_rows_applied()
Gets the value of the counter of rows that have been processed.
Definition: log_event.h:2667
Rows_applier_psi_stage()
Definition: log_event.h:2606
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:2628
void set_progress(PSI_stage_progress *progress)
Definition: log_event.h:2608
void end_work()
Resets this object.
Definition: log_event.h:2652
PSI_stage_progress * m_progress
A cached pointer to this stage PSI_stage_progress.
Definition: log_event.h:2596
Definition: log_event.h:2878
KEY ** m_key_info
Definition: log_event.h:2898
Key_compare(KEY **ki=nullptr)
Definition: log_event.h:2891
bool operator()(uchar *k1, uchar *k2) const
Definition: log_event.h:2892
Common base class for all row-containing log events.
Definition: log_event.h:2704
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:3191
uint32 m_bitbuf[128/(sizeof(uint32) *8)]
Definition: log_event.h:2859
virtual Log_event_type get_general_type_code()=0
uchar * m_rows_end
Definition: log_event.h:2868
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:8757
size_t get_width() const
Definition: log_event.h:2769
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:8702
bool write_data_header(Basic_ostream *ostream) override
Definition: log_event.cc:10261
uchar * m_rows_buf
Definition: log_event.h:2866
uint m_rows_lookup_algorithm
The algorithm to use while searching for rows using the before image.
Definition: log_event.h:2840
TABLE * m_table
Definition: log_event.h:2819
bool is_rbr_logging_format() const override
Return true if the event has to be logged using RBR for DMLs.
Definition: log_event.h:2988
int do_hash_row(Relay_log_info const *rli)
Populates the m_hash when using HASH_SCAN.
Definition: log_event.cc:9152
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:2834
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:2906
int do_hash_scan_and_update(Relay_log_info const *rli)
Implementation of the hash_scan and update algorithm.
Definition: log_event.cc:9387
int add_row_data(uchar *data, size_t length)
Definition: log_event.h:2759
void decide_row_lookup_algorithm_and_key() SUPPRESS_UBSAN_CLANG10
Definition: log_event.cc:8307
uint m_key_index
Definition: log_event.h:2876
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:8732
int row_operations_scan_and_key_setup()
Definition: log_event.cc:8419
MY_BITMAP const * get_cols_ai() const
Definition: log_event.h:2768
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:7665
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:10132