MySQL 8.3.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 */
854
855 /**
856 Allow thread to CLAIM or DISCLAIM the ownership of this object
857 depends on the parameter value passed
858
859 @param claim
860 True - claim ownership of the memory
861 False - disclaim ownership of the memory
862 */
863 virtual void claim_memory_ownership([[maybe_unused]] bool claim) {}
865 virtual ~Log_event() { free_temp_buf(); }
866 void register_temp_buf(char *buf, bool free_in_destructor = true) {
867 m_free_temp_buf_in_destructor = free_in_destructor;
869 }
870 void free_temp_buf() {
871 if (temp_buf) {
873 temp_buf = nullptr;
874 }
875 }
876 /*
877 Get event length for simple events. For complicated events the length
878 is calculated during write()
879 */
880 virtual size_t get_data_size() { return 0; }
881 /**
882 Returns the human readable name of the given event type.
883 */
885 /// Get the name of an event type, or "Unknown" if out of range.
886 /// @param type The type as an int
887 /// @retval name of an event type, if it is one
888 /// @retval "Unknown" if the value is out of range
889 static const char *get_type_str(uint type);
890 /**
891 Returns the human readable name of this event's type.
892 */
893 const char *get_type_str() const;
894 /* Return start of query time or current time */
895
896#if defined(MYSQL_SERVER)
897 /**
898 Is called from get_mts_execution_mode() to
899
900 @return true if the event needs applying with synchronization
901 against Workers, otherwise
902 false
903
904 @note There are incompatile combinations such as referred further events
905 are wrapped with BEGIN/COMMIT. Such cases should be identified
906 by the caller and treats correspondingly.
907
908 todo: to mts-support Old master Load-data related events
909 */
911 switch (get_type_code()) {
917 return true;
918 default:
919 return false;
920 }
921 }
922
923 private:
924 /*
925 possible decisions by get_mts_execution_mode().
926 The execution mode can be PARALLEL or not (thereby sequential
927 unless impossible at all). When it's sequential it further breaks into
928 ASYNChronous and SYNChronous.
929 */
931 /*
932 Event is run by a Worker.
933 */
935 /*
936 Event is run by Coordinator.
937 */
939 /*
940 Event is run by Coordinator and requires synchronization with Workers.
941 */
943 /*
944 Event can't be executed neither by Workers nor Coordinator.
945 */
947 };
948
949 /**
950 MTS Coordinator finds out a way how to execute the current event.
951
952 Besides the parallelizable case, some events have to be applied by
953 Coordinator concurrently with Workers and some to require synchronization
954 with Workers (@c see wait_for_workers_to_finish) before to apply them.
955
956 @param mts_in_group the being group parsing status, true
957 means inside the group
958
959 @retval EVENT_EXEC_PARALLEL if event is executed by a Worker
960 @retval EVENT_EXEC_ASYNC if event is executed by Coordinator
961 @retval EVENT_EXEC_SYNC if event is executed by Coordinator
962 with synchronization against the Workers
963 */
964 enum enum_mts_event_exec_mode get_mts_execution_mode(bool mts_in_group) {
965 /*
966 Slave workers are unable to handle Format_description_log_event,
967 Rotate_log_event and Previous_gtids_log_event correctly.
968 However, when a transaction spans multiple relay logs, these
969 events occur in the middle of a transaction. The way we handle
970 this is by marking the events as 'ASYNC', meaning that the
971 coordinator thread will handle the events without stopping the
972 worker threads.
973
974 @todo Refactor this: make Log_event::get_slave_worker handle
975 transaction boundaries in a more robust way, so that it is able
976 to process Format_description_log_event, Rotate_log_event, and
977 Previous_gtids_log_event. Then, when these events occur in the
978 middle of a transaction, make them part of the transaction so
979 that the worker that handles the transaction handles these
980 events too. /Sven
981 */
982 if (
983 /*
984 When a Format_description_log_event occurs in the middle of
985 a transaction, it either has the slave's server_id, or has
986 end_log_pos==0.
987
988 @todo This does not work when master and slave have the same
989 server_id and replicate-same-server-id is enabled, since
990 events that are not in the middle of a transaction will be
991 executed in ASYNC mode in that case.
992 */
994 ((server_id == (uint32)::server_id) ||
995 (common_header->log_pos == 0))) ||
996 /*
997 All Previous_gtids_log_events in the relay log are generated
998 by the slave. They don't have any meaning to the applier, so
999 they can always be ignored by the applier. So we can process
1000 them asynchronously by the coordinator. It is also important
1001 to not feed them to workers because that confuses
1002 get_slave_worker.
1003 */
1005 /*
1006 Rotate_log_event can occur in the middle of a transaction.
1007 When this happens, either it is a Rotate event generated on
1008 the slave which has the slave's server_id, or it is a Rotate
1009 event that originates from a master but has end_log_pos==0.
1010 */
1012 ((server_id == (uint32)::server_id) ||
1013 (common_header->log_pos == 0 && mts_in_group))))
1014 return EVENT_EXEC_ASYNC;
1015 else if (is_mts_sequential_exec())
1016 return EVENT_EXEC_SYNC;
1017 else
1018 return EVENT_EXEC_PARALLEL;
1019 }
1020
1021 /**
1022 @return index in [0, M] range to indicate
1023 to be assigned worker;
1024 M is the max index of the worker pool.
1025 */
1027
1028 /*
1029 Group of events can be marked to force its execution
1030 in isolation from any other Workers.
1031 Typically that is done for a transaction that contains
1032 a query accessing more than OVER_MAX_DBS_IN_EVENT_MTS databases.
1033 Factually that's a sequential mode where a Worker remains to
1034 be the applier.
1035 */
1036 virtual void set_mts_isolate_group() {
1037 assert(ends_group() ||
1041 }
1042
1043 public:
1044 /**
1045 The method fills in pointers to event's database name c-strings
1046 to a supplied array.
1047 In other than Query-log-event case the returned array contains
1048 just one item.
1049 @param[out] arg pointer to a struct containing char* array
1050 pointers to be filled in and the number
1051 of filled instances.
1052 @param rpl_filter pointer to a replication filter.
1053
1054 @return number of the filled instances indicating how many
1055 databases the event accesses.
1056 */
1057 virtual uint8 get_mts_dbs(Mts_db_names *arg,
1058 Rpl_filter *rpl_filter [[maybe_unused]]) {
1059 arg->name[0] = get_db();
1060
1061 return arg->num = mts_number_dbs();
1062 }
1063
1064 /**
1065 @return true if events carries partitioning data (database names).
1066 */
1067 bool contains_partition_info(bool);
1068
1069 /*
1070 @return the number of updated by the event databases.
1071
1072 @note In other than Query-log-event case that's one.
1073 */
1074 virtual uint8 mts_number_dbs() { return 1; }
1075
1076 /**
1077 @return true if the terminal event of a group is marked to
1078 execute in isolation from other Workers,
1079 false otherwise
1080 */
1081 bool is_mts_group_isolated() {
1083 }
1084
1085 /**
1086 Events of a certain type can start or end a group of events treated
1087 transactionally wrt binlog.
1088
1089 Public access is required by implementation of recovery + skip.
1090
1091 @return true if the event starts a group (transaction)
1092 false otherwise
1094#endif
1095 virtual bool starts_group() const { return false; }
1096 /**
1097 @return true if the event ends a group (transaction)
1098 false otherwise
1099 */
1100 virtual bool ends_group() const { return false; }
1101#ifdef MYSQL_SERVER
1102 /**
1103 Apply the event to the database.
1104
1105 This function represents the public interface for applying an
1106 event.
1107
1108 @see do_apply_event
1109 */
1110 int apply_event(Relay_log_info *rli);
1111
1112 /**
1113 Apply the GTID event in curr_group_data to the database.
1114
1115 @param rli Pointer to coordinato's relay log info.
1116
1117 @retval 0 success
1118 @retval 1 error
1119 */
1120 inline int apply_gtid_event(Relay_log_info *rli);
1121
1122 /**
1123 Update the relay log position.
1124
1125 This function represents the public interface for "stepping over"
1126 the event and will update the relay log information.
1127
1128 @see do_update_pos
1129 */
1130 int update_pos(Relay_log_info *rli) { return do_update_pos(rli); }
1131
1132 /**
1133 Decide if the event shall be skipped, and the reason for skipping
1134 it.
1135
1136 @see do_shall_skip
1137 */
1139 DBUG_TRACE;
1141 DBUG_PRINT("info", ("skip reason=%d=%s", ret,
1142 ret == EVENT_SKIP_NOT
1143 ? "NOT"
1144 : ret == EVENT_SKIP_IGNORE ? "IGNORE" : "COUNT"));
1145 return ret;
1146 }
1147
1148 /**
1149 Primitive to apply an event to the database.
1150
1151 This is where the change to the database is made.
1152
1153 @note The primitive is protected instead of private, since there
1154 is a hierarchy of actions to be performed in some cases.
1155
1156 @see Format_description_log_event::do_apply_event()
1157
1158 @param rli Pointer to relay log info structure
1159
1160 @retval 0 Event applied successfully
1161 @retval errno Error code if event application failed
1162 */
1163 virtual int do_apply_event(Relay_log_info const *rli [[maybe_unused]]) {
1164 return 0; /* Default implementation does nothing */
1165 }
1166
1167 virtual int do_apply_event_worker(Slave_worker *w);
1168
1169 protected:
1170 /**
1171 Helper function to ignore an event w.r.t. the slave skip counter.
1172
1173 This function can be used inside do_shall_skip() for functions
1174 that cannot end a group. If the slave skip counter is 1 when
1175 seeing such an event, the event shall be ignored, the counter
1176 left intact, and processing continue with the next event.
1177
1178 A typical usage is:
1179 @code
1180 enum_skip_reason do_shall_skip(Relay_log_info *rli) {
1181 return continue_group(rli);
1182 }
1183 @endcode
1184
1185 @return Skip reason
1186 */
1188
1189 /**
1190 Advance relay log coordinates.
1191
1192 This function is called to advance the relay log coordinates to
1193 just after the event. It is essential that both the relay log
1194 coordinate and the group log position is updated correctly, since
1195 this function is used also for skipping events.
1196
1197 Normally, each implementation of do_update_pos() shall:
1198
1199 - Update the event position to refer to the position just after
1200 the event.
1201
1202 - Update the group log position to refer to the position just
1203 after the event <em>if the event is last in a group</em>
1204
1205 @param rli Pointer to relay log info structure
1206
1207 @retval 0 Coordinates changed successfully
1208 @retval errno Error code if advancing failed (usually just
1209 1). Observe that handler errors are returned by the
1210 do_apply_event() function, and not by this one.
1211 */
1212 virtual int do_update_pos(Relay_log_info *rli);
1213
1214 /**
1215 Decide if this event shall be skipped or not and the reason for
1216 skipping it.
1217
1218 The default implementation decide that the event shall be skipped
1219 if either:
1220
1221 - the server id of the event is the same as the server id of the
1222 server and <code>rli->replicate_same_server_id</code> is true,
1223 or
1224
1225 - if <code>rli->slave_skip_counter</code> is greater than zero.
1226
1227 @see do_apply_event
1228 @see do_update_pos
1229
1230 @retval Log_event::EVENT_SKIP_NOT
1231 The event shall not be skipped and should be applied.
1232
1233 @retval Log_event::EVENT_SKIP_IGNORE
1234 The event shall be skipped by just ignoring it, i.e., the slave
1235 skip counter shall not be changed. This happends if, for example,
1236 the originating server id of the event is the same as the server
1237 id of the slave.
1238
1239 @retval Log_event::EVENT_SKIP_COUNT
1240 The event shall be skipped because the slave skip counter was
1241 non-zero. The caller shall decrease the counter by one.
1242 */
1244#endif
1245};
1246
1247/*
1248 One class for each type of event.
1249 Two constructors for each class:
1250 - one to create the event for logging (when the server acts as a master),
1251 called after an update to the database is done,
1252 which accepts parameters like the query, the database, the options for LOAD
1253 DATA INFILE...
1254 - one to create the event from a packet (when the server acts as a slave),
1255 called before reproducing the update, which accepts parameters (like a
1256 buffer). Used to read from the master, from the relay log, and in
1257 mysqlbinlog. This constructor must be format-tolerant.
1258*/
1259
1260/**
1261 A Query event is written to the binary log whenever the database is
1262 modified on the master, unless row based logging is used.
1263
1264 Query_log_event is created for logging, and is called after an update to the
1265 database is done. It is used when the server acts as the master.
1266
1267 Virtual inheritance is required here to handle the diamond problem in
1268 the class @c Execute_load_query_log_event.
1269 The diamond structure is explained in @c Excecute_load_query_log_event
1270
1271 @internal
1272 The inheritance structure is as follows:
1273
1274 Binary_log_event
1275 ^
1276 |
1277 |
1278 Query_event Log_event
1279 \ /
1280 <<virtual>>\ /
1281 \ /
1282 Query_log_event
1283 @endinternal
1284*/
1286 public Log_event {
1287 protected:
1289
1290 public:
1291 // disable copy-move semantics
1292 Query_log_event(Query_log_event &&) noexcept = delete;
1293 Query_log_event &operator=(Query_log_event &&) noexcept = delete;
1294 Query_log_event(const Query_log_event &) = delete;
1295 Query_log_event &operator=(const Query_log_event &) = delete;
1296
1297 /*
1298 For events created by Query_log_event::do_apply_event (and
1299 Load_log_event::do_apply_event()) we need the *original* thread
1300 id, to be able to log the event with the original (=master's)
1301 thread id (fix for BUG#1686).
1302 */
1304
1305 /**
1306 True if this is a ROLLBACK event injected by the mts coordinator to finish a
1307 group corresponding to a partial transaction in the relay log.
1308 False otherwise and by default, as it must be explicitly set to true by the
1309 coordinator.
1310 */
1311 bool rollback_injected_by_coord = false;
1312
1313 /**
1314 The flag indicates whether the DDL query has been (already)
1315 committed or not. It's initialized as OFF at the event instantiation,
1316 flips ON when the DDL transaction has been committed with
1317 all its possible extra statement due to replication or GTID.
1318
1319 The flag status is also checked in few places to catch uncommitted
1320 transactions which can normally happen due to filtering out. In
1321 such a case the commit is deferred to @c Log_event::do_update_pos().
1322 */
1323 bool has_ddl_committed;
1324
1325#ifdef MYSQL_SERVER
1326
1327 /**
1328 Instructs the applier to skip temporary tables handling.
1329 */
1331
1335
1338 }
1339
1340 Query_log_event(THD *thd_arg, const char *query_arg, size_t query_length,
1341 bool using_trans, bool immediate, bool suppress_use,
1342 int error, bool ignore_command = false);
1343 const char *get_db() override { return db; }
1344
1345 /**
1346 @param[out] arg pointer to a struct containing char* array
1347 pointers be filled in and the number of
1348 filled instances.
1349 In case the number exceeds MAX_DBS_IN_EVENT_MTS,
1350 the overfill is indicated with assigning the number to
1351 OVER_MAX_DBS_IN_EVENT_MTS.
1352 @param rpl_filter pointer to a replication filter.
1353
1354 @return number of databases in the array or OVER_MAX_DBS_IN_EVENT_MTS.
1355 */
1358 // the empty string db name is special to indicate sequential applying
1359 mts_accessed_db_names[0][0] = 0;
1360 } else {
1361 for (uchar i = 0; i < mts_accessed_dbs; i++) {
1362 const char *db_name = mts_accessed_db_names[i];
1363
1364 // Only default database is rewritten.
1365 if (!rpl_filter->is_rewrite_empty() && !strcmp(get_db(), db_name)) {
1366 size_t dummy_len;
1367 const char *db_filtered =
1368 rpl_filter->get_rewrite_db(db_name, &dummy_len);
1369 // db_name != db_filtered means that db_name is rewritten.
1370 if (strcmp(db_name, db_filtered)) db_name = db_filtered;
1371 }
1372 arg->name[i] = db_name;
1373 }
1374 }
1375 return arg->num = mts_accessed_dbs;
1376 }
1377
1380
1381 uchar mts_number_dbs() override { return mts_accessed_dbs; }
1382
1383 int pack_info(Protocol *protocol) override;
1384#else
1385 void print_query_header(IO_CACHE *file,
1386 PRINT_EVENT_INFO *print_event_info) const;
1387 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
1388 static bool rewrite_db_in_buffer(
1389 char **buf, ulong *event_len,
1391#endif
1392
1394
1396 const char *buf,
1399 ~Query_log_event() override {
1401 }
1402
1403 void claim_memory_ownership(bool claim) override;
1404
1405#ifdef MYSQL_SERVER
1406 bool write(Basic_ostream *ostream) override;
1407 virtual bool write_post_header_for_derived(Basic_ostream *) { return false; }
1408#endif
1409
1410 /*
1411 Returns number of bytes additionally written to post header by derived
1412 events (so far it is only Execute_load_query event).
1413 */
1414 virtual ulong get_post_header_size_for_derived() { return 0; }
1415 /* Writes derived event-specific part of post header. */
1416
1417 public: /* !!! Public in this patch to allow old usage */
1418#if defined(MYSQL_SERVER)
1420 int do_apply_event(Relay_log_info const *rli) override;
1421 int do_update_pos(Relay_log_info *rli) override;
1422
1423 int do_apply_event(Relay_log_info const *rli, const char *query_arg,
1424 size_t q_len_arg);
1425#endif /* MYSQL_SERVER */
1426 /*
1427 If true, the event always be applied by slave SQL thread or be printed by
1428 mysqlbinlog
1429 */
1430 bool is_trans_keyword() const {
1431 /*
1432 Before the patch for bug#50407, The 'SAVEPOINT and ROLLBACK TO'
1433 queries input by user was written into log events directly.
1434 So the keywords can be written in both upper case and lower case
1435 together, strncasecmp is used to check both cases. they also could be
1436 binlogged with comments in the front of these keywords. for examples:
1437 / * bla bla * / SAVEPOINT a;
1438 / * bla bla * / ROLLBACK TO a;
1439 but we don't handle these cases and after the patch, both quiries are
1440 binlogged in upper case with no comments.
1441 */
1442 return !strncmp(query, "BEGIN", q_len) ||
1443 !strncmp(query, "COMMIT", q_len) ||
1444 !native_strncasecmp(query, "SAVEPOINT", 9) ||
1445 !native_strncasecmp(query, "ROLLBACK", 8) ||
1446 !native_strncasecmp(query, STRING_WITH_LEN("XA START")) ||
1448 !native_strncasecmp(query, STRING_WITH_LEN("XA PREPARE")) ||
1449 !native_strncasecmp(query, STRING_WITH_LEN("XA COMMIT")) ||
1450 !native_strncasecmp(query, STRING_WITH_LEN("XA ROLLBACK"));
1451 }
1452
1453 /**
1454 When a query log event contains a non-transaction control statement, we
1455 assume that it is changing database content (DML) and was logged using
1456 binlog_format=statement.
1457
1458 @return True the event represents a statement that was logged using SBR
1459 that can change database content.
1460 False for transaction control statements.
1461 */
1462 bool is_sbr_logging_format() const override { return !is_trans_keyword(); }
1463
1464 /**
1465 Notice, DDL queries are logged without BEGIN/COMMIT parentheses
1466 and identification of such single-query group
1467 occurs within logics of @c get_slave_worker().
1469
1470 bool starts_group() const override {
1471 return !strncmp(query, "BEGIN", q_len) ||
1472 !strncmp(query, STRING_WITH_LEN("XA START"));
1474
1475 bool ends_group() const override {
1476 return !strncmp(query, "COMMIT", q_len) ||
1477 (!native_strncasecmp(query, STRING_WITH_LEN("ROLLBACK")) &&
1478 native_strncasecmp(query, STRING_WITH_LEN("ROLLBACK TO "))) ||
1479 !strncmp(query, STRING_WITH_LEN("XA ROLLBACK"));
1480 }
1481 static size_t get_query(
1482 const char *buf, size_t length,
1484 const char **query_arg);
1485
1486 bool is_query_prefix_match(const char *pattern, uint p_len) {
1487 return !strncmp(query, pattern, p_len);
1488 }
1489
1490 /** Whether or not the statement represented by this event requires
1491 `Q_SQL_REQUIRE_PRIMARY_KEY` to be logged along aside. */
1492 bool need_sql_require_primary_key{false};
1493
1494 /** Whether or not the statement represented by this event requires
1495 `Q_DEFAULT_TABLE_ENCRYPTION` to be logged along aside. */
1497};
1498
1499/**
1500 @class Format_description_log_event
1501
1502 For binlog version 4.
1503 This event is saved by threads which read it, as they need it for future
1504 use (to decode the ordinary events).
1505 This is the subclass of Format_description_event
1506
1507 @internal
1508 The inheritance structure in the current design for the classes is
1509 as follows:
1510
1511 Binary_log_event
1512 ^
1513 |
1514 |
1515 Format_description_event Log_event
1516 \ /
1517 \ /
1518 \ /
1519 Format_description_log_event
1520 @endinternal
1521 @section Format_description_log_event_binary_format Binary Format
1523
1526 public Log_event {
1527 public:
1528 /*
1529 MTS Workers and Coordinator share the event and that affects its
1530 destruction. Instantiation is always done by Coordinator/SQL thread.
1531 Workers are allowed to destroy only "obsolete" instances, those
1532 that are not actual for Coordinator anymore but needed to Workers
1533 that are processing queued events depending on the old instance.
1534 The counter of a new FD is incremented by Coordinator or Worker at
1535 time of {Relay_log_info,Slave_worker}::set_rli_description_event()
1536 execution.
1537 In the same methods the counter of the "old" FD event is decremented
1538 and when it drops to zero the old FD is deleted.
1539 The latest read from relay-log event is to be
1540 destroyed by Coordinator/SQL thread at its thread exit.
1541 Notice the counter is processed even in the single-thread mode where
1542 decrement and increment are done by the single SQL thread.
1543 */
1544 std::atomic<int32> atomic_usage_counter{0};
1545
1548 const char *buf,
1549 const mysql::binlog::event::Format_description_event *description_event);
1550#ifdef MYSQL_SERVER
1551 bool write(Basic_ostream *ostream) override;
1552 int pack_info(Protocol *protocol) override;
1553#else
1554 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
1555#endif
1556
1557 size_t get_data_size() override {
1558 /*
1559 The vector of post-header lengths is considered as part of the
1560 post-header, because in a given version it never changes (contrary to the
1561 query in a Query_log_event).
1562 */
1565 }
1566
1567 void claim_memory_ownership(bool claim) override;
1568
1569 protected:
1570#if defined(MYSQL_SERVER)
1571 int do_apply_event(Relay_log_info const *rli) override;
1572 int do_update_pos(Relay_log_info *rli) override;
1574#endif
1575};
1576
1577/**
1578 @class Intvar_log_event
1579
1580 The class derives from the class Intvar_event in Binlog API,
1581 defined in the header binlog_event.h. An Intvar_log_event is
1582 created just before a Query_log_event, if the query uses one
1583 of the variables LAST_INSERT_ID or INSERT_ID. This class is used
1584 by the slave for applying the event.
1585
1586 @internal
1587 The inheritance structure in the current design for the classes is
1588 as follows:
1589
1590 Binary_log_event
1591 ^
1592 |
1593 |
1594 Intvar_event Log_event
1595 \ /
1596 \ /
1597 \ /
1598 Intvar_log_event
1599 @endinternal
1600*/
1602 public Log_event {
1603 public:
1604 // disable copy-move semantics
1605 Intvar_log_event(Intvar_log_event &&) noexcept = delete;
1606 Intvar_log_event &operator=(Intvar_log_event &&) noexcept = delete;
1607 Intvar_log_event(const Intvar_log_event &) = delete;
1608 Intvar_log_event &operator=(const Intvar_log_event &) = delete;
1610#ifdef MYSQL_SERVER
1611 Intvar_log_event(THD *thd_arg, uchar type_arg, ulonglong val_arg,
1612 enum_event_cache_type cache_type_arg,
1613 enum_event_logging_type logging_type_arg)
1614 : mysql::binlog::event::Intvar_event(type_arg, val_arg),
1615 Log_event(thd_arg, 0, cache_type_arg, logging_type_arg, header(),
1616 footer()) {
1618 }
1619 int pack_info(Protocol *protocol) override;
1620#else
1621 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
1622#endif
1623
1625 const char *buf,
1626 const mysql::binlog::event::Format_description_event *description_event);
1627 ~Intvar_log_event() override = default;
1628
1629 void claim_memory_ownership(bool claim) override;
1630
1631 size_t get_data_size() override {
1632 return 9; /* sizeof(type) + sizeof(val) */
1633 ;
1634 }
1635#ifdef MYSQL_SERVER
1636 bool write(Basic_ostream *ostream) override;
1637#endif
1638
1639 bool is_sbr_logging_format() const override { return true; }
1640
1641 private:
1642#if defined(MYSQL_SERVER)
1643 int do_apply_event(Relay_log_info const *rli) override;
1644 int do_update_pos(Relay_log_info *rli) override;
1646#endif
1647};
1648
1649/**
1650 @class Rand_log_event
1651
1652 Logs random seed used by the next RAND(), and by PASSWORD() in 4.1.0.
1653 4.1.1 does not need it (it's repeatable again) so this event needn't be
1654 written in 4.1.1 for PASSWORD() (but the fact that it is written is just a
1655 waste, it does not cause bugs).
1656
1657 The state of the random number generation consists of 128 bits,
1658 which are stored internally as two 64-bit numbers.
1659
1660 @internal
1661 The inheritance structure in the current design for the classes is
1662 as follows:
1663 Binary_log_event
1664 ^
1665 |
1666 |
1667 Rand_event Log_event
1668 \ /
1669 \ /
1670 \ /
1671 Rand_log_event
1672 @endinternal
1673*/
1675 public Log_event {
1676 public:
1677 // disable copy-move semantics
1678 Rand_log_event(Rand_log_event &&) noexcept = delete;
1679 Rand_log_event &operator=(Rand_log_event &&) noexcept = delete;
1680 Rand_log_event(const Rand_log_event &) = delete;
1681 Rand_log_event &operator=(const Rand_log_event &) = delete;
1683#ifdef MYSQL_SERVER
1684 Rand_log_event(THD *thd_arg, ulonglong seed1_arg, ulonglong seed2_arg,
1685 enum_event_cache_type cache_type_arg,
1686 enum_event_logging_type logging_type_arg)
1687 : mysql::binlog::event::Rand_event(seed1_arg, seed2_arg),
1688 Log_event(thd_arg, 0, cache_type_arg, logging_type_arg, header(),
1689 footer()) {
1691 }
1692 int pack_info(Protocol *protocol) override;
1693#else
1694 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
1695#endif
1696
1698 const char *buf,
1699 const mysql::binlog::event::Format_description_event *description_event);
1700 ~Rand_log_event() override = default;
1701
1702 void claim_memory_ownership(bool claim) override;
1703
1704 size_t get_data_size() override { return 16; /* sizeof(ulonglong) * 2*/ }
1705#ifdef MYSQL_SERVER
1706 bool write(Basic_ostream *ostream) override;
1707#endif
1708
1709 bool is_sbr_logging_format() const override { return true; }
1710
1711 private:
1712#if defined(MYSQL_SERVER)
1713 int do_apply_event(Relay_log_info const *rli) override;
1714 int do_update_pos(Relay_log_info *rli) override;
1716#endif
1717};
1718
1719/**
1720 @class Xid_log_event
1721
1722 This is the subclass of Xid_event defined in libbinlogevent,
1723 An XID event is generated for a commit of a transaction that modifies one or
1724 more tables of an XA-capable storage engine
1725 Logs xid of the transaction-to-be-committed in the 2pc protocol.
1726 Has no meaning in replication, slaves ignore it
1727 The inheritance structure in the current design for the classes is
1728 as follows
1729
1730 @internal
1731 The inheritance structure in the current design for the classes is
1732 as follows:
1733 Binary_log_event
1734 ^
1735 |
1736 |
1737 Xid_event Log_event
1738 \ /
1739 \ /
1740 \ /
1741 Xid_log_event
1742 @endinternal
1743*/
1744#ifndef MYSQL_SERVER
1745typedef ulonglong my_xid; // this line is the same as in handler.h
1746#endif
1747
1748class Xid_apply_log_event : public Log_event {
1749 protected:
1750#ifdef MYSQL_SERVER
1751 Xid_apply_log_event(THD *thd_arg,
1755 Log_event::EVENT_NORMAL_LOGGING, header_arg, footer_arg) {}
1756#endif
1759 : Log_event(header_arg, footer_arg) {}
1760 ~Xid_apply_log_event() override = default;
1761 bool ends_group() const override { return true; }
1762#if defined(MYSQL_SERVER)
1764 int do_apply_event(Relay_log_info const *rli) override;
1765 int do_apply_event_worker(Slave_worker *rli) override;
1766 virtual bool do_commit(THD *thd_arg) = 0;
1767#endif
1769
1771 public Xid_apply_log_event {
1772 public:
1773 // disable copy-move semantics
1774 Xid_log_event(Xid_log_event &&) noexcept = delete;
1775 Xid_log_event &operator=(Xid_log_event &&) noexcept = delete;
1776 Xid_log_event(const Xid_log_event &) = delete;
1777 Xid_log_event &operator=(const Xid_log_event &) = delete;
1779#ifdef MYSQL_SERVER
1780 Xid_log_event(THD *thd_arg, my_xid x)
1781 : mysql::binlog::event::Xid_event(x),
1782 Xid_apply_log_event(thd_arg, header(), footer()) {
1784 }
1785 int pack_info(Protocol *protocol) override;
1786#else
1787 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
1788#endif
1789
1791 const char *buf,
1792 const mysql::binlog::event::Format_description_event *description_event);
1793 ~Xid_log_event() override = default;
1794
1795 void claim_memory_ownership(bool claim) override;
1796
1797 size_t get_data_size() override { return sizeof(xid); }
1798#ifdef MYSQL_SERVER
1799 bool write(Basic_ostream *ostream) override;
1800#endif
1801 private:
1802#if defined(MYSQL_SERVER)
1803 bool do_commit(THD *thd_arg) override;
1804#endif
1805};
1806
1807/**
1808 @class XA_prepare_log_event
1809
1810 Similar to Xid_log_event except that
1811 - it is specific to XA transaction
1812 - it carries out the prepare logics rather than the final committing
1813 when @c one_phase member is off.
1814 From the groupping perspective the event finalizes the current "prepare" group
1815 started with XA START Query-log-event.
1816 When @c one_phase is false Commit of Rollback for XA transaction are
1817 logged separately to the prepare-group events so being a groups of
1818 their own.
1820
1822 public Xid_apply_log_event {
1823 private:
1824 /* Total size of buffers to hold serialized members of XID struct */
1825 static const int xid_bufs_size = 12;
1826
1827 public:
1828#ifdef MYSQL_SERVER
1829 XA_prepare_log_event(THD *thd_arg, XID *xid_arg, bool one_phase_arg = false)
1830 : mysql::binlog::event::XA_prepare_event((void *)xid_arg, one_phase_arg),
1832#endif
1834 const char *buf,
1835 const mysql::binlog::event::Format_description_event *description_event)
1836 : mysql::binlog::event::XA_prepare_event(buf, description_event),
1838 DBUG_TRACE;
1839 xid = nullptr;
1840 return;
1841 }
1844 }
1845 size_t get_data_size() override {
1846 return xid_bufs_size + my_xid.gtrid_length + my_xid.bqual_length;
1847 }
1848
1849 void claim_memory_ownership(bool claim) override;
1850
1851#ifdef MYSQL_SERVER
1852 bool write(Basic_ostream *ostream) override;
1853#else
1854 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
1855#endif
1856#if defined(MYSQL_SERVER)
1857 int pack_info(Protocol *protocol) override;
1858 bool do_commit(THD *thd) override;
1859#endif
1860};
1861
1862/**
1863 @class User_var_log_event
1864
1865 Every time a query uses the value of a user variable, a User_var_log_event is
1866 written before the Query_log_event, to set the user variable.
1867
1868 @internal
1869 The inheritance structure in the current design for the classes is
1870 as follows:
1871 Binary_log_event
1872 ^
1873 |
1874 |
1875 User_var_event Log_event
1876 \ /
1877 \ /
1878 \ /
1879 User_var_log_event
1880 @endinternal
1881*/
1883 public Log_event {
1884 public:
1885 // disable copy-move semantics
1887 User_var_log_event &operator=(User_var_log_event &&) noexcept = delete;
1888 User_var_log_event(const User_var_log_event &) = delete;
1889 User_var_log_event &operator=(const User_var_log_event &) = delete;
1891#ifdef MYSQL_SERVER
1894 User_var_log_event(THD *thd_arg, const char *name_arg, uint name_len_arg,
1895 char *val_arg, ulong val_len_arg, Item_result type_arg,
1896 uint charset_number_arg, uchar flags_arg,
1897 enum_event_cache_type cache_type_arg,
1898 enum_event_logging_type logging_type_arg)
1899 : mysql::binlog::event::User_var_event(name_arg, name_len_arg, val_arg,
1900 val_len_arg, type_arg,
1901 charset_number_arg, flags_arg),
1902 Log_event(thd_arg, 0, cache_type_arg, logging_type_arg, header(),
1903 footer()),
1904 deferred(false) {
1905 common_header->set_is_valid(name != nullptr);
1906 }
1907 int pack_info(Protocol *protocol) override;
1908#else
1909 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
1910#endif
1911
1913 const char *buf,
1914 const mysql::binlog::event::Format_description_event *description_event);
1915 ~User_var_log_event() override = default;
1916
1917 void claim_memory_ownership(bool claim) override;
1918
1919#ifdef MYSQL_SERVER
1920 bool write(Basic_ostream *ostream) override;
1921 /*
1922 Getter and setter for deferred User-event.
1923 Returns true if the event is not applied directly
1924 and which case the applier adjusts execution path.
1925 */
1926 bool is_deferred() { return deferred; }
1927 /*
1928 In case of the deferred applying the variable instance is flagged
1929 and the parsing time query id is stored to be used at applying time.
1930 */
1931 void set_deferred(query_id_t qid) {
1932 deferred = true;
1933 query_id = qid;
1934 }
1935#endif
1936
1937 bool is_sbr_logging_format() const override { return true; }
1938
1939 private:
1940#if defined(MYSQL_SERVER)
1941 int do_apply_event(Relay_log_info const *rli) override;
1942 int do_update_pos(Relay_log_info *rli) override;
1944#endif
1945};
1946
1947/**
1948 @class Stop_log_event
1950*/
1952 public Log_event {
1953 public:
1954 // disable copy-move semantics
1955 Stop_log_event(Stop_log_event &&) noexcept = delete;
1956 Stop_log_event &operator=(Stop_log_event &&) noexcept = delete;
1957 Stop_log_event(const Stop_log_event &) = delete;
1958 Stop_log_event &operator=(const Stop_log_event &) = delete;
1960#ifdef MYSQL_SERVER
1965 }
1966
1967#else
1968 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
1969#endif
1970
1972 const char *buf,
1973 const mysql::binlog::event::Format_description_event *description_event)
1974 : mysql::binlog::event::Stop_event(buf, description_event),
1975 Log_event(header(), footer()) {
1976 DBUG_TRACE;
1977 return;
1980 ~Stop_log_event() override = default;
1983 }
1984
1985 void claim_memory_ownership(bool claim) override;
1986
1987 private:
1988#if defined(MYSQL_SERVER)
1989 int do_update_pos(Relay_log_info *rli) override;
1991 /*
1992 Events from ourself should be skipped, but they should not
1993 decrease the slave skip counter.
1994 */
1995 if (this->server_id == ::server_id)
1997 else
1999 }
2000#endif
2001};
2002
2003/**
2004 @class Rotate_log_event
2005
2006 This will be deprecated when we move to using sequence ids.
2007 This class is a subclass of Rotate_event, defined in binlogevent, and is used
2008 by the slave for updating the position in the relay log.
2009
2010 It is used by the master inorder to write the rotate event in the binary log.
2011
2012 @internal
2013 The inheritance structure in the current design for the classes is
2014 as follows:
2015
2016 Binary_log_event
2017 ^
2018 |
2019 |
2020 Rotate_event Log_event
2021 \ /
2022 \ /
2023 \ /
2024 Rotate_log_event
2025 @endinternal
2026*/
2028 public Log_event {
2029 public:
2030 // disable copy-move semantics
2031 Rotate_log_event(Rotate_log_event &&) noexcept = delete;
2032 Rotate_log_event &operator=(Rotate_log_event &&) noexcept = delete;
2033 Rotate_log_event(const Rotate_log_event &) = delete;
2034 Rotate_log_event &operator=(const Rotate_log_event &) = delete;
2035
2036#ifdef MYSQL_SERVER
2037 Rotate_log_event(const char *new_log_ident_arg, size_t ident_len_arg,
2038 ulonglong pos_arg, uint flags);
2039 int pack_info(Protocol *protocol) override;
2040#else
2041 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
2042#endif
2043
2045 const char *buf,
2047 ~Rotate_log_event() override = default;
2048 size_t get_data_size() override {
2049 return ident_len +
2051 }
2052
2053 void claim_memory_ownership(bool claim) override;
2054
2055#ifdef MYSQL_SERVER
2056 bool write(Basic_ostream *ostream) override;
2057#endif
2058
2059 private:
2060#if defined(MYSQL_SERVER)
2061 int do_update_pos(Relay_log_info *rli) override;
2063#endif
2064};
2065
2066/**
2067 @class Append_block_log_event
2068
2069 This event is created to contain the file data. One LOAD_DATA_INFILE
2070 can have 0 or more instances of this event written to the binary log
2071 depending on the size of the file.
2072
2073 @internal
2074 The inheritance structure is as follows
2075
2076 Binary_log_event
2077 ^
2078 |
2079 |
2080 B_l:A_B_E Log_event
2081 \ /
2082 \ /
2083 <<vir>>\ /
2084 \ /
2085 Append_block_log_event
2086 B_l: Namespace Binary_log
2087 A_B_E: class Append_block_event
2088 @endinternal
2090*/
2093 public Log_event {
2094 public:
2095 // disable copy-move semantics
2096 Append_block_log_event(Append_block_log_event &&) noexcept = delete;
2098 delete;
2100 Append_block_log_event &operator=(const Append_block_log_event &) = delete;
2101
2102#ifdef MYSQL_SERVER
2103 Append_block_log_event(THD *thd, const char *db_arg, uchar *block_arg,
2104 uint block_len_arg, bool using_trans);
2105 int pack_info(Protocol *protocol) override;
2106 virtual int get_create_or_append() const;
2107#else
2108 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
2109#endif
2110
2112 const char *buf,
2113 const mysql::binlog::event::Format_description_event *description_event);
2114 ~Append_block_log_event() override = default;
2115
2116 void claim_memory_ownership(bool claim) override;
2117
2118 size_t get_data_size() override {
2119 return block_len +
2121 }
2122#ifdef MYSQL_SERVER
2123 bool write(Basic_ostream *ostream) override;
2124 const char *get_db() override { return db; }
2125#endif
2126
2127 bool is_sbr_logging_format() const override { return true; }
2128
2129 private:
2130#if defined(MYSQL_SERVER)
2131 int do_apply_event(Relay_log_info const *rli) override;
2132#endif
2133};
2134
2135/**
2136 @class Delete_file_log_event
2137
2138 Delete_file_log_event is created when the LOAD_DATA query fails on the
2139 master for some reason, and the slave should be notified to abort the
2140 load. The event is required since the master starts writing the loaded
2141 block into the binary log before the statement ends. In case of error,
2142 the slave should abort, and delete any temporary file created while
2143 applying the (NEW_)LOAD_EVENT.
2144
2145 @internal
2146 The inheritance structure is as follows
2147
2148 Binary_log_event
2149 ^
2150 |
2151 |
2152 B_l:D_F_E Log_event
2153 \ /
2154 \ /
2155 \ /
2156 \ /
2157 Delete_file_log_event
2158
2159 B_l: Namespace Binary_log
2160 D_F_E: class Delete_file_event
2161 @endinternal
2163*/
2165 public Log_event {
2166 public:
2167 // disable copy-move semantics
2169 Delete_file_log_event &operator=(Delete_file_log_event &&) noexcept = delete;
2171 Delete_file_log_event &operator=(const Delete_file_log_event &) = delete;
2172
2173#ifdef MYSQL_SERVER
2174 Delete_file_log_event(THD *thd, const char *db_arg, bool using_trans);
2175 int pack_info(Protocol *protocol) override;
2176#else
2177 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
2178 void print(FILE *file, PRINT_EVENT_INFO *print_event_info, bool enable_local);
2179#endif
2180
2182 const char *buf,
2183 const mysql::binlog::event::Format_description_event *description_event);
2184 ~Delete_file_log_event() override = default;
2185
2186 void claim_memory_ownership(bool claim) override;
2187
2188 size_t get_data_size() override {
2190 }
2191#ifdef MYSQL_SERVER
2192 bool write(Basic_ostream *ostream) override;
2193 const char *get_db() override { return db; }
2194#endif
2195
2196 bool is_sbr_logging_format() const override { return true; }
2197
2198 private:
2199#if defined(MYSQL_SERVER)
2200 int do_apply_event(Relay_log_info const *rli) override;
2201#endif
2202};
2203
2204/**
2205 @class Begin_load_query_log_event
2206
2207 Event for the first block of file to be loaded, its only difference from
2208 Append_block event is that this event creates or truncates existing file
2209 before writing data.
2210
2211 @internal
2212 The inheritance structure is as follows
2213
2214 Binary_log_event
2215 ^
2216 |
2217 |
2218 |
2219 Log_event B_l:A_B_E
2220 ^ /\
2221 | / \
2222 | <<vir>>/ \ <<vir>>
2223 | / \
2224 | / \
2225 | / \
2226 Append_block_log_event B_l:B_L_Q_E
2227 \ /
2228 \ /
2229 \ /
2230 \ /
2231 \ /
2232 Begin_load_query_log_event
2233
2234 B_l: Namespace Binary_log
2235 A_B_E: class Append_block_event
2236 B_L_Q_E: Begin_load_query_event
2237 @endinternal
2238
2239 @section Begin_load_query_log_event_binary_format Binary Format
2240*/
2242 : public Append_block_log_event,
2244 public:
2245 // disable copy-move semantics
2248 Begin_load_query_log_event &&) noexcept = delete;
2251 delete;
2252
2253#ifdef MYSQL_SERVER
2254 Begin_load_query_log_event(THD *thd_arg, const char *db_arg, uchar *block_arg,
2255 uint block_len_arg, bool using_trans);
2257 int get_create_or_append() const override;
2258#endif
2260 const char *buf,
2261 const mysql::binlog::event::Format_description_event *description_event);
2262 ~Begin_load_query_log_event() override = default;
2263
2264 void claim_memory_ownership(bool claim) override;
2265
2266 private:
2267#if defined(MYSQL_SERVER)
2269#endif
2270};
2271
2272/**
2273 @class Execute_load_query_log_event
2274
2275 Event responsible for LOAD DATA execution, it similar to Query_log_event
2276 but before executing the query it substitutes original filename in LOAD DATA
2277 query with name of temporary file.
2278
2279 @internal
2280 The inheritance structure is as follows:
2281
2282 Binary_log_event
2283 ^
2284 |
2285 |
2286 |
2287 Log_event B_l:Query_event
2288 ^ /\
2289 | / \
2290 | <<vir>>/ \ <<vir>>
2291 | / \
2292 | / \
2293 | / \
2294 Query_log_event B_l:E_L_Q_E
2295 \ /
2296 \ /
2297 \ /
2298 \ /
2299 \ /
2300 Execute_load_query_log_event
2301
2302 B_l: Namespace Binary_log
2303 E_L_Q_E: class Execute_load_query
2304 @endinternal
2305
2306 @section Execute_load_query_log_event_binary_format Binary Format
2307*/
2309 : public Query_log_event,
2311 public:
2312#ifdef MYSQL_SERVER
2314 THD *thd, const char *query_arg, ulong query_length,
2315 uint fn_pos_start_arg, uint fn_pos_end_arg,
2317 bool using_trans, bool immediate, bool suppress_use, int errcode);
2318 int pack_info(Protocol *protocol) override;
2319#else
2320 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
2321 /* Prints the query as LOAD DATA LOCAL and with rewritten filename */
2322 void print(FILE *file, PRINT_EVENT_INFO *print_event_info,
2323 const char *local_fname) const;
2324#endif
2326 const char *buf,
2327 const mysql::binlog::event::Format_description_event *description_event);
2328 ~Execute_load_query_log_event() override = default;
2329
2330 ulong get_post_header_size_for_derived() override;
2331#ifdef MYSQL_SERVER
2332 bool write_post_header_for_derived(Basic_ostream *ostream) override;
2333#endif
2334
2335 bool is_sbr_logging_format() const override { return true; }
2336
2337 void claim_memory_ownership(bool claim) override;
2338
2339 private:
2340#if defined(MYSQL_SERVER)
2341 int do_apply_event(Relay_log_info const *rli) override;
2342#endif
2343};
2345#if defined MYSQL_SERVER
2347 public:
2348 Load_query_generator(THD *thd_arg, const sql_exchange *ex, const char *db_arg,
2349 const char *table_name_arg, bool is_concurrent_arg,
2350 bool replace, bool ignore);
2351
2352 const String *generate(size_t *fn_start, size_t *fn_end);
2354 private:
2355 const size_t BUF_SIZE = 2048;
2356 String str;
2357 char *buf[2048];
2361 const char *db;
2362 const char *table_name;
2363 const char *fname;
2366 bool has_replace;
2367 bool has_ignore;
2368};
2369#endif
2370#ifndef MYSQL_SERVER
2371/**
2372 @class Unknown_log_event
2373
2374*/
2375class Unknown_log_event : public mysql::binlog::event::Unknown_event,
2376 public Log_event {
2377 public:
2378 // disable copy-move semantics
2379 Unknown_log_event(Unknown_log_event &&) noexcept = delete;
2380 Unknown_log_event &operator=(Unknown_log_event &&) noexcept = delete;
2381 Unknown_log_event(const Unknown_log_event &) = delete;
2382 Unknown_log_event &operator=(const Unknown_log_event &) = delete;
2383
2384 /**
2385 Even if this is an unknown event, we still pass description_event to
2386 Log_event's ctor, this way we can extract maximum information from the
2387 event's header (the unique ID for example).
2388 */
2389 Unknown_log_event(
2390 const char *buf,
2391 const mysql::binlog::event::Format_description_event *description_event)
2392 : mysql::binlog::event::Unknown_event(buf, description_event),
2393 Log_event(header(), footer()) {
2394 DBUG_TRACE;
2395 if (!is_valid()) return;
2396 common_header->set_is_valid(true);
2397 return;
2398 }
2399
2400 ~Unknown_log_event() override = default;
2401 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
2404 }
2405};
2406#endif
2407char *str_to_hex(char *to, const char *from, size_t len);
2408
2409/**
2410 @class Table_map_log_event
2411
2412 Table_map_log_event which maps a table definition to a number.
2413
2414 @internal
2415 The inheritance structure in the current design for the classes is
2416 as follows:
2417
2418 Binary_log_event
2419 ^
2420 |
2421 |
2422 Table_map_event Log_event
2423 \ /
2424 \ /
2425 \ /
2426 Table_map_log_event
2427 @endinternal
2428*/
2430 public Log_event {
2431 public:
2432 // disable copy-move semantics
2434 Table_map_log_event &operator=(Table_map_log_event &&) noexcept = delete;
2435 Table_map_log_event(const Table_map_log_event &) = delete;
2436 Table_map_log_event &operator=(const Table_map_log_event &) = delete;
2438 /** Constants */
2440
2441 /**
2442 Enumeration of the errors that can be returned.
2445 ERR_OPEN_FAILURE = -1, /**< Failure to open table */
2446 ERR_OK = 0, /**< No error */
2447 ERR_TABLE_LIMIT_EXCEEDED = 1, /**< No more room for tables */
2448 ERR_OUT_OF_MEM = 2, /**< Out of memory */
2449 ERR_BAD_TABLE_DEF = 3, /**< Table definition does not match */
2450 ERR_RBR_TO_SBR = 4 /**< daisy-chanining RBR to SBR not allowed */
2452
2453 enum enum_flag {
2454 /**
2455 Nothing here right now, but the flags support is there in
2456 preparation for changes that are coming. Need to add a
2457 constant to make it compile under HP-UX: aCC does not like
2458 empty enumerations.
2461 };
2462
2463 /** Special constants representing sets of flags */
2464 enum {
2466 TM_BIT_LEN_EXACT_F = (1U << 0),
2467 TM_REFERRED_FK_DB_F = (1U << 1),
2468 /**
2469 Table has generated invisible primary key. MySQL generates primary key
2470 while creating a table if sql_generate_invisible_primary_key is "ON" and
2471 table is PK-less.
2473 TM_GENERATED_INVISIBLE_PK_F = (1U << 2)
2475
2476 flag_set get_flags(flag_set flag) const { return m_flags & flag; }
2477
2478#ifdef MYSQL_SERVER
2479 Table_map_log_event(THD *thd_arg, TABLE *tbl,
2481 bool using_trans);
2482#endif
2484 const char *buf,
2485 const mysql::binlog::event::Format_description_event *description_event);
2486
2487 void claim_memory_ownership(bool claim) override;
2488
2489 ~Table_map_log_event() override;
2490
2491#ifndef MYSQL_SERVER
2492 table_def *create_table_def() {
2493 assert(m_colcnt > 0);
2496 }
2497 static bool rewrite_db_in_buffer(
2498 char **buf, ulong *event_len,
2500#endif
2504 const char *get_table_name() const { return m_tblnam.c_str(); }
2505 const char *get_db_name() const { return m_dbnam.c_str(); }
2506
2507 size_t get_data_size() override { return m_data_size; }
2508#ifdef MYSQL_SERVER
2509 virtual int save_field_metadata();
2510 bool write_data_header(Basic_ostream *ostream) override;
2511 bool write_data_body(Basic_ostream *ostream) override;
2512 const char *get_db() override { return m_dbnam.c_str(); }
2513 uint8 mts_number_dbs() override {
2515 }
2516 /**
2517 @param[out] arg pointer to a struct containing char* array
2518 pointers be filled in and the number of filled instances.
2519 @param rpl_filter pointer to a replication filter.
2520
2521 @return number of databases in the array: either one or
2522 OVER_MAX_DBS_IN_EVENT_MTS, when the Table map event reports
2523 foreign keys constraint.
2524 */
2526 const char *db_name = get_db();
2527
2529 size_t dummy_len;
2530 const char *db_filtered = rpl_filter->get_rewrite_db(db_name, &dummy_len);
2531 // db_name != db_filtered means that db_name is rewritten.
2532 if (strcmp(db_name, db_filtered)) db_name = db_filtered;
2533 }
2534
2535 if (!get_flags(TM_REFERRED_FK_DB_F)) arg->name[0] = db_name;
2536
2537 return arg->num = mts_number_dbs();
2538 }
2539
2540#endif
2541
2542#if defined(MYSQL_SERVER)
2543 int pack_info(Protocol *protocol) override;
2544#endif
2545
2546#ifndef MYSQL_SERVER
2547 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
2548
2549 /**
2550 Print column metadata. Its format looks like:
2551 # Columns(colume_name type, colume_name type, ...)
2552 if colume_name field is not logged into table_map_log_event, then
2553 only type is printed.
2554
2555 @param[out] file the place where colume metadata is printed
2556 @param[in] fields The metadata extracted from optional metadata fields
2557 */
2558 void print_columns(IO_CACHE *file,
2559 const Optional_metadata_fields &fields) const;
2560 /**
2561 Print primary information. Its format looks like:
2562 # Primary Key(colume_name, column_name(prifix), ...)
2563 if colume_name field is not logged into table_map_log_event, then
2564 colume index is printed.
2565
2566 @param[out] file the place where primary key is printed
2567 @param[in] fields The metadata extracted from optional metadata fields
2568 */
2569 void print_primary_key(IO_CACHE *file,
2570 const Optional_metadata_fields &fields) const;
2571#endif
2572
2574
2575 bool is_rbr_logging_format() const override { return true; }
2576
2577 private:
2578#if defined(MYSQL_SERVER)
2579 int do_apply_event(Relay_log_info const *rli) override;
2580 int do_update_pos(Relay_log_info *rli) override;
2582#endif
2584#ifdef MYSQL_SERVER
2585 TABLE *m_table;
2587 // Metadata fields buffer
2589
2590 /**
2591 Wrapper around `TABLE *m_table` that abstracts the table field set iteration
2592 logic, since it is not mandatory that all table fields are to be
2593 replicated. For details, @see ReplicatedColumnsView class documentation.
2594
2595 A smart pointer is used here as the developer might want to instantiate the
2596 view using different classes in runtime depending on the given context.
2597 As of now the column view is only used on outbound scenarios
2598 */
2600
2601 /**
2602 Capture the optional metadata fields which should be logged into
2603 table_map_log_event and serialize them into m_metadata_buf.
2604 */
2605 void init_metadata_fields();
2606 bool init_signedness_field();
2607 /**
2608 Capture and serialize character sets. Character sets for
2609 character columns (TEXT etc) and character sets for ENUM and SET
2610 columns are stored in different metadata fields. The reason is
2611 that TEXT character sets are included even when
2612 binlog_row_metadata=MINIMAL, whereas ENUM and SET character sets
2613 are included only when binlog_row_metadata=FULL.
2614
2615 @param include_type Predicate to determine if a given Field object
2616 is to be included in the metadata field.
2617
2618 @param default_charset_type Type code when storing in "default
2619 charset" format. (See comment above Table_maps_log_event in
2620 mysql/binlog/event/rows_event.h)
2621
2622 @param column_charset_type Type code when storing in "column
2623 charset" format. (See comment above Table_maps_log_event in
2624 mysql/binlog/event/rows_event.h)
2625 */
2626 bool init_charset_field(std::function<bool(const Field *)> include_type,
2627 Optional_metadata_field_type default_charset_type,
2628 Optional_metadata_field_type column_charset_type);
2635#endif
2636
2637#ifndef MYSQL_SERVER
2638 class Charset_iterator;
2639 class Default_charset_iterator;
2640 class Column_charset_iterator;
2641#endif
2642};
2643
2644#ifdef HAVE_PSI_STAGE_INTERFACE
2645/*
2646 Helper class for PSI context while applying a Rows_log_event.
2647 */
2649 private:
2652
2653 /**
2654 A cached pointer to this stage PSI_stage_progress.
2655 */
2657
2658 /**
2659 Counter that is unconditionally incremented on each row that is processed.
2660 This is helpful in case estimation is needed after started processing
2661 a Rows_log_event.
2662 */
2665 public:
2667
2668 void set_progress(PSI_stage_progress *progress) { m_progress = progress; }
2669
2670 /**
2671 If instrumentation is enabled this member function SHALL return true.
2672 @return true if instrumentation is enabled for the given stage, false
2673 otherwise.
2674 */
2675 bool is_enabled() { return m_progress != nullptr; }
2676
2677 /**
2678 This member function shall update the progress and reestimate the remaining
2679 work needed. This MUST be called after setting n_rows_applied correctly
2680 by calling inc_n_rows_applied beforehand.
2681
2682 Cursor, begin and end are used in case estimation is needed.
2683
2684 @param cursor Pointer to where we are in the buffer of rows to be processed.
2685 @param begin Pointer to the beginning of the rows buffer.
2686 @param end Pointer to the end of the rows buffer.
2687 */
2688 void update_work_estimated_and_completed(const uchar *cursor,
2689 const uchar *begin,
2690 const uchar *end) {
2691 if (!is_enabled()) return;
2692
2694
2695 /* Estimate if need be. */
2696 if (estimated == 0) {
2697 assert(cursor > begin);
2698 const ulonglong avg_row_change_size = (cursor - begin) / m_n_rows_applied;
2699 estimated = (end - begin) / avg_row_change_size;
2701 }
2702
2703 /* reset estimated if done more work than estimated */
2704 if (m_n_rows_applied > estimated)
2707 }
2708
2709 /**
2710 Resets this object.
2711 */
2712 void end_work() {
2713 m_progress = nullptr;
2714 m_n_rows_applied = 0;
2715 }
2716
2717 /**
2718 Updates the counter of processed rows.
2719 @param delta the amount of increment to be done.
2720 */
2721 void inc_n_rows_applied(ulonglong delta) { m_n_rows_applied += delta; }
2722
2723 /**
2724 Gets the value of the counter of rows that have been processed.
2725 @return the value of the counter of rows processed so far.
2726 */
2728};
2729#endif
2730
2731/**
2732 @class Rows_log_event
2733
2734 Common base class for all row-containing log events.
2735
2736 RESPONSIBILITIES
2737
2738 Encode the common parts of all events containing rows, which are:
2739 - Write data header and data body to an IO_CACHE.
2740
2741 Virtual inheritance is required here to handle the diamond problem in
2742 the class Write_rows_log_event, Update_rows_log_event and
2743 Delete_rows_log_event.
2744 The diamond structure is explained in @c Write_rows_log_event,
2745 @c Update_rows_log_event,
2746 @c Delete_rows_log_event
2747
2748 @internal
2749 The inheritance structure in the current design for the classes is
2750 as follows:
2751
2752 Binary_log_event
2753 ^
2754 |
2755 |
2756 Rows_event Log_event
2757 \ /
2758 <<vir>>\ /
2759 \ /
2760 Rows_log_event
2761 @endinternal
2763*/
2765 public Log_event {
2766#ifdef HAVE_PSI_STAGE_INTERFACE
2767 protected:
2769#endif
2770
2771 public:
2772 // disable copy-move semantics
2773 Rows_log_event(Rows_log_event &&) noexcept = delete;
2774 Rows_log_event &operator=(Rows_log_event &&) noexcept = delete;
2775 Rows_log_event(const Rows_log_event &) = delete;
2776 Rows_log_event &operator=(const Rows_log_event &) = delete;
2777
2786 };
2787
2788 /**
2789 Enumeration of the errors that can be returned.
2792 ERR_OPEN_FAILURE = -1, /**< Failure to open table */
2793 ERR_OK = 0, /**< No error */
2794 ERR_TABLE_LIMIT_EXCEEDED = 1, /**< No more room for tables */
2795 ERR_OUT_OF_MEM = 2, /**< Out of memory */
2796 ERR_BAD_TABLE_DEF = 3, /**< Table definition does not match */
2797 ERR_RBR_TO_SBR = 4 /**< daisy-chanining RBR to SBR not allowed */
2798 };
2800 /* Special constants representing sets of flags */
2801 enum { RLE_NO_FLAGS = 0U };
2802
2805 void set_flags(flag_set flags_arg) { m_flags |= flags_arg; }
2806 void clear_flags(flag_set flags_arg) { m_flags &= ~flags_arg; }
2807 flag_set get_flags(flag_set flags_arg) const { return m_flags & flags_arg; }
2810 get_general_type_code() = 0; /* General rows op type, no version */
2811
2812#if defined(MYSQL_SERVER)
2813 int pack_info(Protocol *protocol) override;
2814#endif
2815
2816#ifndef MYSQL_SERVER
2817 void print_verbose(IO_CACHE *file, PRINT_EVENT_INFO *print_event_info);
2818 size_t print_verbose_one_row(IO_CACHE *file, table_def *td,
2819 PRINT_EVENT_INFO *print_event_info,
2820 MY_BITMAP *cols_bitmap, const uchar *ptr,
2821 const uchar *prefix,
2822 enum_row_image_type row_image_type);
2823#endif
2825#ifdef MYSQL_SERVER
2826 int add_row_data(uchar *data, size_t length) {
2827 return do_add_row_data(data, length);
2828 }
2829#endif
2830
2831 /* Member functions to implement superclass interface */
2832 size_t get_data_size() override;
2834 MY_BITMAP const *get_cols() const { return &m_cols; }
2835 MY_BITMAP const *get_cols_ai() const { return &m_cols_ai; }
2837 return m_table_id;
2838 }
2839
2840#if defined(MYSQL_SERVER)
2841 /**
2842 Compares the table's read/write_set with the columns included in
2843 this event's before-image and/or after-image. Each subclass
2844 (Write/Update/Delete) implements this function by comparing on the
2845 image(s) pertinent to the subclass.
2846
2847 @param[in] table The table to compare this events bitmaps
2848 against.
2849
2850 @retval true if sets match
2851 @retval false otherwise (following bitmap_cmp return logic).
2852 */
2853 virtual bool read_write_bitmaps_cmp(const TABLE *table) const = 0;
2854#endif
2855
2856#ifdef MYSQL_SERVER
2857 bool write_data_header(Basic_ostream *ostream) override;
2858 bool write_data_body(Basic_ostream *ostream) override;
2859 const char *get_db() override { return m_table->s->db.str; }
2860#endif
2861
2862 uint m_row_count; /* The number of rows added to the event */
2863
2864 protected:
2865 /*
2866 The constructors are protected since you're supposed to inherit
2867 this class, not create instances of this class.
2868 */
2869#ifdef MYSQL_SERVER
2871 MY_BITMAP const *cols, bool is_transactional,
2873 const unsigned char *extra_row_ndb_info);
2874#endif
2876 const char *row_data,
2877 const mysql::binlog::event::Format_description_event *description_event);
2878
2879#ifndef MYSQL_SERVER
2880 void print_helper(FILE *, PRINT_EVENT_INFO *) const;
2881#endif
2882
2883#ifdef MYSQL_SERVER
2884 virtual int do_add_row_data(uchar *data, size_t length);
2885#endif
2887#ifdef MYSQL_SERVER
2888 TABLE *m_table; /* The table the rows belong to */
2889#endif
2890 MY_BITMAP m_cols; /* Bitmap denoting columns available */
2891 /**
2892 Bitmap denoting columns available in the image as they appear in the table
2893 setup. On some setups, the number and order of columns may differ from
2894 master to slave so, a bitmap for local available columns is computed using
2895 `ReplicatedColumnsView` utility class.
2896 */
2898#ifdef MYSQL_SERVER
2899 /**
2900 Hash table that will hold the entries for while using HASH_SCAN
2901 algorithm to search and update/delete rows.
2902 */
2904
2905 /**
2906 The algorithm to use while searching for rows using the before
2907 image.
2908 */
2910#endif
2911 /**
2912 Bitmap for columns available in the after image, if present. These
2913 fields are only available for Update_rows events. Observe that the
2914 width of both the before image COLS vector and the after image
2915 COLS vector is the same: the number of columns of the table on the
2916 master.
2917 */
2919 /**
2920 Bitmap denoting columns available in the after-image as they appear in the
2921 table setup. On some setups, the number and order of columns may differ from
2922 master to slave so, a bitmap for local available columns is computed using
2923 `ReplicatedColumnsView` utility class.
2924 */
2927 /* Bit buffers in the same memory as the class */
2928 uint32 m_bitbuf[128 / (sizeof(uint32) * 8)];
2929 uint32 m_bitbuf_ai[128 / (sizeof(uint32) * 8)];
2930
2931 /*
2932 is_valid depends on the value of m_rows_buf, so while changing the value
2933 of m_rows_buf check if is_valid also needs to be modified
2935 uchar *m_rows_buf; /* The rows in packed format */
2936 uchar *m_rows_cur; /* One-after the end of the data */
2937 uchar *m_rows_end; /* One-after the end of the allocated space */
2938
2939 /* helper functions */
2941#if defined(MYSQL_SERVER)
2942 const uchar *m_curr_row; /* Start of the row being processed */
2943 const uchar *m_curr_row_end; /* One-after the end of the current row */
2944 uchar *m_key; /* Buffer to keep key value during searches */
2946 KEY *m_key_info; /* Points to description of index #m_key_index */
2947 class Key_compare {
2948 public:
2949 /**
2950 @param ki Where to find KEY description
2951 @note m_distinct_keys is instantiated when Rows_log_event is constructed;
2952 it stores a Key_compare object internally. However at that moment, the
2953 index (KEY*) to use for comparisons, is not yet known. So, at
2954 instantiation, we indicate the Key_compare the place where it can
2955 find the KEY* when needed (this place is Rows_log_event::m_key_info),
2956 Key_compare remembers the place in member m_key_info.
2957 Before we need to do comparisons - i.e. before we need to insert
2958 elements, we update Rows_log_event::m_key_info once for all.
2960 Key_compare(KEY **ki = nullptr) : m_key_info(ki) {}
2961 bool operator()(uchar *k1, uchar *k2) const {
2962 return key_cmp2((*m_key_info)->key_part, k1, (*m_key_info)->key_length,
2963 k2, (*m_key_info)->key_length) < 0;
2964 }
2966 private:
2969 std::set<uchar *, Key_compare> m_distinct_keys;
2970 std::set<uchar *, Key_compare>::iterator m_itr;
2971 /**
2972 A spare buffer which will be used when saving the distinct keys
2973 for doing an index scan with HASH_SCAN search algorithm.
2974 */
2976
2977 /**
2978 Unpack the current row image from the event into m_table->record[0].
2979
2980 @param rli The applier context.
2981
2982 @param cols The bitmap of columns included in the update.
2983
2984 @param is_after_image Should be true if this is an after-image,
2985 false if it is a before-image.
2986
2987 @param only_seek unpack_row()
2988
2989 @retval 0 Success
2990
2991 @retval ER_* On error, it is guaranteed that the error has been
2992 reported through my_error, and the corresponding ER_* code is
2993 returned. Currently the error codes are: EE_OUTOFMEMORY,
2994 ER_REPLICA_CORRUPT_EVENT, or various JSON errors when applying JSON
2995 diffs (ER_COULD_NOT_APPLY_JSON_DIFF, ER_INVALID_JSON_BINARY_DATA,
2996 and maybe others).
2997 */
2998 int unpack_current_row(const Relay_log_info *const rli, MY_BITMAP const *cols,
2999 bool is_after_image, bool only_seek = false);
3000 /**
3001 Updates the generated columns of the `TABLE` object referenced by
3002 `m_table`, that have an active bit in the parameter bitset
3003 `fields_to_update`.
3004
3005 @param fields_to_update A bitset where the bit at the index of
3006 generated columns to update must be set to `1`
3007
3008 @return 0 if the operation terminated successfully, 1 otherwise.
3009 */
3010 int update_generated_columns(MY_BITMAP const &fields_to_update);
3011 /*
3012 This member function is called when deciding the algorithm to be used to
3013 find the rows to be updated on the slave during row based replication.
3014 This this functions sets the m_rows_lookup_algorithm and also the
3015 m_key_index with the key index to be used if the algorithm is dependent on
3016 an index.
3017 TODO(Bug#31173056): Remove SUPPRESS_UBSAN_CLANG10
3018 */
3020
3021 /*
3022 Encapsulates the operations to be done before applying
3023 row event for update and delete.
3024 */
3026
3027 /*
3028 Encapsulates the operations to be done after applying
3029 row event for update and delete.
3030 */
3032
3033 /**
3034 Helper function to check whether there is an auto increment
3035 column on the table where the event is to be applied.
3036 GIPKs when not present in the source table are also considered a
3037 auto inc column in a extra column.
3038
3039 @param rli the relay log object associated to the replicated table
3040
3041 @return true if there is an autoincrement field on the extra
3042 columns, false otherwise.
3043 */
3044 bool is_auto_inc_in_extra_columns(const Relay_log_info *const rli);
3045
3046 /**
3047 Helper function to check whether the storage engine error
3048 allows for the transaction to be retried or not.
3049
3050 @param error Storage engine error
3051 @retval true if the error is retryable.
3052 @retval false if the error is non-retryable.
3053 */
3055#endif
3056
3057 bool is_rbr_logging_format() const override { return true; }
3058
3059 private:
3060#if defined(MYSQL_SERVER)
3061
3062 /**
3063 Wrapper around `TABLE *m_table` that abstracts the table field set iteration
3064 logic, since it is not mandatory that all table fields are to be
3065 replicated. For details, @see ReplicatedColumnsView class documentation.
3066
3067 A smart pointer is used here as the developer might want to instantiate the
3068 view using different classes in runtime depending on the given context.
3069 */
3071
3072 int do_apply_event(Relay_log_info const *rli) override;
3073 int do_update_pos(Relay_log_info *rli) override;
3075
3076 /*
3077 Primitive to prepare for a sequence of row executions.
3078
3079 DESCRIPTION
3080
3081 Before doing a sequence of do_prepare_row() and do_exec_row()
3082 calls, this member function should be called to prepare for the
3083 entire sequence. Typically, this member function will allocate
3084 space for any buffers that are needed for the two member
3085 functions mentioned above.
3086
3087 RETURN VALUE
3088
3089 The member function will return 0 if all went OK, or a non-zero
3090 error code otherwise.
3091 */
3092 virtual int do_before_row_operations(const Relay_log_info *const log) = 0;
3093
3094 /*
3095 Primitive to clean up after a sequence of row executions.
3096
3097 DESCRIPTION
3098
3099 After doing a sequence of do_prepare_row() and do_exec_row(),
3100 this member function should be called to clean up and release
3101 any allocated buffers.
3102
3103 The error argument, if non-zero, indicates an error which happened during
3104 row processing before this function was called. In this case, even if
3105 function is successful, it should return the error code given in the
3106 argument.
3107 */
3108 virtual int do_after_row_operations(const Relay_log_info *const log,
3109 int error) = 0;
3110
3111 /*
3112 Primitive to do the actual execution necessary for a row.
3113
3114 DESCRIPTION
3115 The member function will do the actual execution needed to handle a row.
3116 The row is located at m_curr_row. When the function returns,
3117 m_curr_row_end should point at the next row (one byte after the end
3118 of the current row).
3119
3120 RETURN VALUE
3121 0 if execution succeeded, 1 if execution failed.
3123 */
3124 virtual int do_exec_row(const Relay_log_info *const rli) = 0;
3125
3126 /**
3127 Private member function called while handling idempotent errors.
3128
3129 @param rli Pointer to relay log info structure.
3130 @param [in,out] err the error to handle. If it is listed as
3131 idempotent/ignored related error, then it is cleared.
3132 @returns true if the slave should stop executing rows.
3133 */
3135
3136 /**
3137 Private member function called after updating/deleting a row. It
3138 performs some assertions and more importantly, it updates
3139 m_curr_row so that the next row is processed during the row
3140 execution main loop (@c Rows_log_event::do_apply_event()).
3141
3142 @param rli Pointer to relay log info structure.
3143 @param err the current error code.
3144 */
3145 void do_post_row_operations(Relay_log_info const *rli, int err);
3146
3147 /**
3148 Commodity wrapper around do_exec_row(), that deals with resetting
3149 the thd reference in the table.
3150 */
3151 int do_apply_row(Relay_log_info const *rli);
3152
3153 /**
3154 Implementation of the index scan and update algorithm. It uses
3155 PK, UK or regular Key to search for the record to update. When
3156 found it updates it.
3157 */
3159
3160 /**
3161 Implementation of the hash_scan and update algorithm. It collects
3162 rows positions in a hashtable until the last row is
3163 unpacked. Then it scans the table to update and when a record in
3164 the table matches the one in the hashtable, the update/delete is
3165 performed.
3166 */
3168
3169 /**
3170 Implementation of the legacy table_scan and update algorithm. For
3171 each unpacked row it scans the storage engine table for a
3172 match. When a match is found, the update/delete operations are
3173 performed.
3174 */
3176
3177 /**
3178 Seek past the after-image of an update event, in case a row was processed
3179 without reading the after-image.
3180
3181 An update event may process a row without reading the after-image,
3182 e.g. in case of ignored or idempotent errors. To ensure that the
3183 read position for the next row is correct, we need to seek past
3184 the after-image.
3185
3186 @param rli The applier context
3187
3188 @param curr_bi_start The read position of the beginning of the
3189 before-image. (The function compares this with m_curr_row to know
3190 if the after-image has been read or not.)
3191
3192 @retval 0 Success
3193 @retval ER_* Error code returned by unpack_current_row
3194 */
3196 [[maybe_unused]],
3197 const uchar *curr_bi_start
3198 [[maybe_unused]]) {
3199 return 0;
3200 }
3201
3202 /**
3203 Initializes scanning of rows. Opens an index and initializes an iterator
3204 over a list of distinct keys (m_distinct_keys) if it is a HASH_SCAN
3205 over an index or the table if its a HASH_SCAN over the table.
3206 */
3207 int open_record_scan();
3208
3209 /**
3210 Does the cleanup
3211 - closes the index if opened by open_record_scan
3212 - closes the table if opened for scanning.
3213 */
3214 int close_record_scan();
3215
3216 /**
3217 Fetches next row. If it is a HASH_SCAN over an index, it populates
3218 table->record[0] with the next row corresponding to the index. If
3219 the indexes are in non-contigous ranges it fetches record corresponding
3220 to the key value in the next range.
3221
3222 @param first_read signifying if this is the first time we are reading a row
3223 over an index.
3224 @return error code when there are no more records to be fetched or some
3225 other error occurred,
3226 - 0 otherwise.
3227 */
3228 int next_record_scan(bool first_read);
3229
3230 /**
3231 Populates the m_distinct_keys with unique keys to be modified
3232 during HASH_SCAN over keys.
3233 @returns 0 success, or the error code.
3234 */
3236
3237 /**
3238 Populates the m_hash when using HASH_SCAN. Thence, it:
3239 - unpacks the before image (BI)
3240 - saves the positions
3241 - saves the positions into the hash map, using the
3242 BI checksum as key
3243 - unpacks the after image (AI) if needed, so that
3244 m_curr_row_end gets updated correctly.
3245
3246 @param rli The reference to the relay log info object.
3247 @returns 0 on success. Otherwise, the error code.
3248 */
3249 int do_hash_row(Relay_log_info const *rli);
3250
3251 /**
3252 This member function scans the table and applies the changes
3253 that had been previously hashed. As such, m_hash MUST be filled
3254 by do_hash_row before calling this member function.
3255
3256 @param rli The reference to the relay log info object.
3257 @returns 0 on success. Otherwise, the error code.
3258 */
3259 int do_scan_and_update(Relay_log_info const *rli);
3260#endif /* defined(MYSQL_SERVER) */
3261
3262 friend class Old_rows_log_event;
3263
3264 /**
3265 This bitmap is used as a backup for the write set while we calculate
3266 the values for any hidden generated columns (functional indexes). In order
3267 to calculate the values, the columns must be marked in the write set. After
3268 the values are calculated, we set the write set back to its original value.
3269 */
3271};
3272
3273/**
3274 @class Write_rows_log_event
3275
3276 Log row insertions and updates. The event contain several
3277 insert/update rows for a table. Note that each event contains only
3278 rows for one table.
3279
3280 @internal
3281 The inheritance structure is as follows
3282
3283 Binary_log_event
3284 ^
3285 |
3286 |
3287 |
3288 Log_event B_l:Rows_event
3289 ^ /\
3290 | / \
3291 | <<vir>>/ \ <<vir>>
3292 | / \
3293 | / \
3294 | / \
3295 Rows_log_event B_l:W_R_E
3296 \ /
3297 \ /
3298 \ /
3299 \ /
3300 \ /
3301 \/
3302 Write_rows_log_event
3303
3304 B_l: Namespace Binary_log
3305 W_R_E: class Write_rows_event
3306 @endinternal
3308*/
3311 public:
3312 enum {
3313 /* Support interface to THD::binlog_prepare_pending_rows_event */
3315 };
3316
3317#if defined(MYSQL_SERVER)
3319 const mysql::binlog::event::Table_id &table_id,
3320 bool is_transactional,
3321 const unsigned char *extra_row_ndb_info);
3322#endif
3324 const char *buf,
3325 const mysql::binlog::event::Format_description_event *description_event);
3326#if defined(MYSQL_SERVER)
3328 bool is_transactional,
3329 const uchar *before_record
3330 [[maybe_unused]],
3331 const uchar *after_record);
3332 bool read_write_bitmaps_cmp(const TABLE *table) const override {
3333 return bitmap_cmp(get_cols(), table->write_set);
3334 }
3335#endif
3336
3337 void claim_memory_ownership(bool claim) override;
3338
3339 protected:
3340 int write_row(const Relay_log_info *const, const bool);
3342 private:
3345 }
3346
3347#ifndef MYSQL_SERVER
3348 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
3349#endif
3350
3351#if defined(MYSQL_SERVER)
3352 int do_before_row_operations(const Relay_log_info *const) override;
3353 int do_after_row_operations(const Relay_log_info *const, int) override;
3354 int do_exec_row(const Relay_log_info *const) override;
3355#endif
3356};
3357
3358/**
3359 @class Update_rows_log_event
3360
3361 Log row updates with a before image. The event contain several
3362 update rows for a table. Note that each event contains only rows for
3363 one table.
3364
3365 Also note that the row data consists of pairs of row data: one row
3366 for the old data and one row for the new data.
3367
3368 @internal
3369 The inheritance structure is as follows
3370
3371 Binary_log_event
3372 ^
3373 |
3374 |
3375 |
3376 Log_event B_l:Rows_event
3377 ^ /\
3378 | / \
3379 | <<vir>>/ \ <<vir>>
3380 | / \
3381 | / \
3382 | / \
3383 Rows_log_event B_l:U_R_E
3384 \ /
3385 \ /
3386 \ /
3387 \ /
3388 \ /
3389 \/
3390 Update_rows_log_event
3391
3392
3393 B_l: Namespace Binary_log
3394 U_R_E: class Update_rows_event
3395 @eninternal
3397*/
3400 public:
3401 enum {
3402 /* Support interface to THD::binlog_prepare_pending_rows_event */
3404 };
3406#ifdef MYSQL_SERVER
3408 const mysql::binlog::event::Table_id &table_id,
3409 MY_BITMAP const *cols_bi, MY_BITMAP const *cols_ai,
3410 bool is_transactional,
3411 const unsigned char *extra_row_ndb_info);
3412
3414 const mysql::binlog::event::Table_id &table_id,
3415 bool is_transactional,
3416 const unsigned char *extra_row_ndb_info);
3417
3418 void init(MY_BITMAP const *cols);
3419#endif
3420
3421 ~Update_rows_log_event() override;
3422
3424 const char *buf,
3425 const mysql::binlog::event::Format_description_event *description_event);
3426
3427#ifdef MYSQL_SERVER
3429 bool is_transactional,
3430 const uchar *before_record,
3431 const uchar *after_record);
3432 bool read_write_bitmaps_cmp(const TABLE *table) const override {
3433 return (bitmap_cmp(get_cols(), table->read_set) &&
3434 bitmap_cmp(get_cols_ai(), table->write_set));
3435 }
3436#endif
3437
3438 void claim_memory_ownership(bool claim) override;
3440 protected:
3443 }
3444
3445#ifndef MYSQL_SERVER
3446 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
3447#endif
3448
3449#if defined(MYSQL_SERVER)
3450 int do_before_row_operations(const Relay_log_info *const) override;
3451 int do_after_row_operations(const Relay_log_info *const, int) override;
3452 int do_exec_row(const Relay_log_info *const) override;
3453
3455 const uchar *curr_bi_start) override;
3456
3457 private:
3458 /**
3459 Auxiliary function used in the (THD*, ...) constructor to
3460 determine the type code based on configuration options.
3461
3462 @param thd_arg The THD object for the session.
3463
3464 @return One of UPDATE_ROWS_EVENT_V1, PARTIAL_UPDATE_ROWS_EVENT, or
3465 UPDATE_ROWS_EVENT.
3466 */
3468 const THD *thd_arg);
3469#endif /* defined(MYSQL_SERVER) */
3470};
3471
3472/**
3473 @class Delete_rows_log_event
3474
3475 Log row deletions. The event contain several delete rows for a
3476 table. Note that each event contains only rows for one table.
3477
3478 RESPONSIBILITIES
3479
3480 - Act as a container for rows that has been deleted on the master
3481 and should be deleted on the slave.
3482
3483 COLLABORATION
3484
3485 Row_writer
3486 Create the event and add rows to the event.
3487 Row_reader
3488 Extract the rows from the event.
3489
3490 @internal
3491 The inheritance structure is as follows
3492
3493 Binary_log_event
3494 ^
3495 |
3496 |
3497 |
3498 Log_event B_l:Rows_event
3499 ^ /\
3500 | / \
3501 | <<vir>>/ \ <<vir>>
3502 | / \
3503 | / \
3504 | / \
3505 Rows_log_event B_l:D_R_E
3506 \ /
3507 \ /
3508 \ /
3509 \ /
3510 \ /
3511 \/
3512 Delete_rows_log_event
3513
3514 B_l: Namespace Binary_log
3515 D_R_E: class Delete_rows_event
3516 @endinternal
3518*/
3521 public:
3522 enum {
3523 /* Support interface to THD::binlog_prepare_pending_rows_event */
3525 };
3526
3527#ifdef MYSQL_SERVER
3529 bool is_transactional,
3530 const unsigned char *extra_row_ndb_info);
3531#endif
3533 const char *buf,
3534 const mysql::binlog::event::Format_description_event *description_event);
3535#ifdef MYSQL_SERVER
3537 bool is_transactional,
3538 const uchar *before_record,
3539 const uchar *after_record
3540 [[maybe_unused]]);
3541 bool read_write_bitmaps_cmp(const TABLE *table) const override {
3542 return bitmap_cmp(get_cols(), table->read_set);
3543 }
3544#endif
3545
3546 void claim_memory_ownership(bool claim) override;
3548 protected:
3551 }
3552
3553#ifndef MYSQL_SERVER
3554 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
3555#endif
3556
3557#if defined(MYSQL_SERVER)
3558 int do_before_row_operations(const Relay_log_info *const) override;
3559 int do_after_row_operations(const Relay_log_info *const, int) override;
3560 int do_exec_row(const Relay_log_info *const) override;
3561#endif
3562};
3563
3564/**
3565 @class Incident_log_event
3566
3567 Class representing an incident, an occurrence out of the ordinary,
3568 that happened on the master.
3569
3570 The event is used to inform the slave that something out of the
3571 ordinary happened on the master that might cause the database to be
3572 in an inconsistent state.
3573
3574 It's the derived class of Incident_event
3575
3576 @internal
3577 The inheritance structure is as follows
3578
3579 Binary_log_event
3580 ^
3581 |
3582 |
3583 B_l:Incident_event Log_event
3584 \ /
3585 \ /
3586 \ /
3587 \ /
3588 Incident_log_event
3589
3590 B_l: Namespace Binary_log
3591 @endinternal
3593*/
3595 public Log_event {
3596 public:
3597 // disable copy-move semantics
3599 Incident_log_event &operator=(Incident_log_event &&) noexcept = delete;
3600 Incident_log_event(const Incident_log_event &) = delete;
3601 Incident_log_event &operator=(const Incident_log_event &) = delete;
3603#ifdef MYSQL_SERVER
3604 Incident_log_event(THD *thd_arg, enum_incident incident_arg)
3605 : mysql::binlog::event::Incident_event(incident_arg),
3608 DBUG_TRACE;
3609 DBUG_PRINT("enter", ("incident: %d", incident_arg));
3610 common_header->set_is_valid(incident_arg > INCIDENT_NONE &&
3611 incident_arg < INCIDENT_COUNT);
3612 assert(message == nullptr && message_length == 0);
3613 return;
3615
3616 Incident_log_event(THD *thd_arg, enum_incident incident_arg,
3617 LEX_CSTRING const msg)
3618 : mysql::binlog::event::Incident_event(incident_arg),
3621 DBUG_TRACE;
3622 DBUG_PRINT("enter", ("incident: %d", incident_arg));
3623 common_header->set_is_valid(incident_arg > INCIDENT_NONE &&
3624 incident_arg < INCIDENT_COUNT);
3625 assert(message == nullptr && message_length == 0);
3627 msg.length + 1, MYF(MY_WME)))) {
3628 // The allocation failed. Mark this binlog event as invalid.
3630 return;
3631 }
3632 strmake(message, msg.str, msg.length);
3633 message_length = msg.length;
3634 return;
3635 }
3636#endif
3637
3638#ifdef MYSQL_SERVER
3639 int pack_info(Protocol *) override;
3640#endif
3641
3643 const char *buf,
3644 const mysql::binlog::event::Format_description_event *description_event);
3645
3646 ~Incident_log_event() override;
3647
3648 void claim_memory_ownership(bool claim) override;
3649
3650#ifndef MYSQL_SERVER
3651 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
3652#endif
3653
3654#if defined(MYSQL_SERVER)
3655 int do_apply_event(Relay_log_info const *rli) override;
3656 bool write_data_header(Basic_ostream *ostream) override;
3657 bool write_data_body(Basic_ostream *ostream) override;
3658#endif
3659
3660 size_t get_data_size() override {
3664
3665 bool ends_group() const override { return true; }
3666
3667 private:
3668 const char *description() const;
3669};
3670
3671/**
3672 @class Ignorable_log_event
3673
3674 Base class for ignorable log events is Ignorable_event.
3675 Events deriving from this class can be safely ignored
3676 by slaves that cannot recognize them.
3677
3678 Its the derived class of Ignorable_event
3679
3680 @internal
3681 The inheritance structure is as follows
3682
3683 Binary_log_event
3684 ^
3685 |
3686 |
3687 B_l:Ignorable_event Log_event
3688 \ /
3689 <<virtual>>\ /
3690 \ /
3691 Ignorable_log_event
3692
3693 B_l: Namespace Binary_log
3694 @endinternal
3695*/
3698 public Log_event {
3699 public:
3700 // disable copy-move semantics
3702 Ignorable_log_event &operator=(Ignorable_log_event &&) noexcept = delete;
3703 Ignorable_log_event(const Ignorable_log_event &) = delete;
3704 Ignorable_log_event &operator=(const Ignorable_log_event &) = delete;
3706#ifdef MYSQL_SERVER
3707 Ignorable_log_event(THD *thd_arg)
3710 DBUG_TRACE;
3712 return;
3713 }
3714#endif
3715
3717 const char *buf,
3719 ~Ignorable_log_event() override;
3720
3721 void claim_memory_ownership(bool claim) override;
3722
3723#ifdef MYSQL_SERVER
3724 int pack_info(Protocol *) override;
3725#endif
3726
3727#ifndef MYSQL_SERVER
3728 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
3729#endif
3730
3731 size_t get_data_size() override {
3733 }
3734};
3735
3736/**
3737 @class Rows_query_log_event
3738 It is used to record the original query for the rows
3739 events in RBR.
3740 It is the subclass of Ignorable_log_event and Rows_query_event
3741
3742 @internal
3743 The inheritance structure in the current design for the classes is
3744 as follows:
3745 Binary_log_event
3746 ^
3747 |
3748 |
3749 |
3750 Log_event B_l:Ignorable_event
3751 ^ /\
3752 | / \
3753 | <<vir>>/ \ <<vir>>
3754 | / \
3755 | / \
3756 | / \
3757 Ignorable_log_event B_l:Rows_query_event
3758 \ /
3759 \ /
3760 \ /
3761 \ /
3762 \ /
3763 \/
3764 Rows_query_log_event
3765
3766 B_l : namespace namespace mysql::binlog::event
3767 @endinternal
3768*/
3771 public:
3772#ifdef MYSQL_SERVER
3773 Rows_query_log_event(THD *thd_arg, const char *query, size_t query_len)
3774 : Ignorable_log_event(thd_arg) {
3775 DBUG_TRACE;
3777 if (!(m_rows_query =
3779 query_len + 1, MYF(MY_WME))))
3780 return;
3781 snprintf(m_rows_query, query_len + 1, "%s", query);
3782 DBUG_PRINT("enter", ("%s", m_rows_query));
3783 return;
3784 }
3785#endif
3786
3787#ifdef MYSQL_SERVER
3788 int pack_info(Protocol *) override;
3789 int do_apply_event(Relay_log_info const *rli) override;
3790 bool write_data_body(Basic_ostream *ostream) override;
3791#endif
3792
3794 const char *buf,
3796
3797 void claim_memory_ownership(bool claim) override;
3798
3799 ~Rows_query_log_event() override {
3801 m_rows_query = nullptr;
3802 }
3803#ifndef MYSQL_SERVER
3804 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
3805#endif
3806 size_t get_data_size() override {
3808 strlen(m_rows_query);
3809 }
3811
3812static inline bool copy_event_cache_to_file_and_reinit(IO_CACHE *cache,
3813 FILE *file,
3814 bool flush_stream) {
3815 return my_b_copy_to_file(cache, file) ||
3816 (flush_stream ? (fflush(file) || ferror(file)) : 0) ||
3817 reinit_io_cache(cache, WRITE_CACHE, 0, false, true);
3818}
3819
3820#ifdef MYSQL_SERVER
3821/*****************************************************************************
3822
3823 Heartbeat Log Event class
3824
3825 The class is not logged to a binary log, and is not applied on to the slave.
3826 The decoding of the event on the slave side is done by its superclass,
3827 mysql::binlog::event::Heartbeat_event.
3829 ****************************************************************************/
3831 public Log_event {
3832 public:
3834 const char *buf,
3835 const mysql::binlog::event::Format_description_event *description_event);
3837
3839 public Log_event {
3840 public:
3842 const char *buf,
3843 const mysql::binlog::event::Format_description_event *description_event);
3844};
3845/**
3846 The function is called by slave applier in case there are
3847 active table filtering rules to force gathering events associated
3848 with Query-log-event into an array to execute
3849 them once the fate of the Query is determined for execution.
3850*/
3852#endif
3853
3854int append_query_string(const THD *thd, const CHARSET_INFO *csinfo,
3855 String const *from, String *to);
3857
3860 public Log_event {
3861 public:
3862#ifdef MYSQL_SERVER
3863
3864 class Applier_context {
3865 private:
3866 // context for the applier (to remove if we remove the DATABASE scheduler)
3869 public:
3870 Applier_context() = default;
3871 virtual ~Applier_context() { reset(); }
3875
3876 Transaction_payload_log_event(THD *thd_arg, const char *payload,
3877 uint64_t payload_size,
3878 uint16_t compression_type,
3879 uint64_t uncompressed_size)
3880 : Transaction_payload_event(payload, payload_size, compression_type,
3881 uncompressed_size),
3882 Log_event(thd_arg, 0 /* flags */, Log_event::EVENT_TRANSACTIONAL_CACHE,
3884
3885 Transaction_payload_log_event(THD *thd_arg, const char *payload,
3886 uint64_t payload_size)
3888 thd_arg, payload, payload_size,
3889 mysql::binlog::event::compression::type::NONE, payload_size) {}
3890
3892 : Transaction_payload_log_event(thd_arg, nullptr, (uint64_t)0) {}
3893#endif
3894
3896 const char *buf,
3899
3900 ~Transaction_payload_log_event() override = default;
3901
3902 void claim_memory_ownership(bool claim) override;
3903
3904#ifndef MYSQL_SERVER
3905 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
3906#endif
3907
3908 size_t get_event_length() { return LOG_EVENT_HEADER_LEN + get_data_size(); }
3909 size_t get_data_size() override;
3910
3911#if defined(MYSQL_SERVER)
3912 private:
3914
3915 public:
3916 int do_apply_event(Relay_log_info const *rli) override;
3917 bool apply_payload_event(Relay_log_info const *rli, const uchar *event_buf);
3919 int pack_info(Protocol *protocol) override;
3920 bool ends_group() const override;
3921 bool write(Basic_ostream *ostream) override;
3923 void set_mts_dbs(Mts_db_names &arg);
3924 uint8 mts_number_dbs() override;
3925#endif
3926};
3927
3928/**
3929 @class Gtid_log_event
3930
3931 This is a subclass if Gtid_event and Log_event. It contains
3932 per-transaction fields, including the GTID and logical timestamps
3933 used by MTS.
3934
3935 @internal
3936 The inheritance structure is as follows
3937
3938 Binary_log_event
3939 ^
3940 |
3941 |
3942 B_l:Gtid_event Log_event
3943 \ /
3944 \ /
3945 \ /
3946 \ /
3947 Gtid_log_event
3948
3949 B_l: Namespace Binary_log
3950 @endinternal
3951*/
3953 public Log_event {
3954 public:
3955 // disable copy-move semantics
3956 Gtid_log_event(Gtid_log_event &&) noexcept = delete;
3957 Gtid_log_event &operator=(Gtid_log_event &&) noexcept = delete;
3958 Gtid_log_event(const Gtid_log_event &) = delete;
3959 Gtid_log_event &operator=(const Gtid_log_event &) = delete;
3960
3961#ifdef MYSQL_SERVER
3962 /**
3963 Create a new event using the GTID owned by the given thread.
3964 */
3965 Gtid_log_event(THD *thd_arg, bool using_trans, int64 last_committed_arg,
3966 int64 sequence_number_arg, bool may_have_sbr_stmts_arg,
3967 ulonglong original_commit_timestamp_arg,
3968 ulonglong immediate_commit_timestamp_arg,
3969 uint32_t original_server_version_arg,
3970 uint32_t immediate_server_version_arg);
3971
3972 /**
3973 Create a new event using the GTID from the given Gtid_specification
3974 without a THD object.
3975 */
3976 Gtid_log_event(uint32 server_id_arg, bool using_trans,
3977 int64 last_committed_arg, int64 sequence_number_arg,
3978 bool may_have_sbr_stmts_arg,
3979 ulonglong original_commit_timestamp_arg,
3980 ulonglong immediate_commit_timestamp_arg,
3981 const Gtid_specification spec_arg,
3982 uint32_t original_server_version_arg,
3983 uint32_t immediate_server_version_arg);
3984#endif
3985
3986#ifdef MYSQL_SERVER
3987 int pack_info(Protocol *) override;
3988#endif
3990 const char *buffer,
3992
3993 ~Gtid_log_event() override = default;
3994
3995 void claim_memory_ownership(bool claim) override;
3996
3998
3999 size_t get_data_size() override {
4000 if (is_tagged()) {
4001 auto size_calculated = Encoder_type::get_size(*this);
4002 DBUG_EXECUTE_IF("add_unknown_ignorable_fields_to_gtid_log_event",
4003 { size_calculated += 2; });
4004 return size_calculated;
4005 }
4006 DBUG_EXECUTE_IF("do_not_write_rpl_timestamps", return POST_HEADER_LENGTH;);
4010 }
4011
4012 /// @brief Clears tsid and spec
4013 void clear_gtid_and_spec();
4014
4015 /// @brief Updates parent tsid and gtid info structure
4017
4018 size_t get_event_length() { return LOG_EVENT_HEADER_LEN + get_data_size(); }
4019
4020 /// Used internally by both print() and pack_info().
4021 size_t to_string(char *buf) const;
4022
4023 private:
4024#ifdef MYSQL_SERVER
4025 /**
4026 Writes the post-header to the given output stream.
4027
4028 This is an auxiliary function typically used by the write() member
4029 function.
4030
4031 @param ostream The output stream to write to.
4032
4033 @retval true Error.
4034 @retval false Success.
4035 */
4036 bool write_data_header(Basic_ostream *ostream) override;
4037 bool write_data_body(Basic_ostream *ostream) override;
4038 /**
4039 Writes the post-header to the given memory buffer.
4040
4041 This is an auxiliary function used by write_to_memory.
4042
4043 @param[in,out] buffer Buffer to which the post-header will be written.
4044
4045 @return The number of bytes written, i.e., always
4046 Gtid_log_event::POST_HEADER_LENGTH.
4047 */
4049
4050 /**
4051 Writes the body to the given memory buffer.
4052
4053 This is an auxiliary function used by write_to_memory.
4054
4055 @param [in,out] buff Buffer to which the data will be written.
4056
4057 @return The number of bytes written, i.e.,
4058 If the transaction did not originated on this server
4059 Gtid_event::IMMEDIATE_COMMIT_TIMESTAMP_LENGTH.
4060 else
4061 FULL_COMMIT_TIMESTAMP_LENGTH.
4062 */
4064
4065 /// @copydoc write_body_to_memory
4066 /// @details Version for tagged Gtid log event
4068
4069#endif
4070
4071 public:
4072#ifndef MYSQL_SERVER
4073 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
4074#endif
4075
4076#if defined(MYSQL_SERVER)
4077 int do_apply_event(Relay_log_info const *rli) override;
4078 int do_update_pos(Relay_log_info *rli) override;
4080#endif
4081
4082 /**
4083 Return the gtid type for this Gtid_log_event: this can be
4084 either ANONYMOUS_GTID, AUTOMATIC_GTID, or ASSIGNED_GTID.
4085 */
4086 enum_gtid_type get_type() const { return spec.type; }
4087
4088 /**
4089 Return the TSID for this GTID. The TSID is shared with the
4090 Log_event so it should not be modified.
4091 */
4092 const Tsid &get_tsid() const { return tsid; }
4093 /**
4094 Return the SIDNO relative to the global tsid_map for this GTID.
4095
4096 This requires a lookup and possibly even update of global_tsid_map,
4097 hence global_tsid_lock must be held. If global_tsid_lock is not
4098 held, the caller must pass need_lock=true. If there is an error
4099 (e.g. out of memory) while updating global_tsid_map, this function
4100 returns a negative number.
4101
4102 @param need_lock If true, the read lock on global_tsid_lock is
4103 acquired and released inside this function; if false, the read
4104 lock or write lock must be held prior to calling this function.
4105 @retval SIDNO if successful
4106 @retval negative if adding TSID to global_tsid_map causes an error.
4107 */
4108 rpl_sidno get_sidno(bool need_lock);
4109
4110 /**
4111 Return the SIDNO relative to the given Tsid_map for this GTID.
4112
4113 This assumes that the Tsid_map is local to the thread, and thus
4114 does not use locks.
4115
4116 @param tsid_map The tsid_map to use.
4117 @retval SIDNO if successful.
4118 @retval negative if adding TSID to tsid_map causes an error.
4119 */
4120 rpl_sidno get_sidno(Tsid_map *tsid_map) { return tsid_map->add_tsid(tsid); }
4121 /// Return the GNO for this GTID.
4122 rpl_gno get_gno() const override { return spec.gtid.gno; }
4124 /// string holding the text "SET @@GLOBAL.GTID_NEXT = '"
4125 static const char *SET_STRING_PREFIX;
4126
4127 private:
4128 /// Length of SET_STRING_PREFIX
4129 static const size_t SET_STRING_PREFIX_LENGTH = 26;
4130 /// The maximal length of the entire "SET ..." query.
4131 static const size_t MAX_SET_STRING_LENGTH = SET_STRING_PREFIX_LENGTH +
4134
4135 private:
4136 /**
4137 Internal representation of the GTID. The SIDNO will be
4138 uninitialized (value -1) until the first call to get_sidno(bool).
4139 */
4141 /// TSID for this GTID.
4142 Tsid tsid;
4143
4144 public:
4145 /**
4146 Set the transaction length information based on binlog cache size.
4147
4148 Note that is_checksum_enabled and event_counter are optional parameters.
4149 When not specified, the function will assume that no checksum will be used
4150 and the informed cache_size is the final transaction size without
4151 considering the GTID event size.
4152
4153 The high level formula that will be used by the function is:
4154
4155 trx_length = cache_size +
4156 cache_checksum_active * cache_events * CRC32_payload +
4157 gtid_length +
4158 cache_checksum_active * CRC32_payload; // For the GTID.
4159
4160 @param cache_size The size of the binlog cache in bytes.
4161 @param is_checksum_enabled If checksum will be added to events on flush.
4162 @param event_counter The amount of events in the cache.
4163 */
4165 bool is_checksum_enabled = false,
4166 int event_counter = 0);
4167
4168 /// @copydoc set_trx_length_by_cache_size
4169 /// @detail tagged version of event
4171 bool is_checksum_enabled = false,
4172 int event_counter = 0);
4173};
4174
4175/**
4176 @class Previous_gtids_log_event
4177
4178 This is the subclass of Previous_gtids_event and Log_event
4179 It is used to record the gtid_executed in the last binary log file,
4180 for ex after flush logs, or at the starting of the binary log file
4181
4182 @internal
4183 The inheritance structure is as follows
4184
4185 Binary_log_event
4186 ^
4187 |
4188 |
4189B_l:Previous_gtids_event Log_event
4190 \ /
4191 \ /
4192 \ /
4193 \ /
4194 Previous_gtids_log_event
4195
4196 B_l: Namespace Binary_log
4197 @endinternal
4198*/
4201 public Log_event {
4202 public:
4203 // disable copy-move semantics
4206 delete;
4209 delete;
4210
4211#ifdef MYSQL_SERVER
4213#endif
4214
4215#ifdef MYSQL_SERVER
4216 int pack_info(Protocol *) override;
4217#endif
4218
4220 const char *buf,
4221 const mysql::binlog::event::Format_description_event *description_event);
4222 ~Previous_gtids_log_event() override = default;
4223
4224 size_t get_data_size() override { return buf_size; }
4225
4226 void claim_memory_ownership(bool claim) override;
4227
4228#ifndef MYSQL_SERVER
4229 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
4230#endif
4231#ifdef MYSQL_SERVER
4232 bool write(Basic_ostream *ostream) override {
4233#ifndef NDEBUG
4234 if (DBUG_EVALUATE_IF("skip_writing_previous_gtids_log_event", 1, 0) &&
4235 /*
4236 The skip_writing_previous_gtids_log_event debug point was designed
4237 for skipping the writing of the previous_gtids_log_event on binlog
4238 files only.
4239 */
4240 !is_relay_log_event()) {
4241 DBUG_PRINT("info",
4242 ("skip writing Previous_gtids_log_event because of"
4243 "debug option 'skip_writing_previous_gtids_log_event'"));
4244 return false;
4245 }
4246
4247 if (DBUG_EVALUATE_IF("write_partial_previous_gtids_log_event", 1, 0) &&
4248 /*
4249 The write_partial_previous_gtids_log_event debug point was designed
4250 for writing a partial previous_gtids_log_event on binlog files only.
4251 */
4252 !is_relay_log_event()) {
4253 DBUG_PRINT("info",
4254 ("writing partial Previous_gtids_log_event because of"
4255 "debug option 'write_partial_previous_gtids_log_event'"));
4256 return (Log_event::write_header(ostream, get_data_size()) ||
4258 }
4259#endif
4260
4261 return (Log_event::write_header(ostream, get_data_size()) ||
4262 Log_event::write_data_header(ostream) || write_data_body(ostream) ||
4263 Log_event::write_footer(ostream));
4264 }
4265 bool write_data_body(Basic_ostream *ostream) override;
4266#endif
4268 /// Return the encoded buffer, or NULL on error.
4269 const uchar *get_buf() { return buf; }
4270 /**
4271 Return the formatted string, or NULL on error.
4272 The string is allocated using my_malloc and it is the
4273 responsibility of the caller to free it.
4274 */
4275 char *get_str(size_t *length,
4277 /// Add all GTIDs from this event to the given Gtid_set.
4278 int add_to_set(Gtid_set *gtid_set) const;
4279 /*
4280 Previous Gtid Log events should always be skipped
4281 there is nothing to apply there, whether it is
4282 relay log's (generated on Slave) or it is binary log's
4283 (generated on Master, copied to slave as relay log).
4284 Also, we should not increment slave_skip_counter
4285 for this event, hence return EVENT_SKIP_IGNORE.
4287#if defined(MYSQL_SERVER)
4289 {
4290 return EVENT_SKIP_IGNORE;
4292
4293 int do_apply_event(Relay_log_info const *) override { return 0; }
4294 int do_update_pos(Relay_log_info *rli) override;
4295#endif
4296};
4297
4298/**
4299 @class Transaction_context_log_event
4300
4301 This is the subclass of Transaction_context_event and Log_event
4302 This class encodes the transaction_context_log_event.
4303
4304 @internal
4305 The inheritance structure is as follows
4306
4307 Binary_log_event
4308 ^
4309 |
4310 |
4311B_l:Transaction_context_event Log_event
4312 \ /
4313 \ /
4314 \ /
4315 \ /
4316 Transaction_context_log_event
4317
4318 B_l: Namespace Binary_log
4319 @endinternal
4320*/
4323 public Log_event {
4324 private:
4325 /// The Tsid_map to use for creating the Gtid_set.
4327 /// A gtid_set which is used to store the transaction set used for
4328 /// conflict detection.
4330
4331#ifdef MYSQL_SERVER
4332 bool write_data_header(Basic_ostream *ostream) override;
4333
4334 bool write_data_body(Basic_ostream *ostream) override;
4335
4337
4338 bool write_data_set(Basic_ostream *ostream, std::list<const char *> *set);
4339#endif
4340
4342
4343 static int get_data_set_size(std::list<const char *> *set);
4344
4345 size_t to_string(char *buf, ulong len) const;
4346
4347 public:
4348#ifdef MYSQL_SERVER
4349
4350 Transaction_context_log_event(const char *server_uuid_arg, bool using_trans,
4351 my_thread_id thread_id_arg,
4352 bool is_gtid_specified);
4353
4354#endif
4355
4357 const char *buffer,
4359
4361
4362 void claim_memory_ownership(bool claim) override;
4363
4364 size_t get_data_size() override;
4365
4366 size_t get_event_length();
4367
4368#ifdef MYSQL_SERVER
4369 int pack_info(Protocol *protocol) override;
4370#endif
4371
4372#ifndef MYSQL_SERVER
4373 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
4374#endif
4376#if defined(MYSQL_SERVER)
4377 int do_apply_event(Relay_log_info const *) override { return 0; }
4378 int do_update_pos(Relay_log_info *rli) override;
4379#endif
4380
4381 /**
4382 Add a hash which identifies a inserted/updated/deleted row on the
4383 ongoing transaction.
4384
4385 @param[in] hash row identifier
4386 */
4387 void add_write_set(const char *hash);
4388
4389 /**
4390 Return a pointer to write-set list.
4391 */
4392 std::list<const char *> *get_write_set() { return &write_set; }
4393
4394 /**
4395 Add a hash which identifies a read row on the ongoing transaction.
4396
4397 @param[in] hash row identifier
4398 */
4399 void add_read_set(const char *hash);
4400
4401 /**
4402 Return a pointer to read-set list.
4403 */
4404 std::list<const char *> *get_read_set() { return &read_set; }
4405
4406 /**
4407 Read snapshot version from encoded buffers.
4408 Cannot be executed during data read from file (event constructor),
4409 since its required locks will collide with the server gtid state
4410 initialization procedure.
4411 */
4412 bool read_snapshot_version();
4413
4414 /**
4415 Return the transaction snapshot timestamp.
4416 */
4418
4419 /**
4420 Return the server uuid.
4421 */
4422 const char *get_server_uuid() { return server_uuid; }
4423
4424 /**
4425 Return the id of the committing thread.
4426 */
4427 my_thread_id get_thread_id() const {
4428 return static_cast<my_thread_id>(thread_id);
4429 }
4430
4431 /**
4432 Return true if transaction has GTID fully specified, false otherwise.
4433 */
4434 bool is_gtid_specified() const { return gtid_specified; }
4435};
4436
4437/**
4438 @class View_change_log_event
4439
4440 This is the subclass of View_change_log_event and Log_event
4441 This class created the view_change_log_event which is used as a marker in
4442 case a new node joins or leaves the group.
4443
4444 @internal
4445 The inheritance structure is as follows
4446
4447 Binary_log_event
4448 ^
4449 |
4450 |
4451B_l: View_change_event Log_event
4452 \ /
4453 \ /
4454 \ /
4455 \ /
4456 View_change_log_event
4457
4458 B_l: Namespace Binary_log
4459 @endinternal
4461
4463 public Log_event {
4464 private:
4465 size_t to_string(char *buf, ulong len) const;
4466
4467#ifdef MYSQL_SERVER
4468 bool write_data_header(Basic_ostream *ostream) override;
4469
4470 bool write_data_body(Basic_ostream *ostream) override;
4471
4472 bool write_data_map(Basic_ostream *ostream,
4473 std::map<std::string, std::string> *map);
4474#endif
4475
4476 size_t get_size_data_map(std::map<std::string, std::string> *map);
4477
4478 public:
4479 // disable copy-move semantics
4481 View_change_log_event &operator=(View_change_log_event &&) noexcept = delete;
4483 View_change_log_event &operator=(const View_change_log_event &) = delete;
4484
4485 View_change_log_event(const char *view_id);
4486
4488 const char *buffer,
4489 const mysql::binlog::event::Format_description_event *descr_event);
4490
4491 ~View_change_log_event() override;
4492
4493 void claim_memory_ownership(bool claim) override;
4494
4495 size_t get_data_size() override;
4496
4497#ifdef MYSQL_SERVER
4498 int pack_info(Protocol *protocol) override;
4499#endif
4500
4501#ifndef MYSQL_SERVER
4502 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
4503#endif
4504
4505#if defined(MYSQL_SERVER)
4506 int do_apply_event(Relay_log_info const *rli) override;
4507 int do_update_pos(Relay_log_info *rli) override;
4508#endif
4509
4510 /**
4511 Returns the view id.
4512 */
4513 char *get_view_id() { return view_id; }
4514
4515 /**
4516 Sets the certification info in the event
4517
4518 @note size is calculated on this method as the size of the data
4519 might render the log even invalid. Also due to its size doing it
4520 here avoid looping over the data multiple times.
4521
4522 @param[in] info certification info to be written
4523 @param[out] event_size the event size after this operation
4524 */
4525 void set_certification_info(std::map<std::string, std::string> *info,
4526 size_t *event_size);
4527
4528 /**
4529 Returns the certification info
4530 */
4531 std::map<std::string, std::string> *get_certification_info() {
4532 return &certification_info;
4533 }
4534
4535 /**
4536 Set the certification sequence number
4537
4538 @param number the sequence number
4539 */
4540 void set_seq_number(rpl_gno number) { seq_number = number; }
4541
4542 /**
4543 Returns the certification sequence number
4544 */
4545 rpl_gno get_seq_number() { return seq_number; }
4547
4548inline bool is_any_gtid_event(const Log_event *evt) {
4550 evt->get_type_code()));
4551}
4552
4553/**
4554 Check if the given event is a session control event, one of
4555 `User_var_event`, `Intvar_event` or `Rand_event`.
4556
4557 @param evt The event to check.
4558
4559 @return true if the given event is of type `User_var_event`,
4560 `Intvar_event` or `Rand_event`, false otherwise.
4561 */
4562inline bool is_session_control_event(Log_event *evt) {
4566}
4567
4568/**
4569 The function checks the argument event properties to deduce whether
4570 it represents an atomic DDL.
4571
4572 @param evt a reference to Log_event
4573 @return true when the DDL properties are found,
4574 false otherwise
4575*/
4576inline bool is_atomic_ddl_event(Log_event const *evt) {
4577 return evt != nullptr &&
4579 static_cast<Query_log_event const *>(evt)->ddl_xid !=
4581}
4582
4583/**
4584 The function lists all DDL instances that are supported
4585 for crash-recovery (WL9175).
4586 todo: the supported feature list is supposed to grow. Once
4587 a feature has been readied for 2pc through WL7743,9536(7141/7016) etc
4588 it needs registering in the function.
4589
4590 @param thd an Query-log-event creator thread handle
4591 @param using_trans
4592 The caller must specify the value according to the following
4593 rules:
4594 @c true when
4595 - on master the current statement is not processing
4596 a table in SE which does not support atomic DDL
4597 - on slave the relay-log repository is transactional.
4598 @c false otherwise.
4599 @return true when the being created (master) or handled (slave) event
4600 is 2pc-capable, @c false otherwise.
4601*/
4602bool is_atomic_ddl(THD *thd, bool using_trans);
4603
4604#ifdef MYSQL_SERVER
4605/**
4606 Serialize an binary event to the given output stream. It is more general
4607 than call ev->write() directly. The caller will not be affected if any
4608 change happens in serialization process. For example, serializing the
4609 event in different format.
4611template <class EVENT>
4612bool binary_event_serialize(EVENT *ev, Basic_ostream *ostream) {
4613 return ev->write(ostream);
4614}
4615
4616/*
4617 This is an utility function that adds a quoted identifier into the a buffer.
4618 This also escapes any existence of the quote string inside the identifier.
4619 */
4620size_t my_strmov_quoted_identifier(THD *thd, char *buffer,
4621 const char *identifier, size_t length);
4622#else
4623size_t my_strmov_quoted_identifier(char *buffer, const char *identifier);
4624#endif
4626 const char *identifier,
4627 size_t length);
4628
4629/**
4630 Read an integer in net_field_length format, guarding against read out of
4631 bounds and advancing the position.
4632
4633 @param[in,out] packet Pointer to buffer to read from. On successful
4634 return, the buffer position will be incremented to point to the next
4635 byte after what was read.
4636
4637 @param[in,out] max_length Pointer to the number of bytes in the
4638 buffer. If the function would need to look at more than *max_length
4639 bytes in order to decode the number, the function will do nothing
4640 and return true.
4641
4642 @param[out] out Pointer where the value will be stored.
4643
4644 @retval false Success.
4645 @retval true Failure, i.e., reached end of buffer.
4646*/
4647template <typename T>
4648bool net_field_length_checked(const uchar **packet, size_t *max_length, T *out);
4649
4650/**
4651 Extract basic info about an event: type, query, is it ignorable
4652
4653 @param log_event the event to extract info from
4654 @return a pair first param is true if an error occurred, false otherwise
4655 second param is the event info
4656 */
4657std::pair<bool, mysql::binlog::event::Log_event_basic_info>
4659
4660/**
4661 Extract basic info about an event: type, query, is it ignorable
4662
4663 @param buf The event info buffer
4664 @param length The length of the buffer
4665 @param fd_event The Format description event associated
4666 @return a pair first param is true if an error occurred, false otherwise
4667 second param is the event info
4668 */
4669std::pair<bool, mysql::binlog::event::Log_event_basic_info>
4671 const char *buf, size_t length,
4673
4674/**
4675 @} (end of group Replication)
4676*/
4677
4678#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:441
This event is created to contain the file data.
Definition: log_event.h:2091
bool write(Basic_ostream *ostream) override
Definition: log_event.cc:6999
void claim_memory_ownership(bool claim) override
Allow thread to CLAIM or DISCLAIM the ownership of this object depends on the parameter value passed.
Definition: log_event.cc:7026
virtual int get_create_or_append() const
Definition: log_event.cc:7049
bool is_sbr_logging_format() const override
Return true if the event has to be logged using SBR for DMLs.
Definition: log_event.h:2125
size_t get_data_size() override
Definition: log_event.h:2116
int pack_info(Protocol *protocol) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:7036
~Append_block_log_event() override=default
const char * get_db() override
Definition: log_event.h:2122
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:7079
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:2241
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:7300
void claim_memory_ownership(bool claim) override
Allow thread to CLAIM or DISCLAIM the ownership of this object depends on the parameter value passed.
Definition: log_event.cc:7290
~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:7296
Delete_file_log_event is created when the LOAD_DATA query fails on the master for some reason,...
Definition: log_event.h:2163
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:7240
void claim_memory_ownership(bool claim) override
Allow thread to CLAIM or DISCLAIM the ownership of this object depends on the parameter value passed.
Definition: log_event.cc:7218
size_t get_data_size() override
Definition: log_event.h:2186
~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:2194
bool write(Basic_ostream *ostream) override
Definition: log_event.cc:7195
const char * get_db() override
Definition: log_event.h:2191
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:7228
Log row deletions.
Definition: log_event.h:3518
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:3539
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:12382
int do_after_row_operations(const Relay_log_info *const, int) override
Definition: log_event.cc:12435
void claim_memory_ownership(bool claim) override
Allow thread to CLAIM or DISCLAIM the ownership of this object depends on the parameter value passed.
Definition: log_event.cc:12402
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:12371
mysql::binlog::event::Log_event_type get_general_type_code() override
Definition: log_event.h:3547
int do_exec_row(const Relay_log_info *const) override
Definition: log_event.cc:12442
@ TYPE_CODE
Definition: log_event.h:3522
int do_before_row_operations(const Relay_log_info *const) override
Definition: log_event.cc:12409
Event responsible for LOAD DATA execution, it similar to Query_log_event but before executing the que...
Definition: log_event.h:2308
int do_apply_event(Relay_log_info const *rli) override
Primitive to apply an event to the database.
Definition: log_event.cc:7454
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:2333
bool write_post_header_for_derived(Basic_ostream *ostream) override
Definition: log_event.cc:7364
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:7423
void claim_memory_ownership(bool claim) override
Allow thread to CLAIM or DISCLAIM the ownership of this object depends on the parameter value passed.
Definition: log_event.cc:7358
ulong get_post_header_size_for_derived() override
Definition: log_event.cc:7354
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:7313
~Execute_load_query_log_event() override=default
Definition: field.h:574
For binlog version 4.
Definition: log_event.h:1524
void claim_memory_ownership(bool claim) override
Allow thread to CLAIM or DISCLAIM the ownership of this object depends on the parameter value passed.
Definition: log_event.cc:5321
std::atomic< int32 > atomic_usage_counter
Definition: log_event.h:1542
int pack_info(Protocol *protocol) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:5327
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:5493
size_t get_data_size() override
Definition: log_event.h:1555
bool write(Basic_ostream *ostream) override
Definition: log_event.cc:5337
int do_update_pos(Relay_log_info *rli) override
Advance relay log coordinates.
Definition: log_event.cc:5471
int do_apply_event(Relay_log_info const *rli) override
Primitive to apply an event to the database.
Definition: log_event.cc:5420
Format_description_log_event()
Format_description_log_event 1st ctor.
Definition: log_event.cc:5212
This is a subclass if Gtid_event and Log_event.
Definition: log_event.h:3951
void set_trx_length_by_cache_size_tagged(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:13480
rpl_gno get_gno() const override
Return the GNO for this GTID.
Definition: log_event.h:4120
rpl_sidno get_sidno(bool need_lock)
Return the SIDNO relative to the global tsid_map for this GTID.
Definition: log_event.cc:13511
~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:13194
Gtid_log_event(Gtid_log_event &&) noexcept=delete
size_t get_event_length()
Definition: log_event.h:4016
int do_update_pos(Relay_log_info *rli) override
Advance relay log coordinates.
Definition: log_event.cc:13461
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:4084
uint32 write_body_to_memory(uchar *buff)
Writes the body to the given memory buffer.
Definition: log_event.cc:13231
Gtid_log_event(const Gtid_log_event &)=delete
uint32 write_tagged_event_body_to_memory(uchar *buffer)
Writes the body to the given memory buffer.
Definition: log_event.cc:13204
int do_apply_event(Relay_log_info const *rli) override
Primitive to apply an event to the database.
Definition: log_event.cc:13305
uint32 write_post_header_to_memory(uchar *buffer)
Writes the post-header to the given memory buffer.
Definition: log_event.cc:13139
static const size_t SET_STRING_PREFIX_LENGTH
Length of SET_STRING_PREFIX.
Definition: log_event.h:4127
Tsid tsid
TSID for this GTID.
Definition: log_event.h:4140
const Tsid & get_tsid() const
Return the TSID for this GTID.
Definition: log_event.h:4090
bool write_data_body(Basic_ostream *ostream) override
Definition: log_event.cc:13296
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:13490
static const size_t MAX_SET_STRING_LENGTH
The maximal length of the entire "SET ..." query.
Definition: log_event.h:4129
void update_parent_gtid_info()
Updates parent tsid and gtid info structure.
Definition: log_event.cc:12964
static const char * SET_STRING_PREFIX
string holding the text "SET @@GLOBAL.GTID_NEXT = '"
Definition: log_event.h:4123
void clear_gtid_and_spec()
Clears tsid and spec.
Definition: log_event.cc:12970
void claim_memory_ownership(bool claim) override
Allow thread to CLAIM or DISCLAIM the ownership of this object depends on the parameter value passed.
Definition: log_event.cc:13054
Gtid_specification spec
Internal representation of the GTID.
Definition: log_event.h:4138
int pack_info(Protocol *) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:13035
size_t get_data_size() override
Definition: log_event.h:3997
size_t to_string(char *buf) const
Used internally by both print() and pack_info().
Definition: log_event.cc:13043
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:13475
Represents a set of GTIDs.
Definition: rpl_gtid.h:1555
Definition: rpl_utility.h:108
Definition: log_event.h:3837
Heartbeat_log_event_v2(const char *buf, const mysql::binlog::event::Format_description_event *description_event)
Definition: log_event.cc:14377
Definition: log_event.h:3829
Heartbeat_log_event(const char *buf, const mysql::binlog::event::Format_description_event *description_event)
Definition: log_event.cc:14370
Base class for ignorable log events is Ignorable_event.
Definition: log_event.h:3696
int pack_info(Protocol *) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:12779
void claim_memory_ownership(bool claim) override
Allow thread to CLAIM or DISCLAIM the ownership of this object depends on the parameter value passed.
Definition: log_event.cc:12772
size_t get_data_size() override
Definition: log_event.h:3729
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:3593
Incident_log_event(const Incident_log_event &)=delete
bool write_data_header(Basic_ostream *ostream) override
Definition: log_event.cc:12724
size_t get_data_size() override
Definition: log_event.h:3658
bool write_data_body(Basic_ostream *ostream) override
Definition: log_event.cc:12750
~Incident_log_event() override
Definition: log_event.cc:12638
int do_apply_event(Relay_log_info const *rli) override
Primitive to apply an event to the database.
Definition: log_event.cc:12684
int pack_info(Protocol *) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:12657
void claim_memory_ownership(bool claim) override
Allow thread to CLAIM or DISCLAIM the ownership of this object depends on the parameter value passed.
Definition: log_event.cc:12651
const char * description() const
Definition: log_event.cc:12642
bool ends_group() const override
Definition: log_event.h:3663
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:1600
bool write(Basic_ostream *ostream) override
Definition: log_event.cc:5810
~Intvar_log_event() override=default
Intvar_log_event(Intvar_log_event &&) noexcept=delete
size_t get_data_size() override
Definition: log_event.h:1629
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:5889
void claim_memory_ownership(bool claim) override
Allow thread to CLAIM or DISCLAIM the ownership of this object depends on the parameter value passed.
Definition: log_event.cc:5820
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:5785
bool is_sbr_logging_format() const override
Return true if the event has to be logged using SBR for DMLs.
Definition: log_event.h:1637
int do_apply_event(Relay_log_info const *rli) override
Primitive to apply an event to the database.
Definition: log_event.cc:5864
int do_update_pos(Relay_log_info *rli) override
Advance relay log coordinates.
Definition: log_event.cc:5884
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:933
Definition: key.h:112
Definition: sql_list.h:434
Definition: log_event.h:2344
bool has_replace
Definition: log_event.h:2364
const size_t BUF_SIZE
Definition: log_event.h:2353
const char * table_name
Definition: log_event.h:2360
const char * fname
Definition: log_event.h:2361
const sql_exchange * sql_ex
Definition: log_event.h:2358
THD * thd
Definition: log_event.h:2357
bool has_ignore
Definition: log_event.h:2365
String str
Definition: log_event.h:2354
const char * db
Definition: log_event.h:2359
bool is_concurrent
Definition: log_event.h:2363
const String * generate(size_t *fn_start, size_t *fn_end)
Definition: log_event.cc:7563
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:7546
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:1253
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:908
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:2444
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:3040
virtual int do_apply_event(Relay_log_info const *rli)
Primitive to apply an event to the database.
Definition: log_event.h:1161
virtual const char * get_db()
Definition: log_event.cc:1056
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:1061
uint32 write_header_to_memory(uchar *buf)
Writes the common header of this event to the given memory buffer.
Definition: log_event.cc:1214
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:1093
uint32 server_id
Definition: log_event.h:663
enum_mts_event_exec_mode
Definition: log_event.h:928
@ EVENT_EXEC_PARALLEL
Definition: log_event.h:932
@ EVENT_EXEC_SYNC
Definition: log_event.h:940
@ EVENT_EXEC_CAN_NOT
Definition: log_event.h:944
@ EVENT_EXEC_ASYNC
Definition: log_event.h:936
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:1136
bool is_valid()
Definition: log_event.cc:1306
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:1055
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:878
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:1192
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:2464
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:1128
virtual int do_apply_event_worker(Slave_worker *w)
Definition: log_event.cc:980
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:896
time_t get_time()
Prints a "session_var=value" string.
Definition: log_event.cc:873
bool write_footer(Basic_ostream *ostream)
Definition: log_event.cc:1201
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:962
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:1002
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:1034
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:2996
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