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