3752 magnus.blaudd@stripped 2012-05-11
WL#6004 Server extension for allowing user tables to be put into transactional
SE
- patch 1 which adds commit/rollback into ACL code
modified:
sql/event_db_repository.cc
sql/sql_acl.cc
3751 magnus.blaudd@stripped 2012-05-11
WL#6004
- change alter_table.test since we now have a transactional SE which supports
mysql.* tables
modified:
mysql-test/r/alter_table.result
mysql-test/t/alter_table.test
=== modified file 'sql/event_db_repository.cc'
--- a/sql/event_db_repository.cc 2012-03-06 14:29:42 +0000
+++ b/sql/event_db_repository.cc 2012-05-11 14:20:23 +0000
@@ -29,6 +29,7 @@
#include "events.h"
#include "sql_show.h"
#include "lock.h" // MYSQL_LOCK_IGNORE_TIMEOUT
+#include "transaction.h"
/**
@addtogroup Event_Scheduler
@@ -1188,6 +1189,12 @@ Event_db_repository::check_system_tables
if (table_intact.check(tables.table, &mysql_db_table_def))
ret= 1;
+ if (!thd->transaction.stmt.is_empty())
+ {
+ DBUG_PRINT("info", ("%u: Committing read transaction", __LINE__));
+ trans_commit_stmt(thd);
+ assert(thd->transaction.stmt.is_empty());
+ }
close_mysql_tables(thd);
}
/* Check mysql.user */
@@ -1208,6 +1215,12 @@ Event_db_repository::check_system_tables
event_priv_column_position);
ret= 1;
}
+ if (!thd->transaction.stmt.is_empty())
+ {
+ DBUG_PRINT("info", ("%u: Committing read transaction", __LINE__));
+ trans_commit_stmt(thd);
+ assert(thd->transaction.stmt.is_empty());
+ }
close_mysql_tables(thd);
}
/* Check mysql.event */
=== modified file 'sql/sql_acl.cc'
--- a/sql/sql_acl.cc 2012-03-30 15:38:01 +0000
+++ b/sql/sql_acl.cc 2012-05-11 14:20:23 +0000
@@ -1246,6 +1246,12 @@ my_bool acl_reload(THD *thd)
if (old_initialized)
mysql_mutex_unlock(&acl_cache->lock);
end:
+ if (!thd->transaction.stmt.is_empty())
+ {
+ DBUG_PRINT("info", ("%u: Committing read transaction", __LINE__));
+ trans_commit_stmt(thd);
+ assert(thd->transaction.stmt.is_empty());
+ }
close_mysql_tables(thd);
DBUG_RETURN(return_val);
}
@@ -1972,7 +1978,32 @@ bool change_password(THD *thd, const cha
acl_cache->clear(1); // Clear locked hostname cache
mysql_mutex_unlock(&acl_cache->lock);
result= 0;
- if (mysql_bin_log.is_open())
+
+ if (!thd->transaction.stmt.is_empty())
+ {
+ if (!result)
+ {
+ int err= trans_commit_stmt(thd);
+ if (err == 0)
+ {
+ DBUG_PRINT("info", ("%u: Commit DDL transaction ok", __LINE__));
+ }
+ else
+ {
+ result= 1;
+ DBUG_PRINT("info", ("%u: Commit DDL transaction failed: %d",
+ __LINE__, err));
+ }
+ }
+ else
+ {
+ DBUG_PRINT("info", ("%u: Aborting DDL transaction", __LINE__));
+ trans_rollback_stmt(thd);
+ }
+ assert(thd->transaction.stmt.is_empty());
+ }
+
+ if (!result && mysql_bin_log.is_open())
{
query_length= sprintf(buff, "SET PASSWORD FOR '%-.120s'@'%-.120s'='%-.120s'",
acl_user->user ? acl_user->user : "",
@@ -1983,7 +2014,19 @@ bool change_password(THD *thd, const cha
FALSE, FALSE, FALSE, 0);
}
end:
- close_mysql_tables(thd);
+ if (!thd->transaction.stmt.is_empty())
+ {
+ /**
+ * We get here if something went wrong,
+ * check that result != 0
+ */
+ assert(result != 0);
+ DBUG_PRINT("info", ("%u: Aborting DDL transaction", __LINE__));
+ trans_rollback_stmt(thd);
+ assert(thd->transaction.stmt.is_empty());
+ }
+
+ close_thread_tables(thd);
/* Restore the state of binlog format */
DBUG_ASSERT(!thd->is_current_stmt_binlog_format_row());
@@ -3782,6 +3825,30 @@ int mysql_table_grant(THD *thd, TABLE_LI
thd->mem_root= old_root;
mysql_mutex_unlock(&acl_cache->lock);
+ if (!thd->transaction.stmt.is_empty())
+ {
+ if (!result)
+ {
+ int err= trans_commit_stmt(thd);
+ if (err == 0)
+ {
+ DBUG_PRINT("info", ("%u: Commit DDL transaction ok", __LINE__));
+ }
+ else
+ {
+ result= 1;
+ DBUG_PRINT("info", ("%u: Commit DDL transaction failed: %d",
+ __LINE__, err));
+ }
+ }
+ else
+ {
+ DBUG_PRINT("info", ("%u: Aborting DDL transaction", __LINE__));
+ trans_rollback_stmt(thd);
+ }
+ assert(thd->transaction.stmt.is_empty());
+ }
+
if (should_write_to_binlog)
result= result |
write_bin_log(thd, FALSE, thd->query(), thd->query_length());
@@ -4144,6 +4211,30 @@ bool mysql_grant(THD *thd, const char *d
}
mysql_mutex_unlock(&acl_cache->lock);
+ if (!thd->transaction.stmt.is_empty())
+ {
+ if (!result)
+ {
+ int err= trans_commit_stmt(thd);
+ if (err == 0)
+ {
+ DBUG_PRINT("info", ("%u: Commit DDL transaction ok", __LINE__));
+ }
+ else
+ {
+ result= 1;
+ DBUG_PRINT("info", ("%u: Commit DDL transaction failed: %d",
+ __LINE__, err));
+ }
+ }
+ else
+ {
+ DBUG_PRINT("info", ("%u: Aborting DDL transaction", __LINE__));
+ trans_rollback_stmt(thd);
+ }
+ assert(thd->transaction.stmt.is_empty());
+ }
+
if (should_write_to_binlog)
{
if (thd->rewritten_query.length())
@@ -4439,6 +4530,13 @@ static my_bool grant_reload_procs_priv(T
}
mysql_rwlock_unlock(&LOCK_grant);
+ if (!thd->transaction.stmt.is_empty())
+ {
+ DBUG_PRINT("info", ("%u: Committing read transaction", __LINE__));
+ trans_commit_stmt(thd);
+ assert(thd->transaction.stmt.is_empty());
+ }
+
close_mysql_tables(thd);
DBUG_RETURN(return_val);
}
@@ -4510,6 +4608,13 @@ my_bool grant_reload(THD *thd)
free_root(&old_mem,MYF(0));
}
mysql_rwlock_unlock(&LOCK_grant);
+
+ if (!thd->transaction.stmt.is_empty())
+ {
+ DBUG_PRINT("info", ("%u: Committing read transaction", __LINE__));
+ trans_commit_stmt(thd);
+ assert(thd->transaction.stmt.is_empty());
+ }
close_mysql_tables(thd);
/*
@@ -6595,6 +6700,23 @@ bool mysql_create_user(THD *thd, List <L
if (result)
my_error(ER_CANNOT_USER, MYF(0), "CREATE USER", wrong_users.c_ptr_safe());
+ if (!thd->transaction.stmt.is_empty())
+ {
+ int err= trans_commit_stmt(thd);
+ if (err == 0)
+ {
+ DBUG_PRINT("info", ("%u: Commit DDL ok", __LINE__));
+ }
+ else
+ {
+ result= 1;
+ some_users_created= FALSE;
+ DBUG_PRINT("info",
+ ("%u: Commit DDL transaction failed: %d", __LINE__, err));
+ }
+ assert(thd->transaction.stmt.is_empty());
+ }
+
if (some_users_created)
{
result|= write_bin_log(thd, FALSE,
@@ -6684,6 +6806,31 @@ bool mysql_drop_user(THD *thd, List <LEX
if (result)
my_error(ER_CANNOT_USER, MYF(0), "DROP USER", wrong_users.c_ptr_safe());
+ if (!thd->transaction.stmt.is_empty())
+ {
+ if (!result)
+ {
+ int err= trans_commit_stmt(thd);
+ if (err == 0)
+ {
+ DBUG_PRINT("info", ("%u: Commit DDL transaction ok", __LINE__));
+ }
+ else
+ {
+ result= 1;
+ some_users_deleted= FALSE;
+ DBUG_PRINT("info", ("%u: Commit DDL transaction failed: %d",
+ __LINE__, err));
+ }
+ }
+ else
+ {
+ DBUG_PRINT("info", ("%u: Aborting DDL transaction", __LINE__));
+ trans_rollback_stmt(thd);
+ }
+ assert(thd->transaction.stmt.is_empty());
+ }
+
if (some_users_deleted)
result |= write_bin_log(thd, FALSE, thd->query(), thd->query_length());
@@ -6781,6 +6928,32 @@ bool mysql_rename_user(THD *thd, List <L
if (result)
my_error(ER_CANNOT_USER, MYF(0), "RENAME USER", wrong_users.c_ptr_safe());
+ if (!thd->transaction.stmt.is_empty())
+ {
+ if (!result)
+ {
+ int err= trans_commit_stmt(thd);
+ if (err == 0)
+ {
+ DBUG_PRINT("info", ("%u: Commit DDL transaction ok", __LINE__));
+ }
+ else
+ {
+ result= 1;
+ some_users_renamed= FALSE;
+ DBUG_PRINT("info", ("%u: Commit DDL transaction failed: %d",
+ __LINE__, err));
+ }
+ }
+ else
+ {
+ DBUG_PRINT("info", ("%u: Aborting DDL transaction", __LINE__));
+ trans_rollback_stmt(thd);
+ some_users_renamed= FALSE;
+ }
+ assert(thd->transaction.stmt.is_empty());
+ }
+
if (some_users_renamed && mysql_bin_log.is_open())
result |= write_bin_log(thd, FALSE, thd->query(), thd->query_length());
@@ -6983,6 +7156,30 @@ bool mysql_revoke_all(THD *thd, List <L
if (result)
my_message(ER_REVOKE_GRANTS, ER(ER_REVOKE_GRANTS), MYF(0));
+ if (!thd->transaction.stmt.is_empty())
+ {
+ if (!result)
+ {
+ int err= trans_commit_stmt(thd);
+ if (err == 0)
+ {
+ DBUG_PRINT("info", ("%u: Commit DDL transaction ok", __LINE__));
+ }
+ else
+ {
+ result= 1;
+ DBUG_PRINT("info", ("%u: Commit DDL transaction failed: %d",
+ __LINE__, err));
+ }
+ }
+ else
+ {
+ DBUG_PRINT("info", ("%u: Aborting DDL transaction", __LINE__));
+ trans_rollback_stmt(thd);
+ }
+ assert(thd->transaction.stmt.is_empty());
+ }
+
if (should_write_to_binlog)
{
result= result |
No bundle (reason: useless for push emails).
| Thread |
|---|
| • bzr push into mysql-trunk branch (magnus.blaudd:3751 to 3752) WL#6004 | magnus.blaudd | 22 May |