Commit 5aa81b56 authored by unknown's avatar unknown
Browse files

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
parents 66b87280 9438b985
Loading
Loading
Loading
Loading
+68 −0
Original line number Diff line number Diff line
@@ -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;
+83 −0
Original line number Diff line number Diff line
@@ -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;
+3 −2
Original line number Diff line number Diff line
@@ -1483,8 +1483,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 &&
+5 −1
Original line number Diff line number Diff line
@@ -975,6 +975,10 @@ class handler :public Sql_alloc
        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,
@@ -990,7 +994,7 @@ class handler :public Sql_alloc
  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;
  }
+2 −1
Original line number Diff line number Diff line
@@ -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);
  }

Loading