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