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