MySQL 8.1.0
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 "buffer/buffer_sequence_view.h" // Buffer_sequence_view
47#include "compression/base.h" // binary_log::transaction::compression::type
48#include "template_utils.h"
49#include "uuid.h"
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/// Event that encloses all the events of a transaction.
723///
724/// It is used for carrying compressed payloads, and contains
725/// compression metadata.
727 public:
729
730 private:
732 delete;
734
735 protected:
736 /// The compressed data, when entire payload is in one chunk.
737 const char *m_payload{nullptr};
738
739 /// The compressed data, when payload consists of a sequence of buffers
741
742 /// The size of the compressed data.
743 uint64_t m_payload_size{0};
744
745 /// The compression algorithm that was used.
748
749 /// The uncompressed size of the data. This is the same as @c
750 /// m_payload_size if the algorithms is NONE.
752
753 public:
754 /// There are four fields: "compression type", "payload size",
755 /// "uncompressed size", and "end mark". Each of the three first
756 /// fields is stored as a triple, where:
757 /// - the first element is a type code,
758 /// - the second element is a number containing the length of the
759 /// third element, and
760 /// - the third element is the value.
761 /// The last field, "end mark", is stored as only a type code. All
762 /// elements are stored in the "net_store_length" format.
763 /// net_store_length stores 64 bit numbers in a variable length
764 /// format, using 1 to 9 bytes depending on the magnitude of the
765 /// value; 1 for values up to 250, longer for bigger values.
766 ///
767 /// So:
768 /// - The first element in each triple is always length 1 since type
769 /// codes are small;
770 /// - the second element in each triple is always length 1 since the
771 /// third field is at most 9 bytes;
772 /// - the third field in each triple is:
773 /// - at most 1 for the "compression type" since type codes are small;
774 /// - at most 9 for the "payload size" and "uncompressed size".
775 /// - the end mark is always 1 byte since it is a constant value
776 /// less than 250
777 static constexpr size_t compression_type_max_length = 1 + 1 + 1;
778 static constexpr size_t payload_size_max_length = 1 + 1 + 9;
779 static constexpr size_t uncompressed_size_max_length = 1 + 1 + 9;
780 static constexpr size_t end_mark_max_length = 1;
781
782 /// The maximum size of the "payload data header".
783 ///
784 /// Any log event consists of the common-header (19 bytes, same
785 /// format for all event types), followed by a post-header (size
786 /// defined per event type; 0 for payload events), followed by data
787 /// (variable length and defined by each event type). For payload
788 /// events, the data contains a payload data header (these 4
789 /// fields), followed by the payload (compressed data).
790 static constexpr size_t max_payload_data_header_length =
793
794 /// The maximum size of all headers, i.e., everything but the
795 /// payload.
796 ///
797 /// This includes common-header, post-header, and payload
798 /// data header.
799 static constexpr size_t max_length_of_all_headers =
802 /// The maximum length of the payload size, defined such that the total
803 /// event size does not exceed max_log_event_size.
804 static constexpr size_t max_payload_length =
806
807 /// Construct an object from the given fields.
808 ///
809 /// @param payload The (compressed) payload data.
810 ///
811 /// @param payload_size The size of @c payload in bytes.
812 ///
813 /// @param compression_type the compression type that was used to
814 /// compress @c payload.
815 ///
816 /// @param uncompressed_size the size of the data when uncompressed.
817 ///
818 /// The function does not validate that the payload matches the
819 /// metadata provided.
820 Transaction_payload_event(const char *payload, uint64_t payload_size,
821 uint16_t compression_type,
822 uint64_t uncompressed_size);
823
824 /// Decode the event from a buffer.
825 ///
826 /// @param buf The buffer to decode.
827 ///
828 /// @param fde The format description event used to decode the
829 /// buffer.
830 Transaction_payload_event(const char *buf,
831 const Format_description_event *fde);
832
834
835 /// Set the compression type used for the enclosed payload.
836 ///
837 /// @note API clients must call either all or none of set_payload,
838 /// set_payload_size, set_compression_type, and
839 /// set_uncompressed_size.
840 ///
841 /// @param type the compression type.
844 }
845
846 /// @return the compression type.
848 return m_compression_type;
849 }
850
851 /// Set the (compressed) size of the payload in this event.
852 ///
853 /// @note API clients must call either all or none of set_payload,
854 /// set_payload_size, set_compression_type, and
855 /// set_uncompressed_size.
856 ///
857 /// @param size The compressed size of the payload.
858 void set_payload_size(uint64_t size) { m_payload_size = size; }
859
860 /// @return The payload size.
861 uint64_t get_payload_size() const { return m_payload_size; }
862
863 /// Set the uncompressed size of the payload.
864 ///
865 /// @note API clients must call either all or none of set_payload,
866 /// set_payload_size, set_compression_type, and
867 /// set_uncompressed_size.
868 ///
869 /// @param size The uncompressed size of the payload.
870 void set_uncompressed_size(uint64_t size) { m_uncompressed_size = size; }
871
872 /// Return the alleged uncompressed size according to the field
873 /// stored in the event.
874 ///
875 /// This cannot be trusted; the actual size can only be computed by
876 /// decompressing the event.
877 uint64_t get_uncompressed_size() const { return m_uncompressed_size; }
878
879 /// Set the (possibly compressed) payload for the event.
880 ///
881 /// The ownership and responsibility to destroy the data is
882 /// transferred to the event.
883 ///
884 /// @note API clients must call either all or none of set_payload,
885 /// set_payload_size, set_compression_type, and
886 /// set_uncompressed_size.
887 ///
888 /// @param data The payload of the event.
889 void set_payload(const char *data) { m_payload = data; }
890
891 /// @return the payload of the event.
892 const char *get_payload() const { return m_payload; }
893
894 /// Set the (possibly compressed) payload for the event.
895 ///
896 /// The payload is given as a Buffer_sequence_view. The ownership
897 /// of the data remains with the caller; the caller must ensure that
898 /// the iterators remain valid for as long as this event needs them.
899 ///
900 /// @note API clients must call either all or none of set_payload,
901 /// set_payload_size, set_compression_type, and
902 /// set_uncompressed_size.
903 ///
904 /// @param buffer_sequence_view Container holding the data.
905 void set_payload(Buffer_sequence_view_t *buffer_sequence_view);
906
907 /// @return a textual representation of this event.
908 std::string to_string() const;
909
910#ifndef HAVE_MYSYS
911 void print_event_info(std::ostream &) override;
912 void print_long_info(std::ostream &) override;
913#endif
914};
915
916/**
917 @class Gtid_event
918 GTID stands for Global Transaction IDentifier
919 It is composed of two parts:
920 - SID for Source Identifier, and
921 - GNO for Group Number.
922 The basic idea is to
923 - Associate an identifier, the Global Transaction IDentifier or GTID,
924 to every transaction.
925 - When a transaction is copied to a slave, re-executed on the slave,
926 and written to the slave's binary log, the GTID is preserved.
927 - When a slave connects to a master, the slave uses GTIDs instead of
928 (file, offset)
929
930 @section Gtid_event_binary_format Binary Format
931
932 The Body can have up to nine components:
933
934 <table>
935 <caption>Body for Gtid_event</caption>
936
937 <tr>
938 <th>Name</th>
939 <th>Format</th>
940 <th>Description</th>
941 </tr>
942
943 <tr>
944 <td>GTID_FLAGS</td>
945 <td>1 byte</td>
946 <td>00000001 = Transaction may have changes logged with SBR.
947 In 5.6, 5.7.0-5.7.18, and 8.0.0-8.0.1, this flag is always set.
948 Starting in 5.7.19 and 8.0.2, this flag is cleared if the transaction
949 only contains row events. It is set if any part of the transaction is
950 written in statement format.</td>
951 </tr>
952 <tr>
953 <td>SID</td>
954 <td>16 byte sequence</td>
955 <td>UUID representing the SID</td>
956 </tr>
957 <tr>
958 <td>GNO</td>
959 <td>8 byte integer</td>
960 <td>Group number, second component of GTID.</td>
961 </tr>
962 <tr>
963 <td>logical clock timestamp typecode</td>
964 <td>1 byte integer</td>
965 <td>The type of logical timestamp used in the logical clock fields.</td>
966 </tr>
967 <tr>
968 <td>last_committed</td>
969 <td>8 byte integer</td>
970 <td>Store the transaction's commit parent sequence_number</td>
971 </tr>
972 <tr>
973 <td>sequence_number</td>
974 <td>8 byte integer</td>
975 <td>The transaction's logical timestamp assigned at prepare phase</td>
976 </tr>
977 <tr>
978 <td>immediate_commit_timestamp</td>
979 <td>7 byte integer</td>
980 <td>Timestamp of commit on the immediate master</td>
981 </tr>
982 <tr>
983 <td>original_commit_timestamp</td>
984 <td>7 byte integer</td>
985 <td>Timestamp of commit on the originating master</td>
986 </tr>
987 <tr>
988 <td>transaction_length</td>
989 <td>1 to 9 byte integer // See net_length_size(ulonglong num)</td>
990 <td>The packed transaction's length in bytes, including the Gtid</td>
991 </tr>
992 <tr>
993 <td>immediate_server_version</td>
994 <td>4 byte integer</td>
995 <td>Server version of the immediate server</td>
996 </tr>
997 <tr>
998 <td>original_server_version</td>
999 <td>4 byte integer</td>
1000 <td>Version of the server where the transaction was originally executed</td>
1001 </tr>
1002 </table>
1003
1004*/
1006 public:
1007 /*
1008 The transaction's logical timestamps used for MTS: see
1009 Transaction_ctx::last_committed and
1010 Transaction_ctx::sequence_number for details.
1011 Note: Transaction_ctx is in the MySQL server code.
1012 */
1013 long long int last_committed;
1014 long long int sequence_number;
1015 /** GTID flags constants */
1016 unsigned const char FLAG_MAY_HAVE_SBR = 1;
1017 /** Transaction might have changes logged with SBR */
1019 /** Timestamp when the transaction was committed on the originating master. */
1020 unsigned long long int original_commit_timestamp;
1021 /** Timestamp when the transaction was committed on the nearest master. */
1022 unsigned long long int immediate_commit_timestamp;
1024 /** The length of the transaction in bytes. */
1025 unsigned long long int transaction_length;
1026
1027 public:
1028 /**
1029 Ctor of Gtid_event
1030
1031 The layout of the buffer is as follows
1032 <pre>
1033 +----------+---+---+-------+--------------+---------+----------+
1034 |gtid flags|SID|GNO|TS_TYPE|logical ts(:s)|commit ts|trx length|
1035 +----------+---+---+-------+------------------------+----------+
1036 </pre>
1037 TS_TYPE is from {G_COMMIT_TS2} singleton set of values
1038 Details on commit timestamps in Gtid_event(const char*...)
1039
1040 @param buf Contains the serialized event.
1041 @param fde An FDE event (see Rotate_event constructor for more info).
1042 */
1043
1044 Gtid_event(const char *buf, const Format_description_event *fde);
1045 /**
1046 Constructor.
1047 */
1048 explicit Gtid_event(long long int last_committed_arg,
1049 long long int sequence_number_arg,
1050 bool may_have_sbr_stmts_arg,
1051 unsigned long long int original_commit_timestamp_arg,
1052 unsigned long long int immediate_commit_timestamp_arg,
1053 uint32_t original_server_version_arg,
1054 uint32_t immediate_server_version_arg)
1056 last_committed(last_committed_arg),
1057 sequence_number(sequence_number_arg),
1058 may_have_sbr_stmts(may_have_sbr_stmts_arg),
1059 original_commit_timestamp(original_commit_timestamp_arg),
1060 immediate_commit_timestamp(immediate_commit_timestamp_arg),
1062 original_server_version(original_server_version_arg),
1063 immediate_server_version(immediate_server_version_arg) {}
1064#ifndef HAVE_MYSYS
1065 // TODO(WL#7684): Implement the method print_event_info and print_long_info
1066 // for all the events supported in MySQL Binlog
1067 void print_event_info(std::ostream &) override {}
1068 void print_long_info(std::ostream &) override {}
1069#endif
1070 /*
1071 Commit group ticket consists of: 1st bit, used internally for
1072 synchronization purposes ("is in use"), followed by 63 bits for
1073 the ticket value.
1074 */
1075 static constexpr int COMMIT_GROUP_TICKET_LENGTH = 8;
1076 /*
1077 Default value of commit_group_ticket, which means it is not
1078 being used.
1079 */
1080 static constexpr std::uint64_t kGroupTicketUnset = 0;
1081
1082 protected:
1083 static const int ENCODED_FLAG_LENGTH = 1;
1084 static const int ENCODED_SID_LENGTH = 16; // Uuid::BYTE_LENGTH;
1085 static const int ENCODED_GNO_LENGTH = 8;
1086 /// Length of typecode for logical timestamps.
1088 /// Length of two logical timestamps.
1089 static const int LOGICAL_TIMESTAMP_LENGTH = 16;
1090 // Type code used before the logical timestamps.
1091 static const int LOGICAL_TIMESTAMP_TYPECODE = 2;
1092
1095 // Length of two timestamps (from original/immediate masters)
1098 // We use 7 bytes out of which 1 bit is used as a flag.
1099 static const int ENCODED_COMMIT_TIMESTAMP_LENGTH = 55;
1100 // Minimum and maximum lengths of transaction length field.
1101 static const int TRANSACTION_LENGTH_MIN_LENGTH = 1;
1102 static const int TRANSACTION_LENGTH_MAX_LENGTH = 9;
1103 /// Length of original_server_version
1105 /// Length of immediate_server_version
1107 /// Length of original and immediate server version
1110 // We use 4 bytes out of which 1 bit is used as a flag.
1111 static const int ENCODED_SERVER_VERSION_LENGTH = 31;
1112
1113 /* We have only original commit timestamp if both timestamps are equal. */
1118 }
1119
1120 /**
1121 We only store the immediate_server_version if both server versions are the
1122 same.
1123 */
1128 }
1129
1132
1133 /* Minimum GNO expected in a serialized GTID event */
1134 static const int64_t MIN_GNO = 1;
1135 /// One-past-the-max value of GNO
1136 static const std::int64_t GNO_END = INT64_MAX;
1137
1138 public:
1139 virtual std::int64_t get_gno() const { return gtid_info_struct.rpl_gtid_gno; }
1141 /// Total length of post header
1142 static const int POST_HEADER_LENGTH =
1143 ENCODED_FLAG_LENGTH + /* flags */
1144 ENCODED_SID_LENGTH + /* SID length */
1145 ENCODED_GNO_LENGTH + /* GNO length */
1146 LOGICAL_TIMESTAMP_TYPECODE_LENGTH + /* length of typecode */
1147 LOGICAL_TIMESTAMP_LENGTH; /* length of two logical timestamps */
1148
1149 /*
1150 We keep the commit timestamps in the body section because they can be of
1151 variable length.
1152 On the originating master, the event has only one timestamp as the two
1153 timestamps are equal. On every other server we have two timestamps.
1154 */
1155 static const int MAX_DATA_LENGTH =
1158 COMMIT_GROUP_TICKET_LENGTH; /* 64-bit unsigned integer */
1159
1160 static const int MAX_EVENT_LENGTH =
1162 /**
1163 Set the transaction length information.
1164
1165 This function should be used when the full transaction length (including
1166 the Gtid event length) is known.
1167
1168 @param transaction_length_arg The transaction length.
1169 */
1170 void set_trx_length(unsigned long long int transaction_length_arg) {
1171 transaction_length = transaction_length_arg;
1172 }
1173
1174 /** The version of the server where the transaction was originally executed */
1176 /** The version of the immediate server */
1178
1179 /** Ticket number used to group sessions together during the BGC. */
1181
1182 /**
1183 Returns the length of the packed `commit_group_ticket` field. It may be
1184 8 bytes or 0 bytes, depending on whether or not the value is
1185 instantiated.
1186
1187 @return The length of the packed `commit_group_ticket` field
1188 */
1190
1191 /**
1192 Set the commit_group_ticket and update the transaction length if
1193 needed, that is, if the commit_group_ticket was not set already
1194 account it on the transaction size.
1195
1196 @param value The commit_group_ticket value.
1197 */
1199 std::uint64_t value);
1200};
1201
1202/**
1203 @class Previous_gtids_event
1204
1205 @section Previous_gtids_event_binary_format Binary Format
1206
1207 The Post-Header for this event type is empty. The Body has two
1208 components:
1209
1210 <table>
1211 <caption>Body for Previous_gtids_event</caption>
1212
1213 <tr>
1214 <th>Name</th>
1215 <th>Format</th>
1216 <th>Description</th>
1217 </tr>
1218
1219 <tr>
1220 <td>buf</td>
1221 <td>unsigned char array</td>
1222 <td>It contains the Gtids executed in the
1223 last binary log file.</td>
1224 </tr>
1225
1226 <tr>
1227 <td>buf_size</td>
1228 <td>4 byte integer</td>
1229 <td>Size of the above buffer</td>
1230 </tr>
1231 </table>
1232*/
1234 public:
1235 /**
1236 Decodes the gtid_executed in the last binlog file
1237
1238 <pre>
1239 The buffer layout is as follows
1240 +--------------------------------------------+
1241 | Gtids executed in the last binary log file |
1242 +--------------------------------------------+
1243 </pre>
1244 @param buf Contains the serialized event.
1245 @param fde An FDE event (see Rotate_event constructor for more info).
1246 */
1247 Previous_gtids_event(const char *buf, const Format_description_event *fde);
1248 /**
1249 This is the minimal constructor, and set the
1250 type_code as PREVIOUS_GTIDS_LOG_EVENT in the header object in
1251 Binary_log_event
1252 */
1254#ifndef HAVE_MYSYS
1255 // TODO(WL#7684): Implement the method print_event_info and print_long_info
1256 // for all the events supported in MySQL Binlog
1257 void print_event_info(std::ostream &) override {}
1258 void print_long_info(std::ostream &) override {}
1259#endif
1260 protected:
1261 size_t buf_size;
1262 const unsigned char *buf;
1263};
1264
1265/**
1266 @class Transaction_context_event
1267
1268 This class is used to combine the information of the ongoing transaction
1269 including the write set and other information of the thread executing the
1270 transaction.
1271
1272 <tr>
1273 <th>Name</th>
1274 <th>Format</th>
1275 <th>Description</th>
1276 </tr>
1277
1278 <tr>
1279 <td>thread_id</td>
1280 <td>4 byte integer</td>
1281 <td>The identifier for the thread executing the transaction.</td>
1282 </tr>
1283
1284 <tr>
1285 <td>gtid_specified</td>
1286 <td>bool type variable</td>
1287 <td>Variable to identify whether the Gtid have been specified for the
1288 ongoing transaction or not.
1289 </td>
1290 </tr>
1291
1292 <tr>
1293 <td>encoded_snapshot_version</td>
1294 <td>unsigned char array</td>
1295 <td>A gtid_set which is used to store the transaction set used for
1296 conflict detection.</td>
1297 </tr>
1298
1299 <tr>
1300 <td>encoded_snapshot_version_length</td>
1301 <td>4 byte integer</td>
1302 <td>Length of the above char array.</td>
1303 </tr>
1304
1305 <tr>
1306 <td>write_set</td>
1307 <td>variable length list to store the hash values. </td>
1308 <td>Used to store the hash values of the rows identifier for the rows
1309 which have changed in the ongoing transaction.
1310 </td>
1311 </tr>
1312
1313 <tr>
1314 <td>read_set</td>
1315 <td>variable length list to store the read set values. Currently empty.
1316 </td> <td>Will be used to store the read set values of the current
1317 transaction.</td>
1318 </tr>
1319
1320*/
1322 public:
1323 /**
1324 Decodes the transaction_context_log_event of the ongoing transaction.
1325
1326 <pre>
1327 The buffer layout is as follows
1328 </pre>
1329
1330 @param buf Contains the serialized event.
1331 @param fde An FDE event (see Rotate_event constructor for more info).
1332 */
1333 Transaction_context_event(const char *buf,
1334 const Format_description_event *fde);
1335
1336 Transaction_context_event(unsigned int thread_id_arg,
1337 bool is_gtid_specified_arg)
1339 thread_id(thread_id_arg),
1340 gtid_specified(is_gtid_specified_arg) {}
1341
1342 ~Transaction_context_event() override;
1343
1344 static const char *read_data_set(const char *pos, uint32_t set_len,
1345 std::list<const char *> *set,
1346 uint32_t remaining_buffer);
1347
1348 static void clear_set(std::list<const char *> *set);
1349
1350#ifndef HAVE_MYSYS
1351 void print_event_info(std::ostream &) override {}
1352 void print_long_info(std::ostream &) override {}
1353#endif
1354
1355 protected:
1356 const char *server_uuid;
1357 uint32_t thread_id;
1359 const unsigned char *encoded_snapshot_version;
1361 std::list<const char *> write_set;
1362 std::list<const char *> read_set;
1363
1364 // The values mentioned on the next class constants is the offset where the
1365 // data that will be copied in the buffer.
1366
1367 // 1 byte length.
1369 // 4 bytes length.
1370 static const int ENCODED_THREAD_ID_OFFSET = 1;
1371 // 1 byte length.
1372 static const int ENCODED_GTID_SPECIFIED_OFFSET = 5;
1373 // 4 bytes length
1375 // 4 bytes length.
1376 static const int ENCODED_WRITE_SET_ITEMS_OFFSET = 10;
1377 // 4 bytes length.
1378 static const int ENCODED_READ_SET_ITEMS_OFFSET = 14;
1379
1380 // The values mentioned on the next class's constants is the length of the
1381 // data that will be copied in the buffer.
1383 static const int ENCODED_SNAPSHOT_VERSION_LEN = 2;
1384};
1385
1386/**
1387 @class View_change_event
1388
1389 This class is used to add view change markers in the binary log when a
1390 member of the group enters or leaves the group.
1391
1392 <tr>
1393 <th>Name</th>
1394 <th>Format</th>
1395 <th>Description</th>
1396 </tr>
1397
1398 <tr>
1399 <td>view_id</td>
1400 <td>40 length character array</td>
1401 <td>This is used to store the view id value of the new view change when a
1402 node add or leaves the group.
1403 </td>
1404 </tr>
1405
1406 <tr>
1407 <td>seq_number</td>
1408 <td>8 bytes integer</td>
1409 <td>Variable to identify the next sequence number to be allotted to the
1410 certified transaction.</td>
1411 </tr>
1412
1413 <tr>
1414 <td>certification_info</td>
1415 <td>variable length map to store the certification data.</td>
1416 <td>Map to store the certification info ie. the hash of write_set and the
1417 snapshot sequence value.
1418 </td>
1419 </tr>
1420
1421*/
1423 public:
1424 /**
1425 Decodes the view_change_log_event generated in case a server enters or
1426 leaves the group.
1427
1428 <pre>
1429 The buffer layout is as follows
1430 </pre>
1431
1432 @param buf Contains the serialized event.
1433 @param fde An FDE event (see Rotate_event constructor for more info).
1434 */
1435 View_change_event(const char *buf, const Format_description_event *fde);
1436
1437 explicit View_change_event(const char *raw_view_id);
1438
1439 ~View_change_event() override;
1440
1441#ifndef HAVE_MYSYS
1442 void print_event_info(std::ostream &) override {}
1443 void print_long_info(std::ostream &) override {}
1444#endif
1445
1446 protected:
1447 // The values mentioned on the next class constants is the offset where the
1448 // data that will be copied in the buffer.
1449
1450 // 40 bytes length.
1451 static const int ENCODED_VIEW_ID_OFFSET = 0;
1452 // 8 bytes length.
1453 static const int ENCODED_SEQ_NUMBER_OFFSET = 40;
1454 // 4 bytes length.
1455 static const int ENCODED_CERT_INFO_SIZE_OFFSET = 48;
1456
1457 /*
1458 The layout of the buffer is as follows
1459 +--------------------- -+-------------+----------+
1460 | View Id | seq number | map size |
1461 +-----------------------+-------------+----------+
1462 view id (40 bytes) + seq number (8 bytes) + map size (4 bytes)
1463 Sum of the length of the values at the above OFFSETS.
1464 */
1465
1466 // The values mentioned on the next class constants is the length of the data
1467 // that will be copied in the buffer.
1468
1469 // Field sizes on serialization
1470 static const int ENCODED_VIEW_ID_MAX_LEN = 40;
1472 static const int ENCODED_CERT_INFO_VALUE_LEN = 4;
1473
1475
1476 long long int seq_number;
1477
1478 std::map<std::string, std::string> certification_info;
1479};
1480
1481/**
1482 @class Heartbeat_event_v2
1483
1484 Replication event to ensure to replica that source is alive.
1485 The event is originated by source's dump thread and sent straight to
1486 replica without being logged. Slave itself does not store it in relay log
1487 but rather uses a data for immediate checks and throws away the event.
1488
1489 Two members of the class m_log_filename and m_log_position comprise
1490 @see the rpl_event_coordinates instance. The coordinates that a heartbeat
1491 instance carries correspond to the last event source has sent from
1492 its binlog.
1493
1494 Also this event will be generated only for the source server with
1495 version > 8.0.26
1496
1497 @section Heartbeat_event_v2_binary_format Binary Format
1498
1499 The Body has one component:
1500
1501 <table>
1502 <caption>Body for Heartbeat_event</caption>
1503
1504 <tr>
1505 <th>Name</th>
1506 <th>Format</th>
1507 <th>Description</th>
1508 </tr>
1509
1510 <tr>
1511 <td>m_log_filename</td>
1512 <td>String variable to store the binlog name</td>
1513 <td>Name of the current binlog being written to.</td>
1514 </tr>
1515 <tr>
1516 <td>m_log_pos</td>
1517 <td>8 byte unsigned integar</td>
1518 <td>Name of the current binlog being written to.</td>
1519 </tr>
1520 </table>
1521*/
1522
1524 public:
1525 /**
1526 Sent by a source to a replica to let the replica know that the source is
1527 still alive. Events of this type do not appear in the binary or relay logs.
1528 They are generated on a source server by the thread that dumps events and
1529 sent straight to the replica without ever being written to the binary log.
1530
1531 @param buf Contains the serialized event.
1532 @param fde An FDE event (see Rotate_event constructor for more info).
1533 */
1534 Heartbeat_event_v2(const char *buf, const Format_description_event *fde);
1535
1536 /**
1537 Creates an empty heartbeat event.
1538 */
1540
1541 virtual ~Heartbeat_event_v2() override = default;
1542
1543 // Set the binlog filename
1544 void set_log_filename(const std::string name);
1545 // Set the position
1546 void set_log_position(uint64_t position);
1547 // Return the binlog filename
1548 const std::string get_log_filename() const;
1549 // Return the position
1550 uint64_t get_log_position() const;
1551
1552 // Return the max length of an encoded packet.
1553 static uint64_t max_encoding_length();
1554#ifndef HAVE_MYSYS
1555 void print_event_info(std::ostream &info) override;
1556 void print_long_info(std::ostream &info) override;
1557#endif
1558 protected:
1559 std::string m_log_filename{};
1560 uint64_t m_log_position{0};
1561};
1562
1563/**
1564 @class Heartbeat_event
1565
1566 Replication event to ensure to replica that source is alive.
1567 The event is originated by source's dump thread and sent straight to
1568 replica without being logged. Slave itself does not store it in relay log
1569 but rather uses a data for immediate checks and throws away the event.
1570
1571 Two members of the class log_ident and Binary_log_event::log_pos comprise
1572 @see the rpl_event_coordinates instance. The coordinates that a heartbeat
1573 instance carries correspond to the last event source has sent from
1574 its binlog.
1575
1576 @section Heartbeat_event_binary_format Binary Format
1577
1578 The Body has one component:
1579
1580 <table>
1581 <caption>Body for Heartbeat_event</caption>
1582
1583 <tr>
1584 <th>Name</th>
1585 <th>Format</th>
1586 <th>Description</th>
1587 </tr>
1588
1589 <tr>
1590 <td>log_ident</td>
1591 <td>variable length string without trailing zero, extending to the
1592 end of the event</td>
1593 <td>Name of the current binlog being written to.</td>
1594 </tr>
1595 </table>
1596*/
1598 public:
1599 /**
1600 Sent by a source to a replica to let the replica know that the source is
1601 still alive. Events of this type do not appear in the binary or relay logs.
1602 They are generated on a source server by the thread that dumps events and
1603 sent straight to the replica without ever being written to the binary log.
1604
1605 @param buf Contains the serialized event.
1606 @param fde An FDE event (see Rotate_event constructor for more info).
1607 */
1608 Heartbeat_event(const char *buf, const Format_description_event *fde);
1609
1610 // Return the file name
1611 const char *get_log_ident() { return log_ident; }
1612 // Return the length of file name
1613 unsigned int get_ident_len() { return ident_len; }
1614
1615 protected:
1616 const char *log_ident;
1617 unsigned int ident_len; /** filename length */
1618};
1619
1620} // end namespace binary_log
1621/**
1622 @} (end of group Replication)
1623*/
1624#endif /* CONTROL_EVENTS_INCLUDED */
Contains the classes representing events occurring in the replication stream.
#define LOG_EVENT_HEADER_LEN
Definition: binlog_event.h:414
#define LOG_EVENT_MINIMAL_HEADER_LEN
Fixed header length, where 4.x and 5.0 agree.
Definition: binlog_event.h:428
#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:396
Container class that provides a sequence of buffers to the caller.
This is the abstract base class for binary log events.
Definition: binlog_event.h:819
@ TRANSACTION_PAYLOAD_HEADER_LEN
Definition: binlog_event.h:861
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:1005
long long int sequence_number
Definition: control_events.h:1014
static const int POST_HEADER_LENGTH
Total length of post header.
Definition: control_events.h:1142
static const int LOGICAL_TIMESTAMP_TYPECODE_LENGTH
Length of typecode for logical timestamps.
Definition: control_events.h:1087
static const int ENCODED_GNO_LENGTH
Definition: control_events.h:1085
virtual std::int64_t get_gno() const
Definition: control_events.h:1139
static const int LOGICAL_TIMESTAMP_TYPECODE
Definition: control_events.h:1091
static const int ENCODED_SERVER_VERSION_LENGTH
Definition: control_events.h:1111
bool may_have_sbr_stmts
Transaction might have changes logged with SBR.
Definition: control_events.h:1018
static const int ORIGINAL_COMMIT_TIMESTAMP_LENGTH
Definition: control_events.h:1094
static const int TRANSACTION_LENGTH_MIN_LENGTH
Definition: control_events.h:1101
Uuid get_uuid() const
Definition: control_events.h:1140
uint32_t original_server_version
The version of the server where the transaction was originally executed.
Definition: control_events.h:1175
unsigned long long int original_commit_timestamp
Timestamp when the transaction was committed on the originating master.
Definition: control_events.h:1020
static const int ORIGINAL_SERVER_VERSION_LENGTH
Length of original_server_version.
Definition: control_events.h:1104
int get_commit_group_ticket_length() const
Returns the length of the packed commit_group_ticket field.
Definition: control_events.cpp:574
unsigned long long int immediate_commit_timestamp
Timestamp when the transaction was committed on the nearest master.
Definition: control_events.h:1022
static const int ENCODED_SID_LENGTH
Definition: control_events.h:1084
int get_server_version_length() const
We only store the immediate_server_version if both server versions are the same.
Definition: control_events.h:1124
static const int FULL_COMMIT_TIMESTAMP_LENGTH
Definition: control_events.h:1096
static const int TRANSACTION_LENGTH_MAX_LENGTH
Definition: control_events.h:1102
static const int FULL_SERVER_VERSION_LENGTH
Length of original and immediate server version.
Definition: control_events.h:1108
gtid_info gtid_info_struct
Definition: control_events.h:1130
static const int ENCODED_COMMIT_TIMESTAMP_LENGTH
Definition: control_events.h:1099
static const int IMMEDIATE_COMMIT_TIMESTAMP_LENGTH
Definition: control_events.h:1093
uint32_t immediate_server_version
The version of the immediate server.
Definition: control_events.h:1177
Gtid_event(const char *buf, const Format_description_event *fde)
Ctor of Gtid_event.
Definition: control_events.cpp:417
int get_commit_timestamp_length() const
Definition: control_events.h:1114
static const int64_t MIN_GNO
Definition: control_events.h:1134
static constexpr int COMMIT_GROUP_TICKET_LENGTH
Definition: control_events.h:1075
unsigned const char FLAG_MAY_HAVE_SBR
GTID flags constants.
Definition: control_events.h:1016
bool has_commit_timestamps
Definition: control_events.h:1023
long long int last_committed
Definition: control_events.h:1013
std::uint64_t commit_group_ticket
Ticket number used to group sessions together during the BGC.
Definition: control_events.h:1180
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:1048
static constexpr std::uint64_t kGroupTicketUnset
Definition: control_events.h:1080
static const int IMMEDIATE_SERVER_VERSION_LENGTH
Length of immediate_server_version.
Definition: control_events.h:1106
static const int MAX_DATA_LENGTH
Definition: control_events.h:1155
static const int MAX_EVENT_LENGTH
Definition: control_events.h:1160
static const int ENCODED_FLAG_LENGTH
Definition: control_events.h:1083
Uuid Uuid_parent_struct
Definition: control_events.h:1131
unsigned long long int transaction_length
The length of the transaction in bytes.
Definition: control_events.h:1025
static const int LOGICAL_TIMESTAMP_LENGTH
Length of two logical timestamps.
Definition: control_events.h:1089
void set_trx_length(unsigned long long int transaction_length_arg)
Set the transaction length information.
Definition: control_events.h:1170
static const std::int64_t GNO_END
One-past-the-max value of GNO.
Definition: control_events.h:1136
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:581
Replication event to ensure to replica that source is alive.
Definition: control_events.h:1523
void set_log_position(uint64_t position)
Definition: control_events.cpp:744
uint64_t get_log_position() const
Definition: control_events.cpp:750
uint64_t m_log_position
Definition: control_events.h:1560
static uint64_t max_encoding_length()
This member function returns the len of the event.
Definition: control_events.cpp:757
virtual ~Heartbeat_event_v2() override=default
const std::string get_log_filename() const
Definition: control_events.cpp:747
std::string m_log_filename
Definition: control_events.h:1559
Heartbeat_event_v2()
Creates an empty heartbeat event.
Definition: control_events.cpp:738
void set_log_filename(const std::string name)
Definition: control_events.cpp:741
Replication event to ensure to replica that source is alive.
Definition: control_events.h:1597
unsigned int ident_len
Definition: control_events.h:1617
const char * log_ident
Definition: control_events.h:1616
unsigned int get_ident_len()
Definition: control_events.h:1613
const char * get_log_ident()
Definition: control_events.h:1611
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:703
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:1233
size_t buf_size
Definition: control_events.h:1261
const unsigned char * buf
Definition: control_events.h:1262
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:1253
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:1321
static const int ENCODED_SNAPSHOT_VERSION_LEN_OFFSET
Definition: control_events.h:1374
uint32_t encoded_snapshot_version_length
Definition: control_events.h:1360
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:1370
static const int ENCODED_SERVER_UUID_LEN_OFFSET
Definition: control_events.h:1368
const unsigned char * encoded_snapshot_version
Definition: control_events.h:1359
std::list< const char * > write_set
Definition: control_events.h:1361
Transaction_context_event(unsigned int thread_id_arg, bool is_gtid_specified_arg)
Definition: control_events.h:1336
static const int ENCODED_GTID_SPECIFIED_OFFSET
Definition: control_events.h:1372
static const int ENCODED_READ_WRITE_SET_ITEM_LEN
Definition: control_events.h:1382
std::list< const char * > read_set
Definition: control_events.h:1362
const char * server_uuid
Definition: control_events.h:1356
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:609
static const int ENCODED_READ_SET_ITEMS_OFFSET
Definition: control_events.h:1378
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:647
uint32_t thread_id
Definition: control_events.h:1357
bool gtid_specified
Definition: control_events.h:1358
~Transaction_context_event() override
Destructor of the Transaction_context_event class.
Definition: control_events.cpp:657
static const int ENCODED_SNAPSHOT_VERSION_LEN
Definition: control_events.h:1383
static const int ENCODED_WRITE_SET_ITEMS_OFFSET
Definition: control_events.h:1376
Event that encloses all the events of a transaction.
Definition: control_events.h:726
uint64_t m_uncompressed_size
The uncompressed size of the data.
Definition: control_events.h:751
const char * m_payload
The compressed data, when entire payload is in one chunk.
Definition: control_events.h:737
uint64_t m_payload_size
The size of the compressed data.
Definition: control_events.h:743
static constexpr size_t end_mark_max_length
Definition: control_events.h:780
static constexpr size_t compression_type_max_length
There are four fields: "compression type", "payload size", "uncompressed size", and "end mark".
Definition: control_events.h:777
static constexpr size_t uncompressed_size_max_length
Definition: control_events.h:779
uint64_t get_payload_size() const
Definition: control_events.h:861
void set_compression_type(transaction::compression::type type)
Set the compression type used for the enclosed payload.
Definition: control_events.h:842
static constexpr size_t payload_size_max_length
Definition: control_events.h:778
transaction::compression::type get_compression_type() const
Definition: control_events.h:847
static constexpr size_t max_length_of_all_headers
The maximum size of all headers, i.e., everything but the payload.
Definition: control_events.h:799
uint64_t get_uncompressed_size() const
Return the alleged uncompressed size according to the field stored in the event.
Definition: control_events.h:877
static constexpr size_t max_payload_length
The maximum length of the payload size, defined such that the total event size does not exceed max_lo...
Definition: control_events.h:804
const char * get_payload() const
Definition: control_events.h:892
mysqlns::buffer::Buffer_sequence_view<> Buffer_sequence_view_t
Definition: control_events.h:728
static constexpr size_t max_payload_data_header_length
The maximum size of the "payload data header".
Definition: control_events.h:790
void set_uncompressed_size(uint64_t size)
Set the uncompressed size of the payload.
Definition: control_events.h:870
void set_payload(const char *data)
Set the (possibly compressed) payload for the event.
Definition: control_events.h:889
Transaction_payload_event & operator=(const Transaction_payload_event &)=delete
Buffer_sequence_view_t * m_buffer_sequence_view
The compressed data, when payload consists of a sequence of buffers.
Definition: control_events.h:740
std::string to_string() const
Definition: control_events.cpp:389
void set_payload_size(uint64_t size)
Set the (compressed) size of the payload in this event.
Definition: control_events.h:858
transaction::compression::type m_compression_type
The compression algorithm that was used.
Definition: control_events.h:746
Transaction_payload_event(const Transaction_payload_event &)=delete
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:1422
static const int ENCODED_CERT_INFO_KEY_SIZE_LEN
Definition: control_events.h:1471
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:676
static const int ENCODED_SEQ_NUMBER_OFFSET
Definition: control_events.h:1453
char view_id[ENCODED_VIEW_ID_MAX_LEN]
Definition: control_events.h:1474
static const int ENCODED_CERT_INFO_SIZE_OFFSET
Definition: control_events.h:1455
static const int ENCODED_CERT_INFO_VALUE_LEN
Definition: control_events.h:1472
static const int ENCODED_VIEW_ID_MAX_LEN
Definition: control_events.h:1470
std::map< std::string, std::string > certification_info
Definition: control_events.h:1478
static const int ENCODED_VIEW_ID_OFFSET
Definition: control_events.h:1451
long long int seq_number
Definition: control_events.h:1476
~View_change_event() override
Destructor of the View_change_event class.
Definition: control_events.cpp:701
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
Sequence of memory buffers.
Definition: buffer_sequence_view.h:71
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.
constexpr size_t max_log_event_size
The maximum value for MAX_ALLOWED_PACKET.
Definition: binlog_event.h:419
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:2881
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:211