summaryrefslogtreecommitdiff
path: root/sql/sql_acl.cc
diff options
context:
space:
mode:
authorunknown <hezx@mail.hezx.com>2008-01-25 15:02:26 +0800
committerunknown <hezx@mail.hezx.com>2008-01-25 15:02:26 +0800
commitc78852a517c286d50eecb22c91b141bdf250ac59 (patch)
tree2c4f66dee840b440385fd55d68aef99dc0564950 /sql/sql_acl.cc
parent81805ac5b54b8661751db3f8594e327f66fa8e2e (diff)
downloadmariadb-git-c78852a517c286d50eecb22c91b141bdf250ac59.tar.gz
BUG#33862 completely failed DROP USER statement gets replicated
The problem is when create/rename/drop users, the statement was logged regardless of error, even if no data has been changed, the statement was logged. After this patch, create/rename/drop users don't write the binlog if the statement makes no changes, if the statement does make any changes, log the statement with possible error code. This patch is based on the patch for BUG#29749, which is not pushed sql/sql_acl.cc: when create/rename/drop users, don't write the binlog if the statement make no changes mysql-test/r/rpl_user.result: New BitKeeper file ``mysql-test/r/rpl_user.result'' mysql-test/t/rpl_user.test: New BitKeeper file ``mysql-test/t/rpl_user.test''
Diffstat (limited to 'sql/sql_acl.cc')
-rw-r--r--sql/sql_acl.cc24
1 files changed, 17 insertions, 7 deletions
diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc
index 1850821a287..a5140d6f7d0 100644
--- a/sql/sql_acl.cc
+++ b/sql/sql_acl.cc
@@ -5333,6 +5333,7 @@ bool mysql_create_user(THD *thd, List <LEX_USER> &list)
LEX_USER *user_name, *tmp_user_name;
List_iterator <LEX_USER> user_list(list);
TABLE_LIST tables[GRANT_TABLES];
+ bool some_users_created= FALSE;
DBUG_ENTER("mysql_create_user");
/* CREATE USER may be skipped on replication client. */
@@ -5361,6 +5362,7 @@ bool mysql_create_user(THD *thd, List <LEX_USER> &list)
continue;
}
+ some_users_created= TRUE;
sql_mode= thd->variables.sql_mode;
if (replace_user_table(thd, tables[0].table, *user_name, 0, 0, 1, 0))
{
@@ -5371,7 +5373,10 @@ bool mysql_create_user(THD *thd, List <LEX_USER> &list)
VOID(pthread_mutex_unlock(&acl_cache->lock));
- if (mysql_bin_log.is_open())
+ if (result)
+ my_error(ER_CANNOT_USER, MYF(0), "CREATE USER", wrong_users.c_ptr_safe());
+
+ if (some_users_created && mysql_bin_log.is_open())
{
Query_log_event qinfo(thd, thd->query, thd->query_length, 0, FALSE);
mysql_bin_log.write(&qinfo);
@@ -5379,8 +5384,6 @@ bool mysql_create_user(THD *thd, List <LEX_USER> &list)
rw_unlock(&LOCK_grant);
close_thread_tables(thd);
- if (result)
- my_error(ER_CANNOT_USER, MYF(0), "CREATE USER", wrong_users.c_ptr_safe());
DBUG_RETURN(result);
}
@@ -5405,6 +5408,7 @@ bool mysql_drop_user(THD *thd, List <LEX_USER> &list)
LEX_USER *user_name, *tmp_user_name;
List_iterator <LEX_USER> user_list(list);
TABLE_LIST tables[GRANT_TABLES];
+ bool some_users_deleted= FALSE;
DBUG_ENTER("mysql_drop_user");
/* DROP USER may be skipped on replication client. */
@@ -5426,7 +5430,9 @@ bool mysql_drop_user(THD *thd, List <LEX_USER> &list)
{
append_user(&wrong_users, user_name);
result= TRUE;
+ continue;
}
+ some_users_deleted= TRUE;
}
/* Rebuild 'acl_check_hosts' since 'acl_users' has been modified */
@@ -5440,7 +5446,7 @@ bool mysql_drop_user(THD *thd, List <LEX_USER> &list)
DBUG_PRINT("info", ("thd->net.last_errno: %d", thd->net.last_errno));
DBUG_PRINT("info", ("thd->net.last_error: %s", thd->net.last_error));
- if (mysql_bin_log.is_open())
+ if (some_users_deleted && mysql_bin_log.is_open())
{
Query_log_event qinfo(thd, thd->query, thd->query_length, 0, FALSE);
mysql_bin_log.write(&qinfo);
@@ -5473,6 +5479,7 @@ bool mysql_rename_user(THD *thd, List <LEX_USER> &list)
LEX_USER *user_to, *tmp_user_to;
List_iterator <LEX_USER> user_list(list);
TABLE_LIST tables[GRANT_TABLES];
+ bool some_users_renamed= FALSE;
DBUG_ENTER("mysql_rename_user");
/* RENAME USER may be skipped on replication client. */
@@ -5506,7 +5513,9 @@ bool mysql_rename_user(THD *thd, List <LEX_USER> &list)
{
append_user(&wrong_users, user_from);
result= TRUE;
+ continue;
}
+ some_users_renamed= TRUE;
}
/* Rebuild 'acl_check_hosts' since 'acl_users' has been modified */
@@ -5514,7 +5523,10 @@ bool mysql_rename_user(THD *thd, List <LEX_USER> &list)
VOID(pthread_mutex_unlock(&acl_cache->lock));
- if (mysql_bin_log.is_open())
+ if (result)
+ my_error(ER_CANNOT_USER, MYF(0), "RENAME USER", wrong_users.c_ptr_safe());
+
+ if (some_users_renamed && mysql_bin_log.is_open())
{
Query_log_event qinfo(thd, thd->query, thd->query_length, 0, FALSE);
mysql_bin_log.write(&qinfo);
@@ -5522,8 +5534,6 @@ bool mysql_rename_user(THD *thd, List <LEX_USER> &list)
rw_unlock(&LOCK_grant);
close_thread_tables(thd);
- if (result)
- my_error(ER_CANNOT_USER, MYF(0), "RENAME USER", wrong_users.c_ptr_safe());
DBUG_RETURN(result);
}