MySQL 8.0.32
Source Code Documentation
binlog_event.h
Go to the documentation of this file.
1/* Copyright (c) 2011, 2022, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is also distributed with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23/**
24 @addtogroup Replication
25 @{
26
27 @file binlog_event.h
28
29 @brief Contains the classes representing events occurring in the replication
30 stream. Each event is represented as a byte sequence with logical divisions
31 as event header, event specific data and event footer. The header and footer
32 are common to all the events and are represented as two different subclasses.
33*/
34
35#ifndef BINLOG_EVENT_INCLUDED
36#define BINLOG_EVENT_INCLUDED
37
38#include <stdlib.h>
39#include <sys/types.h>
40#include <zlib.h> //for checksum calculations
41#include <climits>
42#include <cstdio>
43#include <iostream>
44
45#include "debug_vars.h"
46#include "event_reader.h"
47#include "my_checksum.h"
48#include "my_io.h"
49
50#if defined(_WIN32)
51#include <Winsock2.h>
52#else
53#include <sys/times.h>
54#endif
55/*
56 The symbols below are a part of the common definitions between
57 the MySQL server and the client. Since they should not be a part of
58 this library but the server, these should be placed in a header file
59 common to the library and the MySQL server code, so that if they are
60 updated in the server code, it is reflected in the libbinlogevent also.
61
62 TODO(WL#7984): Moving the binlog constant in library libbinlogevents into a
63 separate file and make them const variables
64*/
65#ifndef SYSTEM_CHARSET_MBMAXLEN
66#define SYSTEM_CHARSET_MBMAXLEN 3
67#endif
68#ifndef NAME_CHAR_LEN
69#define NAME_CHAR_LEN 64 /* Field/table name length */
70#endif
71#ifndef NAME_LEN
72#define NAME_LEN (NAME_CHAR_LEN * SYSTEM_CHARSET_MBMAXLEN)
73#endif
74/* Length of the server_version_split array in FDE class */
75#ifndef ST_SERVER_VER_SPLIT_LEN
76#define ST_SERVER_VER_SPLIT_LEN 3
77#endif
78
79/*
80 Do not decrease the value of BIN_LOG_HEADER_SIZE.
81 Do not even increase it before checking code.
82*/
83#ifndef BIN_LOG_HEADER_SIZE
84#define BIN_LOG_HEADER_SIZE 4U
85#endif
86
87/**
88 binlog_version 3 is MySQL 4.x; 4 is MySQL 5.0.0.
89 Compared to version 3, version 4 has:
90 - a different Start_event, which includes info about the binary log
91 (sizes of headers); this info is included for better compatibility if the
92 master's MySQL version is different from the slave's.
93*/
94#define BINLOG_VERSION 4
95
96/*
97 Constants used by Query_event.
98*/
99
100/**
101 The maximum number of updated databases that a status of
102 Query-log-event can carry. It can be redefined within a range
103 [1.. OVER_MAX_DBS_IN_EVENT_MTS].
104*/
105#define MAX_DBS_IN_EVENT_MTS 16
106
107/**
108 When the actual number of databases exceeds MAX_DBS_IN_EVENT_MTS
109 the value of OVER_MAX_DBS_IN_EVENT_MTS is is put into the
110 mts_accessed_dbs status.
111*/
112#define OVER_MAX_DBS_IN_EVENT_MTS 254
113
114/**
115 Maximum length of time zone name that we support (Time zone name is
116 char(64) in db). mysqlbinlog needs it.
117*/
118#define MAX_TIME_ZONE_NAME_LENGTH (NAME_LEN + 1)
119
120/**
121 Max number of possible extra bytes in a replication event compared to a
122 packet (i.e. a query) sent from client to master;
123 First, an auxiliary log_event status vars estimation:
124*/
125#define MAX_SIZE_LOG_EVENT_STATUS \
126 (1U + 4 /* type, flags2 */ + 1U + 8 /* type, sql_mode */ + 1U + 1 + \
127 255 /* type, length, catalog */ + 1U + 4 /* type, auto_increment */ + 1U + \
128 6 /* type, charset */ + 1U + 1 + \
129 MAX_TIME_ZONE_NAME_LENGTH /* type, length, time_zone */ + 1U + \
130 2 /* type, lc_time_names_number */ + 1U + \
131 2 /* type, charset_database_number */ + 1U + \
132 8 /* type, table_map_for_update */ + 1U + 1 + \
133 32 * 3 /* type, user_len, user */ + 1 + 255 /* host_len, host */ \
134 + 1U + 1 + \
135 (MAX_DBS_IN_EVENT_MTS * (1 + NAME_LEN)) /* type, db_1, db_2, ... */ \
136 + 1U + 3 /* type, microseconds */ + 1U + 1 /* type, explicit_def..ts*/ + \
137 1U + 8 /* type, xid of DDL */ + 1U + \
138 2 /* type, default_collation_for_utf8mb4_number */ + 1U + \
139 1 /* sql_require_primary_key */ + 1U + \
140 1 /* type, default_table_encryption */)
141
142/**
143 Uninitialized timestamp value (for either last committed or sequence number).
144 Often carries meaning of the minimum value in the logical timestamp domain.
145*/
146const int64_t SEQ_UNINIT = 0;
147
148/** We use 7 bytes, 1 bit being used as a flag. */
149#define MAX_COMMIT_TIMESTAMP_VALUE (1ULL << 55)
150/**
151 Used to determine whether the original_commit_timestamp is already known or if
152 it still needs to be determined when computing it.
153*/
155
156const uint32_t UNDEFINED_SERVER_VERSION = 999999;
157const uint32_t UNKNOWN_SERVER_VERSION = 0;
158
159/** Setting this flag will mark an event as Ignorable */
160#define LOG_EVENT_IGNORABLE_F 0x80
161
162/**
163 In case the variable is updated,
164 make sure to update it in $MYSQL_SOURCE_DIR/my_io.h.
165*/
166#ifndef FN_REFLEN
167#define FN_REFLEN 512 /* Max length of full path-name */
168#endif
169
170/**
171 Splits server 'version' string into three numeric pieces stored
172 into 'split_versions':
173 X.Y.Zabc (X,Y,Z numbers, a not a digit) -> {X,Y,Z}
174 X.Yabc -> {X,Y,0}
175
176 @param version String representing server version
177 @param split_versions Array with each element containing one split of the
178 input version string
179*/
180inline void do_server_version_split(const char *version,
181 unsigned char split_versions[3]) {
182 const char *p = version;
183 char *r;
184 unsigned long number;
185 for (unsigned int i = 0; i <= 2; i++) {
186 number = strtoul(p, &r, 10);
187 /*
188 It is an invalid version if any version number greater than 255 or
189 first number is not followed by '.'.
190 */
191 if (number < 256 && (*r == '.' || i != 0))
192 split_versions[i] = static_cast<unsigned char>(number);
193 else {
194 split_versions[0] = 0;
195 split_versions[1] = 0;
196 split_versions[2] = 0;
197 break;
198 }
199
200 p = r;
201 if (*r == '.') p++; // skip the dot
202 }
203}
204
205/**
206 Transforms the server version from 'XX.YY.ZZ-suffix' into an integer in the
207 format XXYYZZ.
208
209 @param version String representing server version
210 @return The server version in the format XXYYZZ
211*/
212inline uint32_t do_server_version_int(const char *version) {
213 unsigned char version_split[3];
214 do_server_version_split(version, version_split);
215 uint32_t ret = static_cast<uint32_t>(version_split[0]) * 10000 +
216 static_cast<uint32_t>(version_split[1]) * 100 +
217 static_cast<uint32_t>(version_split[2]);
218 return ret;
219}
220
221/**
222 Calculate the version product from the numeric pieces representing the server
223 version:
224 For a server version X.Y.Zabc (X,Y,Z numbers, a not a digit), the input is
225 {X,Y,Z}. This is converted to XYZ in bit representation.
226
227 @param version_split Array containing the version information of the server
228 @return The version product of the server
229*/
230inline unsigned long version_product(const unsigned char *version_split) {
231 return ((version_split[0] * 256 + version_split[1]) * 256 + version_split[2]);
232}
233
234/**
235 Replication event checksum is introduced in the following "checksum-home"
236 version. The checksum-aware servers extract FD's version to decide whether
237 the FD event carries checksum info.
238*/
239extern const unsigned char checksum_version_split[3];
240extern const unsigned long checksum_version_product;
241/**
242 @namespace binary_log
243
244 The namespace contains classes representing events that can occur in a
245 replication stream.
246*/
247namespace binary_log {
248/*
249 This flag only makes sense for Format_description_event. It is set
250 when the event is written, and *reset* when a binlog file is
251 closed (yes, it's the only case when MySQL modifies an already written
252 part of the binlog). Thus it is a reliable indicator that the binlog was
253 closed correctly. (Stop_event is not enough, there's always a
254 small chance that mysqld crashes in the middle of insert and end of
255 the binlog would look like a Stop_event).
256
257 This flag is used to detect a restart after a crash, and to provide
258 "unbreakable" binlog. The problem is that on a crash storage engines
259 rollback automatically, while binlog does not. To solve this we use this
260 flag and automatically append ROLLBACK to every non-closed binlog (append
261 virtually, on reading, file itself is not changed). If this flag is found,
262 mysqlbinlog simply prints "ROLLBACK". Replication master does not abort on
263 binlog corruption, but takes it as EOF, and replication slave forces a
264 rollback in this case.
265
266 Note, that old binlogs does not have this flag set, so we get a
267 a backward-compatible behaviour.
268*/
269#define LOG_EVENT_BINLOG_IN_USE_F 0x1
270
271/**
272 Enumeration type for the different types of log events.
273*/
275 /**
276 Every time you add a type, you have to
277 - Assign it a number explicitly. Otherwise it will cause trouble
278 if a event type before is deprecated and removed directly from
279 the enum.
280 - Fix Format_description_event::Format_description_event().
281 */
283 /*
284 Deprecated since mysql 8.0.2. It is just a placeholder,
285 should not be used anywhere else.
286 */
292
294
297
304
306
307 /**
308 The V1 event numbers are used from 5.1.16 until mysql-5.6.
309 */
313
314 /**
315 Something out of the ordinary happened on the master
316 */
318
319 /**
320 Heartbeat event to be send by master at its idle time
321 to ensure master's online status to slave
322 */
324
325 /**
326 In some situations, it is necessary to send over ignorable
327 data to the slave: data that a slave can handle in case there
328 is code for handling it, but which can be ignored if it is not
329 recognized.
330 */
333
334 /** Version 2 of the Row events */
338
341
343
345
347
348 /* Prepared XA transaction terminal event similar to Xid */
350
351 /**
352 Extension of UPDATE_ROWS_EVENT, allowing partial values according
353 to binlog_row_value_options.
354 */
356
358
360 /**
361 Add new events here - right above this comment!
362 Existing events (except ENUM_END_EVENT) should never change their numbers
363 */
364 ENUM_END_EVENT /* end marker */
366
367/**
368 Struct to pass basic information about a event: type, query, is it ignorable
369*/
372 const char *query{nullptr};
373 size_t query_length{0};
374 bool ignorable_event{false};
375};
376
377/**
378 The length of the array server_version, which is used to store the version
379 of MySQL server.
380 We could have used SERVER_VERSION_LENGTH, but this introduces an
381 obscure dependency - if somebody decided to change SERVER_VERSION_LENGTH
382 this would break the replication protocol
383 both of these are used to initialize the array server_version
384 SERVER_VERSION_LENGTH is used for global array server_version
385 and ST_SERVER_VER_LEN for the Start_event_v3 member server_version
386*/
387
388#define ST_SERVER_VER_LEN 50
389
390/*
391 Event header offsets;
392 these point to places inside the fixed header.
393*/
394#define EVENT_TYPE_OFFSET 4
395#define SERVER_ID_OFFSET 5
396#define EVENT_LEN_OFFSET 9
397#define LOG_POS_OFFSET 13
398#define FLAGS_OFFSET 17
399
400/** start event post-header (for v3 and v4) */
401#define ST_BINLOG_VER_OFFSET 0
402#define ST_SERVER_VER_OFFSET 2
403#define ST_CREATED_OFFSET (ST_SERVER_VER_OFFSET + ST_SERVER_VER_LEN)
404#define ST_COMMON_HEADER_LEN_OFFSET (ST_CREATED_OFFSET + 4)
405
406#define LOG_EVENT_HEADER_LEN 19U /* the fixed header length */
407
408/**
409 Fixed header length, where 4.x and 5.0 agree. That is, 5.0 may have a longer
410 header (it will for sure when we have the unique event's ID), but at least
411 the first 19 bytes are the same in 4.x and 5.0. So when we have the unique
412 event's ID, LOG_EVENT_HEADER_LEN will be something like 26, but
413 LOG_EVENT_MINIMAL_HEADER_LEN will remain 19.
414*/
415#define LOG_EVENT_MINIMAL_HEADER_LEN 19U
416
417/**
418 Enumeration spcifying checksum algorithm used to encode a binary log event
419*/
421 /**
422 Events are without checksum though its generator is checksum-capable
423 New Master (NM).
424 */
426 /** CRC32 of zlib algorithm */
428 /** the cut line: valid alg range is [1, 0x7f] */
430 /**
431 Special value to tag undetermined yet checksum or events from
432 checksum-unaware servers
433 */
436
437#define CHECKSUM_CRC32_SIGNATURE_LEN 4
438
439/**
440 defined statically while there is just one alg implemented
441*/
442#define BINLOG_CHECKSUM_LEN CHECKSUM_CRC32_SIGNATURE_LEN
443#define BINLOG_CHECKSUM_ALG_DESC_LEN 1 /* 1 byte checksum alg descriptor */
444#define LOG_EVENT_HEADER_SIZE 20
445
446/**
447 Calculate a long checksum for a memoryblock.
448
449 @param crc start value for crc
450 @param pos pointer to memory block
451 @param length length of the block
452
453 @return checksum for a memory block
454*/
455inline uint32_t checksum_crc32(uint32_t crc, const unsigned char *pos,
456 size_t length) {
457 BAPI_ASSERT(length <= UINT_MAX);
458 return my_checksum(crc, pos, length);
459}
460
461/*
462 Forward declaration of Format_description_event class to be used in class
463 Log_event_header
464*/
465class Format_description_event;
466
467/**
468 @class Log_event_footer
469
470 The footer, in the current version of the MySQL server, only contains
471 the checksum algorithm descriptor. The descriptor is contained in the
472 FDE of the binary log. This is common for all the events contained in
473 that binary log, and defines the algorithm used to checksum
474 the events contained in the binary log.
475
476 @anchor Table_common_footer
477 The footer contains the following:
478 <table>
479 <caption>Common-Footer</caption>
480
481 <tr>
482 <th>Name</th>
483 <th>Format</th>
484 <th>Description</th>
485 </tr>
486
487 <tr>
488 <td>checkusm_alg</td>
489 <td>enum_checksum_alg</td>
490 <td>Algorithm used to checksum the events contained in the binary log</td>
491 </tr>
492
493 </table>
494
495 @note checksum *value* is not generated with the event. On master's side, it
496 is calculated right before writing the event into the binary log. The
497 data_written field of the event is adjusted (+BINLOG_CHECKSUM_LEN) to
498 consider the checksum value as part of the event. On reading the event,
499 if the Format Description Event (FDE) used when serializing the event
500 tells that the events have checksum information, the checksum value can
501 be retrieved from a particular offset of the serialized event buffer
502 (event length - BINLOG_CHECKSUM_LEN) and checked for corruption by
503 computing a new value over the event buffer. It is not required after
504 that. Therefore, the checksum value is not required to be stored in the
505 instance as a class member.
506*/
508 public:
509 /**
510 Wrapper to call get_checksum_alg(const char *, ulong) function based on the
511 event reader object (which knows both buffer and buffer length).
512
513 @param[in] reader The Event_reader object associated to the event buffer
514 of the FD event.
515
516 @retval BINLOG_CHECKSUM_ALG_UNDEF originator is checksum-unaware
517 (effectively no checksum).
518 @retval BINLOG_CHECKSUM_ALG_OFF no checksum.
519 @retval other the actual checksum algorithm descriptor.
520 */
522
523 /**
524 The method returns the checksum algorithm used to checksum the binary log
525 from a Format Description Event serialized buffer.
526
527 For MySQL server versions < 5.6, the algorithm is undefined.
528
529 @param buf buffer holding serialized FD event.
530 @param len length of the event buffer.
531
532 @retval BINLOG_CHECKSUM_ALG_UNDEF originator is checksum-unaware
533 (effectively no checksum).
534 @retval BINLOG_CHECKSUM_ALG_OFF no checksum.
535 @retval other the actual checksum algorithm descriptor.
536 */
538 unsigned long len);
539
540 static bool event_checksum_test(unsigned char *buf, unsigned long event_len,
542
543 /* Constructors */
545
546 /**
547 This ctor will create a new object of Log_event_footer, and will adjust
548 the event reader buffer size with respect to CRC usage.
549
550 @param reader the Event_reader containing the serialized event (including
551 header, event data and optional checksum information).
552 @param event_type the type of the event the footer belongs to.
553 @param fde An FDE event, used to get information about CRC.
554 */
555 Log_event_footer(Event_reader &reader, Log_event_type event_type,
556 const Format_description_event *fde);
557
559 : checksum_alg(checksum_alg_arg) {}
560
561 /**
562 @verbatim
563 Master side:
564 The value is set by caller of FD(Format Description) constructor
565 In the FD case it's propagated into the last byte
566 of post_header_len[].
567 Slave side:
568 On the slave side the value is assigned from post_header_len[last]
569 of the last seen FD event.
570 @endverbatim
571 TODO(WL#7546): Revisit this comment when encoder is moved in libbinlogevent
572 */
574};
575
576/**
577 @class Log_event_header
578
579 The Common-Header always has the same form and length within one
580 version of MySQL. Each event type specifies a format and length
581 of the Post-Header. The length of the Common-Header is the same
582 for all events of the same type.
583
584 @anchor Table_common_header
585 The binary format of Common-Header is as follows:
586 <table>
587 <caption>Common-Header</caption>
588
589 <tr>
590 <th>Name</th>
591 <th>Format</th>
592 <th>Description</th>
593 </tr>
594
595 <tr>
596 <td>when</td>
597 <td>4 byte unsigned integer, represented by type struct timeval</td>
598 <td>The time when the query started, in seconds since 1970.
599 </td>
600 </tr>
601
602 <tr>
603 <td>type_code</td>
604 <td>1 byte enumeration</td>
605 <td>See enum #Log_event_type.</td>
606 </tr>
607
608 <tr>
609 <td>unmasked_server_id</td>
610 <td>4 byte unsigned integer</td>
611 <td>Server ID of the server that created the event.</td>
612 </tr>
613
614 <tr>
615 <td>data_written</td>
616 <td>4 byte unsigned integer</td>
617 <td>The total size of this event, in bytes. In other words, this
618 is the sum of the sizes of Common-Header, Post-Header, and Body.
619 </td>
620 </tr>
621
622 <tr>
623 <td>log_pos</td>
624 <td>4 byte unsigned integer</td>
625 <td>The position of the next event in the master binary log, in
626 bytes from the beginning of the file. In a binlog that is not a
627 relay log, this is just the position of the next event, in bytes
628 from the beginning of the file. In a relay log, this is
629 the position of the next event in the master's binlog.
630 </td>
631 </tr>
632
633 <tr>
634 <td>flags</td>
635 <td>2 byte bitfield</td>
636 <td>16 or less flags depending on the version of the binary log.</td>
637 </tr>
638 </table>
639
640 Summing up the numbers above, we see that the total size of the
641 common header is 19 bytes.
642*/
644 public:
645 /*
646 Timestamp on the master(for debugging and replication of
647 NOW()/TIMESTAMP). It is important for queries and LOAD DATA
648 INFILE. This is set at the event's creation time, except for Query
649 and Load (and other events) events where this is set at the query's
650 execution time, which guarantees good replication (otherwise, we
651 could have a query and its event with different timestamps).
652 */
653 struct timeval when;
654
655 /**
656 Event type extracted from the header. In the server, it is decoded
657 by read_log_event(), but adding here for complete decoding.
658 */
660
661 /*
662 The server id read from the Binlog.
663 */
664 unsigned int unmasked_server_id;
665
666 /* Length of an event, which will be written by write() function */
668
669 /*
670 The offset in the log where this event originally appeared (it is
671 preserved in relay logs, making SHOW SLAVE STATUS able to print
672 coordinates of the event in the master's binlog).
673 */
674 unsigned long long log_pos;
675
676 /*
677 16 or less flags depending on the version of the binary log.
678 See the definitions above for LOG_EVENT_TIME_F,
679 LOG_EVENT_FORCED_ROTATE_F, LOG_EVENT_THREAD_SPECIFIC_F, and
680 LOG_EVENT_SUPPRESS_USE_F for notes.
681 */
682 uint16_t flags;
683
684 /**
685 The following type definition is to be used whenever data is placed
686 and manipulated in a common buffer. Use this typedef for buffers
687 that contain data containing binary and character data.
688 */
689 typedef unsigned char Byte;
690
692 : type_code(type_code_arg), data_written(0), log_pos(0), flags(0) {
693 when.tv_sec = 0;
694 when.tv_usec = 0;
695 }
696 /**
697 Log_event_header constructor.
698
699 @param reader the Event_reader containing the serialized event (including
700 header, event data and optional checksum information).
701 */
703
704 /**
705 The get_is_valid function is related to event specific sanity checks to
706 determine that the object was initialized without errors.
707
708 Note that a given event object may be valid at some point (ancestor
709 event type initialization was fine) but be turned invalid in a later
710 stage.
711
712 @return True if the event object is valid, false otherwise.
713 */
714
715 bool get_is_valid() { return m_is_valid; }
716
717 /**
718 Set if the event object shall be considered valid or not.
719
720 @param is_valid if the event object shall be considered valid.
721 */
722
724
725 private:
726 /*
727 As errors might happen when de-serializing events, the m_is_valid variable
728 will hold information about the validity of the event.
729
730 An invalid event shall never be applied/dumped/displayed, as its
731 interpretation (accessing its contents) might lead to using invalid
732 memory pointers.
733 */
735};
736
737/**
738 This is the abstract base class for binary log events.
739
740 @section Binary_log_event_binary_format Binary Format
741
742 @anchor Binary_log_event_format
743 Any @c Binary_log_event saved on disk consists of the following four
744 components.
745
746 - Common-Header
747 - Post-Header
748 - Body
749 - Footer
750
751 Common header has the same format and length in a given MySQL version. It is
752 documented @ref Table_common_header "here".
753
754 The Body may be of different format and length even for different events of
755 the same type. The binary formats of Post-Header and Body are documented
756 separately in each subclass.
757
758 Footer is common to all the events in a given MySQL version. It is documented
759 @ref Table_common_footer "here".
760
761 @anchor packed_integer
762 - Some events, used for RBR use a special format for efficient representation
763 of unsigned integers, called Packed Integer. A Packed Integer has the
764 capacity of storing up to 8-byte integers, while small integers
765 still can use 1, 3, or 4 bytes. The value of the first byte
766 determines how to read the number, according to the following table:
767
768 <table>
769 <caption>Format of Packed Integer</caption>
770
771 <tr>
772 <th>First byte</th>
773 <th>Format</th>
774 </tr>
775
776 <tr>
777 <td>0-250</td>
778 <td>The first byte is the number (in the range 0-250), and no more
779 bytes are used.</td>
780 </tr>
781
782 <tr>
783 <td>252</td>
784 <td>Two more bytes are used. The number is in the range
785 251-0xffff.</td>
786 </tr>
787
788 <tr>
789 <td>253</td>
790 <td>Three more bytes are used. The number is in the range
791 0xffff-0xffffff.</td>
792 </tr>
793
794 <tr>
795 <td>254</td>
796 <td>Eight more bytes are used. The number is in the range
797 0xffffff-0xffffffffffffffff.</td>
798 </tr>
799
800 </table>
801
802 - Strings are stored in various formats. The format of each string
803 is documented separately.
804
805*/
807 public:
808 /*
809 The number of types we handle in Format_description_event (UNKNOWN_EVENT
810 is not to be handled, it does not exist in binlogs, it does not have a
811 format).
812 */
813 static const int LOG_EVENT_TYPES = (ENUM_END_EVENT - 1);
814
815 /**
816 The lengths for the fixed data part of each event.
817 This is an enum that provides post-header lengths for all events.
818 */
820 // where 3.23, 4.x and 5.0 agree
821 QUERY_HEADER_MINIMAL_LEN = (4 + 4 + 1 + 2),
822 // where 5.0 differs: 2 for length of N-bytes vars.
826 // this is FROZEN (the Rotate post-header is frozen)
849 }; // end enum_post_header_length
850 protected:
851 /**
852 This constructor is used to initialize the type_code of header object
853 m_header.
854 We set the type code to ENUM_END_EVENT so that the decoder
855 asserts if event type has not been modified by the sub classes
856 */
858 : m_reader(nullptr, 0), m_header(type_code) {}
859
860 /**
861 This constructor will create a new object of Log_event_header and initialize
862 the variable m_header, which in turn will be used to initialize Log_event's
863 member common_header.
864 It will also advance the Event_reader cursor after decoding the header (it
865 is done through the constructor of Log_event_header) and will be pointing to
866 the start of event data.
867
868 @param buf Contains the serialized event.
869 @param fde An FDE event used to get checksum information of non FDE events.
870 */
871 Binary_log_event(const char **buf, const Format_description_event *fde);
872
873 public:
874#ifndef HAVE_MYSYS
875 /*
876 The print_event_info functions are used in the free standing version of
877 the library only. Since MySQL server does not use them, and it does not
878 link to standard input/output library on Windows 32 bit system ,these
879 methods are commented out when the library(libbinlogevents) is built
880 with the server.
881 */
882 /**
883 Returns short information about the event
884 */
885 virtual void print_event_info(std::ostream &info) = 0;
886 /**
887 Returns detailed information about the event
888 */
889 virtual void print_long_info(std::ostream &info) = 0;
890#endif
891 virtual ~Binary_log_event() = 0;
892
897
898 /**
899 * Helper method
900 */
902
903 /**
904 Return a const pointer to the header of the log event
905 */
906 const Log_event_header *header() const { return &m_header; }
907 /**
908 Return a non-const pointer to the header of the log event
909 */
911 /**
912 Return a const pointer to the footer of the log event
913 */
914 const Log_event_footer *footer() const { return &m_footer; }
915 /**
916 Return a non-const pointer to the footer of the log event
917 */
919 /**
920 Returns a reference to the event Event_reader object.
921 */
923
924 private:
925 /*
926 All the accesses to the event buffer shall be performed by using m_reader
927 methods.
928 */
932};
933
934/**
935 @class Unknown_event
936
937 An unknown event should never occur. It is never written to a binary log.
938 If an event is read from a binary log that cannot be recognized as
939 something else, it is treated as UNKNOWN_EVENT.
940
941 The Post-Header and Body for this event type are empty; it only has
942 the Common-Header.
943*/
945 public:
946 /**
947 This is the minimal constructor, and set the type_code as
948 UNKNOWN_EVENT in the header object in Binary_log_event
949 */
951
952 Unknown_event(const char *buf, const Format_description_event *fde);
953#ifndef HAVE_MYSYS
954 void print_event_info(std::ostream &info) override;
955 void print_long_info(std::ostream &info) override;
956#endif
957};
958} // end namespace binary_log
959/**
960 @} (end of group Replication)
961*/
962#endif /* BINLOG_EVENT_INCLUDED */
#define ST_SERVER_VER_LEN
The length of the array server_version, which is used to store the version of MySQL server.
Definition: binlog_event.h:388
This is the abstract base class for binary log events.
Definition: binlog_event.h:806
Event_reader & reader()
Returns a reference to the event Event_reader object.
Definition: binlog_event.h:922
Log_event_footer * footer()
Return a non-const pointer to the footer of the log event.
Definition: binlog_event.h:918
Event_reader m_reader
Definition: binlog_event.h:929
Binary_log_event(Log_event_type type_code)
This constructor is used to initialize the type_code of header object m_header.
Definition: binlog_event.h:857
const Log_event_header * header() const
Return a const pointer to the header of the log event.
Definition: binlog_event.h:906
Binary_log_event & operator=(Binary_log_event &&)=default
enum_post_header_length
The lengths for the fixed data part of each event.
Definition: binlog_event.h:819
@ XID_HEADER_LEN
Definition: binlog_event.h:834
@ TABLE_MAP_HEADER_LEN
Definition: binlog_event.h:837
@ IGNORABLE_HEADER_LEN
Definition: binlog_event.h:843
@ USER_VAR_HEADER_LEN
Definition: binlog_event.h:832
@ HEARTBEAT_HEADER_LEN
Definition: binlog_event.h:842
@ XA_PREPARE_HEADER_LEN
Definition: binlog_event.h:847
@ VIEW_CHANGE_HEADER_LEN
Definition: binlog_event.h:846
@ APPEND_BLOCK_HEADER_LEN
Definition: binlog_event.h:829
@ DELETE_FILE_HEADER_LEN
Definition: binlog_event.h:830
@ INTVAR_HEADER_LEN
Definition: binlog_event.h:828
@ INCIDENT_HEADER_LEN
Definition: binlog_event.h:841
@ EXECUTE_LOAD_QUERY_HEADER_LEN
Definition: binlog_event.h:839
@ QUERY_HEADER_MINIMAL_LEN
Definition: binlog_event.h:821
@ START_V3_HEADER_LEN
Definition: binlog_event.h:825
@ RAND_HEADER_LEN
Definition: binlog_event.h:831
@ QUERY_HEADER_LEN
Definition: binlog_event.h:823
@ ROWS_HEADER_LEN_V2
Definition: binlog_event.h:844
@ ROWS_HEADER_LEN_V1
Definition: binlog_event.h:836
@ TRANSACTION_PAYLOAD_HEADER_LEN
Definition: binlog_event.h:848
@ STOP_HEADER_LEN
Definition: binlog_event.h:824
@ TRANSACTION_CONTEXT_HEADER_LEN
Definition: binlog_event.h:845
@ EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN
Definition: binlog_event.h:838
@ FORMAT_DESCRIPTION_HEADER_LEN
Definition: binlog_event.h:833
@ ROTATE_HEADER_LEN
Definition: binlog_event.h:827
@ BEGIN_LOAD_QUERY_HEADER_LEN
Definition: binlog_event.h:835
enum Log_event_type get_event_type() const
Helper method.
Definition: binlog_event.h:901
Binary_log_event(const Binary_log_event &)=default
Log_event_footer m_footer
Definition: binlog_event.h:931
static const int LOG_EVENT_TYPES
Definition: binlog_event.h:813
Log_event_header * header()
Return a non-const pointer to the header of the log event.
Definition: binlog_event.h:910
const Log_event_footer * footer() const
Return a const pointer to the footer of the log event.
Definition: binlog_event.h:914
Binary_log_event(Binary_log_event &&)=default
Log_event_header m_header
Definition: binlog_event.h:930
Binary_log_event & operator=(const Binary_log_event &)=default
Event_reader class purpose is to avoid out-of-buffer reads when deserializing binary log events and i...
Definition: event_reader.h:73
For binlog version 4.
Definition: control_events.h:230
The Common-Header always has the same form and length within one version of MySQL.
Definition: binlog_event.h:643
unsigned long long log_pos
Definition: binlog_event.h:674
bool m_is_valid
Definition: binlog_event.h:734
uint16_t flags
Definition: binlog_event.h:682
size_t data_written
Definition: binlog_event.h:667
void set_is_valid(bool is_valid)
Set if the event object shall be considered valid or not.
Definition: binlog_event.h:723
struct timeval when
Definition: binlog_event.h:653
unsigned int unmasked_server_id
Definition: binlog_event.h:664
Log_event_type type_code
Event type extracted from the header.
Definition: binlog_event.h:659
unsigned char Byte
The following type definition is to be used whenever data is placed and manipulated in a common buffe...
Definition: binlog_event.h:689
Log_event_header(Log_event_type type_code_arg=ENUM_END_EVENT)
Definition: binlog_event.h:691
bool get_is_valid()
The get_is_valid function is related to event specific sanity checks to determine that the object was...
Definition: binlog_event.h:715
An unknown event should never occur.
Definition: binlog_event.h:944
Unknown_event()
This is the minimal constructor, and set the type_code as UNKNOWN_EVENT in the header object in Binar...
Definition: binlog_event.h:950
const char * p
Definition: ctype-mb.cc:1236
This header file contains the status of variables used by MySQL tests for debug operations.
Contains the class responsible for deserializing fields of an event previously stored in a buffer.
Fido Client Authentication nullptr
Definition: fido_client_plugin.cc:221
const unsigned char checksum_version_split[3]
Replication event checksum is introduced in the following "checksum-home" version.
Definition: binlog_event.cpp:29
void do_server_version_split(const char *version, unsigned char split_versions[3])
In case the variable is updated, make sure to update it in $MYSQL_SOURCE_DIR/my_io....
Definition: binlog_event.h:180
const int64_t UNDEFINED_COMMIT_TIMESTAMP
Used to determine whether the original_commit_timestamp is already known or if it still needs to be d...
Definition: binlog_event.h:154
const int64_t SEQ_UNINIT
Uninitialized timestamp value (for either last committed or sequence number).
Definition: binlog_event.h:146
unsigned long version_product(const unsigned char *version_split)
Calculate the version product from the numeric pieces representing the server version: For a server v...
Definition: binlog_event.h:230
const uint32_t UNKNOWN_SERVER_VERSION
Definition: binlog_event.h:157
uint32_t do_server_version_int(const char *version)
Transforms the server version from 'XX.YY.ZZ-suffix' into an integer in the format XXYYZZ.
Definition: binlog_event.h:212
const unsigned long checksum_version_product
Definition: binlog_event.cpp:30
#define MAX_COMMIT_TIMESTAMP_VALUE
We use 7 bytes, 1 bit being used as a flag.
Definition: binlog_event.h:149
const uint32_t UNDEFINED_SERVER_VERSION
Definition: binlog_event.h:156
Abstraction functions over zlib/intrinsics.
ha_checksum my_checksum(ha_checksum crc, const unsigned char *pos, size_t length)
Calculate a CRC32 checksum for a memoryblock.
Definition: my_checksum.h:116
Common #defines and includes for file and socket I/O.
Log info(cout, "NOTE")
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:420
@ BINLOG_CHECKSUM_ALG_ENUM_END
the cut line: valid alg range is [1, 0x7f]
Definition: binlog_event.h:429
@ BINLOG_CHECKSUM_ALG_CRC32
CRC32 of zlib algorithm.
Definition: binlog_event.h:427
@ BINLOG_CHECKSUM_ALG_UNDEF
Special value to tag undetermined yet checksum or events from checksum-unaware servers.
Definition: binlog_event.h:434
@ BINLOG_CHECKSUM_ALG_OFF
Events are without checksum though its generator is checksum-capable New Master (NM).
Definition: binlog_event.h:425
Log_event_type
Enumeration type for the different types of log events.
Definition: binlog_event.h:274
@ EXECUTE_LOAD_QUERY_EVENT
Definition: binlog_event.h:303
@ TABLE_MAP_EVENT
Definition: binlog_event.h:305
@ XA_PREPARE_LOG_EVENT
Definition: binlog_event.h:349
@ WRITE_ROWS_EVENT_V1
The V1 event numbers are used from 5.1.16 until mysql-5.6.
Definition: binlog_event.h:310
@ HEARTBEAT_LOG_EVENT_V2
Definition: binlog_event.h:359
@ USER_VAR_EVENT
Definition: binlog_event.h:299
@ DELETE_ROWS_EVENT
Definition: binlog_event.h:337
@ IGNORABLE_LOG_EVENT
In some situations, it is necessary to send over ignorable data to the slave: data that a slave can h...
Definition: binlog_event.h:331
@ DELETE_ROWS_EVENT_V1
Definition: binlog_event.h:312
@ FORMAT_DESCRIPTION_EVENT
Definition: binlog_event.h:300
@ PREVIOUS_GTIDS_LOG_EVENT
Definition: binlog_event.h:342
@ SLAVE_EVENT
Definition: binlog_event.h:293
@ DELETE_FILE_EVENT
Definition: binlog_event.h:296
@ UNKNOWN_EVENT
Every time you add a type, you have to.
Definition: binlog_event.h:282
@ RAND_EVENT
Definition: binlog_event.h:298
@ TRANSACTION_PAYLOAD_EVENT
Definition: binlog_event.h:357
@ TRANSACTION_CONTEXT_EVENT
Definition: binlog_event.h:344
@ INCIDENT_EVENT
Something out of the ordinary happened on the master.
Definition: binlog_event.h:317
@ PARTIAL_UPDATE_ROWS_EVENT
Extension of UPDATE_ROWS_EVENT, allowing partial values according to binlog_row_value_options.
Definition: binlog_event.h:355
@ ROWS_QUERY_LOG_EVENT
Definition: binlog_event.h:332
@ GTID_LOG_EVENT
Definition: binlog_event.h:339
@ WRITE_ROWS_EVENT
Version 2 of the Row events.
Definition: binlog_event.h:335
@ UPDATE_ROWS_EVENT_V1
Definition: binlog_event.h:311
@ ANONYMOUS_GTID_LOG_EVENT
Definition: binlog_event.h:340
@ HEARTBEAT_LOG_EVENT
Heartbeat event to be send by master at its idle time to ensure master's online status to slave.
Definition: binlog_event.h:323
@ ROTATE_EVENT
Definition: binlog_event.h:290
@ BEGIN_LOAD_QUERY_EVENT
Definition: binlog_event.h:302
@ ENUM_END_EVENT
Add new events here - right above this comment! Existing events (except ENUM_END_EVENT) should never ...
Definition: binlog_event.h:364
@ INTVAR_EVENT
Definition: binlog_event.h:291
@ UPDATE_ROWS_EVENT
Definition: binlog_event.h:336
@ APPEND_BLOCK_EVENT
Definition: binlog_event.h:295
@ VIEW_CHANGE_EVENT
Definition: binlog_event.h:346
@ XID_EVENT
Definition: binlog_event.h:301
@ STOP_EVENT
Definition: binlog_event.h:289
@ START_EVENT_V3
Definition: binlog_event.h:287
@ QUERY_EVENT
Definition: binlog_event.h:288
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:455
Definition: buf0block_hint.cc:29
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:75
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:94
const mysql_service_registry_t * r
Definition: pfs_example_plugin_employee.cc:85
required uint64 version
Definition: replication_group_member_actions.proto:40
Struct to pass basic information about a event: type, query, is it ignorable.
Definition: binlog_event.h:370
const char * query
Definition: binlog_event.h:372
Log_event_type event_type
Definition: binlog_event.h:371
bool ignorable_event
Definition: binlog_event.h:374
size_t query_length
Definition: binlog_event.h:373
#define BAPI_ASSERT(x)
Definition: wrapper_functions.h:61