23#ifndef BINLOG_READER_INCLUDED
24#define BINLOG_READER_INCLUDED
42 const unsigned char *event_data,
unsigned int event_data_len,
60 unsigned int max_event_size);
80 template <
class ALLOCATOR>
82 ALLOCATOR *allocator,
bool verify_checksum,
88 if (event_data ==
nullptr)
92 allocator->deallocate(event_data);
128 template <Binlog_read_error::Error_type ERROR_TYPE>
131 if (
length == 0)
return false;
134 if (ret ==
length)
return false;
176template <
class EVENT_DATA_ISTREAM>
180 EVENT_DATA_ISTREAM *istream)
197 template <
class ALLOCATOR>
199 bool verify_checksum, ALLOCATOR *allocator) {
201 unsigned char *data =
nullptr;
210 verify_checksum, &
event))) {
211 allocator->deallocate(data);
216 ALLOCATOR::DELEGATE_MEMORY_TO_EVENT_OBJECT);
244template <
class IFILE,
class EVENT_DATA_ISTREAM,
245 template <
class>
class EVENT_OBJECT_ISTREAM,
class ALLOCATOR>
252 unsigned int max_event_size = UINT_MAX)
386 if (ev ==
nullptr)
break;
#define LOG_EVENT_MINIMAL_HEADER_LEN
Fixed header length, where 4.x and 5.0 agree.
Definition: binlog_event.h:415
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:411
Binlog_read_error::Error_type binlog_event_deserialize(const unsigned char *event_data, unsigned int event_data_len, const Format_description_event *fde, bool verify_checksum, Log_event **event)
Deserialize a binlog event from event_data.
Definition: binlog_reader.cc:109
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:415
It owns an allocator, a byte stream, an event_data stream and an event object stream.
Definition: binlog_reader.h:246
Event_data_istream m_data_istream
Definition: binlog_reader.h:352
Event_data_istream * event_data_istream()
Definition: binlog_reader.h:338
EVENT_DATA_ISTREAM Event_data_istream
Definition: binlog_reader.h:248
Format_description_log_event * read_fdle(my_off_t offset)
Read the Format_description_log_events before 'offset'.
Definition: binlog_reader.h:366
Format_description_event m_fde
Definition: binlog_reader.h:356
bool open(const char *file_name, my_off_t offset=0, Format_description_log_event **fdle=nullptr)
Open a binlog file and set read position to offset.
Definition: binlog_reader.h:276
Binlog_read_error::Error_type get_error_type()
Return the error happened in the stream pipeline.
Definition: binlog_reader.h:331
Log_event * read_event_object()
wrapper of EVENT_OBJECT_ISTREAM::read_event_object.
Definition: binlog_reader.h:318
const char * get_error_str()
Return the error message of the error happened in the stream pipeline.
Definition: binlog_reader.h:335
bool m_verify_checksum
Definition: binlog_reader.h:357
ALLOCATOR m_allocator
Definition: binlog_reader.h:354
Event_object_istream * event_object_istream()
Definition: binlog_reader.h:339
my_off_t event_start_pos()
Definition: binlog_reader.h:346
Binlog_read_error m_error
Definition: binlog_reader.h:349
Basic_binlog_file_reader & operator=(const Basic_binlog_file_reader &)=delete
EVENT_OBJECT_ISTREAM< Event_data_istream > Event_object_istream
Definition: binlog_reader.h:249
Event_object_istream m_object_istream
Definition: binlog_reader.h:353
ALLOCATOR * allocator()
Definition: binlog_reader.h:340
void close()
Close the binlog file.
Definition: binlog_reader.h:297
IFILE m_ifile
Definition: binlog_reader.h:351
bool read_event_data(unsigned char **data, unsigned int *length)
Wrapper of EVENT_DATA_ISTREAM::read_event_data.
Definition: binlog_reader.h:309
my_off_t m_event_start_pos
Definition: binlog_reader.h:358
Basic_binlog_file_reader(bool verify_checksum, unsigned int max_event_size=UINT_MAX)
Definition: binlog_reader.h:251
IFILE * ifile()
Definition: binlog_reader.h:337
Basic_binlog_file_reader(const Basic_binlog_file_reader &)=delete
my_off_t position()
Definition: binlog_reader.h:303
bool seek(my_off_t pos)
Definition: binlog_reader.h:304
void set_format_description_event(const Format_description_event &fde)
Definition: binlog_reader.h:342
~Basic_binlog_file_reader()
Definition: binlog_reader.h:262
bool has_fatal_error()
Definition: binlog_reader.h:327
bool is_open()
Definition: binlog_reader.h:302
const Format_description_event * format_description_event()
Definition: binlog_reader.h:345
The abstract class for basic byte input streams which provides read operations.
Definition: basic_istream.h:32
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:57
unsigned int m_max_event_size
Definition: binlog_reader.h:154
Basic_istream * m_istream
Definition: binlog_reader.h:153
bool read_fixed_length(unsigned char *data, unsigned int length)
Read fixed length of data from Basic_istream.
Definition: binlog_reader.h:129
Binlog_read_error * m_error
It is convenient for caller to share a Binlog_read_error object between streams.
Definition: binlog_reader.h:150
unsigned int m_event_length
Definition: binlog_reader.h:155
Binlog_event_data_istream & operator=(const Binlog_event_data_istream &)=delete
bool fill_event_data(unsigned char *event_data, bool verify_checksum, 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:71
bool check_event_header()
Check if it is a valid event header.
Definition: binlog_reader.cc:98
virtual bool read_event_header()
Read the event header from the Basic_istream.
Definition: binlog_reader.cc:66
virtual ~Binlog_event_data_istream()=default
Binlog_event_data_istream()=delete
Binlog_event_data_istream(const Binlog_event_data_istream &)=delete
unsigned char m_header[LOG_EVENT_MINIMAL_HEADER_LEN]
Definition: binlog_reader.h:101
bool read_event_data(unsigned char **data, unsigned int *length, ALLOCATOR *allocator, bool verify_checksum, 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:81
It reads event_data from an event_data stream and deserialize them to event object.
Definition: binlog_reader.h:177
Binlog_read_error * m_error
It is convenient for caller to share a Binlog_read_error object between streams.
Definition: binlog_reader.h:226
EVENT_DATA_ISTREAM * m_data_istream
Definition: binlog_reader.h:227
Binlog_event_object_istream(const Binlog_event_object_istream &)=delete
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:179
Log_event * read_event_object(const Format_description_event &fde, bool verify_checksum, ALLOCATOR *allocator)
Read an event object from the stream.
Definition: binlog_reader.h:198
Binlog input file.
Definition: binlog_istream.h:236
It defines the error types which could happen when reading binlog files or deserializing binlog event...
Definition: binlog_istream.h:36
Error_type get_type() const
Return the error encountered when reading events.
Definition: binlog_istream.h:85
Error_type
Possible errors which happens when reading an event.
Definition: binlog_istream.h:41
@ MEM_ALLOCATE
Definition: binlog_istream.h:55
@ SYSTEM_IO
Definition: binlog_istream.h:53
@ TRUNC_EVENT
Definition: binlog_istream.h:57
bool set_type(Error_type type)
Set m_error to error.
Definition: binlog_istream.h:103
const char * get_str() const
Return error message of the error type.
Definition: binlog_istream.cc:33
bool has_fatal_error()
Definition: binlog_istream.h:80
Definition: binlog_reader.h:46
unsigned char * allocate(size_t)
Definition: binlog_reader.cc:27
void deallocate(unsigned char *ptr)
Definition: binlog_reader.cc:33
@ DELEGATE_MEMORY_TO_EVENT_OBJECT
Definition: binlog_reader.h:48
This is the abstract base class for binary log events.
Definition: log_event.h:547
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:859
Relaylog input file.
Definition: binlog_istream.h:248
const Log_event_footer * footer() const
Return a const pointer to the footer of the log event.
Definition: binlog_event.h:914
#define BINLOG_VERSION
binlog_version 3 is MySQL 4.x; 4 is MySQL 5.0.0.
Definition: binlog_event.h:94
Binary log event definitions.
#define DBUG_TRACE
Definition: my_dbug.h:145
ulonglong my_off_t
Definition: my_inttypes.h:71
long long int longlong
Definition: my_inttypes.h:54
static char * server_version
Definition: mysql.cc:108
enum_binlog_checksum_alg
Enumeration spcifying checksum algorithm used to encode a binary log event.
Definition: binlog_event.h:420
Log_event_type
Enumeration type for the different types of log events.
Definition: binlog_event.h:274
@ FORMAT_DESCRIPTION_EVENT
Definition: binlog_event.h:300
@ PREVIOUS_GTIDS_LOG_EVENT
Definition: binlog_event.h:342
@ ROTATE_EVENT
Definition: binlog_event.h:290
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
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:93
required string type
Definition: replication_group_member_actions.proto:33
required string event
Definition: replication_group_member_actions.proto:31