diff options
author | Alexander Nozdrin <alik@sun.com> | 2010-02-03 19:21:17 +0300 |
---|---|---|
committer | Alexander Nozdrin <alik@sun.com> | 2010-02-03 19:21:17 +0300 |
commit | 9dc8347c1e55c0e56f4be147d20900d89bfbe4a5 (patch) | |
tree | 33c92e57a94a700ac7dbcca5e9c0ff9181f1e6f0 /sql | |
parent | 8a685b3ce5912c84b2172d785e67a5423da774d4 (diff) | |
parent | 31ba3bf5cb51ed8ccc7f2d6c05b92e18794889a0 (diff) | |
download | mariadb-git-9dc8347c1e55c0e56f4be147d20900d89bfbe4a5.tar.gz |
Manual merge from mysql-trunk-merge.
Conflicts:
- mysql-test/t/bug46080.test
Diffstat (limited to 'sql')
-rwxr-xr-x[-rw-r--r--] | sql/event_scheduler.cc | 3 | ||||
-rw-r--r-- | sql/events.cc | 79 | ||||
-rw-r--r-- | sql/sql_acl.cc | 124 | ||||
-rw-r--r-- | sql/sql_lex.h | 25 | ||||
-rw-r--r-- | sql/sql_yacc.yy | 36 |
5 files changed, 61 insertions, 206 deletions
diff --git a/sql/event_scheduler.cc b/sql/event_scheduler.cc index 5d8455fa88b..733f2a7167f 100644..100755 --- a/sql/event_scheduler.cc +++ b/sql/event_scheduler.cc @@ -237,8 +237,9 @@ event_scheduler_thread(void *arg) if (!res) scheduler->run(thd); + DBUG_LEAVE; // Against gcc warnings my_thread_end(); - DBUG_RETURN(0); // Against gcc warnings + return 0; } diff --git a/sql/events.cc b/sql/events.cc index 35fbca871bb..73f3427607d 100644 --- a/sql/events.cc +++ b/sql/events.cc @@ -246,48 +246,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; } /** @@ -302,7 +285,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 @@ -384,7 +368,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()); + } } mysql_mutex_unlock(&LOCK_event_metadata); /* Restore the state of binlog format */ @@ -503,7 +502,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()); } } mysql_mutex_unlock(&LOCK_event_metadata); diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 8283123f51c..012542a9467 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -196,7 +196,6 @@ static bool compare_hostname(const acl_host_and_ip *host,const char *hostname, const char *ip); static my_bool acl_load(THD *thd, TABLE_LIST *tables); static my_bool grant_load(THD *thd, TABLE_LIST *tables); -static bool acl_write_bin_log(THD *thd, List <LEX_USER> &list, bool clear_error); /* Convert scrambled password to binary form, according to scramble type, @@ -3271,8 +3270,7 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list, if (!result) /* success */ { - if (acl_write_bin_log(thd, user_list, TRUE)) - result= -1; + result= write_bin_log(thd, TRUE, thd->query(), thd->query_length()); } mysql_rwlock_unlock(&LOCK_grant); @@ -3448,7 +3446,8 @@ bool mysql_routine_grant(THD *thd, TABLE_LIST *table_list, bool is_proc, if (write_to_binlog) { - result|= acl_write_bin_log(thd, user_list, FALSE); + if (write_bin_log(thd, FALSE, thd->query(), thd->query_length())) + result= TRUE; } mysql_rwlock_unlock(&LOCK_grant); @@ -3577,7 +3576,7 @@ bool mysql_grant(THD *thd, const char *db, List <LEX_USER> &list, if (!result) { - result= acl_write_bin_log(thd, list, TRUE); + result= write_bin_log(thd, TRUE, thd->query(), thd->query_length()); } mysql_rwlock_unlock(&LOCK_grant); @@ -5756,9 +5755,9 @@ static int handle_grant_data(TABLE_LIST *tables, bool drop, } -static void append_user(String *str, LEX_USER *user, bool comma= TRUE) +static void append_user(String *str, LEX_USER *user) { - if (comma && str->length()) + if (str->length()) str->append(','); str->append('\''); str->append(user->user.str); @@ -5767,65 +5766,6 @@ static void append_user(String *str, LEX_USER *user, bool comma= TRUE) str->append('\''); } -/* - The operations(DROP, RENAME, REVOKE, GRANT) will cause inconsistency between - master and slave, when CURRENT_USER() is used. To solve this problem, we - construct a new binlog statement in which CURRENT_USER() is replaced by - the real user name and host name. - */ -static bool acl_write_bin_log(THD *thd, List <LEX_USER> &list, bool clear_error) -{ - String log_query; - LEX *lex= thd->lex; - List_iterator <LEX_USER> user_list(list); - LEX_USER *user, *tmp_user; - - if (!mysql_bin_log.is_open()) - return FALSE; - - if (log_query.append(lex->stmt_begin, lex->stmt_user_begin - lex->stmt_begin)) - return TRUE; - while ((tmp_user= user_list++)) - { - if (!(user= get_current_user(thd, tmp_user))) - continue; - - /* - No User, but a password? - They did GRANT ... TO CURRENT_USER() IDENTIFIED BY ... ! - Get the current user, and shallow-copy the new password to them! - */ - if (!tmp_user->user.str && tmp_user->password.str) - user->password= tmp_user->password; - - if (log_query.append(" ", 1)) - return TRUE; - append_user(&log_query, user, FALSE); - /* Only 'GRANT' have password */ - if (user->password.str) - { - if (log_query.append(STRING_WITH_LEN(" IDENTIFIED BY ")) || - log_query.append(STRING_WITH_LEN("PASSWORD ")) || - log_query.append("'", 1) || - log_query.append(user->password.str, - user->password.length) || - log_query.append("'", 1)) - return TRUE; - } - if (log_query.append(",", 1)) - return TRUE; - } - /* It is binlogged only when at least one user is in the query */ - if (log_query.c_ptr()[log_query.length()-1] == ',') - { - log_query.length(log_query.length()-1); - if (log_query.append(lex->stmt_user_end, lex->stmt_end - lex->stmt_user_end)) - return TRUE; - return write_bin_log(thd, clear_error, log_query.c_ptr_safe(), - log_query.length()) != 0; - } - return FALSE; -} /* Create a list of users. @@ -5932,7 +5872,6 @@ bool mysql_drop_user(THD *thd, List <LEX_USER> &list) { int result; String wrong_users; - String log_query; LEX_USER *user_name, *tmp_user_name; List_iterator <LEX_USER> user_list(list); TABLE_LIST tables[GRANT_TABLES]; @@ -5962,7 +5901,6 @@ bool mysql_drop_user(THD *thd, List <LEX_USER> &list) mysql_rwlock_wrlock(&LOCK_grant); mysql_mutex_lock(&acl_cache->lock); - log_query.append(STRING_WITH_LEN("DROP USER")); while ((tmp_user_name= user_list++)) { if (!(user_name= get_current_user(thd, tmp_user_name))) @@ -5970,17 +5908,6 @@ bool mysql_drop_user(THD *thd, List <LEX_USER> &list) result= TRUE; continue; } - - /* - The operation will cause inconsistency between master and slave, when - CURRENT_USER() is used. To solve this problem, we construct a new - binlog statement in which CURRENT_USER() is replaced by the real user - name and host name. - */ - log_query.append(STRING_WITH_LEN(" ")); - append_user(&log_query, user_name, FALSE); - log_query.append(STRING_WITH_LEN(",")); - if (handle_grant_data(tables, 1, user_name, NULL) <= 0) { append_user(&wrong_users, user_name); @@ -5999,13 +5926,7 @@ bool mysql_drop_user(THD *thd, List <LEX_USER> &list) my_error(ER_CANNOT_USER, MYF(0), "DROP USER", wrong_users.c_ptr_safe()); if (some_users_deleted) - { - if (log_query.c_ptr()[log_query.length()-1] == ',') - { - log_query.length(log_query.length()-1); - result|= write_bin_log(thd, FALSE, log_query.c_ptr_safe(), log_query.length()); - } - } + result |= write_bin_log(thd, FALSE, thd->query(), thd->query_length()); mysql_rwlock_unlock(&LOCK_grant); close_thread_tables(thd); @@ -6033,7 +5954,6 @@ bool mysql_rename_user(THD *thd, List <LEX_USER> &list) { int result; String wrong_users; - String log_query; LEX_USER *user_from, *tmp_user_from; LEX_USER *user_to, *tmp_user_to; List_iterator <LEX_USER> user_list(list); @@ -6061,7 +5981,6 @@ bool mysql_rename_user(THD *thd, List <LEX_USER> &list) mysql_rwlock_wrlock(&LOCK_grant); mysql_mutex_lock(&acl_cache->lock); - log_query.append(STRING_WITH_LEN("RENAME USER")); while ((tmp_user_from= user_list++)) { if (!(user_from= get_current_user(thd, tmp_user_from))) @@ -6078,18 +5997,6 @@ bool mysql_rename_user(THD *thd, List <LEX_USER> &list) DBUG_ASSERT(user_to != 0); /* Syntax enforces pairs of users. */ /* - The operation will cause inconsistency between master and slave, when - CURRENT_USER() is used. To solve this problem, we construct a new - binlog statement in which CURRENT_USER() is replaced by the real user - name and host name. - */ - log_query.append(STRING_WITH_LEN(" ")); - append_user(&log_query, user_from, FALSE); - log_query.append(STRING_WITH_LEN(" TO ")); - append_user(&log_query, user_to, FALSE); - log_query.append(STRING_WITH_LEN(",")); - - /* Search all in-memory structures and grant tables for a mention of the new user name. */ @@ -6110,15 +6017,9 @@ bool mysql_rename_user(THD *thd, List <LEX_USER> &list) if (result) my_error(ER_CANNOT_USER, MYF(0), "RENAME USER", wrong_users.c_ptr_safe()); - - if (some_users_renamed) - { - if (log_query.c_ptr()[log_query.length()-1] == ',') - { - log_query.length(log_query.length()-1); - result|= write_bin_log(thd, FALSE, log_query.c_ptr_safe(), log_query.length()); - } - } + + if (some_users_renamed && mysql_bin_log.is_open()) + result |= write_bin_log(thd, FALSE, thd->query(), thd->query_length()); mysql_rwlock_unlock(&LOCK_grant); close_thread_tables(thd); @@ -6308,9 +6209,8 @@ bool mysql_revoke_all(THD *thd, List <LEX_USER> &list) mysql_mutex_unlock(&acl_cache->lock); - int binlog_error= 0; - if (acl_write_bin_log(thd, list, FALSE)) - binlog_error= 1; + int binlog_error= + write_bin_log(thd, FALSE, thd->query(), thd->query_length()); mysql_rwlock_unlock(&LOCK_grant); close_thread_tables(thd); diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 67e1861a993..800a16cf2b6 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -1986,8 +1986,6 @@ struct LEX: public Query_tables_list - CREATE TRIGGER (points to "TRIGGER"); - CREATE PROCEDURE (points to "PROCEDURE"); - CREATE FUNCTION (points to "FUNCTION" or "AGGREGATE"); - - CREATE VIEW(points to "VIEW"); - - CREATE EVENT(points to "EVENT"); This pointer is required to add possibly omitted DEFINER-clause to the DDL-statement before dumping it to the binlog. @@ -1996,29 +1994,6 @@ struct LEX: public Query_tables_list const char *stmt_definition_end; - /* - stmt_begin is intended to point to the begin of every statement. - It is now used in the following statements: - - GRANT ALL PRIVELEGES ON *.* (points to "GRANT"); - - REVOKE ALL PRIVELEGES ON *.* (points to "REVOKE"); - */ - const char *stmt_begin; - const char *stmt_end; - - /* - stmt_user_begin is intended to point to the begin of the user list in - the following statements: - - GRANT ALL PRIVELEGES ON *.* TO 'username'@'hostname' - (points to "'username'"); - - REVOKE ALL PRIVELEGES ON *.* FROM 'username'@'hostname' - (points to "'username'"); - - these pointers are required to replace the CURRENT_USER() - function by the real user before dumping it to the binlog. - */ - const char *stmt_user_begin; - const char *stmt_user_end; - /** During name resolution search only in the table list given by Name_resolution_context::first_name_resolution_table and diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 9f4bad45ce5..ab128a9b701 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -1681,11 +1681,7 @@ opt_end_of_input: ; verb_clause: - remember_name statement remember_end - { - Lex->stmt_begin= $1; - Lex->stmt_end= $3; - } + statement | begin ; @@ -6196,7 +6192,7 @@ alter: } view_tail {} - | ALTER definer_opt remember_name EVENT_SYM sp_name + | ALTER definer_opt EVENT_SYM sp_name { /* It is safe to use Lex->spname because @@ -6208,8 +6204,7 @@ alter: if (!(Lex->event_parse_data= Event_parse_data::new_instance(YYTHD))) MYSQL_YYABORT; - Lex->event_parse_data->identifier= $5; - Lex->stmt_definition_begin= $3; + Lex->event_parse_data->identifier= $4; Lex->sql_command= SQLCOM_ALTER_EVENT; } @@ -6219,7 +6214,7 @@ alter: opt_ev_comment opt_ev_sql_stmt { - if (!($7 || $8 || $9 || $10 || $11)) + if (!($6 || $7 || $8 || $9 || $10)) { my_parse_error(ER(ER_SYNTAX_ERROR)); MYSQL_YYABORT; @@ -6280,16 +6275,7 @@ opt_ev_rename_to: ; opt_ev_sql_stmt: - /* empty*/ - { - $$= 0; - /* - Lex->sp_head is not initialized when event body is empty. - So we can not use Lex->sp_head->set_stmt_end() to set - stmt_definition_end. - */ - Lex->stmt_definition_end= (char*) YYLIP->get_cpp_tok_end(); - } + /* empty*/ { $$= 0;} | DO_SYM ev_sql_stmt { $$= 1; } ; @@ -12068,7 +12054,6 @@ user: $$->user = $1; $$->host.str= (char *) "%"; $$->host.length= 1; - Lex->stmt_user_end= YYLIP->get_cpp_ptr(); if (check_string_char_length(&$$->user, ER(ER_USERNAME), USERNAME_CHAR_LENGTH, @@ -12081,7 +12066,6 @@ user: if (!($$=(LEX_USER*) thd->alloc(sizeof(st_lex_user)))) MYSQL_YYABORT; $$->user = $1; $$->host=$3; - Lex->stmt_user_end= YYLIP->get_cpp_ptr(); if (check_string_char_length(&$$->user, ER(ER_USERNAME), USERNAME_CHAR_LENGTH, @@ -12091,7 +12075,6 @@ user: } | CURRENT_USER optional_braces { - Lex->stmt_user_end= YYLIP->get_cpp_ptr(); if (!($$=(LEX_USER*) YYTHD->alloc(sizeof(st_lex_user)))) MYSQL_YYABORT; /* @@ -13297,10 +13280,9 @@ user_list: ; grant_list: - { Lex->stmt_user_begin= YYLIP->get_cpp_ptr(); } grant_user { - if (Lex->users_list.push_back($2)) + if (Lex->users_list.push_back($1)) MYSQL_YYABORT; } | grant_list ',' grant_user @@ -13313,7 +13295,6 @@ grant_list: grant_user: user IDENTIFIED_SYM BY TEXT_STRING { - Lex->stmt_user_end= YYLIP->get_cpp_ptr(); $$=$1; $1->password=$4; if ($4.length) { @@ -13340,10 +13321,7 @@ grant_user: } } | user IDENTIFIED_SYM BY PASSWORD TEXT_STRING - { - Lex->stmt_user_end= YYLIP->get_cpp_ptr(); - $$= $1; $1->password= $5; - } + { $$= $1; $1->password= $5; } | user { $$= $1; $1->password= null_lex_str; } ; |