Commit 1fb9105e authored by mats@romeo.(none)'s avatar mats@romeo.(none)

BUG#23171 (Illegal slave restart group position):

Second patch to fix skipping code. Moving relay and binary log 
position changing code from do_apply_event [old exec_event()] into
do_update_pos() and doing other changes necessary to support that.

Fixing a bug that can cause deadlock if rotating binary log when committing
a changes to a transactional table that is not inside a transaction and
cause a rotate log.
parent edb70453
......@@ -1453,7 +1453,7 @@ static int binlog_prepare(handlerton *hton, THD *thd, bool all)
do nothing.
just pretend we can do 2pc, so that MySQL won't
switch to 1pc.
real work will be done in MYSQL_BIN_LOG::log()
real work will be done in TC_LOG_BINLOG::log()
*/
return 0;
}
......@@ -1467,9 +1467,15 @@ static int binlog_commit(handlerton *hton, THD *thd, bool all)
IO_CACHE *trans_log= &trx_data->trans_log;
DBUG_ASSERT(mysql_bin_log.is_open());
if (all && trx_data->empty())
/*
The condition here has to be identical to the one inside
binlog_end_trans(), guarding the write of the transaction cache to
the binary log.
*/
if ((all || !(thd->options & (OPTION_BEGIN | OPTION_NOT_AUTOCOMMIT))) &&
trx_data->empty())
{
// we're here because trans_log was flushed in MYSQL_BIN_LOG::log()
// we're here because trans_log was flushed in TC_LOG_BINLOG::log()
trx_data->reset();
DBUG_RETURN(0);
}
......@@ -3117,8 +3123,10 @@ void MYSQL_BIN_LOG::new_file_impl(bool need_lock)
{
tc_log_page_waits++;
pthread_mutex_lock(&LOCK_prep_xids);
while (prepared_xids)
while (prepared_xids) {
DBUG_PRINT("info", ("prepared_xids=%lu", prepared_xids));
pthread_cond_wait(&COND_prep_xids, &LOCK_prep_xids);
}
pthread_mutex_unlock(&LOCK_prep_xids);
}
......@@ -4905,8 +4913,10 @@ void TC_LOG_BINLOG::unlog(ulong cookie, my_xid xid)
{
pthread_mutex_lock(&LOCK_prep_xids);
DBUG_ASSERT(prepared_xids > 0);
if (--prepared_xids == 0)
if (--prepared_xids == 0) {
DBUG_PRINT("info", ("prepared_xids=%lu", prepared_xids));
pthread_cond_signal(&COND_prep_xids);
}
pthread_mutex_unlock(&LOCK_prep_xids);
rotate_and_purge(0); // as ::write() did not rotate
}
......
......@@ -531,23 +531,19 @@ Log_event::Log_event(const char* buf,
#ifndef MYSQL_CLIENT
#ifdef HAVE_REPLICATION
/*
Log_event::apply_event_impl()
*/
int Log_event::apply_event_impl(RELAY_LOG_INFO* rli)
int Log_event::do_update_pos(RELAY_LOG_INFO *rli)
{
DBUG_ENTER("Log_event::apply_event_impl");
/*
rli is null when (as far as I (Guilhem) know) the caller is
Load_log_event::apply_event_impl *and* that one is called from
Execute_load_log_event::apply_event_impl. In this case, we don't
do anything here ; Execute_load_log_event::apply_event_impl will
call Log_event::apply_event_impl again later with the proper rli.
Load_log_event::do_apply_event *and* that one is called from
Execute_load_log_event::do_apply_event. In this case, we don't
do anything here ; Execute_load_log_event::do_apply_event will
call Log_event::do_apply_event again later with the proper rli.
Strictly speaking, if we were sure that rli is null only in the
case discussed above, 'if (rli)' is useless here. But as we are
not 100% sure, keep it for now.
Matz: I don't think we will need this check with this refactoring.
*/
if (rli)
{
......@@ -583,7 +579,7 @@ int Log_event::apply_event_impl(RELAY_LOG_INFO* rli)
rli->inc_group_relay_log_pos(log_pos);
flush_relay_log_info(rli);
/*
Note that Rotate_log_event::apply_event_impl() does not call
Note that Rotate_log_event::do_apply_event() does not call
this function, so there is no chance that a fake rotate event
resets last_master_timestamp. Note that we update without
mutex (probably ok - except in some very rare cases, only
......@@ -593,9 +589,9 @@ int Log_event::apply_event_impl(RELAY_LOG_INFO* rli)
rli->last_master_timestamp= when;
}
}
DBUG_RETURN(0);
}
return 0; // Cannot fail currently
}
/*
Log_event::pack_info()
......@@ -1819,18 +1815,18 @@ void Query_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
/*
Query_log_event::apply_event_impl()
Query_log_event::do_apply_event()
*/
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
int Query_log_event::apply_event_impl(RELAY_LOG_INFO* rli)
int Query_log_event::do_apply_event(RELAY_LOG_INFO const *rli)
{
return apply_event_impl(rli, query, q_len);
return do_apply_event(rli, query, q_len);
}
int Query_log_event::apply_event_impl(RELAY_LOG_INFO* rli,
int Query_log_event::do_apply_event(RELAY_LOG_INFO const *rli,
const char *query_arg, uint32 q_len_arg)
{
LEX_STRING new_db;
......@@ -1839,7 +1835,7 @@ int Query_log_event::apply_event_impl(RELAY_LOG_INFO* rli,
Colleagues: please never free(thd->catalog) in MySQL. This would
lead to bugs as here thd->catalog is a part of an alloced block,
not an entire alloced block (see
Query_log_event::apply_event_impl()). Same for thd->db. Thank
Query_log_event::do_apply_event()). Same for thd->db. Thank
you.
*/
thd->catalog= catalog_len ? (char *) catalog : (char *)"";
......@@ -1859,11 +1855,11 @@ int Query_log_event::apply_event_impl(RELAY_LOG_INFO* rli,
END of the current log event (COMMIT). We save it in rli so that InnoDB can
access it.
*/
rli->future_group_master_log_pos= log_pos;
const_cast<RELAY_LOG_INFO*>(rli)->future_group_master_log_pos= log_pos;
DBUG_PRINT("info", ("log_pos: %lu", (ulong) log_pos));
clear_all_errors(thd, rli);
rli->clear_tables_to_lock();
clear_all_errors(thd, const_cast<RELAY_LOG_INFO*>(rli));
const_cast<RELAY_LOG_INFO*>(rli)->clear_tables_to_lock();
/*
Note: We do not need to execute reset_one_shot_variables() if this
......@@ -1872,7 +1868,7 @@ int Query_log_event::apply_event_impl(RELAY_LOG_INFO* rli,
its companion query. If the SET is ignored because of
db_ok(), the companion query will also be ignored, and if
the companion query is ignored in the db_ok() test of
::apply_event_impl(), then the companion SET also have so
::do_apply_event(), then the companion SET also have so
we don't need to reset_one_shot_variables().
*/
if (rpl_filter->db_ok(thd->db))
......@@ -1962,7 +1958,7 @@ int Query_log_event::apply_event_impl(RELAY_LOG_INFO* rli,
to check/fix it.
*/
if (mysql_test_parse_for_slave(thd, thd->query, thd->query_length))
clear_all_errors(thd, rli); /* Can ignore query */
clear_all_errors(thd, const_cast<RELAY_LOG_INFO*>(rli)); /* Can ignore query */
else
{
slave_print_msg(ERROR_LEVEL, rli, expected_error,
......@@ -2013,7 +2009,7 @@ Default database: '%s'. Query: '%s'",
ignored_error_code(actual_error))
{
DBUG_PRINT("info",("error ignored"));
clear_all_errors(thd, rli);
clear_all_errors(thd, const_cast<RELAY_LOG_INFO*>(rli));
}
/*
Other cases: mostly we expected no error and get one.
......@@ -2080,16 +2076,26 @@ Default database: '%s'. Query: '%s'",
thd->first_successful_insert_id_in_prev_stmt= 0;
thd->stmt_depends_on_first_successful_insert_id_in_prev_stmt= 0;
free_root(thd->mem_root,MYF(MY_KEEP_PREALLOC));
return thd->query_error;
}
int Query_log_event::do_update_pos(RELAY_LOG_INFO *rli)
{
/*
If there was an error we stop. Otherwise we increment positions. Note that
we will not increment group* positions if we are just after a SET
ONE_SHOT, because SET ONE_SHOT should not be separated from its following
updating query.
Note that we will not increment group* positions if we are just
after a SET ONE_SHOT, because SET ONE_SHOT should not be separated
from its following updating query.
*/
return (thd->query_error ? thd->query_error :
(thd->one_shot_set ? (rli->inc_event_relay_log_pos(),0) :
Log_event::apply_event_impl(rli)));
if (thd->one_shot_set)
{
rli->inc_event_relay_log_pos();
return 0;
}
else
return Log_event::do_update_pos(rli);
}
#endif
......@@ -2216,7 +2222,7 @@ bool Start_log_event_v3::write(IO_CACHE* file)
/*
Start_log_event_v3::apply_event_impl()
Start_log_event_v3::do_apply_event()
The master started
......@@ -2235,9 +2241,9 @@ bool Start_log_event_v3::write(IO_CACHE* file)
*/
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
int Start_log_event_v3::apply_event_impl(RELAY_LOG_INFO* rli)
int Start_log_event_v3::do_apply_event(RELAY_LOG_INFO const *rli)
{
DBUG_ENTER("Start_log_event_v3::apply_event_impl");
DBUG_ENTER("Start_log_event_v3::do_apply_event");
switch (binlog_version)
{
case 3:
......@@ -2279,7 +2285,7 @@ int Start_log_event_v3::apply_event_impl(RELAY_LOG_INFO* rli)
/* this case is impossible */
DBUG_RETURN(1);
}
DBUG_RETURN(Log_event::apply_event_impl(rli));
DBUG_RETURN(0);
}
#endif /* defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */
......@@ -2468,22 +2474,18 @@ bool Format_description_log_event::write(IO_CACHE* file)
/*
SYNOPSIS
Format_description_log_event::apply_event_impl()
Format_description_log_event::do_apply_event()
IMPLEMENTATION
Save the information which describes the binlog's format, to be
able to read all coming events. Call
Start_log_event_v3::apply_event_impl().
Start_log_event_v3::do_apply_event().
*/
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
int Format_description_log_event::apply_event_impl(RELAY_LOG_INFO* rli)
int Format_description_log_event::do_apply_event(RELAY_LOG_INFO const *rli)
{
DBUG_ENTER("Format_description_log_event::apply_event_impl");
/* save the information describing this binlog */
delete rli->relay_log.description_event_for_exec;
rli->relay_log.description_event_for_exec= this;
DBUG_ENTER("Format_description_log_event::do_apply_event");
#ifdef USING_TRANSACTIONS
/*
......@@ -2505,14 +2507,36 @@ int Format_description_log_event::apply_event_impl(RELAY_LOG_INFO* rli)
"or ROLLBACK in relay log). A probable cause is that "
"the master died while writing the transaction to "
"its binary log, thus rolled back too.");
rli->cleanup_context(thd, 1);
const_cast<RELAY_LOG_INFO*>(rli)->cleanup_context(thd, 1);
}
#endif
/*
If this event comes from ourselves, there is no cleaning task to
perform, we don't call Start_log_event_v3::apply_event_impl()
perform, we don't call Start_log_event_v3::do_apply_event()
(this was just to update the log's description event).
*/
if (server_id != (uint32) ::server_id)
{
/*
If the event was not requested by the slave i.e. the master sent
it while the slave asked for a position >4, the event will make
rli->group_master_log_pos advance. Say that the slave asked for
position 1000, and the Format_desc event's end is 96. Then in
the beginning of replication rli->group_master_log_pos will be
0, then 96, then jump to first really asked event (which is
>96). So this is ok.
*/
DBUG_RETURN(Start_log_event_v3::do_apply_event(rli));
}
DBUG_RETURN(0);
}
int Format_description_log_event::do_update_pos(RELAY_LOG_INFO *rli)
{
/* save the information describing this binlog */
delete rli->relay_log.description_event_for_exec;
rli->relay_log.description_event_for_exec= this;
if (server_id == (uint32) ::server_id)
{
/*
......@@ -2529,19 +2553,14 @@ int Format_description_log_event::apply_event_impl(RELAY_LOG_INFO* rli)
the Intvar_log_event respectively.
*/
rli->inc_event_relay_log_pos();
DBUG_RETURN(0);
return 0;
}
else
{
return Log_event::do_update_pos(rli);
}
/*
If the event was not requested by the slave i.e. the master sent it while
the slave asked for a position >4, the event will make
rli->group_master_log_pos advance. Say that the slave asked for position
1000, and the Format_desc event's end is 96. Then in the beginning of
replication rli->group_master_log_pos will be 0, then 96, then jump to
first really asked event (which is >96). So this is ok.
*/
DBUG_RETURN(Start_log_event_v3::apply_event_impl(rli));
}
#endif
/**************************************************************************
......@@ -3023,18 +3042,18 @@ void Load_log_event::set_fields(const char* affected_db,
Does the data loading job when executing a LOAD DATA on the slave
SYNOPSIS
Load_log_event::apply_event_impl
Load_log_event::do_apply_event
net
rli
use_rli_only_for_errors - if set to 1, rli is provided to
Load_log_event::apply_event_impl
Load_log_event::do_apply_event
only for this function to have
RPL_LOG_NAME and
rli->last_slave_error, both being
used by error reports. rli's
position advancing is skipped (done
by the caller which is
Execute_load_log_event::apply_event_impl).
Execute_load_log_event::do_apply_event).
- if set to 0, rli is provided for
full use, i.e. for error reports and
position advancing.
......@@ -3047,7 +3066,7 @@ void Load_log_event::set_fields(const char* affected_db,
1 Failure
*/
int Load_log_event::apply_event_impl(NET* net, RELAY_LOG_INFO* rli,
int Load_log_event::do_apply_event(NET* net, RELAY_LOG_INFO const *rli,
bool use_rli_only_for_errors)
{
LEX_STRING new_db;
......@@ -3057,9 +3076,9 @@ int Load_log_event::apply_event_impl(NET* net, RELAY_LOG_INFO* rli,
DBUG_ASSERT(thd->query == 0);
thd->query_length= 0; // Should not be needed
thd->query_error= 0;
clear_all_errors(thd, rli);
clear_all_errors(thd, const_cast<RELAY_LOG_INFO*>(rli));
/* see Query_log_event::apply_event_impl() and BUG#13360 */
/* see Query_log_event::do_apply_event() and BUG#13360 */
DBUG_ASSERT(!rli->m_table_map.count());
/*
Usually mysql_init_query() is called by mysql_parse(), but we need it here
......@@ -3070,9 +3089,9 @@ int Load_log_event::apply_event_impl(NET* net, RELAY_LOG_INFO* rli,
{
/*
Saved for InnoDB, see comment in
Query_log_event::apply_event_impl()
Query_log_event::do_apply_event()
*/
rli->future_group_master_log_pos= log_pos;
const_cast<RELAY_LOG_INFO*>(rli)->future_group_master_log_pos= log_pos;
DBUG_PRINT("info", ("log_pos: %lu", (ulong) log_pos));
}
......@@ -3084,7 +3103,7 @@ int Load_log_event::apply_event_impl(NET* net, RELAY_LOG_INFO* rli,
still consume a lot of space on the slave (space in the relay log
+ space of temp files: twice the space of the file to load...)
even if it will finally be ignored. TODO: fix this; this can be
done by testing rules in Create_file_log_event::apply_event_impl()
done by testing rules in Create_file_log_event::do_apply_event()
and then discarding Append_block and al. Another way is do the
filtering in the I/O thread (more efficient: no disk writes at
all).
......@@ -3096,7 +3115,7 @@ int Load_log_event::apply_event_impl(NET* net, RELAY_LOG_INFO* rli,
its companion query. If the SET is ignored because of
db_ok(), the companion query will also be ignored, and if
the companion query is ignored in the db_ok() test of
::apply_event_impl(), then the companion SET also have so
::do_apply_event(), then the companion SET also have so
we don't need to reset_one_shot_variables().
*/
if (rpl_filter->db_ok(thd->db))
......@@ -3293,7 +3312,7 @@ Fatal error running LOAD DATA INFILE on table '%s'. Default database: '%s'",
return 1;
}
return ( use_rli_only_for_errors ? 0 : Log_event::apply_event_impl(rli) );
return ( use_rli_only_for_errors ? 0 : Log_event::do_apply_event(rli) );
}
#endif
......@@ -3407,7 +3426,7 @@ bool Rotate_log_event::write(IO_CACHE* file)
#endif
/*
Rotate_log_event::apply_event_impl()
Rotate_log_event::do_apply_event()
Got a rotate log event from the master
......@@ -3424,10 +3443,9 @@ bool Rotate_log_event::write(IO_CACHE* file)
*/
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
int Rotate_log_event::apply_event_impl(RELAY_LOG_INFO* rli)
int Rotate_log_event::do_update_pos(RELAY_LOG_INFO *rli)
{
DBUG_ENTER("Rotate_log_event::apply_event_impl");
DBUG_ENTER("Rotate_log_event::do_update_pos");
pthread_mutex_lock(&rli->data_lock);
rli->event_relay_log_pos= my_b_tell(rli->cur_log);
/*
......@@ -3470,8 +3488,10 @@ int Rotate_log_event::apply_event_impl(RELAY_LOG_INFO* rli)
pthread_mutex_unlock(&rli->data_lock);
pthread_cond_broadcast(&rli->data_cond);
flush_relay_log_info(rli);
DBUG_RETURN(0);
}
#endif
......@@ -3577,11 +3597,11 @@ void Intvar_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
/*
Intvar_log_event::apply_event_impl()
Intvar_log_event::do_apply_event()
*/
#if defined(HAVE_REPLICATION)&& !defined(MYSQL_CLIENT)
int Intvar_log_event::apply_event_impl(RELAY_LOG_INFO* rli)
int Intvar_log_event::do_apply_event(RELAY_LOG_INFO const *rli)
{
switch (type) {
case LAST_INSERT_ID_EVENT:
......@@ -3592,6 +3612,11 @@ int Intvar_log_event::apply_event_impl(RELAY_LOG_INFO* rli)
thd->force_one_auto_inc_interval(val);
break;
}
return 0;
}
int Intvar_log_event::do_update_pos(RELAY_LOG_INFO *rli)
{
rli->inc_event_relay_log_pos();
return 0;
}
......@@ -3656,13 +3681,19 @@ void Rand_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
int Rand_log_event::apply_event_impl(RELAY_LOG_INFO* rli)
int Rand_log_event::do_apply_event(RELAY_LOG_INFO const *rli)
{
thd->rand.seed1= (ulong) seed1;
thd->rand.seed2= (ulong) seed2;
return 0;
}
int Rand_log_event::do_update_pos(RELAY_LOG_INFO *rli)
{
rli->inc_event_relay_log_pos();
return 0;
}
#endif /* !MYSQL_CLIENT */
......@@ -3729,12 +3760,12 @@ void Xid_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
int Xid_log_event::apply_event_impl(RELAY_LOG_INFO* rli)
int Xid_log_event::do_apply_event(RELAY_LOG_INFO const *rli)
{
/* For a slave Xid_log_event is COMMIT */
general_log_print(thd, COM_QUERY,
"COMMIT /* implicit, from Xid_log_event */");
return end_trans(thd, COMMIT) || Log_event::apply_event_impl(rli);
return end_trans(thd, COMMIT);
}
#endif /* !MYSQL_CLIENT */
......@@ -4010,11 +4041,11 @@ void User_var_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
/*
User_var_log_event::apply_event_impl()
User_var_log_event::do_apply_event()
*/
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
int User_var_log_event::apply_event_impl(RELAY_LOG_INFO* rli)
int User_var_log_event::do_apply_event(RELAY_LOG_INFO const *rli)
{
Item *it= 0;
CHARSET_INFO *charset;
......@@ -4076,9 +4107,15 @@ int User_var_log_event::apply_event_impl(RELAY_LOG_INFO* rli)
e.update_hash(val, val_len, type, charset, DERIVATION_IMPLICIT, 0);
free_root(thd->mem_root,0);
return 0;
}
int User_var_log_event::do_update_pos(RELAY_LOG_INFO *rli)
{
rli->inc_event_relay_log_pos();
return 0;
}
#endif /* !MYSQL_CLIENT */
......@@ -4228,11 +4265,11 @@ Slave_log_event::Slave_log_event(const char* buf, uint event_len)
#ifndef MYSQL_CLIENT
int Slave_log_event::apply_event_impl(RELAY_LOG_INFO* rli)
int Slave_log_event::do_apply_event(RELAY_LOG_INFO const *rli)
{
if (mysql_bin_log.is_open())
mysql_bin_log.write(this);
return Log_event::apply_event_impl(rli);
return 0;
}
#endif /* !MYSQL_CLIENT */
......@@ -4261,7 +4298,7 @@ void Stop_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
/*
Stop_log_event::apply_event_impl()
Stop_log_event::do_apply_event()
The master stopped. We used to clean up all temporary tables but
this is useless as, as the master has shut down properly, it has
......@@ -4270,12 +4307,12 @@ void Stop_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info)
slave_load_tmpdir, but this is useless as it has been cleared at the
end of LOAD DATA INFILE. So we have nothing to do here. The place
were we must do this cleaning is in
Start_log_event_v3::apply_event_impl(), not here. Because if we come
Start_log_event_v3::do_apply_event(), not here. Because if we come
here, the master was sane.
*/
#ifndef MYSQL_CLIENT
int Stop_log_event::apply_event_impl(RELAY_LOG_INFO* rli)
int Stop_log_event::do_update_pos(RELAY_LOG_INFO *rli)
{
/*
We do not want to update master_log pos because we get a rotate event
......@@ -4293,6 +4330,7 @@ int Stop_log_event::apply_event_impl(RELAY_LOG_INFO* rli)
}
return 0;
}
#endif /* !MYSQL_CLIENT */
#endif /* HAVE_REPLICATION */
......@@ -4483,11 +4521,11 @@ void Create_file_log_event::pack_info(Protocol *protocol)
/*
Create_file_log_event::apply_event_impl()
Create_file_log_event::do_apply_event()
*/
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
int Create_file_log_event::apply_event_impl(RELAY_LOG_INFO* rli)
int Create_file_log_event::do_apply_event(RELAY_LOG_INFO const *rli)
{
char proc_info[17+FN_REFLEN+10], *fname_buf;
char *ext;
......@@ -4549,7 +4587,7 @@ int Create_file_log_event::apply_event_impl(RELAY_LOG_INFO* rli)
if (fd >= 0)
my_close(fd, MYF(0));
thd->proc_info= 0;
return error ? 1 : Log_event::apply_event_impl(rli);
return error == 0;
}
#endif /* defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */
......@@ -4657,15 +4695,15 @@ int Append_block_log_event::get_create_or_append() const
}
/*
Append_block_log_event::apply_event_impl()
Append_block_log_event::do_apply_event()
*/
int Append_block_log_event::apply_event_impl(RELAY_LOG_INFO* rli)
int Append_block_log_event::do_apply_event(RELAY_LOG_INFO const *rli)
{
char proc_info[17+FN_REFLEN+10], *fname= proc_info+17;
int fd;
int error = 1;
DBUG_ENTER("Append_block_log_event::apply_event_impl");
DBUG_ENTER("Append_block_log_event::do_apply_event");
fname= strmov(proc_info, "Making temp file ");
slave_load_file_stem(fname, file_id, server_id, ".data");
......@@ -4704,7 +4742,7 @@ int Append_block_log_event::apply_event_impl(RELAY_LOG_INFO* rli)
if (fd >= 0)
my_close(fd, MYF(0));
thd->proc_info= 0;
DBUG_RETURN(error ? error : Log_event::apply_event_impl(rli));
DBUG_RETURN(error);
}
#endif
......@@ -4788,18 +4826,18 @@ void Delete_file_log_event::pack_info(Protocol *protocol)
#endif
/*
Delete_file_log_event::apply_event_impl()
Delete_file_log_event::do_apply_event()
*/
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
int Delete_file_log_event::apply_event_impl(RELAY_LOG_INFO* rli)
int Delete_file_log_event::do_apply_event(RELAY_LOG_INFO const *rli)
{
char fname[FN_REFLEN+10];
char *ext= slave_load_file_stem(fname, file_id, server_id, ".data");
(void) my_delete(fname, MYF(MY_WME));
strmov(ext, ".info");
(void) my_delete(fname, MYF(MY_WME));
return Log_event::apply_event_impl(rli);
return 0;
}
#endif /* defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */
......@@ -4885,10 +4923,10 @@ void Execute_load_log_event::pack_info(Protocol *protocol)
/*
Execute_load_log_event::apply_event_impl()
Execute_load_log_event::do_apply_event()
*/
int Execute_load_log_event::apply_event_impl(RELAY_LOG_INFO* rli)
int Execute_load_log_event::do_apply_event(RELAY_LOG_INFO const *rli)
{
char fname[FN_REFLEN+10];
char *ext;
......@@ -4919,15 +4957,15 @@ int Execute_load_log_event::apply_event_impl(RELAY_LOG_INFO* rli)
lev->thd = thd;
/*
lev->apply_event_impl should use rli only for errors i.e. should
lev->do_apply_event should use rli only for errors i.e. should
not advance rli's position.
lev->apply_event_impl is the place where the table is loaded (it
lev->do_apply_event is the place where the table is loaded (it
calls mysql_load()).
*/
rli->future_group_master_log_pos= log_pos;
if (lev->apply_event_impl(0,rli,1))
const_cast<RELAY_LOG_INFO*>(rli)->future_group_master_log_pos= log_pos;
if (lev->do_apply_event(0,rli,1))
{
/*
We want to indicate the name of the file that could not be loaded
......@@ -4970,7 +5008,7 @@ int Execute_load_log_event::apply_event_impl(RELAY_LOG_INFO* rli)
my_close(fd, MYF(0));
end_io_cache(&file);
}
return error ? error : Log_event::apply_event_impl(rli);
return error;
}
#endif /* defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) */
......@@ -5138,7 +5176,7 @@ void Execute_load_query_log_event::pack_info(Protocol *protocol)
int
Execute_load_query_log_event::apply_event_impl(RELAY_LOG_INFO* rli)
Execute_load_query_log_event::do_apply_event(RELAY_LOG_INFO const *rli)
{
char *p;
char *buf;
......@@ -5175,7 +5213,7 @@ Execute_load_query_log_event::apply_event_impl(RELAY_LOG_INFO* rli)
p= strmake(p, STRING_WITH_LEN(" INTO"));
p= strmake(p, query+fn_pos_end, q_len-fn_pos_end);
error= Query_log_event::apply_event_impl(rli, buf, p-buf);
error= Query_log_event::do_apply_event(rli, buf, p-buf);
/* Forging file name for deletion in same buffer */
*fname_end= 0;
......@@ -5488,7 +5526,7 @@ int Rows_log_event::do_add_row_data(byte *const row_data,
the master does not have a default value (and isn't nullable)
*/
static int
unpack_row(RELAY_LOG_INFO *rli,
unpack_row(RELAY_LOG_INFO const *rli,
TABLE *table, uint const colcnt, byte *record,
char const *row, MY_BITMAP const *cols,
char const **row_end, ulong *master_reclength,
......@@ -5590,17 +5628,17 @@ unpack_row(RELAY_LOG_INFO *rli,
return error;
}
int Rows_log_event::apply_event_impl(st_relay_log_info *rli)
int Rows_log_event::do_apply_event(RELAY_LOG_INFO const *rli)
{
DBUG_ENTER("Rows_log_event::apply_event_impl(st_relay_log_info*)");
DBUG_ENTER("Rows_log_event::do_apply_event(st_relay_log_info*)");
int error= 0;
char const *row_start= (char const *)m_rows_buf;
/*
If m_table_id == ~0UL, then we have a dummy event that does
not contain any data. In that case, we just remove all tables in
the tables_to_lock list, close the thread tables, step the relay
log position, and return with success.
If m_table_id == ~0UL, then we have a dummy event that does not
contain any data. In that case, we just remove all tables in the
tables_to_lock list, close the thread tables, and return with
success. The relay log position will be stepped in
*/
if (m_table_id == ~0UL)
{
......@@ -5610,16 +5648,15 @@ int Rows_log_event::apply_event_impl(st_relay_log_info *rli)
*/
DBUG_ASSERT(get_flags(STMT_END_F));
rli->clear_tables_to_lock();
const_cast<RELAY_LOG_INFO*>(rli)->clear_tables_to_lock();
close_thread_tables(thd);
thd->clear_error();
rli->inc_event_relay_log_pos();
DBUG_RETURN(0);
}
/*
'thd' has been set by exec_relay_log_event(), just before calling
apply_event_impl(). We still check here to prevent future coding
do_apply_event(). We still check here to prevent future coding
errors.
*/
DBUG_ASSERT(rli->sql_thd == thd);
......@@ -5637,7 +5674,7 @@ int Rows_log_event::apply_event_impl(st_relay_log_info *rli)
/*
lock_tables() reads the contents of thd->lex, so they must be
initialized. Contrary to in
Table_map_log_event::apply_event_impl() we don't call
Table_map_log_event::do_apply_event() we don't call
mysql_init_query() as that may reset the binlog format.
*/
lex_start(thd, NULL, 0);
......@@ -5650,7 +5687,7 @@ int Rows_log_event::apply_event_impl(st_relay_log_info *rli)
slave_print_msg(ERROR_LEVEL, rli, error,
"Error in %s event: when locking tables",
get_type_str());
rli->clear_tables_to_lock();
const_cast<RELAY_LOG_INFO*>(rli)->clear_tables_to_lock();
DBUG_RETURN(error);
}
......@@ -5668,10 +5705,12 @@ int Rows_log_event::apply_event_impl(st_relay_log_info *rli)
need to add code to assert that is the case.
*/
thd->binlog_flush_pending_rows_event(false);
close_tables_for_reopen(thd, &rli->tables_to_lock);
close_tables_for_reopen(thd, &const_cast<RELAY_LOG_INFO*>(rli)->tables_to_lock);
if ((error= open_tables(thd, &rli->tables_to_lock,
&rli->tables_to_lock_count, 0)))
if ((error= open_tables(thd,
&const_cast<RELAY_LOG_INFO*>(rli)->tables_to_lock,
&const_cast<RELAY_LOG_INFO*>(rli)->tables_to_lock_count,
0)))
{
if (thd->query_error || thd->is_fatal_error)
{
......@@ -5686,7 +5725,7 @@ int Rows_log_event::apply_event_impl(st_relay_log_info *rli)
"unexpected success or fatal error"));
thd->query_error= 1;
}
rli->clear_tables_to_lock();
const_cast<RELAY_LOG_INFO*>(rli)->clear_tables_to_lock();
DBUG_RETURN(error);
}
}
......@@ -5701,23 +5740,23 @@ int Rows_log_event::apply_event_impl(st_relay_log_info *rli)
TABLE_LIST *ptr;
for (ptr= rli->tables_to_lock ; ptr ; ptr= ptr->next_global)
{
rli->m_table_map.set_table(ptr->table_id, ptr->table);
const_cast<RELAY_LOG_INFO*>(rli)->m_table_map.set_table(ptr->table_id, ptr->table);
}
#ifdef HAVE_QUERY_CACHE
query_cache.invalidate_locked_for_write(rli->tables_to_lock);
#endif
rli->clear_tables_to_lock();
const_cast<RELAY_LOG_INFO*>(rli)->clear_tables_to_lock();
}
DBUG_ASSERT(rli->tables_to_lock == NULL && rli->tables_to_lock_count == 0);
TABLE* table= rli->m_table_map.get_table(m_table_id);
TABLE* table= const_cast<RELAY_LOG_INFO*>(rli)->m_table_map.get_table(m_table_id);
if (table)
{
/*
table == NULL means that this table should not be replicated
(this was set up by Table_map_log_event::apply_event_impl()
(this was set up by Table_map_log_event::do_apply_event()
which tested replicate-* rules).
*/
......@@ -5785,7 +5824,7 @@ int Rows_log_event::apply_event_impl(st_relay_log_info *rli)
row_start= row_end;
}
DBUG_EXECUTE_IF("STOP_SLAVE_after_first_Rows_event",
rli->abort_slave=1;);
const_cast<RELAY_LOG_INFO*>(rli)->abort_slave= 1;);
error= do_after_row_operations(table, error);
if (!cache_stmt)
{
......@@ -5812,7 +5851,7 @@ int Rows_log_event::apply_event_impl(st_relay_log_info *rli)
thread is certainly going to stop.
*/
thd->reset_current_stmt_binlog_row_based();
rli->cleanup_context(thd, 1);
const_cast<RELAY_LOG_INFO*>(rli)->cleanup_context(thd, 1);
thd->query_error= 1;
DBUG_RETURN(error);
}
......@@ -5856,8 +5895,7 @@ int Rows_log_event::apply_event_impl(st_relay_log_info *rli)
*/
thd->reset_current_stmt_binlog_row_based();
rli->cleanup_context(thd, 0);
rli->transaction_end(thd);
const_cast<RELAY_LOG_INFO*>(rli)->cleanup_context(thd, 0);
if (error == 0)
{
......@@ -5870,7 +5908,6 @@ int Rows_log_event::apply_event_impl(st_relay_log_info *rli)
do not become visible. We still prefer to wipe them out.
*/
thd->clear_error();
error= Log_event::apply_event_impl(rli);
}
else
slave_print_msg(ERROR_LEVEL, rli, error,
......@@ -5899,15 +5936,15 @@ int Rows_log_event::apply_event_impl(st_relay_log_info *rli)
problem. When WL#2975 is implemented, just remove the member
st_relay_log_info::unsafe_to_stop_at and all its occurences.
*/
rli->unsafe_to_stop_at= time(0);
const_cast<RELAY_LOG_INFO*>(rli)->unsafe_to_stop_at= time(0);
}
DBUG_ASSERT(error == 0);
thd->clear_error();
rli->inc_event_relay_log_pos();
DBUG_RETURN(0);
}
#endif /* !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) */
#ifndef MYSQL_CLIENT
......@@ -6081,15 +6118,15 @@ Table_map_log_event::Table_map_log_event(const char *buf, uint event_len,
const char *const vpart= buf + common_header_len + post_header_len;
/* Extract the length of the various parts from the buffer */
byte const* const ptr_dblen= (byte const*)vpart + 0;
byte const *const ptr_dblen= (byte const*)vpart + 0;
m_dblen= *(uchar*) ptr_dblen;
/* Length of database name + counter + terminating null */
byte const* const ptr_tbllen= ptr_dblen + m_dblen + 2;
byte const *const ptr_tbllen= ptr_dblen + m_dblen + 2;
m_tbllen= *(uchar*) ptr_tbllen;
/* Length of table name + counter + terminating null */
byte const* const ptr_colcnt= ptr_tbllen + m_tbllen + 2;
byte const *const ptr_colcnt= ptr_tbllen + m_tbllen + 2;
uchar *ptr_after_colcnt= (uchar*) ptr_colcnt;
m_colcnt= net_field_length(&ptr_after_colcnt);
......@@ -6134,9 +6171,9 @@ Table_map_log_event::~Table_map_log_event()
*/
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
int Table_map_log_event::apply_event_impl(st_relay_log_info *rli)
int Table_map_log_event::do_apply_event(RELAY_LOG_INFO const *rli)
{
DBUG_ENTER("Table_map_log_event::apply_event_impl(st_relay_log_info*)");
DBUG_ENTER("Table_map_log_event::do_apply_event(st_relay_log_info*)");
DBUG_ASSERT(rli->sql_thd == thd);
......@@ -6240,29 +6277,24 @@ int Table_map_log_event::apply_event_impl(st_relay_log_info *rli)
locked by linking the table into the list of tables to lock.
*/
table_list->next_global= table_list->next_local= rli->tables_to_lock;
rli->tables_to_lock= table_list;
rli->tables_to_lock_count++;
const_cast<RELAY_LOG_INFO*>(rli)->tables_to_lock= table_list;
const_cast<RELAY_LOG_INFO*>(rli)->tables_to_lock_count++;
/* 'memory' is freed in clear_tables_to_lock */
}
/*
We explicitly do not call Log_event::apply_event_impl() here since
we do not want the relay log position to be flushed to disk. The
flushing will be done by the last Rows_log_event that either ends
a statement (outside a transaction) or a transaction.
A table map event can *never* end a transaction or a statement, so we
just step the relay log position.
*/
if (likely(!error))
rli->inc_event_relay_log_pos();
DBUG_RETURN(error);
err:
my_free((gptr) memory, MYF(MY_WME));
DBUG_RETURN(error);
}
int Table_map_log_event::do_update_pos(RELAY_LOG_INFO *rli)
{
rli->inc_event_relay_log_pos();
return 0;
}
#endif /* !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION) */
#ifndef MYSQL_CLIENT
......@@ -6427,7 +6459,7 @@ int Write_rows_log_event::do_after_row_operations(TABLE *table, int error)
return error;
}
int Write_rows_log_event::do_prepare_row(THD *thd, RELAY_LOG_INFO *rli,
int Write_rows_log_event::do_prepare_row(THD *thd, RELAY_LOG_INFO const *rli,
TABLE *table,
char const *row_start,
char const **row_end)
......@@ -6973,7 +7005,7 @@ int Delete_rows_log_event::do_after_row_operations(TABLE *table, int error)
return error;
}
int Delete_rows_log_event::do_prepare_row(THD *thd, RELAY_LOG_INFO *rli,
int Delete_rows_log_event::do_prepare_row(THD *thd, RELAY_LOG_INFO const *rli,
TABLE *table,
char const *row_start,
char const **row_end)
......@@ -7110,7 +7142,7 @@ int Update_rows_log_event::do_after_row_operations(TABLE *table, int error)
return error;
}
int Update_rows_log_event::do_prepare_row(THD *thd, RELAY_LOG_INFO *rli,
int Update_rows_log_event::do_prepare_row(THD *thd, RELAY_LOG_INFO const *rli,
TABLE *table,
char const *row_start,
char const **row_end)
......
......@@ -1056,30 +1056,19 @@ void st_relay_log_info::cached_charset_invalidate()
}
bool st_relay_log_info::cached_charset_compare(char *charset)
bool st_relay_log_info::cached_charset_compare(char *charset) const
{
DBUG_ENTER("st_relay_log_info::cached_charset_compare");
if (bcmp(cached_charset, charset, sizeof(cached_charset)))
{
memcpy(cached_charset, charset, sizeof(cached_charset));
memcpy(const_cast<char*>(cached_charset), charset, sizeof(cached_charset));
DBUG_RETURN(1);
}
DBUG_RETURN(0);
}
void st_relay_log_info::transaction_end(THD* thd)
{
DBUG_ENTER("st_relay_log_info::transaction_end");
/*
Nothing to do here right now.
*/
DBUG_VOID_RETURN;
}
#if !defined(MYSQL_CLIENT) && defined(HAVE_REPLICATION)
void st_relay_log_info::cleanup_context(THD *thd, bool error)
{
......
......@@ -291,9 +291,7 @@ typedef struct st_relay_log_info
When the 6 bytes are equal to 0 is used to mean "cache is invalidated".
*/
void cached_charset_invalidate();
bool cached_charset_compare(char *charset);
void transaction_end(THD*);
bool cached_charset_compare(char *charset) const;
void cleanup_context(THD *, bool);
void clear_tables_to_lock() {
......
......@@ -109,7 +109,7 @@ field_length_from_packed(enum_field_types const field_type,
*/
int
table_def::compatible_with(RELAY_LOG_INFO *rli, TABLE *table)
table_def::compatible_with(RELAY_LOG_INFO const *rli_arg, TABLE *table)
const
{
/*
......@@ -117,6 +117,7 @@ table_def::compatible_with(RELAY_LOG_INFO *rli, TABLE *table)
*/
uint const cols_to_check= min(table->s->fields, size());
int error= 0;
RELAY_LOG_INFO const *rli= const_cast<RELAY_LOG_INFO*>(rli_arg);
TABLE_SHARE const *const tsh= table->s;
......
......@@ -116,7 +116,7 @@ class table_def
1 if the table definition is not compatible with 'table'
0 if the table definition is compatible with 'table'
*/
int compatible_with(RELAY_LOG_INFO *rli, TABLE *table) const;
int compatible_with(RELAY_LOG_INFO const *rli, TABLE *table) const;
private:
my_size_t m_size; // Number of elements in the types array
......
......@@ -555,7 +555,7 @@ static bool sql_slave_killed(THD* thd, RELAY_LOG_INFO* rli)
void
*/
void slave_print_msg(enum loglevel level, RELAY_LOG_INFO* rli,
void slave_print_msg(enum loglevel level, RELAY_LOG_INFO const *rli,
int err_code, const char* msg, ...)
{
void (*report_function)(const char *, ...);
......@@ -577,9 +577,9 @@ void slave_print_msg(enum loglevel level, RELAY_LOG_INFO* rli,
It's an error, it must be reported in Last_error and Last_errno in SHOW
SLAVE STATUS.
*/
pbuff= rli->last_slave_error;
pbuff= const_cast<RELAY_LOG_INFO*>(rli)->last_slave_error;
pbuffsize= sizeof(rli->last_slave_error);
rli->last_slave_errno = err_code;
const_cast<RELAY_LOG_INFO*>(rli)->last_slave_errno = err_code;
report_function= sql_print_error;
break;
case WARNING_LEVEL:
......@@ -1376,7 +1376,7 @@ void set_slave_thread_options(THD* thd)
DBUG_VOID_RETURN;
}
void set_slave_thread_default_charset(THD* thd, RELAY_LOG_INFO *rli)
void set_slave_thread_default_charset(THD* thd, RELAY_LOG_INFO const *rli)
{
DBUG_ENTER("set_slave_thread_default_charset");
......@@ -1387,7 +1387,14 @@ void set_slave_thread_default_charset(THD* thd, RELAY_LOG_INFO *rli)
thd->variables.collation_server=
global_system_variables.collation_server;
thd->update_charset();
rli->cached_charset_invalidate();
/*
We use a const cast here since the conceptual (and externally
visible) behavior of the function is to set the default charset of
the thread. That the cache has to be invalidated is a secondary
effect.
*/
const_cast<RELAY_LOG_INFO*>(rli)->cached_charset_invalidate();
DBUG_VOID_RETURN;
}
......@@ -1607,7 +1614,8 @@ static ulong read_event(MYSQL* mysql, MASTER_INFO *mi, bool* suppress_warnings)
}
int check_expected_error(THD* thd, RELAY_LOG_INFO* rli, int expected_error)
int check_expected_error(THD* thd, RELAY_LOG_INFO const *rli,
int expected_error)
{
DBUG_ENTER("check_expected_error");
......
......@@ -164,9 +164,9 @@ bool show_master_info(THD* thd, MASTER_INFO* mi);
bool show_binlog_info(THD* thd);
const char *print_slave_db_safe(const char *db);
int check_expected_error(THD* thd, RELAY_LOG_INFO* rli, int error_code);
int check_expected_error(THD* thd, RELAY_LOG_INFO const *rli, int error_code);
void skip_load_data_infile(NET* net);
void slave_print_msg(enum loglevel level, RELAY_LOG_INFO* rli,
void slave_print_msg(enum loglevel level, RELAY_LOG_INFO const *rli,
int err_code, const char* msg, ...)
ATTRIBUTE_FORMAT(printf, 4, 5);
......@@ -184,7 +184,7 @@ int init_relay_log_pos(RELAY_LOG_INFO* rli,const char* log,ulonglong pos,
int purge_relay_logs(RELAY_LOG_INFO* rli, THD *thd, bool just_reset,
const char** errmsg);
void set_slave_thread_options(THD* thd);
void set_slave_thread_default_charset(THD* thd, RELAY_LOG_INFO *rli);
void set_slave_thread_default_charset(THD *thd, RELAY_LOG_INFO const *rli);
void rotate_relay_log(MASTER_INFO* mi);
pthread_handler_t handle_slave_io(void *arg);
......
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