Commit 5018a660 authored by Sergei Golubchik's avatar Sergei Golubchik

cleanup: Log_event::read_log_event()

There are three Log_event::read_log_event() methods:
1. read the event image from IO_CACHE into String
2. create Log_event from the in-memory event image
3. read the event image from IO_CACHE and create Log_event

The 3rd was reading event image into memory and invoking the 2nd to
create Log_event. Now the 3rd also uses the 1st to read the event image
from IO_CACHE into memory, instead of duplicating its functionality.
parent 08687f7e
...@@ -2240,7 +2240,7 @@ static Exit_status check_header(IO_CACHE* file, ...@@ -2240,7 +2240,7 @@ static Exit_status check_header(IO_CACHE* file,
Format_description_log_event *new_description_event; Format_description_log_event *new_description_event;
my_b_seek(file, tmp_pos); /* seek back to event's start */ my_b_seek(file, tmp_pos); /* seek back to event's start */
if (!(new_description_event= (Format_description_log_event*) if (!(new_description_event= (Format_description_log_event*)
Log_event::read_log_event(file, glob_description_event, Log_event::read_log_event(file, 0, glob_description_event,
opt_verify_binlog_checksum))) opt_verify_binlog_checksum)))
/* EOF can't be hit here normally, so it's a real error */ /* EOF can't be hit here normally, so it's a real error */
{ {
...@@ -2274,7 +2274,7 @@ static Exit_status check_header(IO_CACHE* file, ...@@ -2274,7 +2274,7 @@ static Exit_status check_header(IO_CACHE* file,
{ {
Log_event *ev; Log_event *ev;
my_b_seek(file, tmp_pos); /* seek back to event's start */ my_b_seek(file, tmp_pos); /* seek back to event's start */
if (!(ev= Log_event::read_log_event(file, glob_description_event, if (!(ev= Log_event::read_log_event(file, 0, glob_description_event,
opt_verify_binlog_checksum))) opt_verify_binlog_checksum)))
{ {
/* EOF can't be hit here normally, so it's a real error */ /* EOF can't be hit here normally, so it's a real error */
...@@ -2388,7 +2388,7 @@ static Exit_status dump_local_log_entries(PRINT_EVENT_INFO *print_event_info, ...@@ -2388,7 +2388,7 @@ static Exit_status dump_local_log_entries(PRINT_EVENT_INFO *print_event_info,
char llbuff[21]; char llbuff[21];
my_off_t old_off = my_b_tell(file); my_off_t old_off = my_b_tell(file);
Log_event* ev = Log_event::read_log_event(file, glob_description_event, Log_event* ev = Log_event::read_log_event(file, 0, glob_description_event,
opt_verify_binlog_checksum); opt_verify_binlog_checksum);
if (!ev) if (!ev)
{ {
......
This diff is collapsed.
...@@ -1127,6 +1127,39 @@ class Log_event ...@@ -1127,6 +1127,39 @@ class Log_event
Log_event(); Log_event();
Log_event(THD* thd_arg, uint16 flags_arg, bool is_transactional); Log_event(THD* thd_arg, uint16 flags_arg, bool is_transactional);
/*
init_show_field_list() prepares the column names and types for the
output of SHOW BINLOG EVENTS; it is used only by SHOW BINLOG
EVENTS.
*/
static void init_show_field_list(THD *thd, List<Item>* field_list);
#ifdef HAVE_REPLICATION
int net_send(THD *thd, Protocol *protocol, const char* log_name,
my_off_t pos);
/*
pack_info() is used by SHOW BINLOG EVENTS; as print() it prepares and sends
a string to display to the user, so it resembles print().
*/
virtual void pack_info(THD *thd, Protocol *protocol);
#endif /* HAVE_REPLICATION */
virtual const char* get_db()
{
return thd ? thd->db : 0;
}
#else
Log_event() : temp_buf(0), flags(0) {}
/* print*() functions are used by mysqlbinlog */
virtual void print(FILE* file, PRINT_EVENT_INFO* print_event_info) = 0;
void print_timestamp(IO_CACHE* file, time_t *ts = 0);
void print_header(IO_CACHE* file, PRINT_EVENT_INFO* print_event_info,
bool is_more);
void print_base64(IO_CACHE* file, PRINT_EVENT_INFO* print_event_info,
bool is_more);
#endif
/* /*
read_log_event() functions read an event from a binlog or relay read_log_event() functions read an event from a binlog or relay
log; used by SHOW BINLOG EVENTS, the binlog_dump thread on the log; used by SHOW BINLOG EVENTS, the binlog_dump thread on the
...@@ -1155,9 +1188,9 @@ class Log_event ...@@ -1155,9 +1188,9 @@ class Log_event
@param[in] file log file to be read @param[in] file log file to be read
@param[out] packet packet to hold the event @param[out] packet packet to hold the event
@param[in] lock the lock to be used upon read @param[in] checksum_alg_arg verify the event checksum using this
@param[in] log_file_name_arg the log's file name algorithm (or don't if it's
@param[out] is_binlog_active is the current log still active use BINLOG_CHECKSUM_ALG_OFF)
@retval 0 success @retval 0 success
@retval LOG_READ_EOF end of file, nothing was read @retval LOG_READ_EOF end of file, nothing was read
...@@ -1168,46 +1201,7 @@ class Log_event ...@@ -1168,46 +1201,7 @@ class Log_event
@retval LOG_READ_TOO_LARGE event too large @retval LOG_READ_TOO_LARGE event too large
*/ */
static int read_log_event(IO_CACHE* file, String* packet, static int read_log_event(IO_CACHE* file, String* packet,
mysql_mutex_t* log_lock, uint8 checksum_alg_arg);
uint8 checksum_alg_arg,
const char *log_file_name_arg = NULL,
bool* is_binlog_active = NULL);
/*
init_show_field_list() prepares the column names and types for the
output of SHOW BINLOG EVENTS; it is used only by SHOW BINLOG
EVENTS.
*/
static void init_show_field_list(THD *thd, List<Item>* field_list);
#ifdef HAVE_REPLICATION
int net_send(THD *thd, Protocol *protocol, const char* log_name,
my_off_t pos);
/*
pack_info() is used by SHOW BINLOG EVENTS; as print() it prepares and sends
a string to display to the user, so it resembles print().
*/
virtual void pack_info(THD *thd, Protocol *protocol);
#endif /* HAVE_REPLICATION */
virtual const char* get_db()
{
return thd ? thd->db : 0;
}
#else
Log_event() : temp_buf(0), flags(0) {}
/* avoid having to link mysqlbinlog against libpthread */
static Log_event* read_log_event(IO_CACHE* file,
const Format_description_log_event
*description_event, my_bool crc_check);
/* print*() functions are used by mysqlbinlog */
virtual void print(FILE* file, PRINT_EVENT_INFO* print_event_info) = 0;
void print_timestamp(IO_CACHE* file, time_t *ts = 0);
void print_header(IO_CACHE* file, PRINT_EVENT_INFO* print_event_info,
bool is_more);
void print_base64(IO_CACHE* file, PRINT_EVENT_INFO* print_event_info,
bool is_more);
#endif
/* /*
The value is set by caller of FD constructor and The value is set by caller of FD constructor and
Log_event::write_header() for the rest. Log_event::write_header() for the rest.
......
...@@ -1200,9 +1200,9 @@ bool event_checksum_test(uchar *event_buf, ulong event_len, uint8 alg) ...@@ -1200,9 +1200,9 @@ bool event_checksum_test(uchar *event_buf, ulong event_len, uint8 alg)
DBUG_ASSERT(event_buf[EVENT_TYPE_OFFSET] == FORMAT_DESCRIPTION_EVENT); DBUG_ASSERT(event_buf[EVENT_TYPE_OFFSET] == FORMAT_DESCRIPTION_EVENT);
event_buf[FLAGS_OFFSET]= (uchar) flags; event_buf[FLAGS_OFFSET]= (uchar) flags;
} }
res= !(computed == incoming); res= DBUG_EVALUATE_IF("simulate_checksum_test_failure", TRUE, computed != incoming);
} }
return DBUG_EVALUATE_IF("simulate_checksum_test_failure", TRUE, res); return res;
} }
#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION) #if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION)
......
...@@ -1436,8 +1436,9 @@ gtid_state_from_pos(const char *name, uint32 offset, ...@@ -1436,8 +1436,9 @@ gtid_state_from_pos(const char *name, uint32 offset,
break; break;
packet.length(0); packet.length(0);
err= Log_event::read_log_event(&cache, &packet, NULL, err= Log_event::read_log_event(&cache, &packet,
current_checksum_alg); opt_master_verify_checksum
? current_checksum_alg : 0);
if (err) if (err)
{ {
errormsg= "Could not read binlog while searching for slave start " errormsg= "Could not read binlog while searching for slave start "
...@@ -2230,8 +2231,9 @@ static int send_format_descriptor_event(binlog_send_info *info, ...@@ -2230,8 +2231,9 @@ static int send_format_descriptor_event(binlog_send_info *info,
the binlog the binlog
*/ */
info->last_pos= my_b_tell(log); info->last_pos= my_b_tell(log);
error= Log_event::read_log_event(log, packet, /* LOCK_log */ NULL, error= Log_event::read_log_event(log, packet,
info->current_checksum_alg); opt_master_verify_checksum
? info->current_checksum_alg : 0);
linfo->pos= my_b_tell(log); linfo->pos= my_b_tell(log);
if (error) if (error)
...@@ -2566,9 +2568,9 @@ static int send_events(binlog_send_info *info, ...@@ -2566,9 +2568,9 @@ static int send_events(binlog_send_info *info,
return 1; return 1;
info->last_pos= linfo->pos; info->last_pos= linfo->pos;
error = Log_event::read_log_event(log, packet, /* LOCK_log */ NULL, error= Log_event::read_log_event(log, packet,
info->current_checksum_alg, opt_master_verify_checksum
NULL, NULL); ? info->current_checksum_alg : 0);
linfo->pos= my_b_tell(log); linfo->pos= my_b_tell(log);
if (error) if (error)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment