diff options
author | unknown <petr/cps@owlet.local> | 2006-10-24 17:00:23 +0400 |
---|---|---|
committer | unknown <petr/cps@owlet.local> | 2006-10-24 17:00:23 +0400 |
commit | 5aa81b561e9d1604533c37498c471cd853fb72a5 (patch) | |
tree | 2b7e93bbe62a86d3dc9de1c82450398a83d59e1a /sql/sql_rename.cc | |
parent | 66b872805cbd542c6012eef7141443d95a697f7d (diff) | |
parent | 9438b9851901c48f8e280c2665f9469c2f998c2f (diff) | |
download | mariadb-git-5aa81b561e9d1604533c37498c471cd853fb72a5.tar.gz |
Merge pchardin@bk-internal.mysql.com:/home/bk/mysql-5.1-runtime
into mysql.com:/home/cps/mysql/devel/5.1-rename-bug
mysql-test/r/log_tables.result:
Auto merged
mysql-test/t/log_tables.test:
Auto merged
sql/handler.cc:
Auto merged
sql/handler.h:
Auto merged
sql/log.h:
Auto merged
sql/mysql_priv.h:
Auto merged
sql/sql_delete.cc:
Auto merged
sql/sql_rename.cc:
Auto merged
sql/table.cc:
Auto merged
storage/csv/ha_tina.cc:
Auto merged
storage/myisam/ha_myisam.cc:
Auto merged
sql/log.cc:
manual merge
sql/share/errmsg.txt:
manual merge
sql/sql_table.cc:
manual merge
Diffstat (limited to 'sql/sql_rename.cc')
-rw-r--r-- | sql/sql_rename.cc | 102 |
1 files changed, 101 insertions, 1 deletions
diff --git a/sql/sql_rename.cc b/sql/sql_rename.cc index bf2e2d506cd..cd2c3c348d4 100644 --- a/sql/sql_rename.cc +++ b/sql/sql_rename.cc @@ -35,7 +35,10 @@ static TABLE_LIST *reverse_table_list(TABLE_LIST *table_list); bool mysql_rename_tables(THD *thd, TABLE_LIST *table_list, bool silent) { bool error= 1; - TABLE_LIST *ren_table= 0; + TABLE_LIST *ren_table= 0, *new_table; + int to_table; + char *rename_log_table[2]= {NULL, NULL}; + int disable_logs= 0; DBUG_ENTER("mysql_rename_tables"); /* @@ -52,6 +55,96 @@ bool mysql_rename_tables(THD *thd, TABLE_LIST *table_list, bool silent) if (wait_if_global_read_lock(thd,0,1)) DBUG_RETURN(1); + + if (logger.is_log_table_enabled(QUERY_LOG_GENERAL) || + logger.is_log_table_enabled(QUERY_LOG_SLOW)) + { + + /* + Rules for rename of a log table: + + IF 1. Log tables are enabled + AND 2. Rename operates on the log table and nothing is being + renamed to the log table. + DO 3. Throw an error message. + ELSE 4. Perform rename. + */ + + for (to_table= 0, ren_table= table_list; ren_table; + to_table= 1 - to_table, ren_table= ren_table->next_local) + { + int log_table_rename= 0; + + if ((log_table_rename= + check_if_log_table(ren_table->db_length, ren_table->db, + ren_table->table_name_length, + ren_table->table_name, 1))) + { + /* + Log table encoutered we will need to disable and lock logs + for duration of rename. + */ + disable_logs= TRUE; + + /* + as we use log_table_rename as an array index, we need it to start + with 0, while QUERY_LOG_SLOW == 1 and QUERY_LOG_GENERAL == 2. + So, we shift the value to start with 0; + */ + log_table_rename--; + if (rename_log_table[log_table_rename]) + { + if (to_table) + rename_log_table[log_table_rename]= NULL; + else + { + /* + Two renames of "log_table TO" w/o rename "TO log_table" in + between. + */ + my_error(ER_CANT_RENAME_LOG_TABLE, MYF(0), ren_table->table_name, + ren_table->table_name); + DBUG_RETURN(1); + } + } + else + { + if (to_table) + { + /* + Attempt to rename a table TO log_table w/o renaming + log_table TO some table. + */ + my_error(ER_CANT_RENAME_LOG_TABLE, MYF(0), ren_table->table_name, + ren_table->table_name); + DBUG_RETURN(1); + } + else + { + /* save the name of the log table to report an error */ + rename_log_table[log_table_rename]= ren_table->table_name; + } + } + } + } + if (rename_log_table[0] || rename_log_table[1]) + { + if (rename_log_table[0]) + my_error(ER_CANT_RENAME_LOG_TABLE, MYF(0), rename_log_table[0], + rename_log_table[0]); + else + my_error(ER_CANT_RENAME_LOG_TABLE, MYF(0), rename_log_table[1], + rename_log_table[1]); + DBUG_RETURN(1); + } + + if (disable_logs) + { + logger.lock(); + logger.tmp_close_log_tables(thd); + } + } + VOID(pthread_mutex_lock(&LOCK_open)); if (lock_table_names(thd, table_list)) goto err; @@ -95,6 +188,13 @@ bool mysql_rename_tables(THD *thd, TABLE_LIST *table_list, bool silent) err: pthread_mutex_unlock(&LOCK_open); + /* enable logging back if needed */ + if (disable_logs) + { + if (logger.reopen_log_tables()) + error= TRUE; + logger.unlock(); + } start_waiting_global_read_lock(thd); DBUG_RETURN(error); } |