diff options
author | Alexander Nozdrin <alik@sun.com> | 2010-02-02 16:38:44 +0300 |
---|---|---|
committer | Alexander Nozdrin <alik@sun.com> | 2010-02-02 16:38:44 +0300 |
commit | 59f1be1b636e360c410c81de1c41a8c4a254077d (patch) | |
tree | f9c8abdf7dad923c0137a358559ba46ba23e2c61 /sql/events.cc | |
parent | 2db684572ea716de462bf8d79f398dfcc130a8ff (diff) | |
download | mariadb-git-59f1be1b636e360c410c81de1c41a8c4a254077d.tar.gz |
Revert a patch for Bug#48231, which introduced valgrind warnings.
Original revision:
------------------------------------------------------------
revision-id: li-bing.song@sun.com-20100130124925-o6sfex42b6noyc6x
parent: joro@sun.com-20100129145427-0n79l9hnk0q43ajk
committer: <Li-Bing.Song@sun.com>
branch nick: mysql-5.1-bugteam
timestamp: Sat 2010-01-30 20:49:25 +0800
message:
Bug #48321 CURRENT_USER() incorrectly replicated for DROP/RENAME USER;
REVOKE/GRANT; ALTER EVENT.
The following statements support the CURRENT_USER() where a user is needed.
DROP USER
RENAME USER CURRENT_USER() ...
GRANT ... TO CURRENT_USER()
REVOKE ... FROM CURRENT_USER()
ALTER DEFINER = CURRENT_USER() EVENT
but, When these statements are binlogged, CURRENT_USER() just is binlogged
as 'CURRENT_USER()', it is not expanded to the real user name. When slave
executes the log event, 'CURRENT_USER()' is expand to the user of slave
SQL thread, but SQL thread's user name always NULL. This breaks the replication.
After this patch, All above statements are rewritten when they are binlogged.
The CURRENT_USER() is expanded to the real user's name and host.
------------------------------------------------------------
Diffstat (limited to 'sql/events.cc')
-rw-r--r-- | sql/events.cc | 79 |
1 files changed, 40 insertions, 39 deletions
diff --git a/sql/events.cc b/sql/events.cc index 6c8bdb1ea0f..4c6dd0f35d1 100644 --- a/sql/events.cc +++ b/sql/events.cc @@ -341,48 +341,31 @@ common_1_lev_code: } -/* - Binlog '{CREATE|ALTER} EVENT' statements. - Definer part is always rewritten, for definer can be CURRENT_USER() function. - +/** + 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] create CREATE or ALTER statement + @param[in] buf Query string @return - FASE ok - TRUE error + 0 ok + 1 error */ -static bool event_write_bin_log(THD *thd, bool create) +static int +create_query_string(THD *thd, String *buf) { - String log_query; - if (create) - { - /* Append the "CREATE" part of the query */ - if (log_query.append(STRING_WITH_LEN("CREATE "))) - return TRUE; - } - else - { - /* Append the "ALETR " part of the query */ - if (log_query.append(STRING_WITH_LEN("ALTER "))) - return TRUE; - } - - /* Append definer - 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. - */ - append_definer(thd, &log_query, &(thd->lex->definer->user), - &(thd->lex->definer->host)); - + /* 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 (log_query.append(thd->lex->stmt_definition_begin, - thd->lex->stmt_definition_end - - thd->lex->stmt_definition_begin)) - return TRUE; - - return write_bin_log(thd, TRUE, log_query.c_ptr_safe(), log_query.length()) - != 0; + if (buf->append(thd->lex->stmt_definition_begin)) + return 1; + + return 0; } /** @@ -397,7 +380,8 @@ static bool event_write_bin_log(THD *thd, bool create) @sa Events::drop_event for the notes about locking, pre-locking and Events DDL. - @retval FALSE OK @retval TRUE Error (reported) + @retval FALSE OK + @retval TRUE Error (reported) */ bool @@ -481,7 +465,22 @@ Events::create_event(THD *thd, Event_parse_data *parse_data, binlog the create event unless it's been successfully dropped */ if (!dropped) - ret= event_write_bin_log(thd, TRUE); + { + /* Binlog the create event. */ + DBUG_ASSERT(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."); + /* Restore the state of binlog format */ + thd->current_stmt_binlog_row_based= save_binlog_row_based; + 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. */ + ret= write_bin_log(thd, TRUE, log_query.c_ptr(), log_query.length()); + } } pthread_mutex_unlock(&LOCK_event_metadata); /* Restore the state of binlog format */ @@ -603,7 +602,9 @@ Events::update_event(THD *thd, Event_parse_data *parse_data, if (event_queue) event_queue->update_event(thd, parse_data->dbname, parse_data->name, new_element); - ret= event_write_bin_log(thd, FALSE); + /* Binlog the alter event. */ + DBUG_ASSERT(thd->query() && thd->query_length()); + ret= write_bin_log(thd, TRUE, thd->query(), thd->query_length()); } } pthread_mutex_unlock(&LOCK_event_metadata); |