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