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