Commit 9438b985 authored by unknown's avatar unknown

Fix for Bug #17544 "Cannot do atomic log rotate",

Bug #21785 "Server crashes after rename of the log table" and
Bug #21966 "Strange warnings on create like/repair of the log
            tables"

According to the patch, from now on, one should use RENAME to
perform a log table rotation (this should also be reflected in
the manual).

Here is a sample:

use mysql;
CREATE TABLE IF NOT EXISTS general_log2 LIKE general_log;
RENAME TABLE general_log TO general_log_backup, general_log2 TO general_log;

The rules for Rename of the log tables are following:
      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.
 
The very RENAME query will go the the old (backup) table. This is
consistent with the behavoiur we have with binlog ROTATE LOGS
statement.

Other problems, which are solved by the patch are:

1) Now REPAIR of the log table is exclusive operation (as it should be), this
   also eliminates lock-related warnings. and
2) CREATE LIKE TABLE now usese usual read lock on the source table rather
   then name lock, which is too restrictive. This way we get rid of another
   log table-related warning, which occured because of the above fact
   (as a side-effect, name lock resulted in a warning).


mysql-test/r/log_tables.result:
  update result file
mysql-test/t/log_tables.test:
  Add tests for the bugs
sql/handler.cc:
  update comment
sql/handler.h:
  update function to reflect changes in log tables
  locking logic.
sql/lock.cc:
  Now we allow locking of the log tables for "privileged" threads
  Privileged thread must explicitly close and lock log tables. This
  is required for admin operations such as REPAIR.
sql/log.cc:
  Changes to the file:
  1) Add checks for table schema. It's more important now,
     as we allow rename of the log tables. Since we should
     check for schema when writing to a log table.
     E.g. if one created a table with one-only comlumn and
     renamed it to general_log, the server should cope with
     it.
  2) refactor LOGGER::flush(), so that we can now use the same
     machinery as we use in FLUSH LOGS in other statements:
     whenever we have to perform  a serious operation on the log
     tables, we have to
     (a) lock logger, which blocks other concurrent statements (such 
     as selects) (b) close logs. Then perform an
     exclusive operation, c) reenable logs and d) unlock logger.
  3) Add a function to check if a given table is a log table.
  4) Add support for "privileged" thread
  5) merge is_[general/slow]_log_table_enabled() into one function.
  6) Add new function: reopen _log_tables, which reopens the tables,
     which were enabled (after temporary close, required for admin
     operation)
sql/log.h:
  1) add a new call close_n_lock_tables(). Now we use it instead of
     LOGGER::flush() in FLUSH LOGS implementation.
  2) add a prototype for the function to check if a given
     table is a log table;
  3) add privileged table flag to table logger
  4) merge is_[general/slow]_log_table_enabled()
     into one function.
sql/mysql_priv.h:
  move log table defines to log.h
sql/sql_delete.cc:
  use new function check_if_log_table() instead of direct strcmp
sql/sql_rename.cc:
  Traverse the list of tables in mysql_rename_tables
  to make sure that log tables are processed correctly
  (that is, according to the rules specified in the
  main CS comment)
sql/sql_table.cc:
  1) mysql_admin_table() should disable logs if it performs
     exclusive admin operation on a log table. This way we
     also eliminate warning on REPAIR of the log table.
  2) mysql_create_like_table should read-lock the source table
     instead getting name lock on it. Name lock is too restrictive
     in this case.
sql/share/errmsg.txt:
  Add a new error message for rename of the log tables
sql/table.cc:
  use new function instead of direct strcmp.
  change my_strcasecmp() -> strcmp(), when
  comparing system db and table names
storage/csv/ha_tina.cc:
  update function to reflect changes in log tables
  locking logic.
storage/myisam/ha_myisam.cc:
  update function to reflect changes in log tables
  locking logic.
parent d57163fc
......@@ -218,3 +218,71 @@ unlock tables;
use mysql;
lock tables general_log read local, help_category read local;
unlock tables;
use mysql;
RENAME TABLE general_log TO renamed_general_log;
ERROR HY000: Cannot rename 'general_log'. When logging enabled, rename to/from log table must rename two tables: the log table to an archive table and another table back to 'general_log'
RENAME TABLE slow_log TO renamed_slow_log;
ERROR HY000: Cannot rename 'slow_log'. When logging enabled, rename to/from log table must rename two tables: the log table to an archive table and another table back to 'slow_log'
truncate table general_log;
select * from general_log;
event_time user_host thread_id server_id command_type argument
TIMESTAMP USER_HOST THREAD_ID 1 Query select * from general_log
truncate table slow_log;
select * from slow_log;
start_time user_host query_time lock_time rows_sent rows_examined db last_insert_id insert_id server_id sql_text
create table general_log_new like general_log;
rename table general_log TO renamed_general_log, general_log_new TO general_log;
create table slow_log_new like slow_log;
rename table slow_log TO renamed_slow_log, slow_log_new TO slow_log;
rename table general_log TO general_log_new, renamed_general_log TO general_log, slow_log to renamed_slow_log;
ERROR HY000: Cannot rename 'slow_log'. When logging enabled, rename to/from log table must rename two tables: the log table to an archive table and another table back to 'slow_log'
select * from general_log;
event_time user_host thread_id server_id command_type argument
TIMESTAMP USER_HOST THREAD_ID 1 Query create table slow_log_new like slow_log
TIMESTAMP USER_HOST THREAD_ID 1 Query rename table slow_log TO renamed_slow_log, slow_log_new TO slow_log
TIMESTAMP USER_HOST THREAD_ID 1 Query rename table general_log TO general_log_new, renamed_general_log TO general_log, slow_log to renamed_slow_log
TIMESTAMP USER_HOST THREAD_ID 1 Query select * from general_log
select * from renamed_general_log;
event_time user_host thread_id server_id command_type argument
TIMESTAMP USER_HOST THREAD_ID 1 Query select * from general_log
TIMESTAMP USER_HOST THREAD_ID 1 Query truncate table slow_log
TIMESTAMP USER_HOST THREAD_ID 1 Query select * from slow_log
TIMESTAMP USER_HOST THREAD_ID 1 Query create table general_log_new like general_log
TIMESTAMP USER_HOST THREAD_ID 1 Query rename table general_log TO renamed_general_log, general_log_new TO general_log
select * from slow_log;
start_time user_host query_time lock_time rows_sent rows_examined db last_insert_id insert_id server_id sql_text
select * from renamed_slow_log;
start_time user_host query_time lock_time rows_sent rows_examined db last_insert_id insert_id server_id sql_text
set global general_log='OFF';
RENAME TABLE general_log TO general_log2;
set global slow_query_log='OFF';
RENAME TABLE slow_log TO slow_log2;
set global general_log='ON';
ERROR HY000: Cannot activate 'general' log
set global slow_query_log='ON';
ERROR HY000: Cannot activate 'slow query' log
RENAME TABLE general_log2 TO general_log;
RENAME TABLE slow_log2 TO slow_log;
set global general_log='ON';
set global slow_query_log='ON';
flush logs;
flush logs;
drop table renamed_general_log, renamed_slow_log;
use test;
use mysql;
repair table general_log;
Table Op Msg_type Msg_text
mysql.general_log repair status OK
repair table slow_log;
Table Op Msg_type Msg_text
mysql.slow_log repair status OK
create table general_log_new like general_log;
create table slow_log_new like slow_log;
show tables like "%log%";
Tables_in_mysql (%log%)
general_log
general_log_new
slow_log
slow_log_new
drop table slow_log_new, general_log_new;
use test;
......@@ -314,6 +314,89 @@ use mysql;
lock tables general_log read local, help_category read local;
unlock tables;
#
# Bug #17544 Cannot do atomic log rotate and
# Bug #21785 Server crashes after rename of the log table
#
use mysql;
# Should result in error
--error ER_CANT_RENAME_LOG_TABLE
RENAME TABLE general_log TO renamed_general_log;
--error ER_CANT_RENAME_LOG_TABLE
RENAME TABLE slow_log TO renamed_slow_log;
#check rotate logs
truncate table general_log;
--replace_column 1 TIMESTAMP 2 USER_HOST 3 THREAD_ID
select * from general_log;
truncate table slow_log;
--replace_column 1 TIMESTAMP 2 USER_HOST
select * from slow_log;
create table general_log_new like general_log;
rename table general_log TO renamed_general_log, general_log_new TO general_log;
create table slow_log_new like slow_log;
rename table slow_log TO renamed_slow_log, slow_log_new TO slow_log;
# check that rename checks more then first table in the list
--error ER_CANT_RENAME_LOG_TABLE
rename table general_log TO general_log_new, renamed_general_log TO general_log, slow_log to renamed_slow_log;
# now check the content of tables
--replace_column 1 TIMESTAMP 2 USER_HOST 3 THREAD_ID
select * from general_log;
--replace_column 1 TIMESTAMP 2 USER_HOST 3 THREAD_ID
select * from renamed_general_log;
# the content of the slow log is empty, but we will try a select anyway
--replace_column 1 TIMESTAMP 2 USER_HOST
select * from slow_log;
--replace_column 1 TIMESTAMP 2 USER_HOST
select * from renamed_slow_log;
# check that we can do whatever we want with disabled log
set global general_log='OFF';
RENAME TABLE general_log TO general_log2;
set global slow_query_log='OFF';
RENAME TABLE slow_log TO slow_log2;
# this should fail
--error ER_CANT_ACTIVATE_LOG
set global general_log='ON';
--error ER_CANT_ACTIVATE_LOG
set global slow_query_log='ON';
RENAME TABLE general_log2 TO general_log;
RENAME TABLE slow_log2 TO slow_log;
# this should work
set global general_log='ON';
set global slow_query_log='ON';
# now check flush logs
flush logs;
flush logs;
drop table renamed_general_log, renamed_slow_log;
use test;
#
# Bug #21966 Strange warnings on repair of the log tables
#
use mysql;
# check that no warning occurs on repair of the log tables
repair table general_log;
repair table slow_log;
# check that no warning occurs on "create like" for the log tables
create table general_log_new like general_log;
create table slow_log_new like slow_log;
show tables like "%log%";
drop table slow_log_new, general_log_new;
use test;
# kill all connections
disconnect con1;
disconnect con2;
......
......@@ -1427,8 +1427,9 @@ bool handler::check_if_log_table_locking_is_allowed(uint sql_command,
{
/*
Deny locking of the log tables, which is incompatible with
concurrent insert. Unless called from a logger THD:
general_log_thd or slow_log_thd.
concurrent insert. The routine is not called if the table is
being locked from a logger THD (general_log_thd or slow_log_thd)
or from a privileged thread (see log.cc for details)
*/
if (table->s->log_table &&
sql_command != SQLCOM_TRUNCATE &&
......
......@@ -957,6 +957,10 @@ public:
thd Handler of the thread, trying to lock the table
table Table handler to check
count Number of locks already granted to the table
called_by_privileged_thread TRUE if called from a logger THD
(general_log_thd or slow_log_thd)
or by a privileged thread, which
has the right to lock log tables.
DESCRIPTION
Check whether a handler allows to lock the table. For instance,
......@@ -972,7 +976,7 @@ public:
virtual bool check_if_locking_is_allowed(uint sql_command,
ulong type, TABLE *table,
uint count,
bool called_by_logger_thread)
bool called_by_privileged_thread)
{
return TRUE;
}
......
......@@ -691,7 +691,8 @@ static MYSQL_LOCK *get_lock_data(THD *thd, TABLE **table_ptr, uint count,
check_if_locking_is_allowed(thd->lex->sql_command, thd->lex->type,
table_ptr[i], count,
(thd == logger.get_general_log_thd()) ||
(thd == logger.get_slow_log_thd())))
(thd == logger.get_slow_log_thd()) ||
(thd == logger.get_privileged_thread())))
DBUG_RETURN(0);
}
......
This diff is collapsed.
......@@ -403,6 +403,9 @@ public:
};
int check_if_log_table(uint db_len, const char *db, uint table_name_len,
const char *table_name, uint check_if_opened);
class Log_to_csv_event_handler: public Log_event_handler
{
/*
......@@ -411,6 +414,16 @@ class Log_to_csv_event_handler: public Log_event_handler
THD's of the query. The reason is the locking order and duration.
*/
THD *general_log_thd, *slow_log_thd;
/*
This is for the thread, which called tmp_close_log_tables. The thread
will be allowed to write-lock the log tables (as it explicitly disabled
logging). This is used for such operations as REPAIR, which require
exclusive lock on the log tables.
NOTE: there can be only one priviliged thread, as one should
lock logger with logger.lock() before calling tmp_close_log_tables().
So no other thread could get privileged status at the same time.
*/
THD *privileged_thread;
friend class LOGGER;
TABLE_LIST general_log, slow_log;
......@@ -435,13 +448,20 @@ public:
const char *command_type, uint command_type_len,
const char *sql_text, uint sql_text_len,
CHARSET_INFO *client_cs);
bool flush(THD *thd, TABLE_LIST *close_slow_Log,
TABLE_LIST* close_general_log);
void tmp_close_log_tables(THD *thd);
void close_log_table(uint log_type, bool lock_in_use);
bool reopen_log_table(uint log_type);
THD* get_privileged_thread()
{
return privileged_thread;
}
};
/* type of the log table */
#define QUERY_LOG_SLOW 1
#define QUERY_LOG_GENERAL 2
class Log_to_file_event_handler: public Log_event_handler
{
MYSQL_QUERY_LOG mysql_log;
......@@ -497,13 +517,18 @@ public:
{}
void lock() { (void) pthread_mutex_lock(&LOCK_logger); }
void unlock() { (void) pthread_mutex_unlock(&LOCK_logger); }
bool is_general_log_table_enabled()
void tmp_close_log_tables(THD *thd);
bool is_log_table_enabled(uint log_table_type)
{
return table_log_handler && table_log_handler->general_log.table != 0;
}
bool is_slow_log_table_enabled()
{
return table_log_handler && table_log_handler->slow_log.table != 0;
switch (log_table_type) {
case QUERY_LOG_SLOW:
return table_log_handler && table_log_handler->slow_log.table != 0;
case QUERY_LOG_GENERAL:
return table_log_handler && table_log_handler->general_log.table != 0;
default:
DBUG_ASSERT(0);
return FALSE; /* make compiler happy */
}
}
/*
We want to initialize all log mutexes as soon as possible,
......@@ -541,6 +566,7 @@ public:
void close_log_table(uint log_type, bool lock_in_use);
bool reopen_log_table(uint log_type);
bool reopen_log_tables();
/* we use this function to setup all enabled log event handlers */
int set_handlers(uint error_log_printer,
......@@ -563,6 +589,13 @@ public:
return file_log_handler->get_mysql_log();
return NULL;
}
THD* get_privileged_thread()
{
if (table_log_handler)
return table_log_handler->get_privileged_thread();
else
return NULL;
}
};
enum enum_binlog_format {
......
......@@ -1428,10 +1428,6 @@ void sql_print_information(const char *format, ...);
typedef void (*sql_print_message_func)(const char *format, ...);
extern sql_print_message_func sql_print_message_handlers[];
/* type of the log table */
#define QUERY_LOG_SLOW 1
#define QUERY_LOG_GENERAL 2
int error_log_print(enum loglevel level, const char *format,
va_list args);
......
......@@ -5960,3 +5960,5 @@ ER_HOSTNAME
eng "host name"
ER_WRONG_STRING_LENGTH
eng "String '%-.70s' is too long for %s (should be no longer than %d)"
ER_CANT_RENAME_LOG_TABLE
eng "Cannot rename '%s'. When logging enabled, rename to/from log table must rename two tables: the log table to an archive table and another table back to '%s'"
......@@ -912,28 +912,16 @@ bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok)
DBUG_RETURN(TRUE);
}
uint log_type= check_if_log_table(table_list->db_length, table_list->db,
table_list->table_name_length,
table_list->table_name, 1);
/* close log tables in use */
if (!my_strcasecmp(system_charset_info, table_list->db, "mysql"))
if (log_type)
{
if (opt_log &&
!my_strcasecmp(system_charset_info, table_list->table_name,
"general_log"))
{
lock_logger= 1;
logger.lock();
logger.close_log_table(QUERY_LOG_GENERAL, FALSE);
closed_log_tables= closed_log_tables | QUERY_LOG_GENERAL;
}
else
if (opt_slow_log &&
!my_strcasecmp(system_charset_info, table_list->table_name,
"slow_log"))
{
lock_logger= 1;
logger.lock();
logger.close_log_table(QUERY_LOG_SLOW, FALSE);
closed_log_tables= closed_log_tables | QUERY_LOG_SLOW;
}
lock_logger= 1;
logger.lock();
logger.close_log_table(log_type, FALSE);
closed_log_tables= closed_log_tables | log_type;
}
// Remove the .frm extension AIX 5.2 64-bit compiler bug (BUG#16155): this
......
......@@ -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);
}
......
......@@ -1622,11 +1622,8 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
/* Disable drop of enabled log tables */
if (share && share->log_table &&
((!my_strcasecmp(system_charset_info, table->table_name,
"general_log") && opt_log &&
logger.is_general_log_table_enabled()) ||
(!my_strcasecmp(system_charset_info, table->table_name, "slow_log")
&& opt_slow_log && logger.is_slow_log_table_enabled())))
check_if_log_table(table->db_length, table->db,
table->table_name_length, table->table_name, 1))
{
my_error(ER_CANT_DROP_LOG_TABLE, MYF(0));
DBUG_RETURN(1);
......@@ -4019,7 +4016,7 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
Item *item;
Protocol *protocol= thd->protocol;
LEX *lex= thd->lex;
int result_code;
int result_code, disable_logs= 0;
DBUG_ENTER("mysql_admin_table");
if (end_active_trans(thd))
......@@ -4064,6 +4061,23 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
thd->no_warnings_for_error= no_warnings_for_error;
if (view_operator_func == NULL)
table->required_type=FRMTYPE_TABLE;
/*
If we want to perform an admin operation on the log table
(E.g. rename) and lock_type >= TL_READ_NO_INSERT disable
log tables
*/
if (check_if_log_table(table->db_length, table->db,
table->table_name_length,
table->table_name, 1) &&
lock_type >= TL_READ_NO_INSERT)
{
disable_logs= 1;
logger.lock();
logger.tmp_close_log_tables(thd);
}
open_and_lock_tables(thd, table);
thd->no_warnings_for_error= 0;
table->next_global= save_next_global;
......@@ -4380,11 +4394,24 @@ send_result_message:
}
send_eof(thd);
if (disable_logs)
{
if (logger.reopen_log_tables())
my_error(ER_CANT_ACTIVATE_LOG, MYF(0));
logger.unlock();
}
DBUG_RETURN(FALSE);
err:
ha_autocommit_or_rollback(thd, 1);
close_thread_tables(thd); // Shouldn't be needed
/* enable logging back if needed */
if (disable_logs)
{
if (logger.reopen_log_tables())
my_error(ER_CANT_ACTIVATE_LOG, MYF(0));
logger.unlock();
}
if (table)
table->table=0;
DBUG_RETURN(TRUE);
......@@ -4549,6 +4576,7 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table,
{
TABLE *tmp_table;
char src_path[FN_REFLEN], dst_path[FN_REFLEN], tmp_path[FN_REFLEN];
char src_table_name_buff[FN_REFLEN], src_db_name_buff[FN_REFLEN];
uint dst_path_length;
char *db= table->db;
char *table_name= table->table_name;
......@@ -4585,13 +4613,6 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table,
DBUG_RETURN(-1);
}
bzero((gptr)&src_tables_list, sizeof(src_tables_list));
src_tables_list.db= src_db;
src_tables_list.table_name= src_table;
if (lock_and_wait_for_table_name(thd, &src_tables_list))
goto err;
if ((tmp_table= find_temporary_table(thd, src_db, src_table)))
strxmov(src_path, tmp_table->s->path.str, reg_ext, NullS);
else
......@@ -4618,6 +4639,34 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table,
goto err;
}
if (lower_case_table_names)
{
if (src_db)
{
strmake(src_db_name_buff, src_db,
min(sizeof(src_db_name_buff) - 1, table_ident->db.length));
my_casedn_str(files_charset_info, src_db_name_buff);
src_db= src_db_name_buff;
}
if (src_table)
{
strmake(src_table_name_buff, src_table,
min(sizeof(src_table_name_buff) - 1, table_ident->table.length));
my_casedn_str(files_charset_info, src_table_name_buff);
src_table= src_table_name_buff;
}
}
bzero((gptr)&src_tables_list, sizeof(src_tables_list));
src_tables_list.db= src_db;
src_tables_list.db_length= table_ident->db.length;
src_tables_list.lock_type= TL_READ;
src_tables_list.table_name= src_table;
src_tables_list.alias= src_table;
if (simple_open_n_lock_tables(thd, &src_tables_list))
DBUG_RETURN(TRUE);
/*
Validate the destination table
......@@ -4764,9 +4813,6 @@ table_exists:
my_error(ER_TABLE_EXISTS_ERROR, MYF(0), table_name);
err:
pthread_mutex_lock(&LOCK_open);
unlock_table_name(thd, &src_tables_list);
pthread_mutex_unlock(&LOCK_open);
DBUG_RETURN(res);
}
......@@ -5153,37 +5199,27 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
LINT_INIT(index_add_buffer);
LINT_INIT(index_drop_buffer);
if (table_list && table_list->db &&
!my_strcasecmp(system_charset_info, table_list->db, "mysql") &&
table_list->table_name)
if (table_list && table_list->db && table_list->table_name)
{
enum enum_table_kind { NOT_LOG_TABLE= 1, GENERAL_LOG, SLOW_LOG }
table_kind= NOT_LOG_TABLE;
int table_kind= 0;
if (!my_strcasecmp(system_charset_info, table_list->table_name,
"general_log"))
table_kind= GENERAL_LOG;
else
if (!my_strcasecmp(system_charset_info, table_list->table_name,
"slow_log"))
table_kind= SLOW_LOG;
table_kind= check_if_log_table(table_list->db_length, table_list->db,
table_list->table_name_length,
table_list->table_name, 0);
/* Disable alter of enabled log tables */
if ((table_kind == GENERAL_LOG && opt_log &&
logger.is_general_log_table_enabled()) ||
(table_kind == SLOW_LOG && opt_slow_log &&
logger.is_slow_log_table_enabled()))
if (table_kind && logger.is_log_table_enabled(table_kind))
{
my_error(ER_CANT_ALTER_LOG_TABLE, MYF(0));
DBUG_RETURN(TRUE);
}
/* Disable alter of log tables to unsupported engine */
if ((table_kind == GENERAL_LOG || table_kind == SLOW_LOG) &&
if (table_kind &&
(lex_create_info->used_fields & HA_CREATE_USED_ENGINE) &&
(!lex_create_info->db_type || /* unknown engine */
!(lex_create_info->db_type->db_type == DB_TYPE_MYISAM ||
lex_create_info->db_type->db_type == DB_TYPE_CSV_DB)))
!(lex_create_info->db_type->db_type == DB_TYPE_MYISAM ||
lex_create_info->db_type->db_type == DB_TYPE_CSV_DB)))
{
my_error(ER_BAD_LOG_ENGINE, MYF(0));
DBUG_RETURN(TRUE);
......
......@@ -363,25 +363,24 @@ int open_table_def(THD *thd, TABLE_SHARE *share, uint db_flags)
error= open_binary_frm(thd, share, head, file);
*root_ptr= old_root;
if (share->db.length == 5 &&
!my_strcasecmp(system_charset_info, share->db.str, "mysql"))
if (share->db.length == 5 && !(lower_case_table_names ?
my_strcasecmp(system_charset_info, share->db.str, "mysql") :
strcmp(share->db.str, "mysql")))
{
/*
We can't mark all tables in 'mysql' database as system since we don't
allow to lock such tables for writing with any other tables (even with
other system tables) and some privilege tables need this.
*/
if (!my_strcasecmp(system_charset_info, share->table_name.str, "proc"))
if (!(lower_case_table_names ?
my_strcasecmp(system_charset_info, share->table_name.str, "proc") :
strcmp(share->table_name.str, "proc")))
share->system_table= 1;
else
{
if (!my_strcasecmp(system_charset_info, share->table_name.str,
"general_log"))
share->log_table= QUERY_LOG_GENERAL;
else
if (!my_strcasecmp(system_charset_info, share->table_name.str,
"slow_log"))
share->log_table= QUERY_LOG_SLOW;
share->log_table= check_if_log_table(share->db.length, share->db.str,
share->table_name.length,
share->table_name.str, 0);
}
}
error_given= 1;
......
......@@ -817,9 +817,9 @@ void ha_tina::update_status()
bool ha_tina::check_if_locking_is_allowed(uint sql_command,
ulong type, TABLE *table,
uint count,
bool called_by_logger_thread)
bool called_by_privileged_thread)
{
if (!called_by_logger_thread)
if (!called_by_privileged_thread)
return check_if_log_table_locking_is_allowed(sql_command, type, table);
return TRUE;
......
......@@ -255,7 +255,7 @@ err:
bool ha_myisam::check_if_locking_is_allowed(uint sql_command,
ulong type, TABLE *table,
uint count,
bool called_by_logger_thread)
bool called_by_privileged_thread)
{
/*
To be able to open and lock for reading system tables like 'mysql.proc',
......@@ -273,10 +273,10 @@ bool ha_myisam::check_if_locking_is_allowed(uint sql_command,
/*
Deny locking of the log tables, which is incompatible with
concurrent insert. Unless called from a logger THD:
general_log_thd or slow_log_thd.
concurrent insert. Unless called from a logger THD (general_log_thd
or slow_log_thd) or by a privileged thread.
*/
if (!called_by_logger_thread)
if (!called_by_privileged_thread)
return check_if_log_table_locking_is_allowed(sql_command, type, table);
return TRUE;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment