MySQL  8.0.21
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 
349 
350  /**
351  Add new events here - right above this comment!
352  Existing events (except ENUM_END_EVENT) should never change their numbers
353  */
354  ENUM_END_EVENT /* end marker */
355 };
356 
357 /**
358  Struct to pass basic information about a event: type, query, is it ignorable
359 */
362  const char *query{nullptr};
363  size_t query_length{0};
364  bool ignorable_event{false};
365 };
366 
367 /**
368  The length of the array server_version, which is used to store the version
369  of MySQL server.
370  We could have used SERVER_VERSION_LENGTH, but this introduces an
371  obscure dependency - if somebody decided to change SERVER_VERSION_LENGTH
372  this would break the replication protocol
373  both of these are used to initialize the array server_version
374  SERVER_VERSION_LENGTH is used for global array server_version
375  and ST_SERVER_VER_LEN for the Start_event_v3 member server_version
376 */
377 
378 #define ST_SERVER_VER_LEN 50
379 
380 /*
381  Event header offsets;
382  these point to places inside the fixed header.
383 */
384 #define EVENT_TYPE_OFFSET 4
385 #define SERVER_ID_OFFSET 5
386 #define EVENT_LEN_OFFSET 9
387 #define LOG_POS_OFFSET 13
388 #define FLAGS_OFFSET 17
389 
390 /** start event post-header (for v3 and v4) */
391 #define ST_BINLOG_VER_OFFSET 0
392 #define ST_SERVER_VER_OFFSET 2
393 #define ST_CREATED_OFFSET (ST_SERVER_VER_OFFSET + ST_SERVER_VER_LEN)
394 #define ST_COMMON_HEADER_LEN_OFFSET (ST_CREATED_OFFSET + 4)
395 
396 #define LOG_EVENT_HEADER_LEN 19U /* the fixed header length */
397 
398 /**
399  Fixed header length, where 4.x and 5.0 agree. That is, 5.0 may have a longer
400  header (it will for sure when we have the unique event's ID), but at least
401  the first 19 bytes are the same in 4.x and 5.0. So when we have the unique
402  event's ID, LOG_EVENT_HEADER_LEN will be something like 26, but
403  LOG_EVENT_MINIMAL_HEADER_LEN will remain 19.
404 */
405 #define LOG_EVENT_MINIMAL_HEADER_LEN 19U
406 
407 /**
408  Enumeration spcifying checksum algorithm used to encode a binary log event
409 */
411  /**
412  Events are without checksum though its generator is checksum-capable
413  New Master (NM).
414  */
416  /** CRC32 of zlib algorithm */
418  /** the cut line: valid alg range is [1, 0x7f] */
420  /**
421  Special value to tag undetermined yet checksum or events from
422  checksum-unaware servers
423  */
425 };
426 
427 #define CHECKSUM_CRC32_SIGNATURE_LEN 4
428 
429 /**
430  defined statically while there is just one alg implemented
431 */
432 #define BINLOG_CHECKSUM_LEN CHECKSUM_CRC32_SIGNATURE_LEN
433 #define BINLOG_CHECKSUM_ALG_DESC_LEN 1 /* 1 byte checksum alg descriptor */
434 #define LOG_EVENT_HEADER_SIZE 20
435 
436 /**
437  Calculate a long checksum for a memoryblock.
438 
439  @param crc start value for crc
440  @param pos pointer to memory block
441  @param length length of the block
442 
443  @return checksum for a memory block
444 */
445 inline uint32_t checksum_crc32(uint32_t crc, const unsigned char *pos,
446  size_t length) {
447  BAPI_ASSERT(length <= UINT_MAX);
448  return static_cast<uint32_t>(crc32(static_cast<unsigned int>(crc), pos,
449  static_cast<unsigned int>(length)));
450 }
451 
452 /*
453  Forward declaration of Format_description_event class to be used in class
454  Log_event_header
455 */
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  */
512  static enum_binlog_checksum_alg get_checksum_alg(Event_reader &reader);
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  */
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 
714  void set_is_valid(bool is_valid) { m_is_valid = is_valid; }
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.
814  QUERY_HEADER_LEN = (QUERY_HEADER_MINIMAL_LEN + 2),
815  STOP_HEADER_LEN = 0,
816  START_V3_HEADER_LEN = (2 + ST_SERVER_VER_LEN + 4),
817  // this is FROZEN (the Rotate post-header is frozen)
818  ROTATE_HEADER_LEN = 8,
819  INTVAR_HEADER_LEN = 0,
820  APPEND_BLOCK_HEADER_LEN = 4,
821  DELETE_FILE_HEADER_LEN = 4,
822  RAND_HEADER_LEN = 0,
823  USER_VAR_HEADER_LEN = 0,
824  FORMAT_DESCRIPTION_HEADER_LEN = (START_V3_HEADER_LEN + 1 + LOG_EVENT_TYPES),
825  XID_HEADER_LEN = 0,
826  BEGIN_LOAD_QUERY_HEADER_LEN = APPEND_BLOCK_HEADER_LEN,
827  ROWS_HEADER_LEN_V1 = 8,
828  TABLE_MAP_HEADER_LEN = 8,
829  EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN = (4 + 4 + 4 + 1),
830  EXECUTE_LOAD_QUERY_HEADER_LEN =
831  (QUERY_HEADER_LEN + EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN),
832  INCIDENT_HEADER_LEN = 2,
833  HEARTBEAT_HEADER_LEN = 0,
834  IGNORABLE_HEADER_LEN = 0,
835  ROWS_HEADER_LEN_V2 = 10,
836  TRANSACTION_CONTEXT_HEADER_LEN = 18,
837  VIEW_CHANGE_HEADER_LEN = 52,
838  XA_PREPARE_HEADER_LEN = 0,
839  TRANSACTION_PAYLOAD_HEADER_LEN = 0,
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;
885  Binary_log_event(Binary_log_event &&) = default;
886  Binary_log_event &operator=(const Binary_log_event &) = default;
887  Binary_log_event &operator=(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  */
901  Log_event_header *header() { return &m_header; }
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  */
909  Log_event_footer *footer() { return &m_footer; }
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);
946  void print_long_info(std::ostream &info);
947 #endif
948 };
949 } // end namespace binary_log
950 /**
951  @} (end of group Replication)
952 */
953 #endif /* BINLOG_EVENT_INCLUDED */
Definition: binlog_event.h:278
unsigned long long log_pos
Definition: binlog_event.h:665
Definition: binlog_event.h:302
Definition: binlog_event.h:303
Definition: binlog_event.h:340
unsigned int unmasked_server_id
Definition: binlog_event.h:655
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:921
This is the abstract base class for binary log events.
Definition: binlog_event.h:797
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
Version 2 of the Row events.
Definition: binlog_event.h:326
Event_reader m_reader
Definition: binlog_event.h:920
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
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
static WORD get_event_type(Monitor_log_msg_type type)
Map monitor msg type to corresponding event log type.
Definition: restart_monitor_win.cc:152
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:419
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:73
size_t data_written
Definition: binlog_event.h:658
char * pos
Definition: do_ctype.cc:76
Events are without checksum though its generator is checksum-capable New Master (NM).
Definition: binlog_event.h:415
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:445
An unknown event should never occur.
Definition: binlog_event.h:935
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
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: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:680
For binlog version 4.
Definition: control_events.h:230
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
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:417
Definition: binlog_event.h:331
#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:378
const mysql_service_registry_t * r
Definition: pfs_example_plugin_employee.cc:85
uint16_t flags
Definition: binlog_event.h:673
void set_is_valid(bool is_valid)
Set if the event object shall be considered valid or not.
Definition: binlog_event.h:714
Log_event_footer * footer()
Return a non-const pointer to the footer of the log event.
Definition: binlog_event.h:909
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:354
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:905
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:634
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:1235
Definition: binlog_event.h:330
bool m_is_valid
Definition: binlog_event.h:725
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:810
Definition: binlog_event.h:327
Special value to tag undetermined yet checksum or events from checksum-unaware servers.
Definition: binlog_event.h:424
Log info(cout, "NOTE")
Log_event_header * header()
Return a non-const pointer to the header of the log event.
Definition: binlog_event.h:901
Definition: binlog_event.h:293
Definition: binlog_event.h:337
bool ignorable_event
Definition: binlog_event.h:364
enum_binlog_checksum_alg
Enumeration spcifying checksum algorithm used to encode a binary log event.
Definition: binlog_event.h:410
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:848
Definition: binlog_event.h:328
Event_reader & reader()
Returns a reference to the event Event_reader object.
Definition: binlog_event.h:913
Definition: binlog_event.h:290
Log_event_header(Log_event_type type_code_arg=ENUM_END_EVENT)
Definition: binlog_event.h:682
const char * query
Definition: binlog_event.h:362
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:650
size_t query_length
Definition: binlog_event.h:363
Definition: binlog_event.h:296
Dialog Client Authentication nullptr
Definition: dialog.cc:353
const Log_event_header * header() const
Return a const pointer to the header of the log event.
Definition: binlog_event.h:897
Log_event_footer m_footer
Definition: binlog_event.h:922
Struct to pass basic information about a event: type, query, is it ignorable.
Definition: binlog_event.h:360
Definition: binlog_event.h:323
Definition: binlog_event.h:348