MySQL 8.0.32
Source Code Documentation
log_event.h
Go to the documentation of this file.
1/* Copyright (c) 2000, 2022, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is also distributed with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23/**
24 @file sql/log_event.h
25
26 @brief Binary log event definitions. This includes generic code
27 common to all types of log events, as well as specific code for each
28 type of log event.
29
30 @addtogroup Replication
31 @{
32*/
33
34#ifndef _log_event_h
35#define _log_event_h
36
37#include <atomic>
38#include <functional>
39#include <list>
40#include <map>
41#include <set>
42#include <string>
43
44#include "lex_string.h"
51#include "m_string.h" // native_strncasecmp
52#include "my_bitmap.h" // MY_BITMAP
53#include "my_checksum.h" // ha_checksum
54#include "my_dbug.h"
55#include "my_inttypes.h"
56#include "my_psi_config.h"
57#include "my_sharedlib.h"
58#include "my_sys.h"
59#include "my_thread_local.h"
63#include "mysql_com.h" // SERVER_VERSION_LENGTH
64#include "partition_info.h"
65#include "sql/query_options.h" // OPTION_AUTO_IS_NULL
66#include "sql/rpl_gtid.h" // enum_gtid_type
67#include "sql/rpl_utility.h" // Hash_slave_rows
68#include "sql/sql_const.h"
69#include "sql/thr_malloc.h"
70#include "sql_string.h"
71#include "typelib.h" // TYPELIB
72
73class THD;
74class Table_id;
75struct CHARSET_INFO;
76
77enum class enum_row_image_type;
78class Basic_ostream;
79
80#ifdef MYSQL_SERVER
81#include <stdio.h>
82
83#include "my_compiler.h"
84#include "sql/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
806
807 /**
808 Return true if the event has to be logged using SBR for DMLs.
809 */
810 virtual bool is_sbr_logging_format() const { return false; }
811 /**
812 Return true if the event has to be logged using RBR for DMLs.
813 */
814 virtual bool is_rbr_logging_format() const { return false; }
815
816 /*
817 is_valid is event specific sanity checks to determine that the
818 object is correctly initialized.
819 */
820 bool is_valid();
821 void set_artificial_event() {
823 /*
824 Artificial events are automatically generated and do not exist
825 in master's binary log, so log_pos should be set to 0.
826 */
830 bool is_artificial_event() const {
833 bool is_relay_log_event() const {
836 bool is_ignorable_event() const {
839 bool is_no_filter_event() const {
842 inline bool is_using_trans_cache() const {
845 inline bool is_using_stmt_cache() const {
848 inline bool is_using_immediate_logging() const {
850 }
851
852 /*
853 For the events being decoded in BAPI, common_header should
854 point to the header object which is contained within the class
855 Binary_log_event.
856 */
859 virtual ~Log_event() { free_temp_buf(); }
860 void register_temp_buf(char *buf, bool free_in_destructor = true) {
861 m_free_temp_buf_in_destructor = free_in_destructor;
862 temp_buf = buf;
864 void free_temp_buf() {
865 if (temp_buf) {
867 temp_buf = nullptr;
868 }
869 }
870 /*
871 Get event length for simple events. For complicated events the length
872 is calculated during write()
873 */
874 virtual size_t get_data_size() { return 0; }
875 /**
876 Returns the human readable name of the given event type.
877 */
878 static const char *get_type_str(Log_event_type type);
879 /**
880 Returns the human readable name of this event's type.
881 */
882 const char *get_type_str() const;
883 /* Return start of query time or current time */
884
885#if defined(MYSQL_SERVER)
886 /**
887 Is called from get_mts_execution_mode() to
888
889 @return true if the event needs applying with synchronization
890 against Workers, otherwise
891 false
892
893 @note There are incompatile combinations such as referred further events
894 are wrapped with BEGIN/COMMIT. Such cases should be identified
895 by the caller and treats correspondingly.
896
897 todo: to mts-support Old master Load-data related events
898 */
900 switch (get_type_code()) {
906 return true;
907 default:
908 return false;
909 }
910 }
911
912 private:
913 /*
914 possible decisions by get_mts_execution_mode().
915 The execution mode can be PARALLEL or not (thereby sequential
916 unless impossible at all). When it's sequential it further breaks into
917 ASYNChronous and SYNChronous.
918 */
920 /*
921 Event is run by a Worker.
922 */
924 /*
925 Event is run by Coordinator.
926 */
928 /*
929 Event is run by Coordinator and requires synchronization with Workers.
930 */
932 /*
933 Event can't be executed neither by Workers nor Coordinator.
934 */
936 };
937
938 /**
939 MTS Coordinator finds out a way how to execute the current event.
940
941 Besides the parallelizable case, some events have to be applied by
942 Coordinator concurrently with Workers and some to require synchronization
943 with Workers (@c see wait_for_workers_to_finish) before to apply them.
944
945 @param mts_in_group the being group parsing status, true
946 means inside the group
947
948 @retval EVENT_EXEC_PARALLEL if event is executed by a Worker
949 @retval EVENT_EXEC_ASYNC if event is executed by Coordinator
950 @retval EVENT_EXEC_SYNC if event is executed by Coordinator
951 with synchronization against the Workers
952 */
953 enum enum_mts_event_exec_mode get_mts_execution_mode(bool mts_in_group) {
954 /*
955 Slave workers are unable to handle Format_description_log_event,
956 Rotate_log_event and Previous_gtids_log_event correctly.
957 However, when a transaction spans multiple relay logs, these
958 events occur in the middle of a transaction. The way we handle
959 this is by marking the events as 'ASYNC', meaning that the
960 coordinator thread will handle the events without stopping the
961 worker threads.
962
963 @todo Refactor this: make Log_event::get_slave_worker handle
964 transaction boundaries in a more robust way, so that it is able
965 to process Format_description_log_event, Rotate_log_event, and
966 Previous_gtids_log_event. Then, when these events occur in the
967 middle of a transaction, make them part of the transaction so
968 that the worker that handles the transaction handles these
969 events too. /Sven
970 */
971 if (
972 /*
973 When a Format_description_log_event occurs in the middle of
974 a transaction, it either has the slave's server_id, or has
975 end_log_pos==0.
976
977 @todo This does not work when master and slave have the same
978 server_id and replicate-same-server-id is enabled, since
979 events that are not in the middle of a transaction will be
980 executed in ASYNC mode in that case.
981 */
983 ((server_id == (uint32)::server_id) ||
984 (common_header->log_pos == 0))) ||
985 /*
986 All Previous_gtids_log_events in the relay log are generated
987 by the slave. They don't have any meaning to the applier, so
988 they can always be ignored by the applier. So we can process
989 them asynchronously by the coordinator. It is also important
990 to not feed them to workers because that confuses
991 get_slave_worker.
992 */
994 /*
995 Rotate_log_event can occur in the middle of a transaction.
996 When this happens, either it is a Rotate event generated on
997 the slave which has the slave's server_id, or it is a Rotate
998 event that originates from a master but has end_log_pos==0.
999 */
1001 ((server_id == (uint32)::server_id) ||
1002 (common_header->log_pos == 0 && mts_in_group))))
1003 return EVENT_EXEC_ASYNC;
1004 else if (is_mts_sequential_exec())
1005 return EVENT_EXEC_SYNC;
1006 else
1007 return EVENT_EXEC_PARALLEL;
1008 }
1009
1010 /**
1011 @return index in [0, M] range to indicate
1012 to be assigned worker;
1013 M is the max index of the worker pool.
1014 */
1016
1017 /*
1018 Group of events can be marked to force its execution
1019 in isolation from any other Workers.
1020 Typically that is done for a transaction that contains
1021 a query accessing more than OVER_MAX_DBS_IN_EVENT_MTS databases.
1022 Factually that's a sequential mode where a Worker remains to
1023 be the applier.
1025 virtual void set_mts_isolate_group() {
1029 }
1030
1031 public:
1032 /**
1033 The method fills in pointers to event's database name c-strings
1034 to a supplied array.
1035 In other than Query-log-event case the returned array contains
1036 just one item.
1037 @param[out] arg pointer to a struct containing char* array
1038 pointers to be filled in and the number
1039 of filled instances.
1040 @param rpl_filter pointer to a replication filter.
1041
1042 @return number of the filled instances indicating how many
1043 databases the event accesses.
1045 virtual uint8 get_mts_dbs(Mts_db_names *arg,
1046 Rpl_filter *rpl_filter [[maybe_unused]]) {
1047 arg->name[0] = get_db();
1048
1049 return arg->num = mts_number_dbs();
1050 }
1051
1052 /**
1053 @return true if events carries partitioning data (database names).
1054 */
1055 bool contains_partition_info(bool);
1056
1057 /*
1058 @return the number of updated by the event databases.
1059
1060 @note In other than Query-log-event case that's one.
1062 virtual uint8 mts_number_dbs() { return 1; }
1063
1064 /**
1065 @return true if the terminal event of a group is marked to
1066 execute in isolation from other Workers,
1067 false otherwise
1069 bool is_mts_group_isolated() {
1071 }
1072
1073 /**
1074 Events of a certain type can start or end a group of events treated
1075 transactionally wrt binlog.
1076
1077 Public access is required by implementation of recovery + skip.
1078
1079 @return true if the event starts a group (transaction)
1080 false otherwise
1081 */
1082#endif
1083 virtual bool starts_group() const { return false; }
1084 /**
1085 @return true if the event ends a group (transaction)
1086 false otherwise
1088 virtual bool ends_group() const { return false; }
1089#ifdef MYSQL_SERVER
1090 /**
1091 Apply the event to the database.
1092
1093 This function represents the public interface for applying an
1094 event.
1095
1096 @see do_apply_event
1097 */
1098 int apply_event(Relay_log_info *rli);
1099
1100 /**
1101 Apply the GTID event in curr_group_data to the database.
1102
1103 @param rli Pointer to coordinato's relay log info.
1104
1105 @retval 0 success
1106 @retval 1 error
1107 */
1108 inline int apply_gtid_event(Relay_log_info *rli);
1109
1110 /**
1111 Update the relay log position.
1112
1113 This function represents the public interface for "stepping over"
1114 the event and will update the relay log information.
1115
1116 @see do_update_pos
1118 int update_pos(Relay_log_info *rli) { return do_update_pos(rli); }
1119
1120 /**
1121 Decide if the event shall be skipped, and the reason for skipping
1122 it.
1123
1124 @see do_shall_skip
1127 DBUG_TRACE;
1129 DBUG_PRINT("info", ("skip reason=%d=%s", ret,
1130 ret == EVENT_SKIP_NOT
1131 ? "NOT"
1132 : ret == EVENT_SKIP_IGNORE ? "IGNORE" : "COUNT"));
1133 return ret;
1134 }
1135
1136 /**
1137 Primitive to apply an event to the database.
1138
1139 This is where the change to the database is made.
1140
1141 @note The primitive is protected instead of private, since there
1142 is a hierarchy of actions to be performed in some cases.
1143
1144 @see Format_description_log_event::do_apply_event()
1145
1146 @param rli Pointer to relay log info structure
1147
1148 @retval 0 Event applied successfully
1149 @retval errno Error code if event application failed
1151 virtual int do_apply_event(Relay_log_info const *rli [[maybe_unused]]) {
1152 return 0; /* Default implementation does nothing */
1153 }
1154
1155 virtual int do_apply_event_worker(Slave_worker *w);
1156
1157 protected:
1158 /**
1159 Helper function to ignore an event w.r.t. the slave skip counter.
1160
1161 This function can be used inside do_shall_skip() for functions
1162 that cannot end a group. If the slave skip counter is 1 when
1163 seeing such an event, the event shall be ignored, the counter
1164 left intact, and processing continue with the next event.
1165
1166 A typical usage is:
1167 @code
1168 enum_skip_reason do_shall_skip(Relay_log_info *rli) {
1169 return continue_group(rli);
1170 }
1171 @endcode
1172
1173 @return Skip reason
1174 */
1176
1177 /**
1178 Advance relay log coordinates.
1179
1180 This function is called to advance the relay log coordinates to
1181 just after the event. It is essential that both the relay log
1182 coordinate and the group log position is updated correctly, since
1183 this function is used also for skipping events.
1184
1185 Normally, each implementation of do_update_pos() shall:
1186
1187 - Update the event position to refer to the position just after
1188 the event.
1189
1190 - Update the group log position to refer to the position just
1191 after the event <em>if the event is last in a group</em>
1192
1193 @param rli Pointer to relay log info structure
1194
1195 @retval 0 Coordinates changed successfully
1196 @retval errno Error code if advancing failed (usually just
1197 1). Observe that handler errors are returned by the
1198 do_apply_event() function, and not by this one.
1199 */
1200 virtual int do_update_pos(Relay_log_info *rli);
1201
1202 /**
1203 Decide if this event shall be skipped or not and the reason for
1204 skipping it.
1205
1206 The default implementation decide that the event shall be skipped
1207 if either:
1208
1209 - the server id of the event is the same as the server id of the
1210 server and <code>rli->replicate_same_server_id</code> is true,
1211 or
1212
1213 - if <code>rli->slave_skip_counter</code> is greater than zero.
1214
1215 @see do_apply_event
1216 @see do_update_pos
1217
1218 @retval Log_event::EVENT_SKIP_NOT
1219 The event shall not be skipped and should be applied.
1220
1221 @retval Log_event::EVENT_SKIP_IGNORE
1222 The event shall be skipped by just ignoring it, i.e., the slave
1223 skip counter shall not be changed. This happends if, for example,
1224 the originating server id of the event is the same as the server
1225 id of the slave.
1226
1227 @retval Log_event::EVENT_SKIP_COUNT
1228 The event shall be skipped because the slave skip counter was
1229 non-zero. The caller shall decrease the counter by one.
1230 */
1232#endif
1233};
1234
1235/*
1236 One class for each type of event.
1237 Two constructors for each class:
1238 - one to create the event for logging (when the server acts as a master),
1239 called after an update to the database is done,
1240 which accepts parameters like the query, the database, the options for LOAD
1241 DATA INFILE...
1242 - one to create the event from a packet (when the server acts as a slave),
1243 called before reproducing the update, which accepts parameters (like a
1244 buffer). Used to read from the master, from the relay log, and in
1245 mysqlbinlog. This constructor must be format-tolerant.
1246*/
1247
1248/**
1249 A Query event is written to the binary log whenever the database is
1250 modified on the master, unless row based logging is used.
1251
1252 Query_log_event is created for logging, and is called after an update to the
1253 database is done. It is used when the server acts as the master.
1254
1255 Virtual inheritance is required here to handle the diamond problem in
1256 the class @c Execute_load_query_log_event.
1257 The diamond structure is explained in @c Excecute_load_query_log_event
1258
1259 @internal
1260 The inheritance structure is as follows:
1261
1262 Binary_log_event
1263 ^
1264 |
1265 |
1266 Query_event Log_event
1267 \ /
1268 <<virtual>>\ /
1269 \ /
1270 Query_log_event
1271 @endinternal
1273class Query_log_event : public virtual binary_log::Query_event,
1274 public Log_event {
1275 protected:
1276 Log_event_header::Byte *data_buf;
1277
1278 public:
1279 /*
1280 For events created by Query_log_event::do_apply_event (and
1281 Load_log_event::do_apply_event()) we need the *original* thread
1282 id, to be able to log the event with the original (=master's)
1283 thread id (fix for BUG#1686).
1286
1287 /**
1288 True if this is a ROLLBACK event injected by the mts coordinator to finish a
1289 group corresponding to a partial transaction in the relay log.
1290 False otherwise and by default, as it must be explicitly set to true by the
1291 coordinator.
1293 bool rollback_injected_by_coord = false;
1294
1295 /**
1296 The flag indicates whether the DDL query has been (already)
1297 committed or not. It's initialized as OFF at the event instantiation,
1298 flips ON when the DDL transaction has been committed with
1299 all its possible extra statement due to replication or GTID.
1300
1301 The flag status is also checked in few places to catch uncommitted
1302 transactions which can normally happen due to filtering out. In
1303 such a case the commit is deferred to @c Log_event::do_update_pos().
1305 bool has_ddl_committed;
1306
1307#ifdef MYSQL_SERVER
1308
1309 /**
1310 Instructs the applier to skip temporary tables handling.
1316 }
1320 }
1321
1322 Query_log_event(THD *thd_arg, const char *query_arg, size_t query_length,
1323 bool using_trans, bool immediate, bool suppress_use,
1324 int error, bool ignore_command = false);
1325 const char *get_db() override { return db; }
1326
1327 /**
1328 @param[out] arg pointer to a struct containing char* array
1329 pointers be filled in and the number of
1330 filled instances.
1331 In case the number exceeds MAX_DBS_IN_EVENT_MTS,
1332 the overfill is indicated with assigning the number to
1333 OVER_MAX_DBS_IN_EVENT_MTS.
1334 @param rpl_filter pointer to a replication filter.
1335
1336 @return number of databases in the array or OVER_MAX_DBS_IN_EVENT_MTS.
1340 // the empty string db name is special to indicate sequential applying
1341 mts_accessed_db_names[0][0] = 0;
1342 } else {
1343 for (uchar i = 0; i < mts_accessed_dbs; i++) {
1344 const char *db_name = mts_accessed_db_names[i];
1345
1346 // Only default database is rewritten.
1347 if (!rpl_filter->is_rewrite_empty() && !strcmp(get_db(), db_name)) {
1348 size_t dummy_len;
1349 const char *db_filtered =
1350 rpl_filter->get_rewrite_db(db_name, &dummy_len);
1351 // db_name != db_filtered means that db_name is rewritten.
1352 if (strcmp(db_name, db_filtered)) db_name = db_filtered;
1353 }
1354 arg->name[i] = db_name;
1355 }
1356 }
1357 return arg->num = mts_accessed_dbs;
1358 }
1359
1363 uchar mts_number_dbs() override { return mts_accessed_dbs; }
1364
1365 int pack_info(Protocol *protocol) override;
1366#else
1367 void print_query_header(IO_CACHE *file,
1368 PRINT_EVENT_INFO *print_event_info) const;
1369 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
1370 static bool rewrite_db_in_buffer(char **buf, ulong *event_len,
1371 const Format_description_event &fde);
1372#endif
1373
1375
1376 Query_log_event(const char *buf,
1377 const Format_description_event *description_event,
1378 Log_event_type event_type);
1379 ~Query_log_event() override {
1381 }
1382#ifdef MYSQL_SERVER
1383 bool write(Basic_ostream *ostream) override;
1384 virtual bool write_post_header_for_derived(Basic_ostream *) { return false; }
1385#endif
1386
1387 /*
1388 Returns number of bytes additionally written to post header by derived
1389 events (so far it is only Execute_load_query event).
1391 virtual ulong get_post_header_size_for_derived() { return 0; }
1392 /* Writes derived event-specific part of post header. */
1393
1394 public: /* !!! Public in this patch to allow old usage */
1395#if defined(MYSQL_SERVER)
1397 int do_apply_event(Relay_log_info const *rli) override;
1398 int do_update_pos(Relay_log_info *rli) override;
1399
1400 int do_apply_event(Relay_log_info const *rli, const char *query_arg,
1401 size_t q_len_arg);
1402#endif /* MYSQL_SERVER */
1403 /*
1404 If true, the event always be applied by slave SQL thread or be printed by
1405 mysqlbinlog
1407 bool is_trans_keyword() const {
1408 /*
1409 Before the patch for bug#50407, The 'SAVEPOINT and ROLLBACK TO'
1410 queries input by user was written into log events directly.
1411 So the keywords can be written in both upper case and lower case
1412 together, strncasecmp is used to check both cases. they also could be
1413 binlogged with comments in the front of these keywords. for examples:
1414 / * bla bla * / SAVEPOINT a;
1415 / * bla bla * / ROLLBACK TO a;
1416 but we don't handle these cases and after the patch, both quiries are
1417 binlogged in upper case with no comments.
1418 */
1419 return !strncmp(query, "BEGIN", q_len) ||
1420 !strncmp(query, "COMMIT", q_len) ||
1421 !native_strncasecmp(query, "SAVEPOINT", 9) ||
1422 !native_strncasecmp(query, "ROLLBACK", 8) ||
1423 !native_strncasecmp(query, STRING_WITH_LEN("XA START")) ||
1425 !native_strncasecmp(query, STRING_WITH_LEN("XA PREPARE")) ||
1426 !native_strncasecmp(query, STRING_WITH_LEN("XA COMMIT")) ||
1427 !native_strncasecmp(query, STRING_WITH_LEN("XA ROLLBACK"));
1428 }
1429
1430 /**
1431 When a query log event contains a non-transaction control statement, we
1432 assume that it is changing database content (DML) and was logged using
1433 binlog_format=statement.
1434
1435 @return True the event represents a statement that was logged using SBR
1436 that can change database content.
1437 False for transaction control statements.
1439 bool is_sbr_logging_format() const override { return !is_trans_keyword(); }
1440
1441 /**
1442 Notice, DDL queries are logged without BEGIN/COMMIT parentheses
1443 and identification of such single-query group
1444 occurs within logics of @c get_slave_worker().
1445 */
1447 bool starts_group() const override {
1448 return !strncmp(query, "BEGIN", q_len) ||
1449 !strncmp(query, STRING_WITH_LEN("XA START"));
1450 }
1452 bool ends_group() const override {
1453 return !strncmp(query, "COMMIT", q_len) ||
1454 (!native_strncasecmp(query, STRING_WITH_LEN("ROLLBACK")) &&
1455 native_strncasecmp(query, STRING_WITH_LEN("ROLLBACK TO "))) ||
1456 !strncmp(query, STRING_WITH_LEN("XA ROLLBACK"));
1457 }
1458 static size_t get_query(const char *buf, size_t length,
1459 const Format_description_event *fd_event,
1460 const char **query_arg);
1462 bool is_query_prefix_match(const char *pattern, uint p_len) {
1463 return !strncmp(query, pattern, p_len);
1464 }
1465
1466 private:
1467 /** Whether or not the statement represented by this event requires
1468 `Q_SQL_REQUIRE_PRIMARY_KEY` to be logged along aside. */
1469 bool need_sql_require_primary_key{false};
1470
1471 /** Whether or not the statement represented by this event requires
1472 `Q_DEFAULT_TABLE_ENCRYPTION` to be logged along aside. */
1474};
1475
1476/**
1477 @class Format_description_log_event
1478
1479 For binlog version 4.
1480 This event is saved by threads which read it, as they need it for future
1481 use (to decode the ordinary events).
1482 This is the subclass of Format_description_event
1483
1484 @internal
1485 The inheritance structure in the current design for the classes is
1486 as follows:
1487
1488 Binary_log_event
1489 ^
1490 |
1491 |
1492 Format_description_event Log_event
1493 \ /
1494 \ /
1495 \ /
1496 Format_description_log_event
1497 @endinternal
1498 @section Format_description_log_event_binary_format Binary Format
1499*/
1502 public Log_event {
1503 public:
1504 /*
1505 MTS Workers and Coordinator share the event and that affects its
1506 destruction. Instantiation is always done by Coordinator/SQL thread.
1507 Workers are allowed to destroy only "obsolete" instances, those
1508 that are not actual for Coordinator anymore but needed to Workers
1509 that are processing queued events depending on the old instance.
1510 The counter of a new FD is incremented by Coordinator or Worker at
1511 time of {Relay_log_info,Slave_worker}::set_rli_description_event()
1512 execution.
1513 In the same methods the counter of the "old" FD event is decremented
1514 and when it drops to zero the old FD is deleted.
1515 The latest read from relay-log event is to be
1516 destroyed by Coordinator/SQL thread at its thread exit.
1517 Notice the counter is processed even in the single-thread mode where
1518 decrement and increment are done by the single SQL thread.
1520 std::atomic<int32> atomic_usage_counter{0};
1521
1524 const char *buf, const Format_description_event *description_event);
1525#ifdef MYSQL_SERVER
1526 bool write(Basic_ostream *ostream) override;
1527 int pack_info(Protocol *protocol) override;
1528#else
1529 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
1530#endif
1532 size_t get_data_size() override {
1533 /*
1534 The vector of post-header lengths is considered as part of the
1535 post-header, because in a given version it never changes (contrary to the
1536 query in a Query_log_event).
1537 */
1538 return Binary_log_event::FORMAT_DESCRIPTION_HEADER_LEN;
1539 }
1540
1541 protected:
1542#if defined(MYSQL_SERVER)
1543 int do_apply_event(Relay_log_info const *rli) override;
1544 int do_update_pos(Relay_log_info *rli) override;
1546#endif
1547};
1548
1549/**
1550 @class Intvar_log_event
1551
1552 The class derives from the class Intvar_event in Binlog API,
1553 defined in the header binlog_event.h. An Intvar_log_event is
1554 created just before a Query_log_event, if the query uses one
1555 of the variables LAST_INSERT_ID or INSERT_ID. This class is used
1556 by the slave for applying the event.
1557
1558 @internal
1559 The inheritance structure in the current design for the classes is
1560 as follows:
1561
1562 Binary_log_event
1563 ^
1564 |
1565 |
1566 Intvar_event Log_event
1567 \ /
1568 \ /
1569 \ /
1570 Intvar_log_event
1571 @endinternal
1574 public:
1575#ifdef MYSQL_SERVER
1576 Intvar_log_event(THD *thd_arg, uchar type_arg, ulonglong val_arg,
1577 enum_event_cache_type cache_type_arg,
1578 enum_event_logging_type logging_type_arg)
1579 : binary_log::Intvar_event(type_arg, val_arg),
1580 Log_event(thd_arg, 0, cache_type_arg, logging_type_arg, header(),
1581 footer()) {
1583 }
1584 int pack_info(Protocol *protocol) override;
1585#else
1586 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
1587#endif
1588
1589 Intvar_log_event(const char *buf,
1590 const Format_description_event *description_event);
1591 ~Intvar_log_event() override = default;
1592 size_t get_data_size() override {
1593 return 9; /* sizeof(type) + sizeof(val) */
1594 ;
1595 }
1596#ifdef MYSQL_SERVER
1597 bool write(Basic_ostream *ostream) override;
1598#endif
1600 bool is_sbr_logging_format() const override { return true; }
1601
1602 private:
1603#if defined(MYSQL_SERVER)
1604 int do_apply_event(Relay_log_info const *rli) override;
1605 int do_update_pos(Relay_log_info *rli) override;
1607#endif
1608};
1609
1610/**
1611 @class Rand_log_event
1612
1613 Logs random seed used by the next RAND(), and by PASSWORD() in 4.1.0.
1614 4.1.1 does not need it (it's repeatable again) so this event needn't be
1615 written in 4.1.1 for PASSWORD() (but the fact that it is written is just a
1616 waste, it does not cause bugs).
1617
1618 The state of the random number generation consists of 128 bits,
1619 which are stored internally as two 64-bit numbers.
1620
1621 @internal
1622 The inheritance structure in the current design for the classes is
1623 as follows:
1624 Binary_log_event
1625 ^
1626 |
1627 |
1628 Rand_event Log_event
1629 \ /
1630 \ /
1631 \ /
1632 Rand_log_event
1633 @endinternal
1635class Rand_log_event : public binary_log::Rand_event, public Log_event {
1636 public:
1637#ifdef MYSQL_SERVER
1638 Rand_log_event(THD *thd_arg, ulonglong seed1_arg, ulonglong seed2_arg,
1639 enum_event_cache_type cache_type_arg,
1640 enum_event_logging_type logging_type_arg)
1641 : binary_log::Rand_event(seed1_arg, seed2_arg),
1642 Log_event(thd_arg, 0, cache_type_arg, logging_type_arg, header(),
1643 footer()) {
1645 }
1646 int pack_info(Protocol *protocol) override;
1647#else
1648 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
1649#endif
1650
1651 Rand_log_event(const char *buf,
1652 const Format_description_event *description_event);
1653 ~Rand_log_event() override = default;
1654 size_t get_data_size() override { return 16; /* sizeof(ulonglong) * 2*/ }
1655#ifdef MYSQL_SERVER
1656 bool write(Basic_ostream *ostream) override;
1657#endif
1659 bool is_sbr_logging_format() const override { return true; }
1660
1661 private:
1662#if defined(MYSQL_SERVER)
1663 int do_apply_event(Relay_log_info const *rli) override;
1664 int do_update_pos(Relay_log_info *rli) override;
1666#endif
1667};
1668
1669/**
1670 @class Xid_log_event
1671
1672 This is the subclass of Xid_event defined in libbinlogevent,
1673 An XID event is generated for a commit of a transaction that modifies one or
1674 more tables of an XA-capable storage engine
1675 Logs xid of the transaction-to-be-committed in the 2pc protocol.
1676 Has no meaning in replication, slaves ignore it
1677 The inheritance structure in the current design for the classes is
1678 as follows
1679
1680 @internal
1681 The inheritance structure in the current design for the classes is
1682 as follows:
1683 Binary_log_event
1684 ^
1685 |
1686 |
1687 Xid_event Log_event
1688 \ /
1689 \ /
1690 \ /
1691 Xid_log_event
1692 @endinternal
1693*/
1694#ifndef MYSQL_SERVER
1695typedef ulonglong my_xid; // this line is the same as in handler.h
1696#endif
1698class Xid_apply_log_event : public Log_event {
1699 protected:
1700#ifdef MYSQL_SERVER
1701 Xid_apply_log_event(THD *thd_arg, Log_event_header *header_arg,
1702 Log_event_footer *footer_arg)
1704 Log_event::EVENT_NORMAL_LOGGING, header_arg, footer_arg) {}
1705#endif
1707 Log_event_footer *footer_arg)
1708 : Log_event(header_arg, footer_arg) {}
1709 ~Xid_apply_log_event() override = default;
1710 bool ends_group() const override { return true; }
1711#if defined(MYSQL_SERVER)
1713 int do_apply_event(Relay_log_info const *rli) override;
1715 virtual bool do_commit(THD *thd_arg) = 0;
1716#endif
1717};
1720 public:
1721#ifdef MYSQL_SERVER
1722 Xid_log_event(THD *thd_arg, my_xid x)
1723 : binary_log::Xid_event(x),
1724 Xid_apply_log_event(thd_arg, header(), footer()) {
1726 }
1727 int pack_info(Protocol *protocol) override;
1728#else
1729 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
1730#endif
1731
1732 Xid_log_event(const char *buf,
1733 const Format_description_event *description_event);
1734 ~Xid_log_event() override = default;
1735 size_t get_data_size() override { return sizeof(xid); }
1736#ifdef MYSQL_SERVER
1737 bool write(Basic_ostream *ostream) override;
1738#endif
1739 private:
1740#if defined(MYSQL_SERVER)
1741 bool do_commit(THD *thd_arg) override;
1742#endif
1743};
1744
1745/**
1746 @class XA_prepare_log_event
1747
1748 Similar to Xid_log_event except that
1749 - it is specific to XA transaction
1750 - it carries out the prepare logics rather than the final committing
1751 when @c one_phase member is off.
1752 From the groupping perspective the event finalizes the current "prepare" group
1753 started with XA START Query-log-event.
1754 When @c one_phase is false Commit of Rollback for XA transaction are
1755 logged separately to the prepare-group events so being a groups of
1756 their own.
1757*/
1760 public Xid_apply_log_event {
1761 private:
1762 /* Total size of buffers to hold serialized members of XID struct */
1763 static const int xid_bufs_size = 12;
1764
1765 public:
1766#ifdef MYSQL_SERVER
1767 XA_prepare_log_event(THD *thd_arg, XID *xid_arg, bool one_phase_arg = false)
1768 : binary_log::XA_prepare_event((void *)xid_arg, one_phase_arg),
1769 Xid_apply_log_event(thd_arg, header(), footer()) {}
1770#endif
1771 XA_prepare_log_event(const char *buf,
1772 const Format_description_event *description_event)
1773 : binary_log::XA_prepare_event(buf, description_event),
1775 DBUG_TRACE;
1776 xid = nullptr;
1777 return;
1780 size_t get_data_size() override {
1781 return xid_bufs_size + my_xid.gtrid_length + my_xid.bqual_length;
1782 }
1783#ifdef MYSQL_SERVER
1784 bool write(Basic_ostream *ostream) override;
1785#else
1786 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
1787#endif
1788#if defined(MYSQL_SERVER)
1789 int pack_info(Protocol *protocol) override;
1790 bool do_commit(THD *thd) override;
1791#endif
1792};
1793
1794/**
1795 @class User_var_log_event
1796
1797 Every time a query uses the value of a user variable, a User_var_log_event is
1798 written before the Query_log_event, to set the user variable.
1799
1800 @internal
1801 The inheritance structure in the current design for the classes is
1802 as follows:
1803 Binary_log_event
1804 ^
1805 |
1806 |
1807 User_var_event Log_event
1808 \ /
1809 \ /
1810 \ /
1811 User_var_log_event
1812 @endinternal
1815 public:
1816#ifdef MYSQL_SERVER
1819 User_var_log_event(THD *thd_arg, const char *name_arg, uint name_len_arg,
1820 char *val_arg, ulong val_len_arg, Item_result type_arg,
1821 uint charset_number_arg, uchar flags_arg,
1822 enum_event_cache_type cache_type_arg,
1823 enum_event_logging_type logging_type_arg)
1824 : binary_log::User_var_event(name_arg, name_len_arg, val_arg, val_len_arg,
1825 type_arg, charset_number_arg, flags_arg),
1826 Log_event(thd_arg, 0, cache_type_arg, logging_type_arg, header(),
1827 footer()),
1828 deferred(false) {
1829 common_header->set_is_valid(name != nullptr);
1830 }
1831 int pack_info(Protocol *protocol) override;
1832#else
1833 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
1834#endif
1835
1836 User_var_log_event(const char *buf,
1837 const Format_description_event *description_event);
1838 ~User_var_log_event() override = default;
1839#ifdef MYSQL_SERVER
1840 bool write(Basic_ostream *ostream) override;
1841 /*
1842 Getter and setter for deferred User-event.
1843 Returns true if the event is not applied directly
1844 and which case the applier adjusts execution path.
1846 bool is_deferred() { return deferred; }
1847 /*
1848 In case of the deferred applying the variable instance is flagged
1849 and the parsing time query id is stored to be used at applying time.
1851 void set_deferred(query_id_t qid) {
1852 deferred = true;
1853 query_id = qid;
1854 }
1855#endif
1857 bool is_sbr_logging_format() const override { return true; }
1858
1859 private:
1860#if defined(MYSQL_SERVER)
1861 int do_apply_event(Relay_log_info const *rli) override;
1862 int do_update_pos(Relay_log_info *rli) override;
1864#endif
1865};
1866
1867/**
1868 @class Stop_log_event
1869
1871class Stop_log_event : public binary_log::Stop_event, public Log_event {
1872 public:
1873#ifdef MYSQL_SERVER
1878 }
1879
1880#else
1881 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
1882#endif
1884 Stop_log_event(const char *buf,
1885 const Format_description_event *description_event)
1886 : binary_log::Stop_event(buf, description_event),
1887 Log_event(header(), footer()) {
1888 DBUG_TRACE;
1889 return;
1890 }
1892 ~Stop_log_event() override = default;
1894
1895 private:
1896#if defined(MYSQL_SERVER)
1897 int do_update_pos(Relay_log_info *rli) override;
1899 /*
1900 Events from ourself should be skipped, but they should not
1901 decrease the slave skip counter.
1902 */
1903 if (this->server_id == ::server_id)
1905 else
1907 }
1908#endif
1909};
1910
1911/**
1912 @class Rotate_log_event
1913
1914 This will be deprecated when we move to using sequence ids.
1915 This class is a subclass of Rotate_event, defined in binlogevent, and is used
1916 by the slave for updating the position in the relay log.
1917
1918 It is used by the master inorder to write the rotate event in the binary log.
1919
1920 @internal
1921 The inheritance structure in the current design for the classes is
1922 as follows:
1923
1924 Binary_log_event
1925 ^
1926 |
1927 |
1928 Rotate_event Log_event
1929 \ /
1930 \ /
1931 \ /
1932 Rotate_log_event
1933 @endinternal
1936 public:
1937#ifdef MYSQL_SERVER
1938 Rotate_log_event(const char *new_log_ident_arg, size_t ident_len_arg,
1939 ulonglong pos_arg, uint flags);
1940 int pack_info(Protocol *protocol) override;
1941#else
1942 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
1943#endif
1944
1945 Rotate_log_event(const char *buf,
1946 const Format_description_event *description_event);
1947 ~Rotate_log_event() override = default;
1948 size_t get_data_size() override {
1949 return ident_len + Binary_log_event::ROTATE_HEADER_LEN;
1950 }
1951#ifdef MYSQL_SERVER
1952 bool write(Basic_ostream *ostream) override;
1953#endif
1954
1955 private:
1956#if defined(MYSQL_SERVER)
1957 int do_update_pos(Relay_log_info *rli) override;
1959#endif
1960};
1961
1962/**
1963 @class Append_block_log_event
1964
1965 This event is created to contain the file data. One LOAD_DATA_INFILE
1966 can have 0 or more instances of this event written to the binary log
1967 depending on the size of the file.
1968
1969 @internal
1970 The inheritance structure is as follows
1971
1972 Binary_log_event
1973 ^
1974 |
1975 |
1976 B_l:A_B_E Log_event
1977 \ /
1978 \ /
1979 <<vir>>\ /
1980 \ /
1981 Append_block_log_event
1982 B_l: Namespace Binary_log
1983 A_B_E: class Append_block_event
1984 @endinternal
1985
1988 public Log_event {
1989 public:
1990#ifdef MYSQL_SERVER
1991 Append_block_log_event(THD *thd, const char *db_arg, uchar *block_arg,
1992 uint block_len_arg, bool using_trans);
1993 int pack_info(Protocol *protocol) override;
1994 virtual int get_create_or_append() const;
1995#else
1996 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
1997#endif
1998
1999 Append_block_log_event(const char *buf,
2000 const Format_description_event *description_event);
2001 ~Append_block_log_event() override = default;
2002 size_t get_data_size() override {
2003 return block_len + Binary_log_event::APPEND_BLOCK_HEADER_LEN;
2004 }
2005#ifdef MYSQL_SERVER
2006 bool write(Basic_ostream *ostream) override;
2007 const char *get_db() override { return db; }
2008#endif
2010 bool is_sbr_logging_format() const override { return true; }
2011
2012 private:
2013#if defined(MYSQL_SERVER)
2014 int do_apply_event(Relay_log_info const *rli) override;
2015#endif
2016};
2017
2018/**
2019 @class Delete_file_log_event
2020
2021 Delete_file_log_event is created when the LOAD_DATA query fails on the
2022 master for some reason, and the slave should be notified to abort the
2023 load. The event is required since the master starts writing the loaded
2024 block into the binary log before the statement ends. In case of error,
2025 the slave should abort, and delete any temporary file created while
2026 applying the (NEW_)LOAD_EVENT.
2027
2028 @internal
2029 The inheritance structure is as follows
2030
2031 Binary_log_event
2032 ^
2033 |
2034 |
2035 B_l:D_F_E Log_event
2036 \ /
2037 \ /
2038 \ /
2039 \ /
2040 Delete_file_log_event
2041
2042 B_l: Namespace Binary_log
2043 D_F_E: class Delete_file_event
2044 @endinternal
2045
2048 public Log_event {
2049 public:
2050#ifdef MYSQL_SERVER
2051 Delete_file_log_event(THD *thd, const char *db_arg, bool using_trans);
2052 int pack_info(Protocol *protocol) override;
2053#else
2054 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
2055 void print(FILE *file, PRINT_EVENT_INFO *print_event_info, bool enable_local);
2056#endif
2057
2058 Delete_file_log_event(const char *buf,
2059 const Format_description_event *description_event);
2060 ~Delete_file_log_event() override = default;
2061 size_t get_data_size() override {
2062 return Binary_log_event::DELETE_FILE_HEADER_LEN;
2063 }
2064#ifdef MYSQL_SERVER
2065 bool write(Basic_ostream *ostream) override;
2066 const char *get_db() override { return db; }
2067#endif
2069 bool is_sbr_logging_format() const override { return true; }
2070
2071 private:
2072#if defined(MYSQL_SERVER)
2073 int do_apply_event(Relay_log_info const *rli) override;
2074#endif
2075};
2076
2077/**
2078 @class Begin_load_query_log_event
2079
2080 Event for the first block of file to be loaded, its only difference from
2081 Append_block event is that this event creates or truncates existing file
2082 before writing data.
2083
2084 @internal
2085 The inheritance structure is as follows
2086
2087 Binary_log_event
2088 ^
2089 |
2090 |
2091 |
2092 Log_event B_l:A_B_E
2093 ^ /\
2094 | / \
2095 | <<vir>>/ \ <<vir>>
2096 | / \
2097 | / \
2098 | / \
2099 Append_block_log_event B_l:B_L_Q_E
2100 \ /
2101 \ /
2102 \ /
2103 \ /
2104 \ /
2105 Begin_load_query_log_event
2106
2107 B_l: Namespace Binary_log
2108 A_B_E: class Append_block_event
2109 B_L_Q_E: Begin_load_query_event
2110 @endinternal
2111
2112 @section Begin_load_query_log_event_binary_format Binary Format
2116 public:
2117#ifdef MYSQL_SERVER
2118 Begin_load_query_log_event(THD *thd_arg, const char *db_arg, uchar *block_arg,
2119 uint block_len_arg, bool using_trans);
2121 int get_create_or_append() const override;
2122#endif
2123 Begin_load_query_log_event(const char *buf,
2124 const Format_description_event *description_event);
2125 ~Begin_load_query_log_event() override = default;
2126
2127 private:
2128#if defined(MYSQL_SERVER)
2130#endif
2131};
2132
2133/**
2134 @class Execute_load_query_log_event
2135
2136 Event responsible for LOAD DATA execution, it similar to Query_log_event
2137 but before executing the query it substitutes original filename in LOAD DATA
2138 query with name of temporary file.
2139
2140 @internal
2141 The inheritance structure is as follows:
2142
2143 Binary_log_event
2144 ^
2145 |
2146 |
2147 |
2148 Log_event B_l:Query_event
2149 ^ /\
2150 | / \
2151 | <<vir>>/ \ <<vir>>
2152 | / \
2153 | / \
2154 | / \
2155 Query_log_event B_l:E_L_Q_E
2156 \ /
2157 \ /
2158 \ /
2159 \ /
2160 \ /
2161 Execute_load_query_log_event
2162
2163 B_l: Namespace Binary_log
2164 E_L_Q_E: class Execute_load_query
2165 @endinternal
2166
2167 @section Execute_load_query_log_event_binary_format Binary Format
2170 : public Query_log_event,
2172 public:
2173#ifdef MYSQL_SERVER
2175 THD *thd, const char *query_arg, ulong query_length,
2176 uint fn_pos_start_arg, uint fn_pos_end_arg,
2177 binary_log::enum_load_dup_handling dup_handling_arg, bool using_trans,
2178 bool immediate, bool suppress_use, int errcode);
2179 int pack_info(Protocol *protocol) override;
2180#else
2181 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
2182 /* Prints the query as LOAD DATA LOCAL and with rewritten filename */
2183 void print(FILE *file, PRINT_EVENT_INFO *print_event_info,
2184 const char *local_fname) const;
2185#endif
2187 const char *buf, const Format_description_event *description_event);
2188 ~Execute_load_query_log_event() override = default;
2189
2190 ulong get_post_header_size_for_derived() override;
2191#ifdef MYSQL_SERVER
2192 bool write_post_header_for_derived(Basic_ostream *ostream) override;
2193#endif
2195 bool is_sbr_logging_format() const override { return true; }
2196
2197 private:
2198#if defined(MYSQL_SERVER)
2199 int do_apply_event(Relay_log_info const *rli) override;
2200#endif
2201};
2202
2203#if defined MYSQL_SERVER
2205 public:
2206 Load_query_generator(THD *thd_arg, const sql_exchange *ex, const char *db_arg,
2207 const char *table_name_arg, bool is_concurrent_arg,
2208 bool replace, bool ignore);
2209
2210 const String *generate(size_t *fn_start, size_t *fn_end);
2211
2212 private:
2213 const size_t BUF_SIZE = 2048;
2215 char *buf[2048];
2219 const char *db;
2220 const char *table_name;
2221 const char *fname;
2225 bool has_ignore;
2226};
2227#endif
2228#ifndef MYSQL_SERVER
2229/**
2230 @class Unknown_log_event
2231
2232*/
2233class Unknown_log_event : public binary_log::Unknown_event, public Log_event {
2234 public:
2235 /**
2236 Even if this is an unknown event, we still pass description_event to
2237 Log_event's ctor, this way we can extract maximum information from the
2238 event's header (the unique ID for example).
2239 */
2240 Unknown_log_event(const char *buf,
2241 const Format_description_event *description_event)
2242 : binary_log::Unknown_event(buf, description_event),
2243 Log_event(header(), footer()) {
2244 DBUG_TRACE;
2245 if (!is_valid()) return;
2246 common_header->set_is_valid(true);
2247 return;
2248 }
2249
2250 ~Unknown_log_event() override = default;
2251 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
2253};
2254#endif
2255char *str_to_hex(char *to, const char *from, size_t len);
2256
2257/**
2258 @class Table_map_log_event
2259
2260 Table_map_log_event which maps a table definition to a number.
2261
2262 @internal
2263 The inheritance structure in the current design for the classes is
2264 as follows:
2265
2266 Binary_log_event
2267 ^
2268 |
2269 |
2270 Table_map_event Log_event
2271 \ /
2272 \ /
2273 \ /
2274 Table_map_log_event
2275 @endinternal
2278 public Log_event {
2279 public:
2280 /** Constants */
2282
2283 /**
2284 Enumeration of the errors that can be returned.
2287 ERR_OPEN_FAILURE = -1, /**< Failure to open table */
2288 ERR_OK = 0, /**< No error */
2289 ERR_TABLE_LIMIT_EXCEEDED = 1, /**< No more room for tables */
2290 ERR_OUT_OF_MEM = 2, /**< Out of memory */
2291 ERR_BAD_TABLE_DEF = 3, /**< Table definition does not match */
2292 ERR_RBR_TO_SBR = 4 /**< daisy-chanining RBR to SBR not allowed */
2293 };
2295 enum enum_flag {
2296 /**
2297 Nothing here right now, but the flags support is there in
2298 preparation for changes that are coming. Need to add a
2299 constant to make it compile under HP-UX: aCC does not like
2300 empty enumerations.
2301 */
2303 };
2304
2305 /** Special constants representing sets of flags */
2306 enum {
2309 TM_REFERRED_FK_DB_F = (1U << 1),
2310 /**
2311 Table has generated invisible primary key. MySQL generates primary key
2312 while creating a table if sql_generate_invisible_primary_key is "ON" and
2313 table is PK-less.
2314 */
2316 };
2318 flag_set get_flags(flag_set flag) const { return m_flags & flag; }
2319
2320#ifdef MYSQL_SERVER
2321 Table_map_log_event(THD *thd_arg, TABLE *tbl, const Table_id &tid,
2322 bool is_transactional);
2323#endif
2324 Table_map_log_event(const char *buf,
2325 const Format_description_event *description_event);
2327 ~Table_map_log_event() override;
2328
2329#ifndef MYSQL_SERVER
2330 table_def *create_table_def() {
2331 assert(m_colcnt > 0);
2334 }
2335 static bool rewrite_db_in_buffer(char **buf, ulong *event_len,
2336 const Format_description_event &fde);
2337#endif
2338 const Table_id &get_table_id() const { return m_table_id; }
2339 const char *get_table_name() const { return m_tblnam.c_str(); }
2340 const char *get_db_name() const { return m_dbnam.c_str(); }
2342 size_t get_data_size() override { return m_data_size; }
2343#ifdef MYSQL_SERVER
2344 virtual int save_field_metadata();
2345 bool write_data_header(Basic_ostream *ostream) override;
2346 bool write_data_body(Basic_ostream *ostream) override;
2347 const char *get_db() override { return m_dbnam.c_str(); }
2348 uint8 mts_number_dbs() override {
2350 }
2351 /**
2352 @param[out] arg pointer to a struct containing char* array
2353 pointers be filled in and the number of filled instances.
2354 @param rpl_filter pointer to a replication filter.
2355
2356 @return number of databases in the array: either one or
2357 OVER_MAX_DBS_IN_EVENT_MTS, when the Table map event reports
2358 foreign keys constraint.
2361 const char *db_name = get_db();
2362
2364 size_t dummy_len;
2365 const char *db_filtered = rpl_filter->get_rewrite_db(db_name, &dummy_len);
2366 // db_name != db_filtered means that db_name is rewritten.
2367 if (strcmp(db_name, db_filtered)) db_name = db_filtered;
2368 }
2369
2370 if (!get_flags(TM_REFERRED_FK_DB_F)) arg->name[0] = db_name;
2371
2372 return arg->num = mts_number_dbs();
2373 }
2374
2375#endif
2376
2377#if defined(MYSQL_SERVER)
2378 int pack_info(Protocol *protocol) override;
2379#endif
2380
2381#ifndef MYSQL_SERVER
2382 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
2383
2384 /**
2385 Print column metadata. Its format looks like:
2386 # Columns(colume_name type, colume_name type, ...)
2387 if colume_name field is not logged into table_map_log_event, then
2388 only type is printed.
2389
2390 @param[out] file the place where colume metadata is printed
2391 @param[in] The metadata extracted from optional metadata fields
2392 */
2393 void print_columns(IO_CACHE *file,
2394 const Optional_metadata_fields &fields) const;
2395 /**
2396 Print primary information. Its format looks like:
2397 # Primary Key(colume_name, column_name(prifix), ...)
2398 if colume_name field is not logged into table_map_log_event, then
2399 colume index is printed.
2400
2401 @param[out] file the place where primary key is printed
2402 @param[in] The metadata extracted from optional metadata fields
2403 */
2404 void print_primary_key(IO_CACHE *file,
2405 const Optional_metadata_fields &fields) const;
2406#endif
2407
2410 bool is_rbr_logging_format() const override { return true; }
2411
2412 private:
2413#if defined(MYSQL_SERVER)
2414 int do_apply_event(Relay_log_info const *rli) override;
2415 int do_update_pos(Relay_log_info *rli) override;
2417#endif
2418
2419#ifdef MYSQL_SERVER
2420 TABLE *m_table;
2421
2422 // Metadata fields buffer
2424
2425 /**
2426 Wrapper around `TABLE *m_table` that abstracts the table field set iteration
2427 logic, since it is not mandatory that all table fields are to be
2428 replicated. For details, @see ReplicatedColumnsView class documentation.
2429
2430 A smart pointer is used here as the developer might want to instantiate the
2431 view using different classes in runtime depending on the given context.
2432 As of now the column view is only used on outbound scenarios
2435
2436 /**
2437 Capture the optional metadata fields which should be logged into
2438 table_map_log_event and serialize them into m_metadata_buf.
2439 */
2440 void init_metadata_fields();
2441 bool init_signedness_field();
2442 /**
2443 Capture and serialize character sets. Character sets for
2444 character columns (TEXT etc) and character sets for ENUM and SET
2445 columns are stored in different metadata fields. The reason is
2446 that TEXT character sets are included even when
2447 binlog_row_metadata=MINIMAL, whereas ENUM and SET character sets
2448 are included only when binlog_row_metadata=FULL.
2449
2450 @param include_type Predicate to determine if a given Field object
2451 is to be included in the metadata field.
2452
2453 @param default_charset_type Type code when storing in "default
2454 charset" format. (See comment above Table_maps_log_event in
2455 libbinlogevents/include/rows_event.h)
2456
2457 @param column_charset_type Type code when storing in "column
2458 charset" format. (See comment above Table_maps_log_event in
2459 libbinlogevents/include/rows_event.h)
2460 */
2461 bool init_charset_field(std::function<bool(const Field *)> include_type,
2462 Optional_metadata_field_type default_charset_type,
2463 Optional_metadata_field_type column_charset_type);
2470#endif
2471
2472#ifndef MYSQL_SERVER
2473 class Charset_iterator;
2474 class Default_charset_iterator;
2475 class Column_charset_iterator;
2476#endif
2477};
2478
2479#ifdef HAVE_PSI_STAGE_INTERFACE
2480/*
2481 Helper class for PSI context while applying a Rows_log_event.
2484 private:
2487
2488 /**
2489 A cached pointer to this stage PSI_stage_progress.
2492
2493 /**
2494 Counter that is unconditionally incremented on each row that is processed.
2495 This is helpful in case estimation is needed after started processing
2496 a Rows_log_event.
2499
2500 public:
2503 void set_progress(PSI_stage_progress *progress) { m_progress = progress; }
2504
2505 /**
2506 If instrumentation is enabled this member function SHALL return true.
2507 @return true if instrumentation is enabled for the given stage, false
2508 otherwise.
2510 bool is_enabled() { return m_progress != nullptr; }
2511
2512 /**
2513 This member function shall update the progress and reestimate the remaining
2514 work needed. This MUST be called after setting n_rows_applied correctly
2515 by calling inc_n_rows_applied beforehand.
2516
2517 Cursor, begin and end are used in case estimation is needed.
2518
2519 @param cursor Pointer to where we are in the buffer of rows to be processed.
2520 @param begin Pointer to the beginning of the rows buffer.
2521 @param end Pointer to the end of the rows buffer.
2523 void update_work_estimated_and_completed(const uchar *cursor,
2524 const uchar *begin,
2525 const uchar *end) {
2526 if (!is_enabled()) return;
2527
2529
2530 /* Estimate if need be. */
2531 if (estimated == 0) {
2532 assert(cursor > begin);
2533 ulonglong avg_row_change_size = (cursor - begin) / m_n_rows_applied;
2534 estimated = (end - begin) / avg_row_change_size;
2536 }
2537
2538 /* reset estimated if done more work than estimated */
2539 if (m_n_rows_applied > estimated)
2542 }
2543
2544 /**
2545 Resets this object.
2547 void end_work() {
2548 m_progress = nullptr;
2549 m_n_rows_applied = 0;
2550 }
2551
2552 /**
2553 Updates the counter of processed rows.
2554 @param delta the amount of increment to be done.
2556 void inc_n_rows_applied(ulonglong delta) { m_n_rows_applied += delta; }
2557
2558 /**
2559 Gets the value of the counter of rows that have been processed.
2560 @return the value of the counter of rows processed so far.
2563};
2564#endif
2565
2566/**
2567 @class Rows_log_event
2568
2569 Common base class for all row-containing log events.
2570
2571 RESPONSIBILITIES
2572
2573 Encode the common parts of all events containing rows, which are:
2574 - Write data header and data body to an IO_CACHE.
2575
2576 Virtual inheritance is required here to handle the diamond problem in
2577 the class Write_rows_log_event, Update_rows_log_event and
2578 Delete_rows_log_event.
2579 The diamond structure is explained in @c Write_rows_log_event,
2580 @c Update_rows_log_event,
2581 @c Delete_rows_log_event
2582
2583 @internal
2584 The inheritance structure in the current design for the classes is
2585 as follows:
2586
2587 Binary_log_event
2588 ^
2589 |
2590 |
2591 Rows_event Log_event
2592 \ /
2593 <<vir>>\ /
2594 \ /
2595 Rows_log_event
2596 @endinternal
2597
2599class Rows_log_event : public virtual binary_log::Rows_event, public Log_event {
2600#ifdef HAVE_PSI_STAGE_INTERFACE
2601 protected:
2603#endif
2604
2605 public:
2606 typedef uint16 flag_set;
2614 };
2615
2616 /**
2617 Enumeration of the errors that can be returned.
2620 ERR_OPEN_FAILURE = -1, /**< Failure to open table */
2621 ERR_OK = 0, /**< No error */
2622 ERR_TABLE_LIMIT_EXCEEDED = 1, /**< No more room for tables */
2623 ERR_OUT_OF_MEM = 2, /**< Out of memory */
2624 ERR_BAD_TABLE_DEF = 3, /**< Table definition does not match */
2625 ERR_RBR_TO_SBR = 4 /**< daisy-chanining RBR to SBR not allowed */
2626 };
2627
2628 /* Special constants representing sets of flags */
2629 enum { RLE_NO_FLAGS = 0U };
2630
2631 ~Rows_log_event() override;
2633 void set_flags(flag_set flags_arg) { m_flags |= flags_arg; }
2634 void clear_flags(flag_set flags_arg) { m_flags &= ~flags_arg; }
2635 flag_set get_flags(flag_set flags_arg) const { return m_flags & flags_arg; }
2636
2638 get_general_type_code() = 0; /* General rows op type, no version */
2639
2640#if defined(MYSQL_SERVER)
2641 int pack_info(Protocol *protocol) override;
2642#endif
2643
2644#ifndef MYSQL_SERVER
2645 void print_verbose(IO_CACHE *file, PRINT_EVENT_INFO *print_event_info);
2646 size_t print_verbose_one_row(IO_CACHE *file, table_def *td,
2647 PRINT_EVENT_INFO *print_event_info,
2648 MY_BITMAP *cols_bitmap, const uchar *ptr,
2649 const uchar *prefix,
2650 enum_row_image_type row_image_type);
2651#endif
2652
2653#ifdef MYSQL_SERVER
2654 int add_row_data(uchar *data, size_t length) {
2655 return do_add_row_data(data, length);
2656 }
2657#endif
2658
2659 /* Member functions to implement superclass interface */
2660 size_t get_data_size() override;
2662 MY_BITMAP const *get_cols() const { return &m_cols; }
2663 MY_BITMAP const *get_cols_ai() const { return &m_cols_ai; }
2664 size_t get_width() const { return m_width; }
2665 const Table_id &get_table_id() const { return m_table_id; }
2666
2667#if defined(MYSQL_SERVER)
2668 /**
2669 Compares the table's read/write_set with the columns included in
2670 this event's before-image and/or after-image. Each subclass
2671 (Write/Update/Delete) implements this function by comparing on the
2672 image(s) pertinent to the subclass.
2673
2674 @param[in] table The table to compare this events bitmaps
2675 against.
2676
2677 @retval true if sets match
2678 @retval false otherwise (following bitmap_cmp return logic).
2680 virtual bool read_write_bitmaps_cmp(const TABLE *table) const = 0;
2681#endif
2682
2683#ifdef MYSQL_SERVER
2684 bool write_data_header(Basic_ostream *ostream) override;
2685 bool write_data_body(Basic_ostream *ostream) override;
2686 const char *get_db() override { return m_table->s->db.str; }
2687#endif
2689 uint m_row_count; /* The number of rows added to the event */
2690
2691 protected:
2692 /*
2693 The constructors are protected since you're supposed to inherit
2694 this class, not create instances of this class.
2695 */
2696#ifdef MYSQL_SERVER
2697 Rows_log_event(THD *, TABLE *, const Table_id &table_id,
2698 MY_BITMAP const *cols, bool is_transactional,
2699 Log_event_type event_type,
2700 const unsigned char *extra_row_ndb_info);
2701#endif
2702 Rows_log_event(const char *row_data,
2703 const Format_description_event *description_event);
2704
2705#ifndef MYSQL_SERVER
2706 void print_helper(FILE *, PRINT_EVENT_INFO *) const;
2707#endif
2708
2709#ifdef MYSQL_SERVER
2710 virtual int do_add_row_data(uchar *data, size_t length);
2711#endif
2712
2713#ifdef MYSQL_SERVER
2714 TABLE *m_table; /* The table the rows belong to */
2715#endif
2716 MY_BITMAP m_cols; /* Bitmap denoting columns available */
2717 /**
2718 Bitmap denoting columns available in the image as they appear in the table
2719 setup. On some setups, the number and order of columns may differ from
2720 master to slave so, a bitmap for local available columns is computed using
2721 `ReplicatedColumnsView` utility class.
2724#ifdef MYSQL_SERVER
2725 /**
2726 Hash table that will hold the entries for while using HASH_SCAN
2727 algorithm to search and update/delete rows.
2730
2731 /**
2732 The algorithm to use while searching for rows using the before
2733 image.
2736#endif
2737 /**
2738 Bitmap for columns available in the after image, if present. These
2739 fields are only available for Update_rows events. Observe that the
2740 width of both the before image COLS vector and the after image
2741 COLS vector is the same: the number of columns of the table on the
2742 master.
2745 /**
2746 Bitmap denoting columns available in the after-image as they appear in the
2747 table setup. On some setups, the number and order of columns may differ from
2748 master to slave so, a bitmap for local available columns is computed using
2749 `ReplicatedColumnsView` utility class.
2752
2753 /* Bit buffers in the same memory as the class */
2754 uint32 m_bitbuf[128 / (sizeof(uint32) * 8)];
2755 uint32 m_bitbuf_ai[128 / (sizeof(uint32) * 8)];
2756
2757 /*
2758 is_valid depends on the value of m_rows_buf, so while changing the value
2759 of m_rows_buf check if is_valid also needs to be modified
2761 uchar *m_rows_buf; /* The rows in packed format */
2762 uchar *m_rows_cur; /* One-after the end of the data */
2763 uchar *m_rows_end; /* One-after the end of the allocated space */
2764
2765 /* helper functions */
2766
2767#if defined(MYSQL_SERVER)
2768 const uchar *m_curr_row; /* Start of the row being processed */
2769 const uchar *m_curr_row_end; /* One-after the end of the current row */
2770 uchar *m_key; /* Buffer to keep key value during searches */
2772 KEY *m_key_info; /* Points to description of index #m_key_index */
2773 class Key_compare {
2774 public:
2775 /**
2776 @param ki Where to find KEY description
2777 @note m_distinct_keys is instantiated when Rows_log_event is constructed;
2778 it stores a Key_compare object internally. However at that moment, the
2779 index (KEY*) to use for comparisons, is not yet known. So, at
2780 instantiation, we indicate the Key_compare the place where it can
2781 find the KEY* when needed (this place is Rows_log_event::m_key_info),
2782 Key_compare remembers the place in member m_key_info.
2783 Before we need to do comparisons - i.e. before we need to insert
2784 elements, we update Rows_log_event::m_key_info once for all.
2786 Key_compare(KEY **ki = nullptr) : m_key_info(ki) {}
2787 bool operator()(uchar *k1, uchar *k2) const {
2788 return key_cmp2((*m_key_info)->key_part, k1, (*m_key_info)->key_length,
2789 k2, (*m_key_info)->key_length) < 0;
2790 }
2791
2792 private:
2793 KEY **m_key_info;
2795 std::set<uchar *, Key_compare> m_distinct_keys;
2796 std::set<uchar *, Key_compare>::iterator m_itr;
2797 /**
2798 A spare buffer which will be used when saving the distinct keys
2799 for doing an index scan with HASH_SCAN search algorithm.
2802
2803 /**
2804 Unpack the current row image from the event into m_table->record[0].
2805
2806 @param rli The applier context.
2807
2808 @param cols The bitmap of columns included in the update.
2809
2810 @param is_after_image Should be true if this is an after-image,
2811 false if it is a before-image.
2812
2813 @param only_seek unpack_row()
2814
2815 @retval 0 Success
2816
2817 @retval ER_* On error, it is guaranteed that the error has been
2818 reported through my_error, and the corresponding ER_* code is
2819 returned. Currently the error codes are: EE_OUTOFMEMORY,
2820 ER_SLAVE_CORRUPT_EVENT, or various JSON errors when applying JSON
2821 diffs (ER_COULD_NOT_APPLY_JSON_DIFF, ER_INVALID_JSON_BINARY_DATA,
2822 and maybe others).
2823 */
2824 int unpack_current_row(const Relay_log_info *const rli, MY_BITMAP const *cols,
2825 bool is_after_image, bool only_seek = false);
2826 /**
2827 Updates the generated columns of the `TABLE` object referenced by
2828 `m_table`, that have an active bit in the parameter bitset
2829 `fields_to_update`.
2830
2831 @param fields_to_update A bitset where the bit at the index of
2832 generated columns to update must be set to `1`
2833
2834 @return 0 if the operation terminated successfully, 1 otherwise.
2835 */
2836 int update_generated_columns(MY_BITMAP const &fields_to_update);
2837 /*
2838 This member function is called when deciding the algorithm to be used to
2839 find the rows to be updated on the slave during row based replication.
2840 This this functions sets the m_rows_lookup_algorithm and also the
2841 m_key_index with the key index to be used if the algorithm is dependent on
2842 an index.
2843 TODO(Bug#31173056): Remove SUPPRESS_UBSAN_CLANG10
2844 */
2846
2847 /*
2848 Encapsulates the operations to be done before applying
2849 row event for update and delete.
2850 */
2852
2853 /*
2854 Encapsulates the operations to be done after applying
2855 row event for update and delete.
2856 */
2858
2859 /**
2860 Helper function to check whether there is an auto increment
2861 column on the table where the event is to be applied.
2862 GIPKs when not present in the source table are also considered a
2863 auto inc column in a extra column.
2864
2865 @param rli the relay log object associated to the replicated table
2866
2867 @return true if there is an autoincrement field on the extra
2868 columns, false otherwise.
2869 */
2870 bool is_auto_inc_in_extra_columns(const Relay_log_info *const rli);
2871
2872 /**
2873 Helper function to check whether the storage engine error
2874 allows for the transaction to be retried or not.
2875
2876 @param error Storage engine error
2877 @retval true if the error is retryable.
2878 @retval false if the error is non-retryable.
2879 */
2881#endif
2883 bool is_rbr_logging_format() const override { return true; }
2884
2885 private:
2886#if defined(MYSQL_SERVER)
2887
2888 /**
2889 Wrapper around `TABLE *m_table` that abstracts the table field set iteration
2890 logic, since it is not mandatory that all table fields are to be
2891 replicated. For details, @see ReplicatedColumnsView class documentation.
2892
2893 A smart pointer is used here as the developer might want to instantiate the
2894 view using different classes in runtime depending on the given context.
2897
2898 int do_apply_event(Relay_log_info const *rli) override;
2899 int do_update_pos(Relay_log_info *rli) override;
2901
2902 /*
2903 Primitive to prepare for a sequence of row executions.
2904
2905 DESCRIPTION
2906
2907 Before doing a sequence of do_prepare_row() and do_exec_row()
2908 calls, this member function should be called to prepare for the
2909 entire sequence. Typically, this member function will allocate
2910 space for any buffers that are needed for the two member
2911 functions mentioned above.
2912
2913 RETURN VALUE
2914
2915 The member function will return 0 if all went OK, or a non-zero
2916 error code otherwise.
2918 virtual int do_before_row_operations(const Relay_log_info *const log) = 0;
2919
2920 /*
2921 Primitive to clean up after a sequence of row executions.
2922
2923 DESCRIPTION
2924
2925 After doing a sequence of do_prepare_row() and do_exec_row(),
2926 this member function should be called to clean up and release
2927 any allocated buffers.
2928
2929 The error argument, if non-zero, indicates an error which happened during
2930 row processing before this function was called. In this case, even if
2931 function is successful, it should return the error code given in the
2932 argument.
2934 virtual int do_after_row_operations(const Relay_log_info *const log,
2935 int error) = 0;
2936
2937 /*
2938 Primitive to do the actual execution necessary for a row.
2939
2940 DESCRIPTION
2941 The member function will do the actual execution needed to handle a row.
2942 The row is located at m_curr_row. When the function returns,
2943 m_curr_row_end should point at the next row (one byte after the end
2944 of the current row).
2945
2946 RETURN VALUE
2947 0 if execution succeeded, 1 if execution failed.
2948
2950 virtual int do_exec_row(const Relay_log_info *const rli) = 0;
2951
2952 /**
2953 Private member function called while handling idempotent errors.
2954
2955 @param rli Pointer to relay log info structure.
2956 @param [in,out] err the error to handle. If it is listed as
2957 idempotent/ignored related error, then it is cleared.
2958 @returns true if the slave should stop executing rows.
2959 */
2961
2962 /**
2963 Private member function called after updating/deleting a row. It
2964 performs some assertions and more importantly, it updates
2965 m_curr_row so that the next row is processed during the row
2966 execution main loop (@c Rows_log_event::do_apply_event()).
2967
2968 @param rli Pointer to relay log info structure.
2969 @param err the current error code.
2970 */
2971 void do_post_row_operations(Relay_log_info const *rli, int err);
2972
2973 /**
2974 Commodity wrapper around do_exec_row(), that deals with resetting
2975 the thd reference in the table.
2976 */
2977 int do_apply_row(Relay_log_info const *rli);
2978
2979 /**
2980 Implementation of the index scan and update algorithm. It uses
2981 PK, UK or regular Key to search for the record to update. When
2982 found it updates it.
2983 */
2985
2986 /**
2987 Implementation of the hash_scan and update algorithm. It collects
2988 rows positions in a hashtable until the last row is
2989 unpacked. Then it scans the table to update and when a record in
2990 the table matches the one in the hashtable, the update/delete is
2991 performed.
2992 */
2994
2995 /**
2996 Implementation of the legacy table_scan and update algorithm. For
2997 each unpacked row it scans the storage engine table for a
2998 match. When a match is found, the update/delete operations are
2999 performed.
3000 */
3002
3003 /**
3004 Seek past the after-image of an update event, in case a row was processed
3005 without reading the after-image.
3006
3007 An update event may process a row without reading the after-image,
3008 e.g. in case of ignored or idempotent errors. To ensure that the
3009 read position for the next row is correct, we need to seek past
3010 the after-image.
3011
3012 @param rli The applier context
3013
3014 @param curr_bi_start The read position of the beginning of the
3015 before-image. (The function compares this with m_curr_row to know
3016 if the after-image has been read or not.)
3017
3018 @retval 0 Success
3019 @retval ER_* Error code returned by unpack_current_row
3022 [[maybe_unused]],
3023 const uchar *curr_bi_start
3024 [[maybe_unused]]) {
3025 return 0;
3026 }
3027
3028 /**
3029 Initializes scanning of rows. Opens an index and initializes an iterator
3030 over a list of distinct keys (m_distinct_keys) if it is a HASH_SCAN
3031 over an index or the table if its a HASH_SCAN over the table.
3032 */
3033 int open_record_scan();
3034
3035 /**
3036 Does the cleanup
3037 - closes the index if opened by open_record_scan
3038 - closes the table if opened for scanning.
3039 */
3040 int close_record_scan();
3041
3042 /**
3043 Fetches next row. If it is a HASH_SCAN over an index, it populates
3044 table->record[0] with the next row corresponding to the index. If
3045 the indexes are in non-contigous ranges it fetches record corresponding
3046 to the key value in the next range.
3047
3048 @param first_read signifying if this is the first time we are reading a row
3049 over an index.
3050 @return error code when there are no more records to be fetched or some
3051 other error occurred,
3052 - 0 otherwise.
3053 */
3054 int next_record_scan(bool first_read);
3055
3056 /**
3057 Populates the m_distinct_keys with unique keys to be modified
3058 during HASH_SCAN over keys.
3059 @returns 0 success, or the error code.
3060 */
3062
3063 /**
3064 Populates the m_hash when using HASH_SCAN. Thence, it:
3065 - unpacks the before image (BI)
3066 - saves the positions
3067 - saves the positions into the hash map, using the
3068 BI checksum as key
3069 - unpacks the after image (AI) if needed, so that
3070 m_curr_row_end gets updated correctly.
3071
3072 @param rli The reference to the relay log info object.
3073 @returns 0 on success. Otherwise, the error code.
3074 */
3075 int do_hash_row(Relay_log_info const *rli);
3076
3077 /**
3078 This member function scans the table and applies the changes
3079 that had been previously hashed. As such, m_hash MUST be filled
3080 by do_hash_row before calling this member function.
3081
3082 @param rli The reference to the relay log info object.
3083 @returns 0 on success. Otherwise, the error code.
3084 */
3085 int do_scan_and_update(Relay_log_info const *rli);
3086#endif /* defined(MYSQL_SERVER) */
3088 friend class Old_rows_log_event;
3089
3090 /**
3091 This bitmap is used as a backup for the write set while we calculate
3092 the values for any hidden generated columns (functional indexes). In order
3093 to calculate the values, the columns must be marked in the write set. After
3094 the values are calculated, we set the write set back to its original value.
3097};
3098
3099/**
3100 @class Write_rows_log_event
3101
3102 Log row insertions and updates. The event contain several
3103 insert/update rows for a table. Note that each event contains only
3104 rows for one table.
3105
3106 @internal
3107 The inheritance structure is as follows
3108
3109 Binary_log_event
3110 ^
3111 |
3112 |
3113 |
3114 Log_event B_l:Rows_event
3115 ^ /\
3116 | / \
3117 | <<vir>>/ \ <<vir>>
3118 | / \
3119 | / \
3120 | / \
3121 Rows_log_event B_l:W_R_E
3122 \ /
3123 \ /
3124 \ /
3125 \ /
3126 \ /
3127 \/
3128 Write_rows_log_event
3129
3130 B_l: Namespace Binary_log
3131 W_R_E: class Write_rows_event
3132 @endinternal
3133
3137 public:
3138 enum {
3139 /* Support interface to THD::binlog_prepare_pending_rows_event */
3141 };
3142
3143#if defined(MYSQL_SERVER)
3144 Write_rows_log_event(THD *, TABLE *, const Table_id &table_id,
3145 bool is_transactional,
3146 const unsigned char *extra_row_ndb_info);
3147#endif
3148 Write_rows_log_event(const char *buf,
3149 const Format_description_event *description_event);
3150#if defined(MYSQL_SERVER)
3151 static bool binlog_row_logging_function(THD *thd, TABLE *table,
3152 bool is_transactional,
3153 const uchar *before_record
3154 [[maybe_unused]],
3155 const uchar *after_record);
3156 bool read_write_bitmaps_cmp(const TABLE *table) const override {
3157 return bitmap_cmp(get_cols(), table->write_set);
3158 }
3159#endif
3160
3161 protected:
3162 int write_row(const Relay_log_info *const, const bool);
3163
3164 private:
3166 return (Log_event_type)TYPE_CODE;
3167 }
3168
3169#ifndef MYSQL_SERVER
3170 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
3171#endif
3172
3173#if defined(MYSQL_SERVER)
3174 int do_before_row_operations(const Relay_log_info *const) override;
3175 int do_after_row_operations(const Relay_log_info *const, int) override;
3176 int do_exec_row(const Relay_log_info *const) override;
3177#endif
3178};
3179
3180/**
3181 @class Update_rows_log_event
3182
3183 Log row updates with a before image. The event contain several
3184 update rows for a table. Note that each event contains only rows for
3185 one table.
3186
3187 Also note that the row data consists of pairs of row data: one row
3188 for the old data and one row for the new data.
3189
3190 @internal
3191 The inheritance structure is as follows
3192
3193 Binary_log_event
3194 ^
3195 |
3196 |
3197 |
3198 Log_event B_l:Rows_event
3199 ^ /\
3200 | / \
3201 | <<vir>>/ \ <<vir>>
3202 | / \
3203 | / \
3204 | / \
3205 Rows_log_event B_l:U_R_E
3206 \ /
3207 \ /
3208 \ /
3209 \ /
3210 \ /
3211 \/
3212 Update_rows_log_event
3213
3214
3215 B_l: Namespace Binary_log
3216 U_R_E: class Update_rows_event
3217 @eninternal
3218
3222 public:
3223 enum {
3224 /* Support interface to THD::binlog_prepare_pending_rows_event */
3226 };
3227
3228#ifdef MYSQL_SERVER
3229 Update_rows_log_event(THD *, TABLE *, const Table_id &table_id,
3230 MY_BITMAP const *cols_bi, MY_BITMAP const *cols_ai,
3231 bool is_transactional,
3232 const unsigned char *extra_row_ndb_info);
3233
3234 Update_rows_log_event(THD *, TABLE *, const Table_id &table_id,
3235 bool is_transactional,
3236 const unsigned char *extra_row_ndb_info);
3237
3238 void init(MY_BITMAP const *cols);
3239#endif
3240
3241 ~Update_rows_log_event() override;
3242
3243 Update_rows_log_event(const char *buf,
3244 const Format_description_event *description_event);
3245
3246#ifdef MYSQL_SERVER
3247 static bool binlog_row_logging_function(THD *thd, TABLE *table,
3248 bool is_transactional,
3249 const uchar *before_record,
3250 const uchar *after_record);
3251 bool read_write_bitmaps_cmp(const TABLE *table) const override {
3252 return (bitmap_cmp(get_cols(), table->read_set) &&
3253 bitmap_cmp(get_cols_ai(), table->write_set));
3254 }
3255#endif
3256
3257 protected:
3259 return (Log_event_type)TYPE_CODE;
3260 }
3261
3262#ifndef MYSQL_SERVER
3263 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
3264#endif
3265
3266#if defined(MYSQL_SERVER)
3267 int do_before_row_operations(const Relay_log_info *const) override;
3268 int do_after_row_operations(const Relay_log_info *const, int) override;
3269 int do_exec_row(const Relay_log_info *const) override;
3270
3272 const uchar *curr_bi_start) override;
3273
3274 private:
3275 /**
3276 Auxiliary function used in the (THD*, ...) constructor to
3277 determine the type code based on configuration options.
3278
3279 @param thd_arg The THD object for the session.
3280
3281 @return One of UPDATE_ROWS_EVENT_V1, PARTIAL_UPDATE_ROWS_EVENT, or
3282 UPDATE_ROWS_EVENT.
3283 */
3285 const THD *thd_arg);
3286#endif /* defined(MYSQL_SERVER) */
3287};
3288
3289/**
3290 @class Delete_rows_log_event
3291
3292 Log row deletions. The event contain several delete rows for a
3293 table. Note that each event contains only rows for one table.
3294
3295 RESPONSIBILITIES
3296
3297 - Act as a container for rows that has been deleted on the master
3298 and should be deleted on the slave.
3299
3300 COLLABORATION
3301
3302 Row_writer
3303 Create the event and add rows to the event.
3304 Row_reader
3305 Extract the rows from the event.
3306
3307 @internal
3308 The inheritance structure is as follows
3309
3310 Binary_log_event
3311 ^
3312 |
3313 |
3314 |
3315 Log_event B_l:Rows_event
3316 ^ /\
3317 | / \
3318 | <<vir>>/ \ <<vir>>
3319 | / \
3320 | / \
3321 | / \
3322 Rows_log_event B_l:D_R_E
3323 \ /
3324 \ /
3325 \ /
3326 \ /
3327 \ /
3328 \/
3329 Delete_rows_log_event
3330
3331 B_l: Namespace Binary_log
3332 D_R_E: class Delete_rows_event
3333 @endinternal
3334
3338 public:
3339 enum {
3340 /* Support interface to THD::binlog_prepare_pending_rows_event */
3342 };
3343
3344#ifdef MYSQL_SERVER
3345 Delete_rows_log_event(THD *, TABLE *, const Table_id &, bool is_transactional,
3346 const unsigned char *extra_row_ndb_info);
3347#endif
3348 Delete_rows_log_event(const char *buf,
3349 const Format_description_event *description_event);
3350#ifdef MYSQL_SERVER
3351 static bool binlog_row_logging_function(THD *thd, TABLE *table,
3352 bool is_transactional,
3353 const uchar *before_record,
3354 const uchar *after_record
3355 [[maybe_unused]]);
3356 bool read_write_bitmaps_cmp(const TABLE *table) const override {
3357 return bitmap_cmp(get_cols(), table->read_set);
3358 }
3359#endif
3360
3361 protected:
3363 return (Log_event_type)TYPE_CODE;
3364 }
3365
3366#ifndef MYSQL_SERVER
3367 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
3368#endif
3369
3370#if defined(MYSQL_SERVER)
3371 int do_before_row_operations(const Relay_log_info *const) override;
3372 int do_after_row_operations(const Relay_log_info *const, int) override;
3373 int do_exec_row(const Relay_log_info *const) override;
3374#endif
3375};
3376
3377/**
3378 @class Incident_log_event
3379
3380 Class representing an incident, an occurrence out of the ordinary,
3381 that happened on the master.
3382
3383 The event is used to inform the slave that something out of the
3384 ordinary happened on the master that might cause the database to be
3385 in an inconsistent state.
3386
3387 It's the derived class of Incident_event
3388
3389 @internal
3390 The inheritance structure is as follows
3391
3392 Binary_log_event
3393 ^
3394 |
3395 |
3396 B_l:Incident_event Log_event
3397 \ /
3398 \ /
3399 \ /
3400 \ /
3401 Incident_log_event
3402
3403 B_l: Namespace Binary_log
3404 @endinternal
3405
3408 public:
3409#ifdef MYSQL_SERVER
3410 Incident_log_event(THD *thd_arg, enum_incident incident_arg)
3411 : binary_log::Incident_event(incident_arg),
3414 DBUG_TRACE;
3415 DBUG_PRINT("enter", ("incident: %d", incident_arg));
3416 common_header->set_is_valid(incident_arg > INCIDENT_NONE &&
3417 incident_arg < INCIDENT_COUNT);
3418 assert(message == nullptr && message_length == 0);
3419 return;
3420 }
3422 Incident_log_event(THD *thd_arg, enum_incident incident_arg,
3423 LEX_CSTRING const msg)
3424 : binary_log::Incident_event(incident_arg),
3427 DBUG_TRACE;
3428 DBUG_PRINT("enter", ("incident: %d", incident_arg));
3429 common_header->set_is_valid(incident_arg > INCIDENT_NONE &&
3430 incident_arg < INCIDENT_COUNT);
3431 assert(message == nullptr && message_length == 0);
3433 msg.length + 1, MYF(MY_WME)))) {
3434 // The allocation failed. Mark this binlog event as invalid.
3436 return;
3437 }
3438 strmake(message, msg.str, msg.length);
3439 message_length = msg.length;
3440 return;
3441 }
3442#endif
3443
3444#ifdef MYSQL_SERVER
3445 int pack_info(Protocol *) override;
3446#endif
3447
3448 Incident_log_event(const char *buf,
3449 const Format_description_event *description_event);
3450
3451 ~Incident_log_event() override;
3452
3453#ifndef MYSQL_SERVER
3454 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
3455#endif
3456
3457#if defined(MYSQL_SERVER)
3458 int do_apply_event(Relay_log_info const *rli) override;
3459 bool write_data_header(Basic_ostream *ostream) override;
3460 bool write_data_body(Basic_ostream *ostream) override;
3461#endif
3463 size_t get_data_size() override {
3464 return Binary_log_event::INCIDENT_HEADER_LEN + 1 + message_length;
3465 }
3467 bool ends_group() const override { return true; }
3468
3469 private:
3470 const char *description() const;
3471};
3472
3473/**
3474 @class Ignorable_log_event
3475
3476 Base class for ignorable log events is Ignorable_event.
3477 Events deriving from this class can be safely ignored
3478 by slaves that cannot recognize them.
3479
3480 Its the derived class of Ignorable_event
3481
3482 @internal
3483 The inheritance structure is as follows
3484
3485 Binary_log_event
3486 ^
3487 |
3488 |
3489 B_l:Ignorable_event Log_event
3490 \ /
3491 <<virtual>>\ /
3492 \ /
3493 Ignorable_log_event
3494
3495 B_l: Namespace Binary_log
3496 @endinternal
3499 public Log_event {
3500 public:
3501#ifdef MYSQL_SERVER
3502 Ignorable_log_event(THD *thd_arg)
3505 DBUG_TRACE;
3507 return;
3508 }
3509#endif
3510
3511 Ignorable_log_event(const char *buf,
3512 const Format_description_event *descr_event);
3513 ~Ignorable_log_event() override;
3514
3515#ifdef MYSQL_SERVER
3516 int pack_info(Protocol *) override;
3517#endif
3518
3519#ifndef MYSQL_SERVER
3520 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
3521#endif
3523 size_t get_data_size() override {
3524 return Binary_log_event::IGNORABLE_HEADER_LEN;
3525 }
3526};
3527
3528/**
3529 @class Rows_query_log_event
3530 It is used to record the original query for the rows
3531 events in RBR.
3532 It is the subclass of Ignorable_log_event and Rows_query_event
3533
3534 @internal
3535 The inheritance structure in the current design for the classes is
3536 as follows:
3537 Binary_log_event
3538 ^
3539 |
3540 |
3541 |
3542 Log_event B_l:Ignorable_event
3543 ^ /\
3544 | / \
3545 | <<vir>>/ \ <<vir>>
3546 | / \
3547 | / \
3548 | / \
3549 Ignorable_log_event B_l:Rows_query_event
3550 \ /
3551 \ /
3552 \ /
3553 \ /
3554 \ /
3555 \/
3556 Rows_query_log_event
3557
3558 B_l : namespace binary_log
3559 @endinternal
3563 public:
3564#ifdef MYSQL_SERVER
3565 Rows_query_log_event(THD *thd_arg, const char *query, size_t query_len)
3566 : Ignorable_log_event(thd_arg) {
3567 DBUG_TRACE;
3569 if (!(m_rows_query =
3571 query_len + 1, MYF(MY_WME))))
3572 return;
3573 snprintf(m_rows_query, query_len + 1, "%s", query);
3574 DBUG_PRINT("enter", ("%s", m_rows_query));
3575 return;
3576 }
3577#endif
3578
3579#ifdef MYSQL_SERVER
3580 int pack_info(Protocol *) override;
3581 int do_apply_event(Relay_log_info const *rli) override;
3582 bool write_data_body(Basic_ostream *ostream) override;
3583#endif
3584
3585 Rows_query_log_event(const char *buf,
3586 const Format_description_event *descr_event);
3588 ~Rows_query_log_event() override {
3590 m_rows_query = nullptr;
3591 }
3592#ifndef MYSQL_SERVER
3593 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
3594#endif
3595 size_t get_data_size() override {
3596 return Binary_log_event::IGNORABLE_HEADER_LEN + 1 + strlen(m_rows_query);
3597 }
3598};
3600static inline bool copy_event_cache_to_file_and_reinit(IO_CACHE *cache,
3601 FILE *file,
3602 bool flush_stream) {
3603 return my_b_copy_to_file(cache, file) ||
3604 (flush_stream ? (fflush(file) || ferror(file)) : 0) ||
3605 reinit_io_cache(cache, WRITE_CACHE, 0, false, true);
3606}
3607
3608#ifdef MYSQL_SERVER
3609/*****************************************************************************
3610
3611 Heartbeat Log Event class
3612
3613 The class is not logged to a binary log, and is not applied on to the slave.
3614 The decoding of the event on the slave side is done by its superclass,
3615 binary_log::Heartbeat_event.
3616
3617 ****************************************************************************/
3619 public Log_event {
3620 public:
3621 Heartbeat_log_event(const char *buf,
3622 const Format_description_event *description_event);
3623};
3626 public Log_event {
3627 public:
3628 Heartbeat_log_event_v2(const char *buf,
3629 const Format_description_event *description_event);
3630};
3631/**
3632 The function is called by slave applier in case there are
3633 active table filtering rules to force gathering events associated
3634 with Query-log-event into an array to execute
3635 them once the fate of the Query is determined for execution.
3636*/
3638#endif
3639
3640int append_query_string(const THD *thd, const CHARSET_INFO *csinfo,
3641 String const *from, String *to);
3646 public Log_event {
3647 public:
3648#ifdef MYSQL_SERVER
3650 class Applier_context {
3651 private:
3652 // context for the applier (to remove if we remove the DATABASE scheduler)
3654
3655 public:
3656 Applier_context() = default;
3657 virtual ~Applier_context() { reset(); }
3660 };
3662 Transaction_payload_log_event(THD *thd_arg, const char *payload,
3663 uint64_t payload_size,
3664 uint16_t compression_type,
3665 uint64_t uncompressed_size)
3666 : Transaction_payload_event(payload, payload_size, compression_type,
3667 uncompressed_size),
3668 Log_event(thd_arg, 0 /* flags */, Log_event::EVENT_TRANSACTIONAL_CACHE,
3671 Transaction_payload_log_event(THD *thd_arg, const char *payload,
3672 uint64_t payload_size)
3674 thd_arg, payload, payload_size,
3675 binary_log::transaction::compression::type::NONE, payload_size) {}
3678 : Transaction_payload_log_event(thd_arg, nullptr, (uint64_t)0) {}
3679#endif
3682 const Format_description_event *fde)
3685 ~Transaction_payload_log_event() override = default;
3686
3687#ifndef MYSQL_SERVER
3688 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
3689#endif
3691 size_t get_event_length() { return LOG_EVENT_HEADER_LEN + get_data_size(); }
3692 size_t get_data_size() override;
3693
3694#if defined(MYSQL_SERVER)
3695 private:
3697
3698 public:
3699 int do_apply_event(Relay_log_info const *rli) override;
3700 bool apply_payload_event(Relay_log_info const *rli, const uchar *event_buf);
3702 int pack_info(Protocol *protocol) override;
3703 bool ends_group() const override;
3704 bool write(Basic_ostream *ostream) override;
3706 void set_mts_dbs(Mts_db_names &arg);
3707 uint8 mts_number_dbs() override;
3708#endif
3709};
3710
3711/**
3712 @class Gtid_log_event
3713
3714 This is a subclass if Gtid_event and Log_event. It contains
3715 per-transaction fields, including the GTID and logical timestamps
3716 used by MTS.
3717
3718 @internal
3719 The inheritance structure is as follows
3720
3721 Binary_log_event
3722 ^
3723 |
3724 |
3725 B_l:Gtid_event Log_event
3726 \ /
3727 \ /
3728 \ /
3729 \ /
3730 Gtid_log_event
3731
3732 B_l: Namespace Binary_log
3733 @endinternal
3735class Gtid_log_event : public binary_log::Gtid_event, public Log_event {
3736 public:
3737#ifdef MYSQL_SERVER
3738 /**
3739 Create a new event using the GTID owned by the given thread.
3740 */
3741 Gtid_log_event(THD *thd_arg, bool using_trans, int64 last_committed_arg,
3742 int64 sequence_number_arg, bool may_have_sbr_stmts_arg,
3743 ulonglong original_commit_timestamp_arg,
3744 ulonglong immediate_commit_timestamp_arg,
3745 uint32_t original_server_version_arg,
3746 uint32_t immediate_server_version_arg);
3747
3748 /**
3749 Create a new event using the GTID from the given Gtid_specification
3750 without a THD object.
3751 */
3752 Gtid_log_event(uint32 server_id_arg, bool using_trans,
3753 int64 last_committed_arg, int64 sequence_number_arg,
3754 bool may_have_sbr_stmts_arg,
3755 ulonglong original_commit_timestamp_arg,
3756 ulonglong immediate_commit_timestamp_arg,
3757 const Gtid_specification spec_arg,
3758 uint32_t original_server_version_arg,
3759 uint32_t immediate_server_version_arg);
3760#endif
3761
3762#ifdef MYSQL_SERVER
3763 int pack_info(Protocol *) override;
3764#endif
3765 Gtid_log_event(const char *buffer,
3766 const Format_description_event *description_event);
3768 ~Gtid_log_event() override = default;
3770 size_t get_data_size() override {
3771 DBUG_EXECUTE_IF("do_not_write_rpl_timestamps", return POST_HEADER_LENGTH;);
3775 }
3777 size_t get_event_length() { return LOG_EVENT_HEADER_LEN + get_data_size(); }
3778
3779 private:
3780 /// Used internally by both print() and pack_info().
3781 size_t to_string(char *buf) const;
3782
3783#ifdef MYSQL_SERVER
3784 /**
3785 Writes the post-header to the given output stream.
3786
3787 This is an auxiliary function typically used by the write() member
3788 function.
3789
3790 @param ostream The output stream to write to.
3791
3792 @retval true Error.
3793 @retval false Success.
3794 */
3795 bool write_data_header(Basic_ostream *ostream) override;
3796 bool write_data_body(Basic_ostream *ostream) override;
3797 /**
3798 Writes the post-header to the given memory buffer.
3799
3800 This is an auxiliary function used by write_to_memory.
3801
3802 @param[in,out] buffer Buffer to which the post-header will be written.
3803
3804 @return The number of bytes written, i.e., always
3805 Gtid_log_event::POST_HEADER_LENGTH.
3806 */
3808
3809 /**
3810 Writes the body to the given memory buffer.
3811
3812 This is an auxiliary function used by write_to_memory.
3813
3814 @param [in,out] buff Buffer to which the data will be written.
3815
3816 @return The number of bytes written, i.e.,
3817 If the transaction did not originated on this server
3818 Gtid_event::IMMEDIATE_COMMIT_TIMESTAMP_LENGTH.
3819 else
3820 FULL_COMMIT_TIMESTAMP_LENGTH.
3821 */
3823#endif
3824
3825 public:
3826#ifndef MYSQL_SERVER
3827 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
3828#endif
3829
3830#if defined(MYSQL_SERVER)
3831 int do_apply_event(Relay_log_info const *rli) override;
3832 int do_update_pos(Relay_log_info *rli) override;
3834#endif
3835
3836 /**
3837 Return the gtid type for this Gtid_log_event: this can be
3838 either ANONYMOUS_GTID, AUTOMATIC_GTID, or ASSIGNED_GTID.
3840 enum_gtid_type get_type() const { return spec.type; }
3841
3842 /**
3843 Return the SID for this GTID. The SID is shared with the
3844 Log_event so it should not be modified.
3846 const rpl_sid *get_sid() const { return &sid; }
3847 /**
3848 Return the SIDNO relative to the global sid_map for this GTID.
3849
3850 This requires a lookup and possibly even update of global_sid_map,
3851 hence global_sid_lock must be held. If global_sid_lock is not
3852 held, the caller must pass need_lock=true. If there is an error
3853 (e.g. out of memory) while updating global_sid_map, this function
3854 returns a negative number.
3855
3856 @param need_lock If true, the read lock on global_sid_lock is
3857 acquired and released inside this function; if false, the read
3858 lock or write lock must be held prior to calling this function.
3859 @retval SIDNO if successful
3860 @retval negative if adding SID to global_sid_map causes an error.
3861 */
3862 rpl_sidno get_sidno(bool need_lock);
3863
3864 /**
3865 Return the SIDNO relative to the given Sid_map for this GTID.
3866
3867 This assumes that the Sid_map is local to the thread, and thus
3868 does not use locks.
3869
3870 @param sid_map The sid_map to use.
3871 @retval SIDNO if successful.
3872 @retval negative if adding SID to sid_map causes an error.
3874 rpl_sidno get_sidno(Sid_map *sid_map) { return sid_map->add_sid(sid); }
3875 /// Return the GNO for this GTID.
3876 rpl_gno get_gno() const { return spec.gtid.gno; }
3877
3878 /// string holding the text "SET @@GLOBAL.GTID_NEXT = '"
3879 static const char *SET_STRING_PREFIX;
3880
3881 private:
3882 /// Length of SET_STRING_PREFIX
3883 static const size_t SET_STRING_PREFIX_LENGTH = 26;
3884 /// The maximal length of the entire "SET ..." query.
3885 static const size_t MAX_SET_STRING_LENGTH = SET_STRING_PREFIX_LENGTH +
3887 1 + MAX_GNO_TEXT_LENGTH + 1;
3888
3889 private:
3890 /**
3891 Internal representation of the GTID. The SIDNO will be
3892 uninitialized (value -1) until the first call to get_sidno(bool).
3895 /// SID for this GTID.
3896 rpl_sid sid;
3897
3898 public:
3899 /**
3900 Set the transaction length information based on binlog cache size.
3901
3902 Note that is_checksum_enabled and event_counter are optional parameters.
3903 When not specified, the function will assume that no checksum will be used
3904 and the informed cache_size is the final transaction size without
3905 considering the GTID event size.
3906
3907 The high level formula that will be used by the function is:
3908
3909 trx_length = cache_size +
3910 cache_checksum_active * cache_events * CRC32_payload +
3911 gtid_length +
3912 cache_checksum_active * CRC32_payload; // For the GTID.
3913
3914 @param cache_size The size of the binlog cache in bytes.
3915 @param is_checksum_enabled If checksum will be added to events on flush.
3916 @param event_counter The amount of events in the cache.
3917 */
3919 bool is_checksum_enabled = false,
3920 int event_counter = 0);
3921};
3922
3923/**
3924 @class Previous_gtids_log_event
3925
3926 This is the subclass of Previous_gtids_event and Log_event
3927 It is used to record the gtid_executed in the last binary log file,
3928 for ex after flush logs, or at the starting of the binary log file
3929
3930 @internal
3931 The inheritance structure is as follows
3932
3933 Binary_log_event
3934 ^
3935 |
3936 |
3937B_l:Previous_gtids_event Log_event
3938 \ /
3939 \ /
3940 \ /
3941 \ /
3942 Previous_gtids_log_event
3943
3944 B_l: Namespace Binary_log
3945 @endinternal
3948 public Log_event {
3949 public:
3950#ifdef MYSQL_SERVER
3952#endif
3953
3954#ifdef MYSQL_SERVER
3955 int pack_info(Protocol *) override;
3956#endif
3957
3958 Previous_gtids_log_event(const char *buf,
3959 const Format_description_event *description_event);
3960 ~Previous_gtids_log_event() override = default;
3962 size_t get_data_size() override { return buf_size; }
3963
3964#ifndef MYSQL_SERVER
3965 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
3966#endif
3967#ifdef MYSQL_SERVER
3968 bool write(Basic_ostream *ostream) override {
3969#ifndef NDEBUG
3970 if (DBUG_EVALUATE_IF("skip_writing_previous_gtids_log_event", 1, 0) &&
3971 /*
3972 The skip_writing_previous_gtids_log_event debug point was designed
3973 for skipping the writing of the previous_gtids_log_event on binlog
3974 files only.
3975 */
3976 !is_relay_log_event()) {
3977 DBUG_PRINT("info",
3978 ("skip writing Previous_gtids_log_event because of"
3979 "debug option 'skip_writing_previous_gtids_log_event'"));
3980 return false;
3981 }
3982
3983 if (DBUG_EVALUATE_IF("write_partial_previous_gtids_log_event", 1, 0) &&
3984 /*
3985 The write_partial_previous_gtids_log_event debug point was designed
3986 for writing a partial previous_gtids_log_event on binlog files only.
3987 */
3988 !is_relay_log_event()) {
3989 DBUG_PRINT("info",
3990 ("writing partial Previous_gtids_log_event because of"
3991 "debug option 'write_partial_previous_gtids_log_event'"));
3992 return (Log_event::write_header(ostream, get_data_size()) ||
3994 }
3995#endif
3996
3997 return (Log_event::write_header(ostream, get_data_size()) ||
3998 Log_event::write_data_header(ostream) || write_data_body(ostream) ||
3999 Log_event::write_footer(ostream));
4000 }
4001 bool write_data_body(Basic_ostream *ostream) override;
4002#endif
4003
4004 /// Return the encoded buffer, or NULL on error.
4005 const uchar *get_buf() { return buf; }
4006 /**
4007 Return the formatted string, or NULL on error.
4008 The string is allocated using my_malloc and it is the
4009 responsibility of the caller to free it.
4010 */
4011 char *get_str(size_t *length,
4013 /// Add all GTIDs from this event to the given Gtid_set.
4014 int add_to_set(Gtid_set *gtid_set) const;
4015 /*
4016 Previous Gtid Log events should always be skipped
4017 there is nothing to apply there, whether it is
4018 relay log's (generated on Slave) or it is binary log's
4019 (generated on Master, copied to slave as relay log).
4020 Also, we should not increment slave_skip_counter
4021 for this event, hence return EVENT_SKIP_IGNORE.
4022 */
4023#if defined(MYSQL_SERVER)
4025 {
4026 return EVENT_SKIP_IGNORE;
4027 }
4029 int do_apply_event(Relay_log_info const *) override { return 0; }
4030 int do_update_pos(Relay_log_info *rli) override;
4031#endif
4032};
4033
4034/**
4035 @class Transaction_context_log_event
4036
4037 This is the subclass of Transaction_context_event and Log_event
4038 This class encodes the transaction_context_log_event.
4039
4040 @internal
4041 The inheritance structure is as follows
4042
4043 Binary_log_event
4044 ^
4045 |
4046 |
4047B_l:Transaction_context_event Log_event
4048 \ /
4049 \ /
4050 \ /
4051 \ /
4052 Transaction_context_log_event
4053
4054 B_l: Namespace Binary_log
4055 @endinternal
4059 public Log_event {
4060 private:
4061 /// The Sid_map to use for creating the Gtid_set.
4063 /// A gtid_set which is used to store the transaction set used for
4064 /// conflict detection.
4066
4067#ifdef MYSQL_SERVER
4068 bool write_data_header(Basic_ostream *ostream) override;
4069
4070 bool write_data_body(Basic_ostream *ostream) override;
4071
4073
4074 bool write_data_set(Basic_ostream *ostream, std::list<const char *> *set);
4075#endif
4076
4078
4079 static int get_data_set_size(std::list<const char *> *set);
4080
4081 size_t to_string(char *buf, ulong len) const;
4082
4083 public:
4084#ifdef MYSQL_SERVER
4085 Transaction_context_log_event(const char *server_uuid_arg, bool using_trans,
4086 my_thread_id thread_id_arg,
4087 bool is_gtid_specified_arg);
4088#endif
4089
4091 const Format_description_event *descr_event);
4092
4094
4095 size_t get_data_size() override;
4096
4097 size_t get_event_length();
4098
4099#ifdef MYSQL_SERVER
4100 int pack_info(Protocol *protocol) override;
4101#endif
4102
4103#ifndef MYSQL_SERVER
4104 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
4105#endif
4106
4107#if defined(MYSQL_SERVER)
4108 int do_apply_event(Relay_log_info const *) override { return 0; }
4109 int do_update_pos(Relay_log_info *rli) override;
4110#endif
4111
4112 /**
4113 Add a hash which identifies a inserted/updated/deleted row on the
4114 ongoing transaction.
4115
4116 @param[in] hash row identifier
4117 */
4118 void add_write_set(const char *hash);
4119
4120 /**
4121 Return a pointer to write-set list.
4123 std::list<const char *> *get_write_set() { return &write_set; }
4124
4125 /**
4126 Add a hash which identifies a read row on the ongoing transaction.
4127
4128 @param[in] hash row identifier
4129 */
4130 void add_read_set(const char *hash);
4131
4132 /**
4133 Return a pointer to read-set list.
4135 std::list<const char *> *get_read_set() { return &read_set; }
4136
4137 /**
4138 Read snapshot version from encoded buffers.
4139 Cannot be executed during data read from file (event constructor),
4140 since its required locks will collide with the server gtid state
4141 initialization procedure.
4142 */
4143 bool read_snapshot_version();
4144
4145 /**
4146 Return the transaction snapshot timestamp.
4149
4150 /**
4151 Return the server uuid.
4153 const char *get_server_uuid() { return server_uuid; }
4154
4155 /**
4156 Return the id of the committing thread.
4158 my_thread_id get_thread_id() { return static_cast<my_thread_id>(thread_id); }
4159
4160 /**
4161 Return true if transaction has GTID_NEXT specified, false otherwise.
4163 bool is_gtid_specified() { return gtid_specified == true; }
4164};
4165
4166/**
4167 @class View_change_log_event
4168
4169 This is the subclass of View_change_log_event and Log_event
4170 This class created the view_change_log_event which is used as a marker in
4171 case a new node joins or leaves the group.
4172
4173 @internal
4174 The inheritance structure is as follows
4175
4176 Binary_log_event
4177 ^
4178 |
4179 |
4180B_l: View_change_event Log_event
4181 \ /
4182 \ /
4183 \ /
4184 \ /
4185 View_change_log_event
4186
4187 B_l: Namespace Binary_log
4188 @endinternal
4189*/
4192 public Log_event {
4193 private:
4194 size_t to_string(char *buf, ulong len) const;
4195
4196#ifdef MYSQL_SERVER
4197 bool write_data_header(Basic_ostream *ostream) override;
4198
4199 bool write_data_body(Basic_ostream *ostream) override;
4200
4201 bool write_data_map(Basic_ostream *ostream,
4202 std::map<std::string, std::string> *map);
4203#endif
4204
4205 size_t get_size_data_map(std::map<std::string, std::string> *map);
4206
4207 public:
4208 View_change_log_event(const char *view_id);
4209
4210 View_change_log_event(const char *buffer,
4211 const Format_description_event *descr_event);
4212
4213 ~View_change_log_event() override;
4214
4215 size_t get_data_size() override;
4216
4217#ifdef MYSQL_SERVER
4218 int pack_info(Protocol *protocol) override;
4219#endif
4220
4221#ifndef MYSQL_SERVER
4222 void print(FILE *file, PRINT_EVENT_INFO *print_event_info) const override;
4223#endif
4224
4225#if defined(MYSQL_SERVER)
4226 int do_apply_event(Relay_log_info const *rli) override;
4227 int do_update_pos(Relay_log_info *rli) override;
4228#endif
4229
4230 /**
4231 Returns the view id.
4233 char *get_view_id() { return view_id; }
4234
4235 /**
4236 Sets the certification info in the event
4237
4238 @note size is calculated on this method as the size of the data
4239 might render the log even invalid. Also due to its size doing it
4240 here avoid looping over the data multiple times.
4241
4242 @param[in] info certification info to be written
4243 @param[out] event_size the event size after this operation
4244 */
4245 void set_certification_info(std::map<std::string, std::string> *info,
4246 size_t *event_size);
4247
4248 /**
4249 Returns the certification info
4251 std::map<std::string, std::string> *get_certification_info() {
4252 return &certification_info;
4253 }
4254
4255 /**
4256 Set the certification sequence number
4257
4258 @param number the sequence number
4260 void set_seq_number(rpl_gno number) { seq_number = number; }
4261
4262 /**
4263 Returns the certification sequence number
4265 rpl_gno get_seq_number() { return seq_number; }
4266};
4268inline bool is_gtid_event(Log_event *evt) {
4269 return (evt->get_type_code() == binary_log::GTID_LOG_EVENT ||
4271}
4272
4273/**
4274 Check if the given event is a session control event, one of
4275 `User_var_event`, `Intvar_event` or `Rand_event`.
4276
4277 @param evt The event to check.
4278
4279 @return true if the given event is of type `User_var_event`,
4280 `Intvar_event` or `Rand_event`, false otherwise.
4282inline bool is_session_control_event(Log_event *evt) {
4283 return (evt->get_type_code() == binary_log::USER_VAR_EVENT ||
4286}
4287
4288/**
4289 The function checks the argument event properties to deduce whether
4290 it represents an atomic DDL.
4291
4292 @param evt a reference to Log_event
4293 @return true when the DDL properties are found,
4294 false otherwise
4296inline bool is_atomic_ddl_event(Log_event const *evt) {
4297 return evt != nullptr && evt->get_type_code() == binary_log::QUERY_EVENT &&
4298 static_cast<Query_log_event const *>(evt)->ddl_xid !=
4300}
4301
4302/**
4303 The function lists all DDL instances that are supported
4304 for crash-recovery (WL9175).
4305 todo: the supported feature list is supposed to grow. Once
4306 a feature has been readied for 2pc through WL7743,9536(7141/7016) etc
4307 it needs registering in the function.
4308
4309 @param thd an Query-log-event creator thread handle
4310 @param using_trans
4311 The caller must specify the value according to the following
4312 rules:
4313 @c true when
4314 - on master the current statement is not processing
4315 a table in SE which does not support atomic DDL
4316 - on slave the relay-log repository is transactional.
4317 @c false otherwise.
4318 @return true when the being created (master) or handled (slave) event
4319 is 2pc-capable, @c false otherwise.
4320*/
4321bool is_atomic_ddl(THD *thd, bool using_trans);
4322
4323#ifdef MYSQL_SERVER
4324/**
4325 Serialize an binary event to the given output stream. It is more general
4326 than call ev->write() directly. The caller will not be affected if any
4327 change happens in serialization process. For example, serializing the
4328 event in different format.
4329 */
4330template <class EVENT>
4331bool binary_event_serialize(EVENT *ev, Basic_ostream *ostream) {
4332 return ev->write(ostream);
4333}
4334
4335/*
4336 This is an utility function that adds a quoted identifier into the a buffer.
4337 This also escapes any existence of the quote string inside the identifier.
4338 */
4339size_t my_strmov_quoted_identifier(THD *thd, char *buffer,
4340 const char *identifier, size_t length);
4341#else
4342size_t my_strmov_quoted_identifier(char *buffer, const char *identifier);
4343#endif
4345 const char *identifier,
4346 size_t length);
4347
4348/**
4349 Read an integer in net_field_length format, guarding against read out of
4350 bounds and advancing the position.
4351
4352 @param[in,out] packet Pointer to buffer to read from. On successful
4353 return, the buffer position will be incremented to point to the next
4354 byte after what was read.
4355
4356 @param[in,out] max_length Pointer to the number of bytes in the
4357 buffer. If the function would need to look at more than *max_length
4358 bytes in order to decode the number, the function will do nothing
4359 and return true.
4360
4361 @param[out] out Pointer where the value will be stored.
4362
4363 @retval false Success.
4364 @retval true Failure, i.e., reached end of buffer.
4365*/
4366template <typename T>
4367bool net_field_length_checked(const uchar **packet, size_t *max_length, T *out);
4368
4369/**
4370 Extract basic info about an event: type, query, is it ignorable
4371
4372 @param log_event the event to extract info from
4373 @return a pair first param is true if an error occurred, false otherwise
4374 second param is the event info
4375 */
4376std::pair<bool, binary_log::Log_event_basic_info> extract_log_event_basic_info(
4377 Log_event *log_event);
4378
4379/**
4380 Extract basic info about an event: type, query, is it ignorable
4381
4382 @param buf The event info buffer
4383 @param length The length of the buffer
4384 @param fd_event The Format description event associated
4385 @return a pair first param is true if an error occurred, false otherwise
4386 second param is the event info
4387 */
4388std::pair<bool, binary_log::Log_event_basic_info> extract_log_event_basic_info(
4389 const char *buf, size_t length,
4390 const binary_log::Format_description_event *fd_event);
4391
4392/**
4393 @} (end of group Replication)
4394*/
4395
4396#endif /* _log_event_h */
int64 query_id_t
Definition: binlog.h:70
Contains the classes representing events occurring in the replication stream.
#define LOG_EVENT_HEADER_LEN
Definition: binlog_event.h:406
This event is created to contain the file data.
Definition: log_event.h:1987
Append_block_log_event(THD *thd, const char *db_arg, uchar *block_arg, uint block_len_arg, bool using_trans)
Definition: log_event.cc:6937
bool write(Basic_ostream *ostream) override
Definition: log_event.cc:6967
virtual int get_create_or_append() const
Definition: log_event.cc:7012
bool is_sbr_logging_format() const override
Return true if the event has to be logged using SBR for DMLs.
Definition: log_event.h:2009
size_t get_data_size() override
Definition: log_event.h:2001
int pack_info(Protocol *protocol) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:6999
~Append_block_log_event() override=default
const char * get_db() override
Definition: log_event.h:2006
int do_apply_event(Relay_log_info const *rli) override
Primitive to apply an event to the database.
Definition: log_event.cc:7042
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:2114
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:7253
~Begin_load_query_log_event() override=default
int get_create_or_append() const override
Definition: log_event.cc:7249
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:7225
Delete_file_log_event is created when the LOAD_DATA query fails on the master for some reason,...
Definition: log_event.h:2047
int do_apply_event(Relay_log_info const *rli) override
Primitive to apply an event to the database.
Definition: log_event.cc:7198
size_t get_data_size() override
Definition: log_event.h:2060
~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:2068
bool write(Basic_ostream *ostream) override
Definition: log_event.cc:7158
const char * get_db() override
Definition: log_event.h:2065
Delete_file_log_event(THD *thd, const char *db_arg, bool using_trans)
Definition: log_event.cc:7131
int pack_info(Protocol *protocol) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:7186
Log row deletions.
Definition: log_event.h:3336
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:3355
@ TYPE_CODE
Definition: log_event.h:3340
Delete_rows_log_event(THD *, TABLE *, const Table_id &, bool is_transactional, const unsigned char *extra_row_ndb_info)
Definition: log_event.cc:12335
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:12351
int do_after_row_operations(const Relay_log_info *const, int) override
Definition: log_event.cc:12396
Log_event_type get_general_type_code() override
Definition: log_event.h:3361
int do_exec_row(const Relay_log_info *const) override
Definition: log_event.cc:12403
int do_before_row_operations(const Relay_log_info *const) override
Definition: log_event.cc:12373
Event responsible for LOAD DATA execution, it similar to Query_log_event but before executing the que...
Definition: log_event.h:2170
int do_apply_event(Relay_log_info const *rli) override
Primitive to apply an event to the database.
Definition: log_event.cc:7400
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:2194
bool write_post_header_for_derived(Basic_ostream *ostream) override
Definition: log_event.cc:7310
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:7266
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:7369
ulong get_post_header_size_for_derived() override
Definition: log_event.cc:7305
~Execute_load_query_log_event() override=default
Definition: field.h:574
For binlog version 4.
Definition: log_event.h:1501
std::atomic< int32 > atomic_usage_counter
Definition: log_event.h:1519
int pack_info(Protocol *protocol) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:5332
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:5497
size_t get_data_size() override
Definition: log_event.h:1531
bool write(Basic_ostream *ostream) override
Definition: log_event.cc:5342
int do_update_pos(Relay_log_info *rli) override
Advance relay log coordinates.
Definition: log_event.cc:5475
int do_apply_event(Relay_log_info const *rli) override
Primitive to apply an event to the database.
Definition: log_event.cc:5424
Format_description_log_event()
Format_description_log_event 1st ctor.
Definition: log_event.cc:5222
This is a subclass if Gtid_event and Log_event.
Definition: log_event.h:3734
rpl_sidno get_sidno(bool need_lock)
Return the SIDNO relative to the global sid_map for this GTID.
Definition: log_event.cc:13382
const rpl_sid * get_sid() const
Return the SID for this GTID.
Definition: log_event.h:3845
rpl_sid sid
SID for this GTID.
Definition: log_event.h:3895
~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:13094
size_t get_event_length()
Definition: log_event.h:3776
int do_update_pos(Relay_log_info *rli) override
Advance relay log coordinates.
Definition: log_event.cc:13314
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:3839
uint32 write_body_to_memory(uchar *buff)
Writes the body to the given memory buffer.
Definition: log_event.cc:13101
int do_apply_event(Relay_log_info const *rli) override
Primitive to apply an event to the database.
Definition: log_event.cc:13172
uint32 write_post_header_to_memory(uchar *buffer)
Writes the post-header to the given memory buffer.
Definition: log_event.cc:13041
static const size_t SET_STRING_PREFIX_LENGTH
Length of SET_STRING_PREFIX.
Definition: log_event.h:3882
rpl_gno get_gno() const
Return the GNO for this GTID.
Definition: log_event.h:3875
bool write_data_body(Basic_ostream *ostream) override
Definition: log_event.cc:13163
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:13333
static const size_t MAX_SET_STRING_LENGTH
The maximal length of the entire "SET ..." query.
Definition: log_event.h:3884
static const char * SET_STRING_PREFIX
string holding the text "SET @@GLOBAL.GTID_NEXT = '"
Definition: log_event.h:3878
Gtid_specification spec
Internal representation of the GTID.
Definition: log_event.h:3893
int pack_info(Protocol *) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:12947
size_t get_data_size() override
Definition: log_event.h:3769
size_t to_string(char *buf) const
Used internally by both print() and pack_info().
Definition: log_event.cc:12955
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:12855
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:13328
Represents a set of GTIDs.
Definition: rpl_gtid.h:1454
Definition: rpl_utility.h:108
Definition: log_event.h:3625
Heartbeat_log_event_v2(const char *buf, const Format_description_event *description_event)
Definition: log_event.cc:14214
Definition: log_event.h:3618
Heartbeat_log_event(const char *buf, const Format_description_event *description_event)
Definition: log_event.cc:14207
Base class for ignorable log events is Ignorable_event.
Definition: log_event.h:3498
Ignorable_log_event(THD *thd_arg)
Definition: log_event.h:3501
int pack_info(Protocol *) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:12721
size_t get_data_size() override
Definition: log_event.h:3522
~Ignorable_log_event() override
Class representing an incident, an occurrence out of the ordinary, that happened on the master.
Definition: log_event.h:3406
bool write_data_header(Basic_ostream *ostream) override
Definition: log_event.cc:12671
size_t get_data_size() override
Definition: log_event.h:3462
Incident_log_event(THD *thd_arg, enum_incident incident_arg)
Definition: log_event.h:3409
bool write_data_body(Basic_ostream *ostream) override
Definition: log_event.cc:12697
~Incident_log_event() override
Definition: log_event.cc:12591
int do_apply_event(Relay_log_info const *rli) override
Primitive to apply an event to the database.
Definition: log_event.cc:12632
int pack_info(Protocol *) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:12605
const char * description() const
Definition: log_event.cc:12595
bool ends_group() const override
Definition: log_event.h:3466
The class derives from the class Intvar_event in Binlog API, defined in the header binlog_event....
Definition: log_event.h:1572
bool write(Basic_ostream *ostream) override
Definition: log_event.cc:5809
~Intvar_log_event() override=default
size_t get_data_size() override
Definition: log_event.h:1591
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:1575
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:5883
int pack_info(Protocol *protocol) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:5784
bool is_sbr_logging_format() const override
Return true if the event has to be logged using SBR for DMLs.
Definition: log_event.h:1599
int do_apply_event(Relay_log_info const *rli) override
Primitive to apply an event to the database.
Definition: log_event.cc:5858
int do_update_pos(Relay_log_info *rli) override
Advance relay log coordinates.
Definition: log_event.cc:5878
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:2203
bool has_replace
Definition: log_event.h:2223
const size_t BUF_SIZE
Definition: log_event.h:2212
const char * table_name
Definition: log_event.h:2219
const char * fname
Definition: log_event.h:2220
const sql_exchange * sql_ex
Definition: log_event.h:2217
THD * thd
Definition: log_event.h:2216
bool has_ignore
Definition: log_event.h:2224
String str
Definition: log_event.h:2213
const char * db
Definition: log_event.h:2218
bool is_concurrent
Definition: log_event.h:2222
const String * generate(size_t *fn_start, size_t *fn_end)
Definition: log_event.cc:7509
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:7492
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:898
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:844
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:838
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:1150
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:1082
uint32 server_id
Definition: log_event.h:673
enum_mts_event_exec_mode
Definition: log_event.h:918
@ EVENT_EXEC_PARALLEL
Definition: log_event.h:922
@ EVENT_EXEC_SYNC
Definition: log_event.h:930
@ EVENT_EXEC_CAN_NOT
Definition: log_event.h:934
@ EVENT_EXEC_ASYNC
Definition: log_event.h:926
enum_skip_reason shall_skip(Relay_log_info *rli)
Decide if the event shall be skipped, and the reason for skipping it.
Definition: log_event.h:1125
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:1044
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:873
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:832
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:835
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
int update_pos(Relay_log_info *rli)
Update the relay log position.
Definition: log_event.h:1117
virtual int do_apply_event_worker(Slave_worker *w)
Definition: log_event.cc:1022
void set_artificial_event()
Definition: log_event.h:820
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:841
enum enum_mts_event_exec_mode get_mts_execution_mode(bool mts_in_group)
MTS Coordinator finds out a way how to execute the current event.
Definition: log_event.h:952
virtual enum_skip_reason do_shall_skip(Relay_log_info *rli)
Decide if this event shall be skipped or not and the reason for skipping it.
Definition: log_event.cc: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:1024
THD * thd
Definition: log_event.h:728
Log_event_type get_type_code() const
Definition: log_event.h:804
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:859
virtual uint8 mts_number_dbs()
Definition: log_event.h:1061
void free_temp_buf()
Definition: log_event.h:863
bool is_mts_group_isolated()
Definition: log_event.h:1068
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:813
virtual ~Log_event()
Definition: log_event.h:858
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:809
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:847
void set_relay_log_event()
Definition: log_event.h:828
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:829
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:1087
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:3947
bool write_data_body(Basic_ostream *ostream) override
Definition: log_event.cc:13478
int do_update_pos(Relay_log_info *rli) override
Advance relay log coordinates.
Definition: log_event.cc:13485
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:13459
int pack_info(Protocol *) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:13422
int do_apply_event(Relay_log_info const *) override
Primitive to apply an event to the database.
Definition: log_event.h:4028
int add_to_set(Gtid_set *gtid_set) const
Add all GTIDs from this event to the given Gtid_set.
Definition: log_event.cc:13448
size_t get_data_size() override
Definition: log_event.h:3961
Previous_gtids_log_event(const Gtid_set *set)
Definition: log_event.cc:13402
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:4023
bool write(Basic_ostream *ostream) override
Definition: log_event.h:3967
~Previous_gtids_log_event() override=default
const uchar * get_buf()
Return the encoded buffer, or NULL on error.
Definition: log_event.h:4004
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:1273
int do_update_pos(Relay_log_info *rli) override
Advance relay log coordinates.
Definition: log_event.cc:5111
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:1468
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:1438
bool is_trans_keyword() const
Definition: log_event.h:1406
bool m_skip_temp_tables_handling_by_worker
Instructs the applier to skip temporary tables handling.
Definition: log_event.h:1311
Query_log_event()
The simplest constructor that could possibly work.
Definition: log_event.cc:3646
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:5125
virtual ulong get_post_header_size_for_derived()
Definition: log_event.h:1390
bool starts_group() const override
Notice, DDL queries are logged without BEGIN/COMMIT parentheses and identification of such single-que...
Definition: log_event.h:1446
uchar mts_number_dbs() override
Definition: log_event.h:1362
my_thread_id slave_proxy_id
Definition: log_event.h:1284
void set_skip_temp_tables_handling_by_worker()
Definition: log_event.h:1313
bool has_ddl_committed
The flag indicates whether the DDL query has been (already) committed or not.
Definition: log_event.h:1304
int do_apply_event(Relay_log_info const *rli) override
Primitive to apply an event to the database.
Definition: log_event.cc:4392
~Query_log_event() override
Definition: log_event.h:1378
void attach_temp_tables_worker(THD *, const Relay_log_info *)
Associating slave Worker thread to a subset of temporary tables.
Definition: log_event.cc:4369
bool write(Basic_ostream *ostream) override
Query_log_event::write().
Definition: log_event.cc:3354
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:1292
bool is_query_prefix_match(const char *pattern, uint p_len)
Definition: log_event.h:1461
uint8 get_mts_dbs(Mts_db_names *arg, Rpl_filter *rpl_filter) override
Definition: log_event.h:1337
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:1472
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:5161
const char * get_db() override
Definition: log_event.h:1324
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:3303
Log_event_header::Byte * data_buf
Definition: log_event.h:1275
bool ends_group() const override
Definition: log_event.h:1451
bool is_skip_temp_tables_handling_by_worker()
Definition: log_event.h:1317
virtual bool write_post_header_for_derived(Basic_ostream *)
Definition: log_event.h:1383
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:4383
Logs random seed used by the next RAND(), and by PASSWORD() in 4.1.0.
Definition: log_event.h:1634
bool write(Basic_ostream *ostream) override
Definition: log_event.cc:5919
bool is_sbr_logging_format() const override
Return true if the event has to be logged using SBR for DMLs.
Definition: log_event.h:1658
~Rand_log_event() override=default
size_t get_data_size() override
Definition: log_event.h:1653
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:1637
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:5964
int do_apply_event(Relay_log_info const *rli) override
Primitive to apply an event to the database.
Definition: log_event.cc:5945
int pack_info(Protocol *protocol) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:5900
int do_update_pos(Relay_log_info *rli) override
Advance relay log coordinates.
Definition: log_event.cc:5959
Definition: rpl_rli.h:201
This will be deprecated when we move to using sequence ids.
Definition: log_event.h:1934
int do_update_pos(Relay_log_info *rli) override
Advance relay log coordinates.
Definition: log_event.cc:5617
int pack_info(Protocol *protocol) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:5510
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:5760
~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:5546
bool write(Basic_ostream *ostream) override
Definition: log_event.cc:5588
size_t get_data_size() override
Definition: log_event.h:1947
Definition: log_event.h:2482
bool is_enabled()
If instrumentation is enabled this member function SHALL return true.
Definition: log_event.h:2509
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:2555
ulonglong m_n_rows_applied
Counter that is unconditionally incremented on each row that is processed.
Definition: log_event.h:2497
ulonglong get_n_rows_applied()
Gets the value of the counter of rows that have been processed.
Definition: log_event.h:2561
Rows_applier_psi_stage()
Definition: log_event.h:2500
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:2522
void set_progress(PSI_stage_progress *progress)
Definition: log_event.h:2502
void end_work()
Resets this object.
Definition: log_event.h:2546
PSI_stage_progress * m_progress
A cached pointer to this stage PSI_stage_progress.
Definition: log_event.h:2490
Definition: log_event.h:2772
KEY ** m_key_info
Definition: log_event.h:2792
Key_compare(KEY **ki=nullptr)
Definition: log_event.h:2785
bool operator()(uchar *k1, uchar *k2) const
Definition: log_event.h:2786
Common base class for all row-containing log events.
Definition: log_event.h:2598
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:3095
uint32 m_bitbuf[128/(sizeof(uint32) *8)]
Definition: log_event.h:2753
virtual Log_event_type get_general_type_code()=0
uchar * m_rows_end
Definition: log_event.h:2762
int close_record_scan()
Does the cleanup.
Definition: log_event.cc:8783
size_t get_width() const
Definition: log_event.h:2663
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:8728
bool write_data_header(Basic_ostream *ostream) override
Definition: log_event.cc:10323
virtual int do_before_row_operations(const Relay_log_info *const log)=0
uchar * m_rows_buf
Definition: log_event.h:2760
uint m_rows_lookup_algorithm
The algorithm to use while searching for rows using the before image.
Definition: log_event.h:2734
TABLE * m_table
Definition: log_event.h:2713
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:2895
bool is_rbr_logging_format() const override
Return true if the event has to be logged using RBR for DMLs.
Definition: log_event.h:2882
int do_hash_row(Relay_log_info const *rli)
Populates the m_hash when using HASH_SCAN.
Definition: log_event.cc:9178
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:2728
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:2800
int do_hash_scan_and_update(Relay_log_info const *rli)
Implementation of the hash_scan and update algorithm.
Definition: log_event.cc:9421
int add_row_data(uchar *data, size_t length)
Definition: log_event.h:2653
void decide_row_lookup_algorithm_and_key() SUPPRESS_UBSAN_CLANG10
Definition: log_event.cc:8322
uint m_key_index
Definition: log_event.h:2770
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:8758
int row_operations_scan_and_key_setup()
Definition: log_event.cc:8434
MY_BITMAP const * get_cols_ai() const
Definition: log_event.h:2662
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:7676
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:10185
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:2750
uchar * m_key
Definition: log_event.h:2769
int do_index_scan_and_update(Relay_log_info const *rli)
Implementation of the index scan and update algorithm.
Definition: log_event.cc:8934
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:9246
virtual int do_add_row_data(uchar *data, size_t length)
Definition: log_event.cc:8051
Rows_applier_psi_stage m_psi_progress
Definition: log_event.h:2601
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:8525
size_t get_data_size() override
Definition: log_event.cc:8012
const char * get_db() override
Definition: log_event.h:2685
uint16 flag_set
Definition: log_event.h:2605
row_lookup_mode
Definition: log_event.h:2607
@ ROW_LOOKUP_INDEX_SCAN
Definition: log_event.h:2610
@ ROW_LOOKUP_UNDEFINED
Definition: log_event.h:2608
@ ROW_LOOKUP_NOT_NEEDED
Definition: log_event.h:2609
@ ROW_LOOKUP_TABLE_SCAN
Definition: log_event.h:2611
@ ROW_LOOKUP_HASH_SCAN
Definition: log_event.h:2612
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:3020
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:8507
uchar * m_rows_cur
Definition: log_event.h:2761
const Table_id & get_table_id() const
Definition: log_event.h:2664
uint m_row_count
Definition: log_event.h:2688
int do_apply_event(Relay_log_info const *rli) override
Primitive to apply an event to the database.
Definition: log_event.cc:9525
int next_record_scan(bool first_read)
Fetches next row.
Definition: log_event.cc:8796
int pack_info(Protocol *protocol) override
Stores a string representation of this event in the Protocol.
Definition: log_event.cc:10437
@ RLE_NO_FLAGS
Definition: log_event.h:2628
int do_table_scan_and_update(Relay_log_info const *rli)
Implementation of the legacy table_scan and update algorithm.
Definition: log_event.cc:9442
MY_BITMAP m_local_cols
Bitmap denoting columns available in the image as they appear in the table setup.
Definition: log_event.h:2722
int open_record_scan()
Initializes scanning of rows.
Definition: log_event.cc:8858
void clear_flags(flag_set flags_arg)
Definition: log_event.h:2633
virtual int do_exec_row(const Relay_log_info *const rli)=0
std::set< uchar *, Key_compare >::iterator m_itr
Definition: log_event.h:2795
enum_error
Enumeration of the errors that can be returned.
Definition: log_event.h:2618
@ ERR_TABLE_LIMIT_EXCEEDED
No more room for tables.
Definition: log_event.h:2621
@ ERR_BAD_TABLE_DEF
Table definition does not match.
Definition: log_event.h:2623
@ ERR_OPEN_FAILURE
Failure to open table.
Definition: log_event.h:2619
@ ERR_RBR_TO_SBR
daisy-chanining RBR to SBR not allowed
Definition: log_event.h:2624
@ ERR_OUT_OF_MEM
Out of memory.
Definition: log_event.h:2622
@ ERR_OK
No error.
Definition: log_event.h:2620
int row_operations_scan_and_key_teardown(int error)
Definition: log_event.cc:8477
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:7989
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:2661
std::set< uchar *, Key_compare > m_distinct_keys
Definition: log_event.h:2794
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:8640
const uchar * m_curr_row
Definition: log_event.h:2767
MY_BITMAP m_cols_ai
Bitmap for columns available in the after image, if present.
Definition: log_event.h:2743
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:8914
KEY * m_key_info
Definition: log_event.h:2771
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:7906
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:10291
~Rows_log_event() override
Definition: log_event.cc:7886
void set_flags(flag_set flags_arg)
Definition: log_event.h:2632
friend class Old_rows_log_event
Definition: log_event.h:3087
const uchar * m_curr_row_end
Definition: log_event.h:2768
bool write_data_body(Basic_ostream *ostream) override
Definition: log_event.cc:10404
uint32 m_bitbuf_ai[128/(sizeof(uint32) *8)]
Definition: log_event.h:2754
MY_BITMAP m_cols
Definition: log_event.h:2715
It is used to record the original query for the rows events in RBR.
Definition: log_event.h:3561
size_t get_data_size() override
Definition: log_event.h:3594
~Rows_query_log_event() override
Definition: log_event.h:3587
int do_apply_event(Relay_log_info const *rli) override
Primitive to apply an event to the database.
Definition: log_event.cc:12804
bool write_data_body(Basic_ostream *ostream) override
Definition: log_event.cc:12794