Skip to content

Commit 8865e79

Browse files
author
Neha Kumari
committed
WL#7440: Moving binlog decoding into separate package
Addressing review comments from Tor, the comments on value.h/cpp still to be fixed.
1 parent 9aa7c6e commit 8865e79

17 files changed

+627
-618
lines changed

cmake/os/WindowsCache.cmake

+1
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ SET(HAVE_SLEEP CACHE INTERNAL "")
127127
SET(HAVE_STPCPY CACHE INTERNAL "")
128128
SET(HAVE_STPNCPY CACHE INTERNAL "")
129129
SET(HAVE_STRLCPY CACHE INTERNAL "")
130+
SET(HAVE_STRNDUP CACHE INTERNAL "") # Used by libbinlogevents
130131
SET(HAVE_STRNLEN 1 CACHE INTERNAL "")
131132
SET(HAVE_STRLCAT CACHE INTERNAL "")
132133
SET(HAVE_STRSIGNAL CACHE INTERNAL "")

configure.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ CHECK_FUNCTION_EXISTS (sleep HAVE_SLEEP)
457457
CHECK_FUNCTION_EXISTS (stpcpy HAVE_STPCPY)
458458
CHECK_FUNCTION_EXISTS (stpncpy HAVE_STPNCPY)
459459
CHECK_FUNCTION_EXISTS (strlcpy HAVE_STRLCPY)
460-
CHECK_FUNCTION_EXISTS (strndup HAVE_STRNDUP)
460+
CHECK_FUNCTION_EXISTS (strndup HAVE_STRNDUP) # Used by libbinlogevents
461461
CHECK_FUNCTION_EXISTS (strnlen HAVE_STRNLEN)
462462
CHECK_FUNCTION_EXISTS (strlcat HAVE_STRLCAT)
463463
CHECK_FUNCTION_EXISTS (strsignal HAVE_STRSIGNAL)

libbinlogevents/include/binlog_event.h

+4-41
Original file line numberDiff line numberDiff line change
@@ -88,43 +88,6 @@
8888
*/
8989
#define BINLOG_VERSION 4
9090

91-
/**
92-
Check if jump value is within buffer limits.
93-
94-
@param jump Number of positions we want to advance.
95-
@param buf_start Pointer to buffer start.
96-
@param buf_current Pointer to the current position on buffer.
97-
@param buf_len Buffer length.
98-
99-
@return Number of bytes available on event buffer.
100-
*/
101-
template <class T> T available_buffer(const char* buf_start,
102-
const char* buf_current,
103-
T buf_len)
104-
{
105-
return buf_len - (buf_current - buf_start);
106-
}
107-
108-
109-
/**
110-
Check if jump value is within buffer limits.
111-
112-
@param jump Number of positions we want to advance.
113-
@param buf_start Pointer to buffer start
114-
@param buf_current Pointer to the current position on buffer.
115-
@param buf_len Buffer length.
116-
117-
@retval True If jump value is within buffer limits.
118-
@retval False Otherwise.
119-
*/
120-
template <class T> bool valid_buffer_range(T jump,
121-
const char* buf_start,
122-
const char* buf_current,
123-
T buf_len)
124-
{
125-
return (jump <= available_buffer(buf_start, buf_current, buf_len));
126-
}
127-
12891

12992
/**
13093
G_COMMIT_TS status variable stores the logical timestamp when the transaction
@@ -191,7 +154,7 @@ template <class T> bool valid_buffer_range(T jump,
191154
*/
192155
namespace binary_log
193156
{
194-
/**
157+
/*
195158
This flag only makes sense for Format_description_event. It is set
196159
when the event is written, and *reset* when a binlog file is
197160
closed (yes, it's the only case when MySQL modifies an already written
@@ -462,8 +425,8 @@ class Log_event_footer
462425
{
463426
public:
464427

465-
enum_binlog_checksum_alg
466-
static get_checksum_alg(const char* buf, unsigned long len);
428+
static enum_binlog_checksum_alg get_checksum_alg(const char* buf,
429+
unsigned long len);
467430

468431
static bool event_checksum_test(unsigned char* buf,
469432
unsigned long event_len,
@@ -801,7 +764,7 @@ class Binary_log_event
801764
*/
802765
enum Log_event_type get_event_type() const
803766
{
804-
return (enum Log_event_type) m_header.type_code;
767+
return m_header.type_code;
805768
}
806769

807770
/**

libbinlogevents/include/control_events.h

+32-109
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ class Rotate_event: public Binary_log_event
129129
130130
@param buf Contains the serialized event.
131131
@param length Length of the serialized event.
132-
@param description_event An FDE event, used to get the following information
132+
@param description_event An FDE event, used to get the
133+
following information
133134
-binlog_version
134135
-server_version
135136
-post_header_len
@@ -260,7 +261,8 @@ class Start_event_v3: public Binary_log_event
260261
</pre>
261262
262263
@param buf Contains the serialized event.
263-
@param description_event An FDE event, used to get the following information
264+
@param description_event An FDE event, used to get the
265+
following information
264266
-binlog_version
265267
-server_version
266268
-post_header_len
@@ -344,7 +346,7 @@ class Format_description_event: public virtual Start_event_v3
344346
The list of post-headers' lengths followed
345347
by the checksum alg decription byte
346348
*/
347-
uint8_t *post_header_len;
349+
std::vector<uint8_t> post_header_len;
348350
unsigned char server_version_split[ST_SERVER_VER_SPLIT_LEN];
349351
/**
350352
In some previous version > 5.1 GA event types are assigned
@@ -391,7 +393,8 @@ class Format_description_event: public virtual Start_event_v3
391393
</pre>
392394
@param buf Contains the serialized event.
393395
@param length Length of the serialized event.
394-
@param description_event An FDE event, used to get the following information
396+
@param description_event An FDE event, used to get the
397+
following information
395398
-binlog_version
396399
-server_version
397400
-post_header_len
@@ -447,7 +450,8 @@ class Stop_event: public Binary_log_event
447450
- A slave writes the event to the relay log when it shuts down or when a
448451
RESET SLAVE statement is executed
449452
@param buf Contains the serialized event.
450-
@param description_event An FDE event, used to get the following information
453+
@param description_event An FDE event, used to get the
454+
following information
451455
-binlog_version
452456
-server_version
453457
-post_header_len
@@ -557,7 +561,8 @@ class Incident_event: public Binary_log_event
557561
558562
@param buf Contains the serialized event.
559563
@param length Length of the serialized event.
560-
@param description_event An FDE event, used to get the following information
564+
@param description_event An FDE event, used to get the
565+
following information
561566
-binlog_version
562567
-server_version
563568
-post_header_len
@@ -610,8 +615,9 @@ class Xid_event: public Binary_log_event
610615
{
611616
public:
612617
/**
613-
The minimal constructor of Xid_event, it initializes the instance variable xid
614-
and set the type_code as XID_EVENT in the header object in Binary_log_event
618+
The minimal constructor of Xid_event, it initializes the instance variable
619+
xid and set the type_code as XID_EVENT in the header object in
620+
Binary_log_event
615621
*/
616622
explicit Xid_event(uint64_t xid_arg)
617623
: Binary_log_event(XID_EVENT),
@@ -623,7 +629,8 @@ class Xid_event: public Binary_log_event
623629
An XID event is generated for a commit of a transaction that modifies one or
624630
more tables of an XA-capable storage engine
625631
@param buf Contains the serialized event.
626-
@param description_event An FDE event, used to get the following information
632+
@param description_event An FDE event, used to get the
633+
following information
627634
-binlog_version
628635
-server_version
629636
-post_header_len
@@ -639,97 +646,6 @@ class Xid_event: public Binary_log_event
639646
#endif
640647
};
641648

642-
643-
/**
644-
@class Rand_event
645-
646-
Logs random seed used by the next RAND(), and by PASSWORD() in 4.1.0.
647-
4.1.1 does not need it (it's repeatable again) so this event needn't be
648-
written in 4.1.1 for PASSWORD() (but the fact that it is written is just a
649-
waste, it does not cause bugs).
650-
651-
The state of the random number generation consists of 128 bits,
652-
which are stored internally as two 64-bit numbers.
653-
654-
@section Rand_event_binary_format Binary Format
655-
656-
The Post-Header for this event type is empty. The Body has two
657-
components:
658-
659-
<table>
660-
<caption>Body for Rand_event</caption>
661-
662-
<tr>
663-
<th>Name</th>
664-
<th>Format</th>
665-
<th>Description</th>
666-
</tr>
667-
668-
<tr>
669-
<td>seed1</td>
670-
<td>8 byte unsigned integer</td>
671-
<td>64 bit random seed1.</td>
672-
</tr>
673-
674-
<tr>
675-
<td>seed2</td>
676-
<td>8 byte unsigned integer</td>
677-
<td>64 bit random seed2.</td>
678-
</tr>
679-
</table>
680-
*/
681-
class Rand_event: public Binary_log_event
682-
{
683-
public:
684-
unsigned long long seed1;
685-
unsigned long long seed2;
686-
enum Rand_event_data
687-
{
688-
RAND_SEED1_OFFSET= 0,
689-
RAND_SEED2_OFFSET= 8
690-
};
691-
692-
/**
693-
This will initialize the instance variables seed1 & seed2, and set the
694-
type_code as RAND_EVENT in the header object in Binary_log_event
695-
*/
696-
Rand_event(unsigned long long seed1_arg, unsigned long long seed2_arg)
697-
: Binary_log_event(RAND_EVENT)
698-
{
699-
seed1= seed1_arg;
700-
seed2= seed2_arg;
701-
}
702-
703-
/**
704-
Written every time a statement uses the RAND() function; precedes other
705-
events for the statement. Indicates the seed values to use for generating a
706-
random number with RAND() in the next statement. This is written only before
707-
a QUERY_EVENT and is not used with row-based logging
708-
709-
<pre>
710-
The buffer layout for variable part is as follows:
711-
+----------------------------------------------+
712-
| value for first seed | value for second seed |
713-
+----------------------------------------------+
714-
</pre>
715-
@param buf Contains the serialized event.
716-
@param description_event An FDE event, used to get the following information
717-
-binlog_version
718-
-server_version
719-
-post_header_len
720-
-common_header_len
721-
The content of this object
722-
depends on the binlog-version currently in use.
723-
*/
724-
Rand_event(const char* buf,
725-
const Format_description_event *description_event);
726-
#ifndef HAVE_MYSYS
727-
void print_event_info(std::ostream& info);
728-
void print_long_info(std::ostream& info);
729-
#endif
730-
};
731-
732-
733649
/**
734650
@class Ignorable_event
735651
@@ -767,7 +683,8 @@ class Ignorable_event: public Binary_log_event
767683
{}
768684
/*
769685
@param buf Contains the serialized event.
770-
@param description_event An FDE event, used to get the following information
686+
@param description_event An FDE event, used to get the
687+
following information
771688
-binlog_version
772689
-server_version
773690
-post_header_len
@@ -845,7 +762,10 @@ struct Uuid
845762
/// Set to all zeros.
846763
void clear() { memset(bytes, 0, BYTE_LENGTH); }
847764
/// Copies the given 16-byte data to this UUID.
848-
void copy_from(const unsigned char *data) { memcpy(bytes, data, BYTE_LENGTH);}
765+
void copy_from(const unsigned char *data)
766+
{
767+
memcpy(bytes, data, BYTE_LENGTH);
768+
}
849769
/// Copies the given UUID object to this UUID.
850770
void copy_from(const Uuid &data) { copy_from((unsigned char *)data.bytes); }
851771
/// Copies the given UUID object to this UUID.
@@ -968,7 +888,8 @@ class Gtid_event: public Binary_log_event
968888
969889
@param buffer Contains the serialized event.
970890
@param event_len Length of the serialized event.
971-
@param description_event An FDE event, used to get the following information
891+
@param description_event An FDE event, used to get the
892+
following information
972893
-binlog_version
973894
-server_version
974895
-post_header_len
@@ -986,8 +907,8 @@ class Gtid_event: public Binary_log_event
986907
: commit_flag(commit_flag_arg)
987908
{}
988909
#ifndef HAVE_MYSYS
989-
//TODO(WL#7684): Implement the method print_event_info and print_long_info for
990-
// all the events supported in MySQL Binlog
910+
//TODO(WL#7684): Implement the method print_event_info and print_long_info
911+
// for all the events supported in MySQL Binlog
991912
void print_event_info(std::ostream& info) { }
992913
void print_long_info(std::ostream& info) { }
993914
#endif
@@ -1057,7 +978,8 @@ class Previous_gtids_event : public Binary_log_event
1057978
</pre>
1058979
@param buffer Contains the serialized event.
1059980
@param event_len Length of the serialized event.
1060-
@param description_event An FDE event, used to get the following information
981+
@param description_event An FDE event, used to get the
982+
following information
1061983
-binlog_version
1062984
-server_version
1063985
-post_header_len
@@ -1076,8 +998,8 @@ class Previous_gtids_event : public Binary_log_event
1076998
: Binary_log_event(PREVIOUS_GTIDS_LOG_EVENT)
1077999
{}
10781000
#ifndef HAVE_MYSYS
1079-
//TODO(WL#7684): Implement the method print_event_info and print_long_info for
1080-
// all the events supported in MySQL Binlog
1001+
//TODO(WL#7684): Implement the method print_event_info and print_long_info
1002+
// for all the events supported in MySQL Binlog
10811003
void print_event_info(std::ostream& info) { }
10821004
void print_long_info(std::ostream& info) { }
10831005
#endif
@@ -1133,7 +1055,8 @@ class Heartbeat_event: public Binary_log_event
11331055
11341056
@param buf Contains the serialized event.
11351057
@param event_len Length of the serialized event.
1136-
@param description_event An FDE event, used to get the following information
1058+
@param description_event An FDE event, used to get the
1059+
following information
11371060
-binlog_version
11381061
-server_version
11391062
-post_header_len

0 commit comments

Comments
 (0)