MySQL 8.0.33
Source Code Documentation
control_events.h
Go to the documentation of this file.
1/* Copyright (c) 2014, 2023, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is also distributed with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23/**
24 @addtogroup Replication
25 @{
26
27 @file control_events.h
28
29 @brief Contains the classes representing events operating in the replication
30 stream properties. Each event is represented as a byte sequence with logical
31 divisions as event header, event specific data and event footer. The header
32 and footer are common to all the events and are represented as two different
33 subclasses.
34*/
35
36#ifndef CONTROL_EVENT_INCLUDED
37#define CONTROL_EVENT_INCLUDED
38
39#include <sys/types.h>
40#include <time.h>
41#include <list>
42#include <map>
43#include <vector>
44
45#include "binlog_event.h"
46#include "template_utils.h"
47#include "uuid.h"
48
49#include "compression/base.h" // binary_log::transaction::compression::type
50
51namespace binary_log {
52/**
53 @class Rotate_event
54
55 When a binary log file exceeds a size limit, a ROTATE_EVENT is written
56 at the end of the file that points to the next file in the sequence.
57 This event is information for the slave to know the name of the next
58 binary log it is going to receive.
59
60 ROTATE_EVENT is generated locally and written to the binary log
61 on the master. It is written to the relay log on the slave when FLUSH LOGS
62 occurs, and when receiving a ROTATE_EVENT from the master.
63 In the latter case, there will be two rotate events in total originating
64 on different servers.
65
66 @section Rotate_event_binary_format Binary Format
67
68 <table>
69 <caption>Post-Header for Rotate_event</caption>
70
71 <tr>
72 <th>Name</th>
73 <th>Format</th>
74 <th>Description</th>
75 </tr>
76
77 <tr>
78 <td>position</td>
79 <td>8 byte integer</td>
80 <td>The position within the binary log to rotate to.</td>
81 </tr>
82
83 </table>
84
85 The Body has one component:
86
87 <table>
88 <caption>Body for Rotate_event</caption>
89
90 <tr>
91 <th>Name</th>
92 <th>Format</th>
93 <th>Description</th>
94 </tr>
95
96 <tr>
97 <td>new_log_ident</td>
98 <td>variable length string without trailing zero, extending to the
99 end of the event (determined by the length field of the
100 Common-Header)
101 </td>
102 <td>Name of the binlog to rotate to.</td>
103 </tr>
104
105 </table>
106*/
108 public:
109 const char *new_log_ident;
110 size_t ident_len;
111 unsigned int flags;
112 uint64_t pos;
113
114 enum {
115 /* Values taken by the flag member variable */
116 DUP_NAME = 2, // if constructor should dup the string argument
117 RELAY_LOG = 4 // rotate event for the relay log
118 };
119
120 enum {
121 /* Rotate event post_header */
124 };
125
126 /**
127 This is the minimal constructor, it will set the type code as ROTATE_EVENT.
128 */
129 Rotate_event(const char *new_log_ident_arg, size_t ident_len_arg,
130 unsigned int flags_arg, uint64_t pos_arg)
132 new_log_ident(new_log_ident_arg),
133 ident_len(ident_len_arg ? ident_len_arg : strlen(new_log_ident_arg)),
134 flags(flags_arg),
135 pos(pos_arg) {}
136
137 /**
138 The layout of Rotate_event data part is as follows:
139
140 <pre>
141 +-----------------------------------------------------------------------+
142 | common_header | post_header | position of the first event | file name |
143 +-----------------------------------------------------------------------+
144 </pre>
145
146 @param buf Contains the serialized event.
147 @param fde An FDE event, used to get the following information:
148 -binlog_version
149 -server_version
150 -post_header_len
151 -common_header_len
152 The content of this object depends on the binlog-version
153 currently in use.
154 */
155 Rotate_event(const char *buf, const Format_description_event *fde);
156
157#ifndef HAVE_MYSYS
158 void print_event_info(std::ostream &) override;
159 void print_long_info(std::ostream &) override;
160#endif
161
162 ~Rotate_event() override {
163 if (flags & DUP_NAME) bapi_free(const_cast<char *>(new_log_ident));
164 }
165};
166
167/**
168 @class Format_description_event
169 For binlog version 4.
170 This event is saved by threads which read it, as they need it for future
171 use (to decode the ordinary events).
172
173 @section Format_description_event_binary_format Binary Format
174
175 The Post-Header has six components:
176
177 <table>
178 <caption>Post-Header for Format_description_event</caption>
179
180 <tr>
181 <th>Name</th>
182 <th>Format</th>
183 <th>Description</th>
184 </tr>
185
186 <tr>
187 <td>created</td>
188 <td>4 byte unsigned integer</td>
189 <td>The creation timestamp, if non-zero,
190 is the time in seconds when this event was created</td>
191 </tr>
192 <tr>
193 <td>binlog_version</td>
194 <td>2 byte unsigned integer</td>
195 <td>This is 1 in MySQL 3.23 and 3 in MySQL 4.0 and 4.1
196 (In MySQL 5.0 and up, FORMAT_DESCRIPTION_EVENT is
197 used instead of START_EVENT_V3 and for them its 4).</td>
198 </tr>
199 <tr>
200 <td>server_version</td>
201 <td>char array of 50 bytes</td>
202 <td>The MySQL server's version (example: 4.0.14-debug-log),
203 padded with 0x00 bytes on the right</td>
204 </tr>
205 <tr>
206 <td>common_header_len</td>
207 <td>1 byte unsigned integer</td>
208 <td>The length of the event header. This value includes the extra_headers
209 field, so this header length - 19 yields the size
210 of the extra_headers field.</td>
211 </tr>
212 <tr>
213 <td>post_header_len</td>
214 <td>array of type 1 byte unsigned integer</td>
215 <td>The lengths for the fixed data part of each event</td>
216 </tr>
217 <tr>
218 <td>server_version_split</td>
219 <td>unsigned char array</td>
220 <td>Stores the server version of the server
221 and splits them in three parts</td>
222 </tr>
223 <tr>
224 <td>number_of_event_types</td>
225 <td>1 byte unsigned integer</td>
226 <td>number of event types present in the server</td>
227 </tr>
228 </table>
229*/
231 public:
232 /**
233 If this event is at the start of the first binary log since server
234 startup 'created' should be the timestamp when the event (and the
235 binary log) was created. In the other case (i.e. this event is at
236 the start of a binary log created by FLUSH LOGS or automatic
237 rotation), 'created' should be 0. This "trick" is used by MySQL
238 >=4.0.14 slaves to know whether they must drop stale temporary
239 tables and whether they should abort unfinished transaction.
240
241 Note that when 'created'!=0, it is always equal to the event's
242 timestamp; indeed Format_description_event is written only in binlog.cc
243 where the first constructor below is called, in which 'created' is set to
244 'when'. So in fact 'created' is a useless variable. When it is 0 we can
245 read the actual value from timestamp ('when') and when it is non-zero we
246 can read the same value from timestamp
247 ('when'). Conclusion:
248 - we use timestamp to print when the binlog was created.
249 - we use 'created' only to know if this is a first binlog or not.
250 */
251 time_t created;
254 /*
255 We set this to 1 if we don't want to have the created time in the log,
256 which is the case when we rollover to a new log.
257 */
259
260 /**
261 The size of the fixed header which _all_ events have
262 (for binlogs written by this version, this is equal to
263 LOG_EVENT_HEADER_LEN), except FORMAT_DESCRIPTION_EVENT and ROTATE_EVENT
264 (those have a header of size LOG_EVENT_MINIMAL_HEADER_LEN).
265 */
267 /*
268 The list of post-headers' lengths followed
269 by the checksum alg description byte
270 */
271 std::vector<uint8_t> post_header_len;
273
274 /**
275 Format_description_event 1st constructor.
276
277 This constructor can be used to create the event to write to the binary log
278 (when the server starts or when FLUSH LOGS)
279
280 @param binlog_ver the binlog version for which we want to build
281 an event. It should only be 4, old versions are not compatible anymore
282 since 8.0.2.
283 @param server_ver The MySQL server's version.
284 */
285 Format_description_event(uint8_t binlog_ver, const char *server_ver);
286 /**
287 The layout of Format_description_event data part is as follows:
288
289 <pre>
290 +=====================================+
291 | event | binlog_version 19 : 2 | = 4
292 | data +----------------------------+
293 | | server_version 21 : 50 |
294 | +----------------------------+
295 | | create_timestamp 71 : 4 |
296 | +----------------------------+
297 | | header_length 75 : 1 |
298 | +----------------------------+
299 | | post-header 76 : n | = array of n bytes, one byte
300 | | lengths for all | per event type that the
301 | | event types | server knows about
302 +=====================================+
303 </pre>
304 @param buf Contains the serialized event.
305 @param fde An FDE event (see Rotate_event constructor for more info).
306
307 @note The fde passed to this constructor was created through another
308 constructor of FDE class.
309 */
310 Format_description_event(const char *buf,
311 const Format_description_event *fde);
312
315 default;
317 /**
318 This method is used to find out the version of server that originated
319 the current FD instance.
320
321 @return the version of server.
322 */
323 unsigned long get_product_version() const;
324 /**
325 This method checks the MySQL version to determine whether checksums may be
326 present in the events contained in the binary log.
327
328 @retval true if the event's version is earlier than one that introduced
329 the replication event checksum.
330 @retval false otherwise.
331 */
332 bool is_version_before_checksum() const;
333 /**
334 This method populates the array server_version_split which is then used for
335 lookups to find if the server which created this event has some known bug.
336 */
338#ifndef HAVE_MYSYS
339 void print_event_info(std::ostream &info) override;
340 void print_long_info(std::ostream &info) override;
341#endif
343
344 bool header_is_valid() const {
346 (!post_header_len.empty()));
347 }
348
349 bool version_is_valid() const {
350 /* It is invalid only when all version numbers are 0 */
351 return server_version_split[0] != 0 || server_version_split[1] != 0 ||
352 server_version_split[2] != 0;
353 }
354};
355
356/**
357 @class Stop_event
358
359 A stop event is written to the log files under these circumstances:
360 - A master writes the event to the binary log when it shuts down.
361 - A slave writes the event to the relay log when it shuts down or
362 when a RESET SLAVE statement is executed.
363
364 @section Stop_event_binary_format Binary Format
365
366 The Post-Header and Body for this event type are empty; it only has
367 the Common-Header.
368*/
369
371 public:
372 /**
373 It is the minimal constructor, and all it will do is set the type_code as
374 STOP_EVENT in the header object in Binary_log_event.
375 */
377
378 /**
379 A Stop_event is occurs under these circumstances:
380 - A master writes the event to the binary log when it shuts down
381 - A slave writes the event to the relay log when it shuts down or when a
382 RESET SLAVE statement is executed
383 @param buf Contains the serialized event.
384 @param fde An FDE event (see Rotate_event constructor for more info).
385 */
386 Stop_event(const char *buf, const Format_description_event *fde);
387
388#ifndef HAVE_MYSYS
389 void print_event_info(std::ostream &) override {}
390 void print_long_info(std::ostream &info) override;
391#endif
392};
393
394/**
395 @class Incident_event
396
397 Class representing an incident, an occurrence out of the ordinary,
398 that happened on the master.
399
400 The event is used to inform the slave that something out of the
401 ordinary happened on the master that might cause the database to be
402 in an inconsistent state.
403
404 @section Incident_event_binary_format Binary Format
405
406 <table id="IncidentFormat">
407 <caption>Incident event format</caption>
408 <tr>
409 <th>Symbol</th>
410 <th>Format</th>
411 <th>Description</th>
412 </tr>
413 <tr>
414 <td>INCIDENT</td>
415 <td align="right">2</td>
416 <td>Incident number as an unsigned integer</td>
417 </tr>
418 <tr>
419 <td>MSGLEN</td>
420 <td align="right">1</td>
421 <td>Message length as an unsigned integer</td>
422 </tr>
423 <tr>
424 <td>MESSAGE</td>
425 <td align="right">MSGLEN</td>
426 <td>The message, if present. Not null terminated.</td>
427 </tr>
428 </table>
429
430*/
432 public:
433 /**
434 Enumeration of the incidents that can occur for the server.
435 */
437 /** No incident */
439 /** There are possibly lost events in the replication stream */
441 /** Shall be last event of the enumeration */
443 };
444
446 char *get_message() { return message; }
447
448 /**
449 This will create an Incident_event with an empty message and set the
450 type_code as INCIDENT_EVENT in the header object in Binary_log_event.
451 */
452 explicit Incident_event(enum_incident incident_arg)
454 incident(incident_arg),
456 message_length(0) {}
457
458 /**
459 Constructor of Incident_event
460 The buffer layout is as follows:
461 <pre>
462 +-----------------------------------------------------+
463 | Incident_number | message_length | Incident_message |
464 +-----------------------------------------------------+
465 </pre>
466
467 Incident number codes are listed in binlog_evnet.h.
468 The only code currently used is INCIDENT_LOST_EVENTS, which indicates that
469 there may be lost events (a "gap") in the replication stream that requires
470 databases to be resynchronized.
471
472 @param buf Contains the serialized event.
473 @param fde An FDE event (see Rotate_event constructor for more info).
474 */
475 Incident_event(const char *buf, const Format_description_event *fde);
476#ifndef HAVE_MYSYS
477 void print_event_info(std::ostream &info) override;
478 void print_long_info(std::ostream &info) override;
479#endif
480 protected:
482 char *message;
484};
485
486/**
487 @class Xid_event
488
489 An XID event is generated for a commit of a transaction that modifies one or
490 more tables of an XA-capable storage engine.
491
492 @section Xid_event_binary_format Binary Format
493
494The Body has the following component:
495
496 <table>
497 <caption>Body for Xid_event</caption>
498
499 <tr>
500 <th>Name</th>
501 <th>Format</th>
502 <th>Description</th>
503 </tr>
504
505 <tr>
506 <td>xid</td>
507 <td>8 byte unsigned integer</td>
508 <td>The XID transaction number.</td>
509 </tr>
510 </table>
511 The Post-Header and Body for this event type are empty; it only has
512 the common header.
513*/
515 public:
516 /**
517 The minimal constructor of Xid_event, it initializes the instance variable
518 xid and set the type_code as XID_EVENT in the header object in
519 Binary_log_event
520 */
521 explicit Xid_event(uint64_t xid_arg)
522 : Binary_log_event(XID_EVENT), xid(xid_arg) {}
523
524 /**
525 An XID event is generated for a commit of a transaction that modifies one or
526 more tables of an XA-capable storage engine
527 @param buf Contains the serialized event.
528 @param fde An FDE event (see Rotate_event constructor for more info).
529 */
530 Xid_event(const char *buf, const Format_description_event *fde);
531 uint64_t xid;
532#ifndef HAVE_MYSYS
533 void print_event_info(std::ostream &info) override;
534 void print_long_info(std::ostream &info) override;
535#endif
536};
537
538/**
539 @class XA_prepare_event
540
541 An XA_prepare event is generated for a XA prepared transaction.
542 Like Xid_event it contains XID of the *prepared* transaction.
543
544 @section XA_prepare_event_binary_format Binary Format
545
546The Body has the following component:
547
548 <table>
549 <caption>Body for XA_prepare_event</caption>
550
551 <tr>
552 <th>Name</th>
553 <th>Format</th>
554 <th>Description</th>
555 </tr>
556
557 <tr>
558 <td>my_xid</td>
559 <td>a struct similar to mysql/plugin.h containing three members.</td>
560 <td>serialized XID representation of XA transaction.</td>
561 </tr>
562
563 <tr>
564 <td>xid</td>
565 <td>a pointer to XID object.</td>
566 <td>a reference to an object for mysql logger.</td>
567 </tr>
568
569 <tr>
570 <td>one_phase</td>
571 <td>a bool</td>
572 <td>the value specifies the current XA transaction commit method.</td>
573 </tr>
574 </table>
575 The Post-Header and Body for this event type are empty; it only has
576 the common header.
577*/
578
580 /*
581 Struct def is copied from $MYSQL/include/mysql/plugin.h,
582 consult there about fine details.
583 */
584 static const int MY_XIDDATASIZE = 128;
585
586 public:
587 struct MY_XID {
591 char data[MY_XIDDATASIZE]; /* Not \0-terminated */
592 };
593
594 protected:
595 /* size of serialization buffer is explained in $MYSQL/sql/xa.h. */
596 static const uint16_t ser_buf_size =
597 8 + 2 * MY_XIDDATASIZE + 4 * sizeof(long) + 1;
599 void *xid; /* Master side only */
601
602 public:
603 /**
604 The minimal constructor of XA_prepare_event, it initializes the
605 instance variable xid and set the type_code as XID_EVENT in the
606 header object in Binary_log_event
607 */
608 XA_prepare_event(void *xid_arg, bool oph_arg)
610 xid(xid_arg),
611 one_phase(oph_arg) {}
612
613 /**
614 An XID event is generated for a commit of a transaction that modifies one or
615 more tables of an XA-capable storage engine
616 @param buf Contains the serialized event.
617 @param fde An FDE event (see Rotate_event constructor for more info).
618 */
619 XA_prepare_event(const char *buf, const Format_description_event *fde);
620#ifndef HAVE_MYSYS
621 /*
622 todo: we need to find way how to exploit server's code of
623 serialize_xid()
624 */
625 void print_event_info(std::ostream &) override {}
626 void print_long_info(std::ostream &) override {}
627#endif
628 /**
629 Whether or not this `XA_prepare_event` represents an `XA COMMIT ONE
630 PHASE`.
631
632 @return true if it's an `XA COMMIT ONE PHASE`, false otherwise.
633 */
634 bool is_one_phase() const;
635 /**
636 Retrieves the content of `my_xid` member variable.
637
638 @return The const-reference to the `my_xid` member variable.
639 */
640 MY_XID const &get_xid() const;
641};
642
643/**
644 @class Ignorable_event
645
646 Base class for ignorable log events. Events deriving from
647 this class can be safely ignored by slaves that cannot
648 recognize them. Newer slaves, will be able to read and
649 handle them. This has been designed to be an open-ended
650 architecture, so adding new derived events shall not harm
651 the old slaves that support ignorable log event mechanism
652 (they will just ignore unrecognized ignorable events).
653
654 @note The only thing that makes an event ignorable is that it has
655 the LOG_EVENT_IGNORABLE_F flag set. It is not strictly necessary
656 that ignorable event types derive from Ignorable_event; they may
657 just as well derive from Binary_log_event and Log_event and pass
658 LOG_EVENT_IGNORABLE_F as argument to the Log_event constructor.
659
660 @section Ignoarble_event_binary_format Binary format
661
662 The Post-Header and Body for this event type are empty; it only has
663 the Common-Header.
664*/
666 public:
667 // buf is advanced in Binary_log_event constructor to point to beginning of
668 // post-header
669
670 /**
671 The minimal constructor and all it will do is set the type_code as
672 IGNORABLE_LOG_EVENT in the header object in Binary_log_event.
673 */
675 : Binary_log_event(type_arg) {}
676 /**
677 @param buf Contains the serialized event.
678 @param fde An FDE event (see Rotate_event constructor for more info).
679 */
680 Ignorable_event(const char *buf, const Format_description_event *fde);
681#ifndef HAVE_MYSYS
682 void print_event_info(std::ostream &) override {}
683 void print_long_info(std::ostream &) override {}
684#endif
685};
686
687/**
688 @struct gtid_info
689 Structure to hold the members declared in the class Gtid_log_event those
690 member are objects of classes defined in server(rpl_gtid.h). As we can not
691 move all the classes defined there(in rpl_gtid.h) in libbinlogevents so this
692 structure was created, to provide a way to map the decoded value in Gtid_event
693 ctor and the class members defined in rpl_gtid.h, these classes are also the
694 members of Gtid_log_event(subclass of this in server code)
695
696 The structure contains the following components.
697 <table>
698 <caption>Structure gtid_info</caption>
699
700 <tr>
701 <th>Name</th>
702 <th>Format</th>
703 <th>Description</th>
704 </tr>
705 <tr>
706 <td>rpl_gtid_sidno</td>
707 <td>4 bytes integer</td>
708 <td>SIDNO (source ID number, first component of GTID)</td>
709 </tr>
710 <tr>
711 <td>rpl_gtid_gno</td>
712 <td>8 bytes integer</td>
713 <td>GNO (group number, second component of GTID)</td>
714 </tr>
715 </table>
716*/
717struct gtid_info {
720};
721
722/**
723 This event is a wrapper event and encloses many other events.
724
725 It is mostly used for carrying compressed payloads as its content
726 can be compressed, in which case, its metadata shall contain
727 information about the compression metadata as well.
728 */
730 private:
732 delete;
734
735 protected:
736 /**
737 The raw bytes which are the data that this event contains.
738 */
739 const char *m_payload{nullptr};
740
741 /**
742 The size of the data.
743 */
744 uint64_t m_payload_size{0};
745
746 /**
747 If the data is compressed, which compression was used.
748
749 For now, the only compressors supported are: ZSTD or NONE.
750
751 NONE means no compression at all. ZSTD means using ZSTD compression.
752 */
755
756 /**
757 The size of the data uncompressed. This is the same as @c m_payload_size if
758 there is no compression involved.
759 */
761
762 public:
763 static const unsigned short COMPRESSION_TYPE_MIN_LENGTH = 1;
764 static const unsigned short COMPRESSION_TYPE_MAX_LENGTH = 9;
765 static const unsigned short PAYLOAD_SIZE_MIN_LENGTH = 0;
766 static const unsigned short PAYLOAD_SIZE_MAX_LENGTH = 9;
767 static const unsigned short UNCOMPRESSED_SIZE_MIN_LENGTH = 0;
768 static const unsigned short UNCOMPRESSED_SIZE_MAX_LENGTH = 9;
769
773 /**
774 Creates @c Transaction_payload_event with the given data which has the
775 given size.
776
777 @param payload the data that this event shall wrap.
778 @param payload_size the size of the payload.
779
780 The data shall not be compressed. However, there is no other validation
781 that this is the case.
782 */
783 Transaction_payload_event(const char *payload, uint64_t payload_size);
784
785 /**
786 Creates @c Transaction_payload_event with the given data which has the
787 given size. The data provided may or may not have been compressed. In
788 any case the compression_type must be set.
789
790 @param payload the data that this event shall wrap.
791 @param payload_size the size of the payload.
792 @param compression_type the compression type used for the data provided.
793 @param uncompressed_size the size of the data when uncompressed.
794
795 The data may or may not be compressed. There is no validation or check
796 that it is or that the payload matches the metadata provided.
797 */
798 Transaction_payload_event(const char *payload, uint64_t payload_size,
799 uint16_t compression_type,
800 uint64_t uncompressed_size);
801
802 /**
803 This constructor takes a raw buffer and a format descriptor event and
804 decodes the buffer. It populates this event metadata with the contents
805 of the buffer.
806
807 @param buf the buffer to decode.
808 @param fde the format description event used to decode the buffer.
809 */
810 Transaction_payload_event(const char *buf,
811 const Format_description_event *fde);
812
813 /**
814 This destroys the transaction payload event.
815 */
817
818 /**
819 Shall set the compression type used for the enclosed payload.
820
821 @param type the compression type.
822 */
825 }
826
827 /**
828 Shall return the compression type used for the enclosed payload.
829
830 @return the compression type.
831 */
833 return m_compression_type;
834 }
835
836 /**
837 Shall set the size of the payload inside this event.
838
839 @param size The payload size.
840 */
841 void set_payload_size(uint64_t size) { m_payload_size = size; }
842
843 /**
844 Shall get the size of the payload inside this event.
845
846 @return The payload size.
847 */
848 uint64_t get_payload_size() const { return m_payload_size; }
849
850 /**
851 Shall set the uncompressed size of the payload.
852
853 @param size the uncompressed size of the payload.
854 */
855 void set_uncompressed_size(uint64_t size) { m_uncompressed_size = size; }
856
857 /**
858 Shall get the uncompressed size of the event.
859
860 @return uncompressed_size.
861 */
862 uint64_t get_uncompressed_size() const { return m_uncompressed_size; }
863
864 /**
865 Shall set the payload of the event.
866
867 @param data the payload of the event.
868 */
869 void set_payload(const char *data) { m_payload = data; }
870
871 /**
872 Shall get the payload of the event.
873
874 @return the payload of the event.
875 */
876 const char *get_payload() const { return m_payload; }
877
878 /**
879 Shall return a textual representation of this event.
880
881 @return a textial representation of this event.
882 */
883 std::string to_string() const;
884
885#ifndef HAVE_MYSYS
886 void print_event_info(std::ostream &) override;
887 void print_long_info(std::ostream &) override;
888#endif
889};
890
891/**
892 @class Gtid_event
893 GTID stands for Global Transaction IDentifier
894 It is composed of two parts:
895 - SID for Source Identifier, and
896 - GNO for Group Number.
897 The basic idea is to
898 - Associate an identifier, the Global Transaction IDentifier or GTID,
899 to every transaction.
900 - When a transaction is copied to a slave, re-executed on the slave,
901 and written to the slave's binary log, the GTID is preserved.
902 - When a slave connects to a master, the slave uses GTIDs instead of
903 (file, offset)
904
905 @section Gtid_event_binary_format Binary Format
906
907 The Body can have up to nine components:
908
909 <table>
910 <caption>Body for Gtid_event</caption>
911
912 <tr>
913 <th>Name</th>
914 <th>Format</th>
915 <th>Description</th>
916 </tr>
917
918 <tr>
919 <td>GTID_FLAGS</td>
920 <td>1 byte</td>
921 <td>00000001 = Transaction may have changes logged with SBR.
922 In 5.6, 5.7.0-5.7.18, and 8.0.0-8.0.1, this flag is always set.
923 Starting in 5.7.19 and 8.0.2, this flag is cleared if the transaction
924 only contains row events. It is set if any part of the transaction is
925 written in statement format.</td>
926 </tr>
927 <tr>
928 <td>SID</td>
929 <td>16 byte sequence</td>
930 <td>UUID representing the SID</td>
931 </tr>
932 <tr>
933 <td>GNO</td>
934 <td>8 byte integer</td>
935 <td>Group number, second component of GTID.</td>
936 </tr>
937 <tr>
938 <td>logical clock timestamp typecode</td>
939 <td>1 byte integer</td>
940 <td>The type of logical timestamp used in the logical clock fields.</td>
941 </tr>
942 <tr>
943 <td>last_committed</td>
944 <td>8 byte integer</td>
945 <td>Store the transaction's commit parent sequence_number</td>
946 </tr>
947 <tr>
948 <td>sequence_number</td>
949 <td>8 byte integer</td>
950 <td>The transaction's logical timestamp assigned at prepare phase</td>
951 </tr>
952 <tr>
953 <td>immediate_commit_timestamp</td>
954 <td>7 byte integer</td>
955 <td>Timestamp of commit on the immediate master</td>
956 </tr>
957 <tr>
958 <td>original_commit_timestamp</td>
959 <td>7 byte integer</td>
960 <td>Timestamp of commit on the originating master</td>
961 </tr>
962 <tr>
963 <td>transaction_length</td>
964 <td>1 to 9 byte integer // See net_length_size(ulonglong num)</td>
965 <td>The packed transaction's length in bytes, including the Gtid</td>
966 </tr>
967 <tr>
968 <td>immediate_server_version</td>
969 <td>4 byte integer</td>
970 <td>Server version of the immediate server</td>
971 </tr>
972 <tr>
973 <td>original_server_version</td>
974 <td>4 byte integer</td>
975 <td>Version of the server where the transaction was originally executed</td>
976 </tr>
977 </table>
978
979*/
981 public:
982 /*
983 The transaction's logical timestamps used for MTS: see
984 Transaction_ctx::last_committed and
985 Transaction_ctx::sequence_number for details.
986 Note: Transaction_ctx is in the MySQL server code.
987 */
988 long long int last_committed;
989 long long int sequence_number;
990 /** GTID flags constants */
991 unsigned const char FLAG_MAY_HAVE_SBR = 1;
992 /** Transaction might have changes logged with SBR */
994 /** Timestamp when the transaction was committed on the originating master. */
995 unsigned long long int original_commit_timestamp;
996 /** Timestamp when the transaction was committed on the nearest master. */
997 unsigned long long int immediate_commit_timestamp;
999 /** The length of the transaction in bytes. */
1000 unsigned long long int transaction_length;
1001
1002 public:
1003 /**
1004 Ctor of Gtid_event
1005
1006 The layout of the buffer is as follows
1007 <pre>
1008 +----------+---+---+-------+--------------+---------+----------+
1009 |gtid flags|SID|GNO|TS_TYPE|logical ts(:s)|commit ts|trx length|
1010 +----------+---+---+-------+------------------------+----------+
1011 </pre>
1012 TS_TYPE is from {G_COMMIT_TS2} singleton set of values
1013 Details on commit timestamps in Gtid_event(const char*...)
1014
1015 @param buf Contains the serialized event.
1016 @param fde An FDE event (see Rotate_event constructor for more info).
1017 */
1018
1019 Gtid_event(const char *buf, const Format_description_event *fde);
1020 /**
1021 Constructor.
1022 */
1023 explicit Gtid_event(long long int last_committed_arg,
1024 long long int sequence_number_arg,
1025 bool may_have_sbr_stmts_arg,
1026 unsigned long long int original_commit_timestamp_arg,
1027 unsigned long long int immediate_commit_timestamp_arg,
1028 uint32_t original_server_version_arg,
1029 uint32_t immediate_server_version_arg)
1031 last_committed(last_committed_arg),
1032 sequence_number(sequence_number_arg),
1033 may_have_sbr_stmts(may_have_sbr_stmts_arg),
1034 original_commit_timestamp(original_commit_timestamp_arg),
1035 immediate_commit_timestamp(immediate_commit_timestamp_arg),
1037 original_server_version(original_server_version_arg),
1038 immediate_server_version(immediate_server_version_arg) {}
1039#ifndef HAVE_MYSYS
1040 // TODO(WL#7684): Implement the method print_event_info and print_long_info
1041 // for all the events supported in MySQL Binlog
1042 void print_event_info(std::ostream &) override {}
1043 void print_long_info(std::ostream &) override {}
1044#endif
1045 /*
1046 Commit group ticket consists of: 1st bit, used internally for
1047 synchronization purposes ("is in use"), followed by 63 bits for
1048 the ticket value.
1049 */
1050 static constexpr int COMMIT_GROUP_TICKET_LENGTH = 8;
1051 /*
1052 Default value of commit_group_ticket, which means it is not
1053 being used.
1054 */
1055 static constexpr std::uint64_t kGroupTicketUnset = 0;
1056
1057 protected:
1058 static const int ENCODED_FLAG_LENGTH = 1;
1059 static const int ENCODED_SID_LENGTH = 16; // Uuid::BYTE_LENGTH;
1060 static const int ENCODED_GNO_LENGTH = 8;
1061 /// Length of typecode for logical timestamps.
1063 /// Length of two logical timestamps.
1064 static const int LOGICAL_TIMESTAMP_LENGTH = 16;
1065 // Type code used before the logical timestamps.
1066 static const int LOGICAL_TIMESTAMP_TYPECODE = 2;
1067
1070 // Length of two timestamps (from original/immediate masters)
1073 // We use 7 bytes out of which 1 bit is used as a flag.
1074 static const int ENCODED_COMMIT_TIMESTAMP_LENGTH = 55;
1075 // Minimum and maximum lengths of transaction length field.
1076 static const int TRANSACTION_LENGTH_MIN_LENGTH = 1;
1077 static const int TRANSACTION_LENGTH_MAX_LENGTH = 9;
1078 /// Length of original_server_version
1080 /// Length of immediate_server_version
1082 /// Length of original and immediate server version
1085 // We use 4 bytes out of which 1 bit is used as a flag.
1086 static const int ENCODED_SERVER_VERSION_LENGTH = 31;
1087
1088 /* We have only original commit timestamp if both timestamps are equal. */
1093 }
1094
1095 /**
1096 We only store the immediate_server_version if both server versions are the
1097 same.
1098 */
1103 }
1104
1107
1108 /* Minimum GNO expected in a serialized GTID event */
1109 static const int64_t MIN_GNO = 1;
1110 /// One-past-the-max value of GNO
1111 static const std::int64_t GNO_END = INT64_MAX;
1112
1113 public:
1114 virtual std::int64_t get_gno() const { return gtid_info_struct.rpl_gtid_gno; }
1116 /// Total length of post header
1117 static const int POST_HEADER_LENGTH =
1118 ENCODED_FLAG_LENGTH + /* flags */
1119 ENCODED_SID_LENGTH + /* SID length */
1120 ENCODED_GNO_LENGTH + /* GNO length */
1121 LOGICAL_TIMESTAMP_TYPECODE_LENGTH + /* length of typecode */
1122 LOGICAL_TIMESTAMP_LENGTH; /* length of two logical timestamps */
1123
1124 /*
1125 We keep the commit timestamps in the body section because they can be of
1126 variable length.
1127 On the originating master, the event has only one timestamp as the two
1128 timestamps are equal. On every other server we have two timestamps.
1129 */
1130 static const int MAX_DATA_LENGTH =
1133 COMMIT_GROUP_TICKET_LENGTH; /* 64-bit unsigned integer */
1134
1135 static const int MAX_EVENT_LENGTH =
1137 /**
1138 Set the transaction length information.
1139
1140 This function should be used when the full transaction length (including
1141 the Gtid event length) is known.
1142
1143 @param transaction_length_arg The transaction length.
1144 */
1145 void set_trx_length(unsigned long long int transaction_length_arg) {
1146 transaction_length = transaction_length_arg;
1147 }
1148
1149 /** The version of the server where the transaction was originally executed */
1151 /** The version of the immediate server */
1153
1154 /** Ticket number used to group sessions together during the BGC. */
1156
1157 /**
1158 Returns the length of the packed `commit_group_ticket` field. It may be
1159 8 bytes or 0 bytes, depending on whether or not the value is
1160 instantiated.
1161
1162 @return The length of the packed `commit_group_ticket` field
1163 */
1165
1166 /**
1167 Set the commit_group_ticket and update the transaction length if
1168 needed, that is, if the commit_group_ticket was not set already
1169 account it on the transaction size.
1170
1171 @param value The commit_group_ticket value.
1172 */
1174 std::uint64_t value);
1175};
1176
1177/**
1178 @class Previous_gtids_event
1179
1180 @section Previous_gtids_event_binary_format Binary Format
1181
1182 The Post-Header for this event type is empty. The Body has two
1183 components:
1184
1185 <table>
1186 <caption>Body for Previous_gtids_event</caption>
1187
1188 <tr>
1189 <th>Name</th>
1190 <th>Format</th>
1191 <th>Description</th>
1192 </tr>
1193
1194 <tr>
1195 <td>buf</td>
1196 <td>unsigned char array</td>
1197 <td>It contains the Gtids executed in the
1198 last binary log file.</td>
1199 </tr>
1200
1201 <tr>
1202 <td>buf_size</td>
1203 <td>4 byte integer</td>
1204 <td>Size of the above buffer</td>
1205 </tr>
1206 </table>
1207*/
1209 public:
1210 /**
1211 Decodes the gtid_executed in the last binlog file
1212
1213 <pre>
1214 The buffer layout is as follows
1215 +--------------------------------------------+
1216 | Gtids executed in the last binary log file |
1217 +--------------------------------------------+
1218 </pre>
1219 @param buf Contains the serialized event.
1220 @param fde An FDE event (see Rotate_event constructor for more info).
1221 */
1222 Previous_gtids_event(const char *buf, const Format_description_event *fde);
1223 /**
1224 This is the minimal constructor, and set the
1225 type_code as PREVIOUS_GTIDS_LOG_EVENT in the header object in
1226 Binary_log_event
1227 */
1229#ifndef HAVE_MYSYS
1230 // TODO(WL#7684): Implement the method print_event_info and print_long_info
1231 // for all the events supported in MySQL Binlog
1232 void print_event_info(std::ostream &) override {}
1233 void print_long_info(std::ostream &) override {}
1234#endif
1235 protected:
1236 size_t buf_size;
1237 const unsigned char *buf;
1238};
1239
1240/**
1241 @class Transaction_context_event
1242
1243 This class is used to combine the information of the ongoing transaction
1244 including the write set and other information of the thread executing the
1245 transaction.
1246
1247 <tr>
1248 <th>Name</th>
1249 <th>Format</th>
1250 <th>Description</th>
1251 </tr>
1252
1253 <tr>
1254 <td>thread_id</td>
1255 <td>4 byte integer</td>
1256 <td>The identifier for the thread executing the transaction.</td>
1257 </tr>
1258
1259 <tr>
1260 <td>gtid_specified</td>
1261 <td>bool type variable</td>
1262 <td>Variable to identify whether the Gtid have been specified for the
1263 ongoing transaction or not.
1264 </td>
1265 </tr>
1266
1267 <tr>
1268 <td>encoded_snapshot_version</td>
1269 <td>unsigned char array</td>
1270 <td>A gtid_set which is used to store the transaction set used for
1271 conflict detection.</td>
1272 </tr>
1273
1274 <tr>
1275 <td>encoded_snapshot_version_length</td>
1276 <td>4 byte integer</td>
1277 <td>Length of the above char array.</td>
1278 </tr>
1279
1280 <tr>
1281 <td>write_set</td>
1282 <td>variable length list to store the hash values. </td>
1283 <td>Used to store the hash values of the rows identifier for the rows
1284 which have changed in the ongoing transaction.
1285 </td>
1286 </tr>
1287
1288 <tr>
1289 <td>read_set</td>
1290 <td>variable length list to store the read set values. Currently empty.
1291 </td> <td>Will be used to store the read set values of the current
1292 transaction.</td>
1293 </tr>
1294
1295*/
1297 public:
1298 /**
1299 Decodes the transaction_context_log_event of the ongoing transaction.
1300
1301 <pre>
1302 The buffer layout is as follows
1303 </pre>
1304
1305 @param buf Contains the serialized event.
1306 @param fde An FDE event (see Rotate_event constructor for more info).
1307 */
1308 Transaction_context_event(const char *buf,
1309 const Format_description_event *fde);
1310
1311 Transaction_context_event(unsigned int thread_id_arg,
1312 bool is_gtid_specified_arg)
1314 thread_id(thread_id_arg),
1315 gtid_specified(is_gtid_specified_arg) {}
1316
1317 ~Transaction_context_event() override;
1318
1319 static const char *read_data_set(const char *pos, uint32_t set_len,
1320 std::list<const char *> *set,
1321 uint32_t remaining_buffer);
1322
1323 static void clear_set(std::list<const char *> *set);
1324
1325#ifndef HAVE_MYSYS
1326 void print_event_info(std::ostream &) override {}
1327 void print_long_info(std::ostream &) override {}
1328#endif
1329
1330 protected:
1331 const char *server_uuid;
1332 uint32_t thread_id;
1334 const unsigned char *encoded_snapshot_version;
1336 std::list<const char *> write_set;
1337 std::list<const char *> read_set;
1338
1339 // The values mentioned on the next class constants is the offset where the
1340 // data that will be copied in the buffer.
1341
1342 // 1 byte length.
1344 // 4 bytes length.
1345 static const int ENCODED_THREAD_ID_OFFSET = 1;
1346 // 1 byte length.
1347 static const int ENCODED_GTID_SPECIFIED_OFFSET = 5;
1348 // 4 bytes length
1350 // 4 bytes length.
1351 static const int ENCODED_WRITE_SET_ITEMS_OFFSET = 10;
1352 // 4 bytes length.
1353 static const int ENCODED_READ_SET_ITEMS_OFFSET = 14;
1354
1355 // The values mentioned on the next class's constants is the length of the
1356 // data that will be copied in the buffer.
1358 static const int ENCODED_SNAPSHOT_VERSION_LEN = 2;
1359};
1360
1361/**
1362 @class View_change_event
1363
1364 This class is used to add view change markers in the binary log when a
1365 member of the group enters or leaves the group.
1366
1367 <tr>
1368 <th>Name</th>
1369 <th>Format</th>
1370 <th>Description</th>
1371 </tr>
1372
1373 <tr>
1374 <td>view_id</td>
1375 <td>40 length character array</td>
1376 <td>This is used to store the view id value of the new view change when a
1377 node add or leaves the group.
1378 </td>
1379 </tr>
1380
1381 <tr>
1382 <td>seq_number</td>
1383 <td>8 bytes integer</td>
1384 <td>Variable to identify the next sequence number to be allotted to the
1385 certified transaction.</td>
1386 </tr>
1387
1388 <tr>
1389 <td>certification_info</td>
1390 <td>variable length map to store the certification data.</td>
1391 <td>Map to store the certification info ie. the hash of write_set and the
1392 snapshot sequence value.
1393 </td>
1394 </tr>
1395
1396*/
1398 public:
1399 /**
1400 Decodes the view_change_log_event generated in case a server enters or
1401 leaves the group.
1402
1403 <pre>
1404 The buffer layout is as follows
1405 </pre>
1406
1407 @param buf Contains the serialized event.
1408 @param fde An FDE event (see Rotate_event constructor for more info).
1409 */
1410 View_change_event(const char *buf, const Format_description_event *fde);
1411
1412 explicit View_change_event(const char *raw_view_id);
1413
1414 ~View_change_event() override;
1415
1416#ifndef HAVE_MYSYS
1417 void print_event_info(std::ostream &) override {}
1418 void print_long_info(std::ostream &) override {}
1419#endif
1420
1421 protected:
1422 // The values mentioned on the next class constants is the offset where the
1423 // data that will be copied in the buffer.
1424
1425 // 40 bytes length.
1426 static const int ENCODED_VIEW_ID_OFFSET = 0;
1427 // 8 bytes length.
1428 static const int ENCODED_SEQ_NUMBER_OFFSET = 40;
1429 // 4 bytes length.
1430 static const int ENCODED_CERT_INFO_SIZE_OFFSET = 48;
1431
1432 /*
1433 The layout of the buffer is as follows
1434 +--------------------- -+-------------+----------+
1435 | View Id | seq number | map size |
1436 +-----------------------+-------------+----------+
1437 view id (40 bytes) + seq number (8 bytes) + map size (4 bytes)
1438 Sum of the length of the values at the above OFFSETS.
1439 */
1440
1441 // The values mentioned on the next class constants is the length of the data
1442 // that will be copied in the buffer.
1443
1444 // Field sizes on serialization
1445 static const int ENCODED_VIEW_ID_MAX_LEN = 40;
1447 static const int ENCODED_CERT_INFO_VALUE_LEN = 4;
1448
1450
1451 long long int seq_number;
1452
1453 std::map<std::string, std::string> certification_info;
1454};
1455
1456/**
1457 @class Heartbeat_event_v2
1458
1459 Replication event to ensure to replica that source is alive.
1460 The event is originated by source's dump thread and sent straight to
1461 replica without being logged. Slave itself does not store it in relay log
1462 but rather uses a data for immediate checks and throws away the event.
1463
1464 Two members of the class m_log_filename and m_log_position comprise
1465 @see the rpl_event_coordinates instance. The coordinates that a heartbeat
1466 instance carries correspond to the last event source has sent from
1467 its binlog.
1468
1469 Also this event will be generated only for the source server with
1470 version > 8.0.26
1471
1472 @section Heartbeat_event_v2_binary_format Binary Format
1473
1474 The Body has one component:
1475
1476 <table>
1477 <caption>Body for Heartbeat_event</caption>
1478
1479 <tr>
1480 <th>Name</th>
1481 <th>Format</th>
1482 <th>Description</th>
1483 </tr>
1484
1485 <tr>
1486 <td>m_log_filename</td>
1487 <td>String variable to store the binlog name</td>
1488 <td>Name of the current binlog being written to.</td>
1489 </tr>
1490 <tr>
1491 <td>m_log_pos</td>
1492 <td>8 byte unsigned integar</td>
1493 <td>Name of the current binlog being written to.</td>
1494 </tr>
1495 </table>
1496*/
1497
1499 public:
1500 /**
1501 Sent by a source to a replica to let the replica know that the source is
1502 still alive. Events of this type do not appear in the binary or relay logs.
1503 They are generated on a source server by the thread that dumps events and
1504 sent straight to the replica without ever being written to the binary log.
1505
1506 @param buf Contains the serialized event.
1507 @param fde An FDE event (see Rotate_event constructor for more info).
1508 */
1509 Heartbeat_event_v2(const char *buf, const Format_description_event *fde);
1510
1511 /**
1512 Creates an empty heartbeat event.
1513 */
1515
1516 virtual ~Heartbeat_event_v2() override = default;
1517
1518 // Set the binlog filename
1519 void set_log_filename(const std::string name);
1520 // Set the position
1521 void set_log_position(uint64_t position);
1522 // Return the binlog filename
1523 const std::string get_log_filename() const;
1524 // Return the position
1525 uint64_t get_log_position() const;
1526
1527 // Return the max length of an encoded packet.
1528 static uint64_t max_encoding_length();
1529#ifndef HAVE_MYSYS
1530 void print_event_info(std::ostream &info) override;
1531 void print_long_info(std::ostream &info) override;
1532#endif
1533 protected:
1534 std::string m_log_filename{};
1535 uint64_t m_log_position{0};
1536};
1537
1538/**
1539 @class Heartbeat_event
1540
1541 Replication event to ensure to replica that source is alive.
1542 The event is originated by source's dump thread and sent straight to
1543 replica without being logged. Slave itself does not store it in relay log
1544 but rather uses a data for immediate checks and throws away the event.
1545
1546 Two members of the class log_ident and Binary_log_event::log_pos comprise
1547 @see the rpl_event_coordinates instance. The coordinates that a heartbeat
1548 instance carries correspond to the last event source has sent from
1549 its binlog.
1550
1551 @section Heartbeat_event_binary_format Binary Format
1552
1553 The Body has one component:
1554
1555 <table>
1556 <caption>Body for Heartbeat_event</caption>
1557
1558 <tr>
1559 <th>Name</th>
1560 <th>Format</th>
1561 <th>Description</th>
1562 </tr>
1563
1564 <tr>
1565 <td>log_ident</td>
1566 <td>variable length string without trailing zero, extending to the
1567 end of the event</td>
1568 <td>Name of the current binlog being written to.</td>
1569 </tr>
1570 </table>
1571*/
1573 public:
1574 /**
1575 Sent by a source to a replica to let the replica know that the source is
1576 still alive. Events of this type do not appear in the binary or relay logs.
1577 They are generated on a source server by the thread that dumps events and
1578 sent straight to the replica without ever being written to the binary log.
1579
1580 @param buf Contains the serialized event.
1581 @param fde An FDE event (see Rotate_event constructor for more info).
1582 */
1583 Heartbeat_event(const char *buf, const Format_description_event *fde);
1584
1585 // Return the file name
1586 const char *get_log_ident() { return log_ident; }
1587 // Return the length of file name
1588 unsigned int get_ident_len() { return ident_len; }
1589
1590 protected:
1591 const char *log_ident;
1592 unsigned int ident_len; /** filename length */
1593};
1594
1595} // end namespace binary_log
1596/**
1597 @} (end of group Replication)
1598*/
1599#endif /* CONTROL_EVENTS_INCLUDED */
Contains the classes representing events occurring in the replication stream.
#define LOG_EVENT_HEADER_LEN
Definition: binlog_event.h:406
#define LOG_EVENT_MINIMAL_HEADER_LEN
Fixed header length, where 4.x and 5.0 agree.
Definition: binlog_event.h:415
#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
For binlog version 4.
Definition: control_events.h:230
unsigned char server_version_split[ST_SERVER_VER_SPLIT_LEN]
Definition: control_events.h:272
Format_description_event(const Format_description_event &)=default
uint8_t number_of_event_types
Definition: control_events.h:316
char server_version[ST_SERVER_VER_LEN]
Definition: control_events.h:253
Format_description_event(uint8_t binlog_ver, const char *server_ver)
Format_description_event 1st constructor.
Definition: control_events.cpp:70
bool is_version_before_checksum() const
This method checks the MySQL version to determine whether checksums may be present in the events cont...
Definition: control_events.cpp:168
bool dont_set_created
Definition: control_events.h:258
bool version_is_valid() const
Definition: control_events.h:349
Format_description_event & operator=(const Format_description_event &)=default
uint8_t common_header_len
The size of the fixed header which all events have (for binlogs written by this version,...
Definition: control_events.h:266
unsigned long get_product_version() const
This method is used to find out the version of server that originated the current FD instance.
Definition: control_events.cpp:156
void calc_server_version_split()
This method populates the array server_version_split which is then used for lookups to find if the se...
Definition: control_events.cpp:147
std::vector< uint8_t > post_header_len
Definition: control_events.h:271
uint16_t binlog_version
Definition: control_events.h:252
time_t created
If this event is at the start of the first binary log since server startup 'created' should be the ti...
Definition: control_events.h:251
bool header_is_valid() const
Definition: control_events.h:344
GTID stands for Global Transaction IDentifier It is composed of two parts:
Definition: control_events.h:980
long long int sequence_number
Definition: control_events.h:989
static const int POST_HEADER_LENGTH
Total length of post header.
Definition: control_events.h:1117
static const int LOGICAL_TIMESTAMP_TYPECODE_LENGTH
Length of typecode for logical timestamps.
Definition: control_events.h:1062
static const int ENCODED_GNO_LENGTH
Definition: control_events.h:1060
virtual std::int64_t get_gno() const
Definition: control_events.h:1114
static const int LOGICAL_TIMESTAMP_TYPECODE
Definition: control_events.h:1066
static const int ENCODED_SERVER_VERSION_LENGTH
Definition: control_events.h:1086
bool may_have_sbr_stmts
Transaction might have changes logged with SBR.
Definition: control_events.h:993
static const int ORIGINAL_COMMIT_TIMESTAMP_LENGTH
Definition: control_events.h:1069
static const int TRANSACTION_LENGTH_MIN_LENGTH
Definition: control_events.h:1076
Uuid get_uuid() const
Definition: control_events.h:1115
uint32_t original_server_version
The version of the server where the transaction was originally executed.
Definition: control_events.h:1150
unsigned long long int original_commit_timestamp
Timestamp when the transaction was committed on the originating master.
Definition: control_events.h:995
static const int ORIGINAL_SERVER_VERSION_LENGTH
Length of original_server_version.
Definition: control_events.h:1079
int get_commit_group_ticket_length() const
Returns the length of the packed commit_group_ticket field.
Definition: control_events.cpp:575
unsigned long long int immediate_commit_timestamp
Timestamp when the transaction was committed on the nearest master.
Definition: control_events.h:997
static const int ENCODED_SID_LENGTH
Definition: control_events.h:1059
int get_server_version_length() const
We only store the immediate_server_version if both server versions are the same.
Definition: control_events.h:1099
static const int FULL_COMMIT_TIMESTAMP_LENGTH
Definition: control_events.h:1071
static const int TRANSACTION_LENGTH_MAX_LENGTH
Definition: control_events.h:1077
static const int FULL_SERVER_VERSION_LENGTH
Length of original and immediate server version.
Definition: control_events.h:1083
gtid_info gtid_info_struct
Definition: control_events.h:1105
static const int ENCODED_COMMIT_TIMESTAMP_LENGTH
Definition: control_events.h:1074
static const int IMMEDIATE_COMMIT_TIMESTAMP_LENGTH
Definition: control_events.h:1068
uint32_t immediate_server_version
The version of the immediate server.
Definition: control_events.h:1152
Gtid_event(const char *buf, const Format_description_event *fde)
Ctor of Gtid_event.
Definition: control_events.cpp:418
int get_commit_timestamp_length() const
Definition: control_events.h:1089
static const int64_t MIN_GNO
Definition: control_events.h:1109
static constexpr int COMMIT_GROUP_TICKET_LENGTH
Definition: control_events.h:1050
unsigned const char FLAG_MAY_HAVE_SBR
GTID flags constants.
Definition: control_events.h:991
bool has_commit_timestamps
Definition: control_events.h:998
long long int last_committed
Definition: control_events.h:988
std::uint64_t commit_group_ticket
Ticket number used to group sessions together during the BGC.
Definition: control_events.h:1155
Gtid_event(long long int last_committed_arg, long long int sequence_number_arg, bool may_have_sbr_stmts_arg, unsigned long long int original_commit_timestamp_arg, unsigned long long int immediate_commit_timestamp_arg, uint32_t original_server_version_arg, uint32_t immediate_server_version_arg)
Constructor.
Definition: control_events.h:1023
static constexpr std::uint64_t kGroupTicketUnset
Definition: control_events.h:1055
static const int IMMEDIATE_SERVER_VERSION_LENGTH
Length of immediate_server_version.
Definition: control_events.h:1081
static const int MAX_DATA_LENGTH
Definition: control_events.h:1130
static const int MAX_EVENT_LENGTH
Definition: control_events.h:1135
static const int ENCODED_FLAG_LENGTH
Definition: control_events.h:1058
Uuid Uuid_parent_struct
Definition: control_events.h:1106
unsigned long long int transaction_length
The length of the transaction in bytes.
Definition: control_events.h:1000
static const int LOGICAL_TIMESTAMP_LENGTH
Length of two logical timestamps.
Definition: control_events.h:1064
void set_trx_length(unsigned long long int transaction_length_arg)
Set the transaction length information.
Definition: control_events.h:1145
static const std::int64_t GNO_END
One-past-the-max value of GNO.
Definition: control_events.h:1111
void set_commit_group_ticket_and_update_transaction_length(std::uint64_t value)
Set the commit_group_ticket and update the transaction length if needed, that is, if the commit_group...
Definition: control_events.cpp:582
Replication event to ensure to replica that source is alive.
Definition: control_events.h:1498
void set_log_position(uint64_t position)
Definition: control_events.cpp:745
uint64_t get_log_position() const
Definition: control_events.cpp:751
uint64_t m_log_position
Definition: control_events.h:1535
static uint64_t max_encoding_length()
This member function returns the len of the event.
Definition: control_events.cpp:758
virtual ~Heartbeat_event_v2() override=default
const std::string get_log_filename() const
Definition: control_events.cpp:748
std::string m_log_filename
Definition: control_events.h:1534
Heartbeat_event_v2()
Creates an empty heartbeat event.
Definition: control_events.cpp:739
void set_log_filename(const std::string name)
Definition: control_events.cpp:742
Replication event to ensure to replica that source is alive.
Definition: control_events.h:1572
unsigned int ident_len
Definition: control_events.h:1592
const char * log_ident
Definition: control_events.h:1591
unsigned int get_ident_len()
Definition: control_events.h:1588
const char * get_log_ident()
Definition: control_events.h:1586
Heartbeat_event(const char *buf, const Format_description_event *fde)
Sent by a source to a replica to let the replica know that the source is still alive.
Definition: control_events.cpp:704
Base class for ignorable log events.
Definition: control_events.h:665
Ignorable_event(Log_event_type type_arg=IGNORABLE_LOG_EVENT)
The minimal constructor and all it will do is set the type_code as IGNORABLE_LOG_EVENT in the header ...
Definition: control_events.h:674
Class representing an incident, an occurrence out of the ordinary, that happened on the master.
Definition: control_events.h:431
enum_incident get_incident_type()
Definition: control_events.h:445
size_t message_length
Definition: control_events.h:483
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:452
enum_incident incident
Definition: control_events.h:481
char * get_message()
Definition: control_events.h:446
char * message
Definition: control_events.h:482
enum_incident
Enumeration of the incidents that can occur for the server.
Definition: control_events.h:436
@ INCIDENT_LOST_EVENTS
There are possibly lost events in the replication stream.
Definition: control_events.h:440
@ INCIDENT_COUNT
Shall be last event of the enumeration.
Definition: control_events.h:442
@ INCIDENT_NONE
No incident.
Definition: control_events.h:438
Definition: control_events.h:1208
size_t buf_size
Definition: control_events.h:1236
const unsigned char * buf
Definition: control_events.h:1237
Previous_gtids_event()
This is the minimal constructor, and set the type_code as PREVIOUS_GTIDS_LOG_EVENT in the header obje...
Definition: control_events.h:1228
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:107
size_t ident_len
Definition: control_events.h:110
uint64_t pos
Definition: control_events.h:112
unsigned int flags
Definition: control_events.h:111
const char * new_log_ident
Definition: control_events.h:109
~Rotate_event() override
Definition: control_events.h:162
Rotate_event(const char *new_log_ident_arg, size_t ident_len_arg, unsigned int flags_arg, uint64_t pos_arg)
This is the minimal constructor, it will set the type code as ROTATE_EVENT.
Definition: control_events.h:129
@ RELAY_LOG
Definition: control_events.h:117
@ DUP_NAME
Definition: control_events.h:116
@ R_POS_OFFSET
Definition: control_events.h:122
@ R_IDENT_OFFSET
Definition: control_events.h:123
A stop event is written to the log files under these circumstances:
Definition: control_events.h:370
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:376
This class is used to combine the information of the ongoing transaction including the write set and ...
Definition: control_events.h:1296
static const int ENCODED_SNAPSHOT_VERSION_LEN_OFFSET
Definition: control_events.h:1349
uint32_t encoded_snapshot_version_length
Definition: control_events.h:1335
static const char * read_data_set(const char *pos, uint32_t set_len, std::list< const char * > *set, uint32_t remaining_buffer)
static const int ENCODED_THREAD_ID_OFFSET
Definition: control_events.h:1345
static const int ENCODED_SERVER_UUID_LEN_OFFSET
Definition: control_events.h:1343
const unsigned char * encoded_snapshot_version
Definition: control_events.h:1334
std::list< const char * > write_set
Definition: control_events.h:1336
Transaction_context_event(unsigned int thread_id_arg, bool is_gtid_specified_arg)
Definition: control_events.h:1311
static const int ENCODED_GTID_SPECIFIED_OFFSET
Definition: control_events.h:1347
static const int ENCODED_READ_WRITE_SET_ITEM_LEN
Definition: control_events.h:1357
std::list< const char * > read_set
Definition: control_events.h:1337
const char * server_uuid
Definition: control_events.h:1331
Transaction_context_event(const char *buf, const Format_description_event *fde)
Decodes the transaction_context_log_event of the ongoing transaction.
Definition: control_events.cpp:610
static const int ENCODED_READ_SET_ITEMS_OFFSET
Definition: control_events.h:1353
static void clear_set(std::list< const char * > *set)
Function to clear the memory of the write_set and the read_set.
Definition: control_events.cpp:648
uint32_t thread_id
Definition: control_events.h:1332
bool gtid_specified
Definition: control_events.h:1333
~Transaction_context_event() override
Destructor of the Transaction_context_event class.
Definition: control_events.cpp:658
static const int ENCODED_SNAPSHOT_VERSION_LEN
Definition: control_events.h:1358
static const int ENCODED_WRITE_SET_ITEMS_OFFSET
Definition: control_events.h:1351
This event is a wrapper event and encloses many other events.
Definition: control_events.h:729
uint64_t m_uncompressed_size
The size of the data uncompressed.
Definition: control_events.h:760
const char * m_payload
The raw bytes which are the data that this event contains.
Definition: control_events.h:739
static const int MAX_DATA_LENGTH
Definition: control_events.h:770
uint64_t m_payload_size
The size of the data.
Definition: control_events.h:744
static const unsigned short COMPRESSION_TYPE_MIN_LENGTH
Definition: control_events.h:763
uint64_t get_payload_size() const
Shall get the size of the payload inside this event.
Definition: control_events.h:848
static const unsigned short UNCOMPRESSED_SIZE_MAX_LENGTH
Definition: control_events.h:768
static const unsigned short PAYLOAD_SIZE_MIN_LENGTH
Definition: control_events.h:765
void set_compression_type(transaction::compression::type type)
Shall set the compression type used for the enclosed payload.
Definition: control_events.h:823
transaction::compression::type get_compression_type() const
Shall return the compression type used for the enclosed payload.
Definition: control_events.h:832
uint64_t get_uncompressed_size() const
Shall get the uncompressed size of the event.
Definition: control_events.h:862
static const unsigned short PAYLOAD_SIZE_MAX_LENGTH
Definition: control_events.h:766
const char * get_payload() const
Shall get the payload of the event.
Definition: control_events.h:876
void set_uncompressed_size(uint64_t size)
Shall set the uncompressed size of the payload.
Definition: control_events.h:855
void set_payload(const char *data)
Shall set the payload of the event.
Definition: control_events.h:869
Transaction_payload_event & operator=(const Transaction_payload_event &)=delete
static const unsigned short COMPRESSION_TYPE_MAX_LENGTH
Definition: control_events.h:764
std::string to_string() const
Shall return a textual representation of this event.
Definition: control_events.cpp:395
void set_payload_size(uint64_t size)
Shall set the size of the payload inside this event.
Definition: control_events.h:841
transaction::compression::type m_compression_type
If the data is compressed, which compression was used.
Definition: control_events.h:753
Transaction_payload_event(const Transaction_payload_event &)=delete
static const unsigned short UNCOMPRESSED_SIZE_MIN_LENGTH
Definition: control_events.h:767
~Transaction_payload_event() override
This destroys the transaction payload event.
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:1397
static const int ENCODED_CERT_INFO_KEY_SIZE_LEN
Definition: control_events.h:1446
View_change_event(const char *buf, const Format_description_event *fde)
Decodes the view_change_log_event generated in case a server enters or leaves the group.
Definition: control_events.cpp:677
static const int ENCODED_SEQ_NUMBER_OFFSET
Definition: control_events.h:1428
char view_id[ENCODED_VIEW_ID_MAX_LEN]
Definition: control_events.h:1449
static const int ENCODED_CERT_INFO_SIZE_OFFSET
Definition: control_events.h:1430
static const int ENCODED_CERT_INFO_VALUE_LEN
Definition: control_events.h:1447
static const int ENCODED_VIEW_ID_MAX_LEN
Definition: control_events.h:1445
std::map< std::string, std::string > certification_info
Definition: control_events.h:1453
static const int ENCODED_VIEW_ID_OFFSET
Definition: control_events.h:1426
long long int seq_number
Definition: control_events.h:1451
~View_change_event() override
Destructor of the View_change_event class.
Definition: control_events.cpp:702
An XA_prepare event is generated for a XA prepared transaction.
Definition: control_events.h:579
MY_XID const & get_xid() const
Retrieves the content of my_xid member variable.
Definition: control_events.cpp:352
MY_XID my_xid
Definition: control_events.h:598
void * xid
Definition: control_events.h:599
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:608
bool one_phase
Definition: control_events.h:600
static const int MY_XIDDATASIZE
Definition: control_events.h:584
static const uint16_t ser_buf_size
Definition: control_events.h:596
bool is_one_phase() const
Whether or not this XA_prepare_event represents an XA COMMIT ONE PHASE.
Definition: control_events.cpp:350
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:514
uint64_t xid
Definition: control_events.h:531
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:521
Fido Client Authentication nullptr
Definition: fido_client_plugin.cc:221
#define ST_SERVER_VER_SPLIT_LEN
Definition: binlog_event.h:76
Log info(cout, "NOTE")
The namespace contains classes representing events that can occur in a replication stream.
Log_event_type
Enumeration type for the different types of log events.
Definition: binlog_event.h:274
@ XA_PREPARE_LOG_EVENT
Definition: binlog_event.h:349
@ 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
@ PREVIOUS_GTIDS_LOG_EVENT
Definition: binlog_event.h:342
@ TRANSACTION_CONTEXT_EVENT
Definition: binlog_event.h:344
@ INCIDENT_EVENT
Something out of the ordinary happened on the master.
Definition: binlog_event.h:317
@ GTID_LOG_EVENT
Definition: binlog_event.h:339
@ ROTATE_EVENT
Definition: binlog_event.h:290
@ XID_EVENT
Definition: binlog_event.h:301
@ STOP_EVENT
Definition: binlog_event.h:289
Definition: buf0block_hint.cc:29
std::set< Key, Compare, ut::allocator< Key > > set
Specialization of set which uses ut_allocator.
Definition: ut0new.h:2880
required string type
Definition: replication_group_member_actions.proto:33
case opt name
Definition: sslopt-case.h:32
This is a POD.
Definition: uuid.h:60
Definition: control_events.h:587
long gtrid_length
Definition: control_events.h:589
long bqual_length
Definition: control_events.h:590
char data[MY_XIDDATASIZE]
Definition: control_events.h:591
long formatID
Definition: control_events.h:588
Structure to hold the members declared in the class Gtid_log_event those member are objects of classe...
Definition: control_events.h:717
int64_t rpl_gtid_gno
Definition: control_events.h:719
int32_t rpl_gtid_sidno
Definition: control_events.h:718
Include file for Sun RPC to compile out of the box.
void bapi_free(void *ptr)
This is a wrapper function in order to free the memory allocated from the heap in the binlogevent lib...
Definition: wrapper_functions.h:189