mirror of
https://github.com/MariaDB/server.git
synced 2026-04-22 08:15:31 +02:00
Bug #44331 Restore of database with events produces warning in replication
If an EVENT is created without the DEFINER clause set explicitly or with it set to CURRENT_USER, the master and slaves become inconsistent. This issue stems from the fact that in both cases, the DEFINER is set to the CURRENT_USER of the current thread. On the master, the CURRENT_USER is the mysqld's user, while on the slave, the CURRENT_USER is empty for the SQL Thread which is responsible for executing the statement. To fix the problem, we do what follows. If the definer is not set explicitly, a DEFINER clause is added when writing the query into binlog; if 'CURRENT_USER' is used as the DEFINER, it is replaced with the value of the current user before writing to binlog. mysql-test/suite/rpl/r/rpl_create_if_not_exists.result: Updated the result file after fixing bug#44331 mysql-test/suite/rpl/r/rpl_drop_if_exists.result: Updated the result file after fixing bug#44331 mysql-test/suite/rpl/r/rpl_events.result: Test result of Bug#44331 mysql-test/suite/rpl/r/rpl_innodb_mixed_dml.result: Updated the result file after fixing bug#44331 mysql-test/suite/rpl/t/rpl_events.test: Added test to verify if the definer is consistent between master and slave when the event is created without the DEFINER clause set explicitly or the DEFINER is set to CURRENT_USER sql/events.cc: The "create_query_string" function is added to create a new query string for removing executable comments. sql/sql_yacc.yy: The remember_name token was added for recording the offset of EVENT_SYM.
This commit is contained in:
parent
dc7106f5ca
commit
f32c08bd0c
7 changed files with 131 additions and 12 deletions
|
|
@ -341,6 +341,33 @@ common_1_lev_code:
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
Create a new query string for removing executable comments
|
||||
for avoiding leak and keeping consistency of the execution
|
||||
on master and slave.
|
||||
|
||||
@param[in] thd Thread handler
|
||||
@param[in] buf Query string
|
||||
|
||||
@return
|
||||
0 ok
|
||||
1 error
|
||||
*/
|
||||
static int
|
||||
create_query_string(THD *thd, String *buf)
|
||||
{
|
||||
/* Append the "CREATE" part of the query */
|
||||
if (buf->append(STRING_WITH_LEN("CREATE ")))
|
||||
return 1;
|
||||
/* Append definer */
|
||||
append_definer(thd, buf, &(thd->lex->definer->user), &(thd->lex->definer->host));
|
||||
/* Append the left part of thd->query after "DEFINER" part */
|
||||
if (buf->append(thd->lex->stmt_definition_begin))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
Create a new event.
|
||||
|
||||
|
|
@ -439,7 +466,16 @@ Events::create_event(THD *thd, Event_parse_data *parse_data,
|
|||
{
|
||||
/* Binlog the create event. */
|
||||
DBUG_ASSERT(thd->query && thd->query_length);
|
||||
write_bin_log(thd, TRUE, thd->query, thd->query_length);
|
||||
String log_query;
|
||||
if (create_query_string(thd, &log_query))
|
||||
{
|
||||
sql_print_error("Event Error: An error occurred while creating query string, "
|
||||
"before writing it into binary log.");
|
||||
DBUG_RETURN(TRUE);
|
||||
}
|
||||
/* If the definer is not set or set to CURRENT_USER, the value of CURRENT_USER
|
||||
will be written into the binary log as the definer for the SQL thread. */
|
||||
write_bin_log(thd, TRUE, log_query.c_ptr(), log_query.length());
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&LOCK_event_metadata);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue