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