diff options
author | <Dao-Gang.Qu@sun.com> | 2009-08-29 16:52:22 +0800 |
---|---|---|
committer | <Dao-Gang.Qu@sun.com> | 2009-08-29 16:52:22 +0800 |
commit | 90e25c6fb09350fb048f7c50762c050d68ce3c1f (patch) | |
tree | 7b9f786af53e5a6e82eb856d81565f2687e89823 /sql/events.cc | |
parent | 2d6c97e0e67b357c75fffa5e95559befafab5c90 (diff) | |
download | mariadb-git-90e25c6fb09350fb048f7c50762c050d68ce3c1f.tar.gz |
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.
Diffstat (limited to 'sql/events.cc')
-rw-r--r-- | sql/events.cc | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/sql/events.cc b/sql/events.cc index 10edfff2402..34da0e185b7 100644 --- a/sql/events.cc +++ b/sql/events.cc @@ -342,6 +342,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. @param[in,out] thd THD @@ -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); |