24#ifndef BINLOG_READER_INCLUDED
25#define BINLOG_READER_INCLUDED
78 const unsigned char *event_data,
unsigned int event_data_len,
121 unsigned int max_event_size);
141 template <
class ALLOCATOR>
143 unsigned char **data,
unsigned int *
length, ALLOCATOR *allocator,
144 bool verify_checksum,
172 template <
class ALLOCATOR>
174 unsigned char **data,
unsigned int *
length, ALLOCATOR *allocator,
175 bool verify_checksum,
179 if (event_data ==
nullptr)
183 allocator->deallocate(event_data);
219 template <Binlog_read_error::Error_type ERROR_TYPE>
222 if (
length == 0)
return false;
225 if (ret ==
length)
return false;
260 unsigned char *event_data,
bool verify_checksum,
268template <
class EVENT_DATA_ISTREAM>
272 EVENT_DATA_ISTREAM *istream)
289 template <
class ALLOCATOR>
292 bool verify_checksum, ALLOCATOR *allocator) {
294 unsigned char *data =
nullptr;
303 verify_checksum, &
event))) {
304 allocator->deallocate(data);
309 ALLOCATOR::DELEGATE_MEMORY_TO_EVENT_OBJECT);
313 template <
class ALLOCATOR>
316 bool verify_checksum, ALLOCATOR *allocator) {
318 unsigned char *data =
nullptr;
327 verify_checksum, &
event))) {
328 allocator->deallocate(data);
333 ALLOCATOR::DELEGATE_MEMORY_TO_EVENT_OBJECT);
337 template <
class ALLOCATOR>
340 bool verify_checksum, ALLOCATOR *allocator) {
342 unsigned char *data =
nullptr;
467template <
class IFILE,
class EVENT_DATA_ISTREAM,
468 template <
class>
class EVENT_OBJECT_ISTREAM,
class ALLOCATOR>
475 unsigned int max_event_size = UINT_MAX)
667 if (ev ==
nullptr)
break;
#define EVENT_TYPE_OFFSET
Definition: binlog_event.h:424
#define LOG_EVENT_MINIMAL_HEADER_LEN
Fixed header length, where 4.x and 5.0 agree.
Definition: binlog_event.h:450
#define FLAGS_OFFSET
Definition: binlog_event.h:428
Binlog_read_error::Error_type binlog_event_deserialize(const unsigned char *event_data, unsigned int event_data_len, const mysql::binlog::event::Format_description_event *fde, bool verify_checksum, Log_event **event)
Deserialize a binlog event from event_data.
Definition: binlog_reader.cc:125
Basic_binlog_file_reader< Binlog_ifile, Binlog_event_data_istream, Binlog_event_object_istream, Default_binlog_event_allocator > Binlog_file_reader
Definition: binlog_reader.h:693
Basic_binlog_file_reader< Relaylog_ifile, Binlog_event_data_istream, Binlog_event_object_istream, Default_binlog_event_allocator > Relaylog_file_reader
Definition: binlog_reader.h:697
It owns an allocator, a byte stream, an event_data stream and an event object stream.
Definition: binlog_reader.h:469
Event_data_istream m_data_istream
Definition: binlog_reader.h:632
Event_data_istream * event_data_istream()
Definition: binlog_reader.h:608
EVENT_DATA_ISTREAM Event_data_istream
Definition: binlog_reader.h:471
Format_description_log_event * read_fdle(my_off_t offset)
Read the Format_description_log_events before 'offset'.
Definition: binlog_reader.h:647
void set_format_description_event(const mysql::binlog::event::Format_description_event &fde)
Definition: binlog_reader.h:612
~Basic_binlog_file_reader() override
Definition: binlog_reader.h:489
const char * m_file_name
Definition: binlog_reader.h:638
const char * get_error_str() const override
Return the error message of the error happened in the stream pipeline.
Definition: binlog_reader.h:605
bool seek(my_off_t pos) override
Seek to a given position.
Definition: binlog_reader.h:533
Log_event * read_event_payload(const Event_metadata &) override
Reads event payload after header metadata has been read.
Definition: binlog_reader.h:559
bool m_verify_checksum
Definition: binlog_reader.h:637
Binlog_read_error::Error_type get_error_type() const override
Return the error happened in the stream pipeline.
Definition: binlog_reader.h:599
ALLOCATOR m_allocator
Definition: binlog_reader.h:634
Event_object_istream * event_object_istream()
Definition: binlog_reader.h:609
bool is_open() const
Definition: binlog_reader.h:531
bool has_fatal_error() const override
Return true if there was a previous error.
Definition: binlog_reader.h:595
void close() override
Close the binlog file.
Definition: binlog_reader.h:525
std::optional< Event_payload > read_payload(const Event_metadata &) override
Reads raw payload after header metadata has been read.
Definition: binlog_reader.h:570
Basic_binlog_file_reader & operator=(const Basic_binlog_file_reader &&)=delete
std::optional< Event_metadata > read_event_metadata() override
Reads event header metadata without updating position to the next header (see skip_event_payload)
Definition: binlog_reader.h:554
my_off_t event_start_pos()
Definition: binlog_reader.h:620
Binlog_read_error m_error
Definition: binlog_reader.h:629
Basic_binlog_file_reader & operator=(const Basic_binlog_file_reader &)=delete
EVENT_OBJECT_ISTREAM< Event_data_istream > Event_object_istream
Definition: binlog_reader.h:472
Event_object_istream m_object_istream
Definition: binlog_reader.h:633
ALLOCATOR * allocator()
Definition: binlog_reader.h:610
IFILE m_ifile
Definition: binlog_reader.h:631
mysql::binlog::event::Format_description_event m_fde
Definition: binlog_reader.h:636
bool read_event_data(unsigned char **data, unsigned int *length)
Wrapper of EVENT_DATA_ISTREAM::read_event_data.
Definition: binlog_reader.h:538
my_off_t m_event_start_pos
Definition: binlog_reader.h:639
Basic_binlog_file_reader(bool verify_checksum, unsigned int max_event_size=UINT_MAX)
Definition: binlog_reader.h:474
my_off_t position() const override
Return the current position in bytes, relative to the beginning of the file.
Definition: binlog_reader.h:532
Basic_binlog_file_reader(const Basic_binlog_file_reader &&)=delete
const mysql::binlog::event::Format_description_event & format_description_event() const override
Return a pointer the currently used Format_description_log_event.
Definition: binlog_reader.h:617
IFILE * ifile()
Definition: binlog_reader.h:607
Basic_binlog_file_reader(const Basic_binlog_file_reader &)=delete
bool skip_event_payload(const Event_metadata &metadata) override
Skips event payload data.
Definition: binlog_reader.h:576
Log_event * read_event_object() override
wrapper of EVENT_OBJECT_ISTREAM::read_event_object.
Definition: binlog_reader.h:584
bool open(const char *file_name, my_off_t offset=0, Format_description_log_event **fdle=nullptr) override
Open a binlog file and set read position to offset.
Definition: binlog_reader.h:503
const char * get_file_name() const
Definition: binlog_reader.h:626
bool read_payload_data(unsigned char **data, unsigned int *length)
Definition: binlog_reader.h:545
void reset_error()
Resets the error.
Definition: binlog_reader.h:625
The abstract class for basic byte input streams which provides read operations.
Definition: basic_istream.h:35
virtual ssize_t read(unsigned char *buffer, size_t length)=0
Read some bytes from the input stream.
Binlog_event_data_istream fetches byte data from Basic_istream and divides them into event_data chunk...
Definition: binlog_reader.h:118
unsigned int m_max_event_size
Definition: binlog_reader.h:245
bool read_event_data(unsigned char **data, unsigned int *length, ALLOCATOR *allocator, bool verify_checksum, mysql::binlog::event::enum_binlog_checksum_alg checksum_alg)
Read an event data from the stream and verify its checksum if verify_checksum is true.
Definition: binlog_reader.h:142
Basic_istream * m_istream
Definition: binlog_reader.h:244
bool read_fixed_length(unsigned char *data, unsigned int length)
Read fixed length of data from Basic_istream.
Definition: binlog_reader.h:220
Binlog_read_error * m_error
It is convenient for caller to share a Binlog_read_error object between streams.
Definition: binlog_reader.h:241
unsigned int m_event_length
Definition: binlog_reader.h:246
Binlog_event_data_istream & operator=(const Binlog_event_data_istream &)=delete
std::optional< Event_metadata > read_event_metadata()
Reads event header metadata.
Definition: binlog_reader.h:154
bool read_payload_data(unsigned char **data, unsigned int *length, ALLOCATOR *allocator, bool verify_checksum, mysql::binlog::event::enum_binlog_checksum_alg checksum_alg)
Reads event payload (read event metadata has to be called before to read header) and fills data with ...
Definition: binlog_reader.h:173
bool check_event_header()
Check if it is a valid event header.
Definition: binlog_reader.cc:108
virtual bool read_event_header()
Read the event header from the Basic_istream.
Definition: binlog_reader.cc:74
virtual ~Binlog_event_data_istream()=default
Binlog_event_data_istream()=delete
Binlog_event_data_istream(const Binlog_event_data_istream &)=delete
bool fill_event_data(unsigned char *event_data, bool verify_checksum, mysql::binlog::event::enum_binlog_checksum_alg checksum_alg)
Fill the event data into the given buffer and verify checksum if 'verify_checksum' is true.
Definition: binlog_reader.cc:79
unsigned char m_header[LOG_EVENT_MINIMAL_HEADER_LEN]
Definition: binlog_reader.h:192
It reads event_data from an event_data stream and deserialize them to event object.
Definition: binlog_reader.h:269
Binlog_read_error * m_error
It is convenient for caller to share a Binlog_read_error object between streams.
Definition: binlog_reader.h:358
EVENT_DATA_ISTREAM * m_data_istream
Definition: binlog_reader.h:359
std::optional< Event_payload > read_payload(const mysql::binlog::event::Format_description_event &fde, bool verify_checksum, ALLOCATOR *allocator)
Definition: binlog_reader.h:338
Binlog_event_object_istream(const Binlog_event_object_istream &)=delete
Log_event * read_event_payload(const mysql::binlog::event::Format_description_event &fde, bool verify_checksum, ALLOCATOR *allocator)
Definition: binlog_reader.h:314
Binlog_event_object_istream & operator=(const Binlog_event_object_istream &)=delete
Binlog_event_object_istream()=delete
Binlog_event_object_istream(Binlog_read_error *error, EVENT_DATA_ISTREAM *istream)
Definition: binlog_reader.h:271
Log_event * read_event_object(const mysql::binlog::event::Format_description_event &fde, bool verify_checksum, ALLOCATOR *allocator)
Read an event object from the stream.
Definition: binlog_reader.h:290
Binlog input file.
Definition: binlog_istream.h:241
It defines the error types which could happen when reading binlog files or deserializing binlog event...
Definition: binlog_istream.h:37
Error_type get_type() const
Return the error encountered when reading events.
Definition: binlog_istream.h:88
Error_type
Possible errors which happens when reading an event.
Definition: binlog_istream.h:42
@ MEM_ALLOCATE
Definition: binlog_istream.h:56
@ SUCCESS
Definition: binlog_istream.h:44
@ SYSTEM_IO
Definition: binlog_istream.h:54
@ TRUNC_EVENT
Definition: binlog_istream.h:58
bool set_type(Error_type type)
Set m_error to error.
Definition: binlog_istream.h:106
const char * get_str() const
Return error message of the error type.
Definition: binlog_istream.cc:34
bool has_fatal_error() const
Definition: binlog_istream.h:83
Definition: binlog_reader.h:82
unsigned char * allocate(size_t)
Definition: binlog_reader.cc:33
void deallocate(unsigned char *ptr)
Definition: binlog_reader.cc:39
@ DELEGATE_MEMORY_TO_EVENT_OBJECT
Definition: binlog_reader.h:84
Interface class that all specializations of template <...> Basic_binlog_file_reader inherit from.
Definition: binlog_reader.h:364
virtual Log_event * read_event_payload(const Event_metadata &metadata)=0
Reads event payload after header metadata has been read.
IBasic_binlog_file_reader(IBasic_binlog_file_reader &)=delete
virtual std::optional< Event_payload > read_payload(const Event_metadata &metadata)=0
Reads raw payload after header metadata has been read.
virtual bool skip_event_payload(const Event_metadata &metadata)=0
Skips event payload data.
IBasic_binlog_file_reader & operator=(IBasic_binlog_file_reader &&)=delete
virtual ~IBasic_binlog_file_reader()=default
IBasic_binlog_file_reader & operator=(IBasic_binlog_file_reader &)=delete
virtual std::optional< Event_metadata > read_event_metadata()=0
Reads event header metadata without updating position to the next header (see skip_event_payload)
virtual const char * get_error_str() const =0
Return a string representing the error.
virtual bool open(const char *file_name, my_off_t offset=0, Format_description_log_event **fdle=nullptr)=0
Open a binlog file and set read position to offset.
virtual my_off_t position() const =0
Return the current position in bytes, relative to the beginning of the file.
virtual void close()=0
Closes the reader.
virtual bool seek(my_off_t pos)=0
Seek to a given position.
IBasic_binlog_file_reader(IBasic_binlog_file_reader &&)=delete
IBasic_binlog_file_reader()=default
virtual Binlog_read_error::Error_type get_error_type() const =0
Return the type of error.
virtual const mysql::binlog::event::Format_description_event & format_description_event() const =0
Return a pointer the currently used Format_description_log_event.
virtual Log_event * read_event_object()=0
Read the next event from the stream.
virtual bool has_fatal_error() const =0
Return true if there was a previous error.
This is the abstract base class for binary log events.
Definition: log_event.h:539
virtual mysql::binlog::event::Log_event_type get_type_code() const
Definition: log_event.h:804
void register_temp_buf(char *buf, bool free_in_destructor=true)
Definition: log_event.h:882
Relaylog input file.
Definition: binlog_istream.h:253
const Log_event_footer * footer() const
Return a const pointer to the footer of the log event.
Definition: binlog_event.h:960
mysql::binlog::event::Format_description_event Format_description_event
Definition: file_storage.cc:40
#define LOG_EVENT_IGNORABLE_F
Setting this flag will mark an event as Ignorable.
Definition: binlog_event.h:165
#define BINLOG_VERSION
binlog_version 3 is MySQL 4.x; 4 is MySQL 5.0.0.
Definition: binlog_event.h:98
static int flags[50]
Definition: hp_test1.cc:40
uint16_t le16toh(uint16_t x)
Converting a 16 bit integer from little-endian byte order to host byteorder.
Definition: byteorder.h:62
Binary log event definitions.
#define DBUG_TRACE
Definition: my_dbug.h:146
ulonglong my_off_t
Definition: my_inttypes.h:72
long long int longlong
Definition: my_inttypes.h:55
static char * server_version
Definition: mysql.cc:120
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:76
std::string file_name(Log_file_id file_id)
Provides name of the log file with the given file id, e.g.
Definition: log0pre_8_0_30.cc:45
Log_event_type
Enumeration type for the different types of log events.
Definition: binlog_event.h:279
@ FORMAT_DESCRIPTION_EVENT
Definition: binlog_event.h:305
@ PREVIOUS_GTIDS_LOG_EVENT
Definition: binlog_event.h:348
@ ROTATE_EVENT
Definition: binlog_event.h:295
enum_binlog_checksum_alg
Enumeration spcifying checksum algorithm used to encode a binary log event.
Definition: binlog_event.h:455
required string type
Definition: replication_group_member_actions.proto:34
required string event
Definition: replication_group_member_actions.proto:32
Helper structure used by the reader to aggregate payload and information needed to decode an event.
Definition: binlog_reader.h:91
Event_payload()=default
Default constructor.
Event_payload(uint8_t *data, std::size_t length, bool verify_checksum)
Construct from payload data and metadata.
Definition: binlog_reader.h:97
bool m_verify_checksum
Parameter used by the reader to identify if checksum of the event should be checked after event decod...
Definition: binlog_reader.h:110
uint8_t * m_data
Allocated dynamic array containing payload raw bytes.
Definition: binlog_reader.h:105
std::size_t m_length
length Length of the event
Definition: binlog_reader.h:107