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