diff options
-rw-r--r-- | include/mysql_com.h | 6 | ||||
-rw-r--r-- | mysql-test/suite/rpl/r/rpl_flush_logs.result | 67 | ||||
-rw-r--r-- | mysql-test/suite/rpl/t/rpl_flush_logs-master.opt | 1 | ||||
-rw-r--r-- | mysql-test/suite/rpl/t/rpl_flush_logs.test | 172 | ||||
-rw-r--r-- | sql/lex.h | 4 | ||||
-rw-r--r-- | sql/log.cc | 48 | ||||
-rw-r--r-- | sql/log.h | 2 | ||||
-rw-r--r-- | sql/sql_parse.cc | 39 | ||||
-rw-r--r-- | sql/sql_yacc.yy | 18 |
9 files changed, 346 insertions, 11 deletions
diff --git a/include/mysql_com.h b/include/mysql_com.h index db5a5eb8741..43bdcb4c3c7 100644 --- a/include/mysql_com.h +++ b/include/mysql_com.h @@ -115,6 +115,12 @@ enum enum_server_command thread */ #define REFRESH_MASTER 128 /* Remove all bin logs in the index and truncate the index */ +#define REFRESH_ERROR_LOG 256 /* Rotate only the erorr log */ +#define REFRESH_ENGINE_LOG 512 /* Flush all storage engine logs */ +#define REFRESH_BINARY_LOG 1024 /* Flush the binary log */ +#define REFRESH_RELAY_LOG 2048 /* Flush the relay log */ +#define REFRESH_GENERAL_LOG 4096 /* Flush the general log */ +#define REFRESH_SLOW_LOG 8192 /* Flush the slow query log */ /* The following can't be set with mysql_refresh() */ #define REFRESH_READ_LOCK 16384 /* Lock tables for read */ diff --git a/mysql-test/suite/rpl/r/rpl_flush_logs.result b/mysql-test/suite/rpl/r/rpl_flush_logs.result new file mode 100644 index 00000000000..7f50ce0cdd0 --- /dev/null +++ b/mysql-test/suite/rpl/r/rpl_flush_logs.result @@ -0,0 +1,67 @@ +stop slave; +drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; +reset master; +reset slave; +drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; +start slave; +# Make sure the 'master_log.err-old' file does not +# exist before execute 'flush error logs' statement. +# Test if support 'flush error logs' statement. +flush error logs; +# Check the 'master_log.err-old' file is created +# after executed 'flush error logs' statement. +# Make sure binary logs was not be flushed +# after execute 'flush error logs' statement. +# Make sure relay logs was not be flushed +# after execute 'flush error logs' statement. +# Make sure the 'slave-relay-bin.000004' file does not +# exist before execute 'flush relay logs' statement. +# Test if support 'flush relay logs' statement. +flush relay logs; +# Check the 'slave-relay-bin.000004' file is created +# after executed 'flush relay logs' statement. +# Make sure binary logs was not be flushed +# after execute 'flush relay logs' statement. +# Test if support 'flush slow logs' statement. +flush slow logs; +# Make sure binary logs was not be flushed +# after execute 'flush slow logs' statement. +# Test if support 'flush general logs' statement. +flush general logs; +# Make sure binary logs was not be flushed +# after execute 'flush general logs' statement. +# Test if support 'flush engine logs' statement. +flush engine logs; +# Make sure binary logs was not be flushed +# after execute 'flush engine logs' statement. +# Make sure the 'master-bin.000002' file does not +# exist before execute 'flush binary logs' statement. +# Test if support 'flush binary logs' statement. +flush binary logs; +# Check the 'master-bin.000002' file is created +# after executed 'flush binary logs' statement. +# Make sure the 'slave-relay-bin.000007' file does not exist +# exist before execute 'flush error logs, relay logs' statement. +# Make sure the 'master_log.err-old' file does not exist +# before execute 'flush error logs, relay logs' statement. +# Test if support to combine all kinds of logs into one statement. +flush error logs, relay logs; +# Check the 'master_log.err-old' file is created +# after executed 'flush error logs, relay logs' statement. +# Make sure binary logs was not be flushed +# after execute 'flush error logs, relay logs' statement. +# Check the 'slave-relay-bin.000007' file is created after +# execute 'flush error logs, relay logs' statement. +# Make sure the 'slave-relay-bin.000008' and 'slave-relay-bin.000009' +# files do not exist before execute 'flush error logs, relay logs' +# statement. +# Make sure the 'master_log.err-old' file does not exist +# before execute 'flush logs' statement. +# Test if 'flush logs' statement works fine and flush all the logs. +flush logs; +# Check the 'master_log.err-old' file is created +# after executed 'flush logs' statement. +# Check 'master-bin.000003' is created +# after execute 'flush logs' statement. +# Check the 'slave-relay-bin.000008' and 'slave-relay-bin.000009' +# files are created after execute 'flush logs' statement. diff --git a/mysql-test/suite/rpl/t/rpl_flush_logs-master.opt b/mysql-test/suite/rpl/t/rpl_flush_logs-master.opt new file mode 100644 index 00000000000..36eab1d6c8f --- /dev/null +++ b/mysql-test/suite/rpl/t/rpl_flush_logs-master.opt @@ -0,0 +1 @@ +--log-error=$MYSQLTEST_VARDIR/tmp/master_log.err diff --git a/mysql-test/suite/rpl/t/rpl_flush_logs.test b/mysql-test/suite/rpl/t/rpl_flush_logs.test new file mode 100644 index 00000000000..2118b48f946 --- /dev/null +++ b/mysql-test/suite/rpl/t/rpl_flush_logs.test @@ -0,0 +1,172 @@ +# +# WL#5124 +# This test verifies if the 'flush individual logs' statement +# works fine. +# + +--source include/master-slave.inc +--source include/have_binlog_format_statement.inc +connection master; + +# Test 'flush error logs' statement. +--echo # Make sure the 'master_log.err-old' file does not +--echo # exist before execute 'flush error logs' statement. +--error 1 +file_exists $MYSQLTEST_VARDIR/tmp/master_log.err-old; + +--echo # Test if support 'flush error logs' statement. +flush error logs; + +--echo # Check the 'master_log.err-old' file is created +--echo # after executed 'flush error logs' statement. +file_exists $MYSQLTEST_VARDIR/tmp/master_log.err-old; +file_exists $MYSQLTEST_VARDIR/tmp/master_log.err; + +--echo # Make sure binary logs was not be flushed +--echo # after execute 'flush error logs' statement. +--error 1 +file_exists $MYSQLTEST_VARDIR/mysqld.1/data/master-bin.000002; + +sync_slave_with_master; +--echo # Make sure relay logs was not be flushed +--echo # after execute 'flush error logs' statement. +--error 1 +file_exists $MYSQLTEST_VARDIR/mysqld.2/data/slave-relay-bin.000004; + + +# Test 'flush relay logs' statement. +--echo # Make sure the 'slave-relay-bin.000004' file does not +--echo # exist before execute 'flush relay logs' statement. +--error 1 +file_exists $MYSQLTEST_VARDIR/mysqld.2/data/slave-relay-bin.000004; + +connection master; +--echo # Test if support 'flush relay logs' statement. +flush relay logs; + +sync_slave_with_master; +--echo # Check the 'slave-relay-bin.000004' file is created +--echo # after executed 'flush relay logs' statement. +file_exists $MYSQLTEST_VARDIR/mysqld.2/data/slave-relay-bin.000004; + +connection master; +--echo # Make sure binary logs was not be flushed +--echo # after execute 'flush relay logs' statement. +--error 1 +file_exists $MYSQLTEST_VARDIR/mysqld.1/data/master-bin.000002; + + +# Test 'flush slow logs' statement. +--echo # Test if support 'flush slow logs' statement. +flush slow logs; + +--echo # Make sure binary logs was not be flushed +--echo # after execute 'flush slow logs' statement. +--error 1 +file_exists $MYSQLTEST_VARDIR/mysqld.1/data/master-bin.000002; + + +# Test 'flush general logs' statement. +--echo # Test if support 'flush general logs' statement. +flush general logs; + +--echo # Make sure binary logs was not be flushed +--echo # after execute 'flush general logs' statement. +--error 1 +file_exists $MYSQLTEST_VARDIR/mysqld.1/data/master-bin.000002; + + +# Test 'flush engine logs' statement. +--echo # Test if support 'flush engine logs' statement. +flush engine logs; + +--echo # Make sure binary logs was not be flushed +--echo # after execute 'flush engine logs' statement. +--error 1 +file_exists $MYSQLTEST_VARDIR/mysqld.1/data/master-bin.000002; + + +# Test 'flush binary logs' statement. +--echo # Make sure the 'master-bin.000002' file does not +--echo # exist before execute 'flush binary logs' statement. +--error 1 +file_exists $MYSQLTEST_VARDIR/mysqld.1/data/master-bin.000002; + +--echo # Test if support 'flush binary logs' statement. +flush binary logs; + +--echo # Check the 'master-bin.000002' file is created +--echo # after executed 'flush binary logs' statement. +file_exists $MYSQLTEST_VARDIR/mysqld.1/data/master-bin.000002; +file_exists $MYSQLTEST_VARDIR/mysqld.1/data/master-bin.000001; + + +# Test 'flush error logs, relay logs' statement +sync_slave_with_master; +--echo # Make sure the 'slave-relay-bin.000007' file does not exist +--echo # exist before execute 'flush error logs, relay logs' statement. +--error 1 +file_exists $MYSQLTEST_VARDIR/mysqld.2/data/slave-relay-bin.000007; + +connection master; +remove_file $MYSQLTEST_VARDIR/tmp/master_log.err-old; + +--echo # Make sure the 'master_log.err-old' file does not exist +--echo # before execute 'flush error logs, relay logs' statement. +--error 1 +file_exists $MYSQLTEST_VARDIR/tmp/master_log.err-old; + +--echo # Test if support to combine all kinds of logs into one statement. +flush error logs, relay logs; + +--echo # Check the 'master_log.err-old' file is created +--echo # after executed 'flush error logs, relay logs' statement. +file_exists $MYSQLTEST_VARDIR/tmp/master_log.err-old; +file_exists $MYSQLTEST_VARDIR/tmp/master_log.err; + +--echo # Make sure binary logs was not be flushed +--echo # after execute 'flush error logs, relay logs' statement. +--error 1 +file_exists $MYSQLTEST_VARDIR/mysqld.1/data/master-bin.000003; + +sync_slave_with_master; +--echo # Check the 'slave-relay-bin.000007' file is created after +--echo # execute 'flush error logs, relay logs' statement. +file_exists $MYSQLTEST_VARDIR/mysqld.2/data/slave-relay-bin.000007; + + +# Test 'flush logs' statement +--echo # Make sure the 'slave-relay-bin.000008' and 'slave-relay-bin.000009' +--echo # files do not exist before execute 'flush error logs, relay logs' +--echo # statement. +--error 1 +file_exists $MYSQLTEST_VARDIR/mysqld.2/data/slave-relay-bin.000008; +--error 1 +file_exists $MYSQLTEST_VARDIR/mysqld.2/data/slave-relay-bin.000009; + +connection master; +remove_file $MYSQLTEST_VARDIR/tmp/master_log.err-old; + +--echo # Make sure the 'master_log.err-old' file does not exist +--echo # before execute 'flush logs' statement. +--error 1 +file_exists $MYSQLTEST_VARDIR/tmp/master_log.err-old; + +--echo # Test if 'flush logs' statement works fine and flush all the logs. +flush logs; + +--echo # Check the 'master_log.err-old' file is created +--echo # after executed 'flush logs' statement. +file_exists $MYSQLTEST_VARDIR/tmp/master_log.err-old; +file_exists $MYSQLTEST_VARDIR/tmp/master_log.err; + +--echo # Check 'master-bin.000003' is created +--echo # after execute 'flush logs' statement. +file_exists $MYSQLTEST_VARDIR/mysqld.1/data/master-bin.000003; + +sync_slave_with_master; +--echo # Check the 'slave-relay-bin.000008' and 'slave-relay-bin.000009' +--echo # files are created after execute 'flush logs' statement. +file_exists $MYSQLTEST_VARDIR/mysqld.2/data/slave-relay-bin.000008; +file_exists $MYSQLTEST_VARDIR/mysqld.2/data/slave-relay-bin.000009; + diff --git a/sql/lex.h b/sql/lex.h index 71d52914e3b..b1a88b200e6 100644 --- a/sql/lex.h +++ b/sql/lex.h @@ -189,6 +189,7 @@ static SYMBOL symbols[] = { { "ENGINE", SYM(ENGINE_SYM)}, { "ENGINES", SYM(ENGINES_SYM)}, { "ENUM", SYM(ENUM)}, + { "ERROR", SYM(ERROR_SYM)}, { "ERRORS", SYM(ERRORS)}, { "ESCAPE", SYM(ESCAPE_SYM)}, { "ESCAPED", SYM(ESCAPED)}, @@ -223,6 +224,7 @@ static SYMBOL symbols[] = { { "FULL", SYM(FULL)}, { "FULLTEXT", SYM(FULLTEXT_SYM)}, { "FUNCTION", SYM(FUNCTION_SYM)}, + { "GENERAL", SYM(GENERAL)}, { "GEOMETRY", SYM(GEOMETRY_SYM)}, { "GEOMETRYCOLLECTION",SYM(GEOMETRYCOLLECTION)}, { "GET_FORMAT", SYM(GET_FORMAT)}, @@ -429,6 +431,7 @@ static SYMBOL symbols[] = { { "REDUNDANT", SYM(REDUNDANT_SYM)}, { "REFERENCES", SYM(REFERENCES)}, { "REGEXP", SYM(REGEXP)}, + { "RELAY", SYM(RELAY)}, { "RELAYLOG", SYM(RELAYLOG_SYM)}, { "RELAY_LOG_FILE", SYM(RELAY_LOG_FILE_SYM)}, { "RELAY_LOG_POS", SYM(RELAY_LOG_POS_SYM)}, @@ -481,6 +484,7 @@ static SYMBOL symbols[] = { { "SIGNED", SYM(SIGNED_SYM)}, { "SIMPLE", SYM(SIMPLE_SYM)}, { "SLAVE", SYM(SLAVE)}, + { "SLOW", SYM(SLOW)}, { "SNAPSHOT", SYM(SNAPSHOT_SYM)}, { "SMALLINT", SYM(SMALLINT)}, { "SOCKET", SYM(SOCKET_SYM)}, diff --git a/sql/log.cc b/sql/log.cc index 3d863583859..1c95b21f533 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -965,6 +965,54 @@ bool LOGGER::flush_logs(THD *thd) } +/** + Close and reopen the slow log (with locks). + + @returns FALSE. +*/ +bool LOGGER::flush_slow_log() +{ + /* + Now we lock logger, as nobody should be able to use logging routines while + log tables are closed + */ + logger.lock_exclusive(); + + /* Reopen slow log file */ + if (opt_slow_log) + file_log_handler->get_mysql_slow_log()->reopen_file(); + + /* End of log flush */ + logger.unlock(); + + return 0; +} + + +/** + Close and reopen the general log (with locks). + + @returns FALSE. +*/ +bool LOGGER::flush_general_log() +{ + /* + Now we lock logger, as nobody should be able to use logging routines while + log tables are closed + */ + logger.lock_exclusive(); + + /* Reopen general log file */ + if (opt_log) + file_log_handler->get_mysql_log()->reopen_file(); + + /* End of log flush */ + logger.unlock(); + + return 0; +} + + /* Log slow query with all enabled log event handlers diff --git a/sql/log.h b/sql/log.h index 9be86b797a7..76ca18c8288 100644 --- a/sql/log.h +++ b/sql/log.h @@ -570,6 +570,8 @@ public: void init_base(); void init_log_tables(); bool flush_logs(THD *thd); + bool flush_slow_log(); + bool flush_general_log(); /* Perform basic logger cleanup. this will leave e.g. error log open. */ void cleanup_base(); /* Free memory. Nothing could be logged after this function is called */ diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 80f366d774a..0a6c04b82ce 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -6664,6 +6664,30 @@ bool reload_acl_and_cache(THD *thd, ulong options, TABLE_LIST *tables, tables. */ + options|= REFRESH_BINARY_LOG; + options|= REFRESH_RELAY_LOG; + options|= REFRESH_SLOW_LOG; + options|= REFRESH_GENERAL_LOG; + options|= REFRESH_ENGINE_LOG; + options|= REFRESH_ERROR_LOG; + } + + if (options & REFRESH_ERROR_LOG) + if (flush_error_log()) + result= 1; + + if ((options & REFRESH_SLOW_LOG) && opt_slow_log) + logger.flush_slow_log(); + + if ((options & REFRESH_GENERAL_LOG) && opt_log) + logger.flush_general_log(); + + if (options & REFRESH_ENGINE_LOG) + if (ha_flush_logs(NULL)) + result= 1; + + if (options & REFRESH_BINARY_LOG) + { /* Writing this command to the binlog may result in infinite loops when doing mysqlbinlog|mysql, and anyway it does not really make @@ -6671,23 +6695,16 @@ bool reload_acl_and_cache(THD *thd, ulong options, TABLE_LIST *tables, than it would help them) */ tmp_write_to_binlog= 0; - if( mysql_bin_log.is_open() ) - { + if (mysql_bin_log.is_open()) mysql_bin_log.rotate_and_purge(RP_FORCE_ROTATE); - } + } + if (options & REFRESH_RELAY_LOG) + { #ifdef HAVE_REPLICATION pthread_mutex_lock(&LOCK_active_mi); rotate_relay_log(active_mi); pthread_mutex_unlock(&LOCK_active_mi); #endif - - /* flush slow and general logs */ - logger.flush_logs(thd); - - if (ha_flush_logs(NULL)) - result=1; - if (flush_error_log()) - result=1; } #ifdef HAVE_QUERY_CACHE if (options & REFRESH_QUERY_CACHE_FREE) diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 1b85e5afdce..577f0b5ef71 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -681,6 +681,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %token ENUM %token EQ /* OPERATOR */ %token EQUAL_SYM /* OPERATOR */ +%token ERROR_SYM %token ERRORS %token ESCAPED %token ESCAPE_SYM /* SQL-2003-R */ @@ -714,6 +715,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %token FULLTEXT_SYM %token FUNCTION_SYM /* SQL-2003-R */ %token GE +%token GENERAL %token GEOMETRYCOLLECTION %token GEOMETRY_SYM %token GET_FORMAT /* MYSQL-FUNC */ @@ -931,6 +933,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %token REDUNDANT_SYM %token REFERENCES /* SQL-2003-R */ %token REGEXP +%token RELAY %token RELAYLOG_SYM %token RELAY_LOG_FILE_SYM %token RELAY_LOG_POS_SYM @@ -985,6 +988,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %token SIGNED_SYM %token SIMPLE_SYM /* SQL-2003-N */ %token SLAVE +%token SLOW %token SMALLINT /* SQL-2003-R */ %token SNAPSHOT_SYM %token SOCKET_SYM @@ -10313,6 +10317,18 @@ flush_option: opt_table_list {} | TABLES WITH READ_SYM LOCK_SYM { Lex->type|= REFRESH_TABLES | REFRESH_READ_LOCK; } + | ERROR_SYM LOGS_SYM + { Lex->type|= REFRESH_ERROR_LOG; } + | ENGINE_SYM LOGS_SYM + { Lex->type|= REFRESH_ENGINE_LOG; } + | GENERAL LOGS_SYM + { Lex->type|= REFRESH_GENERAL_LOG; } + | SLOW LOGS_SYM + { Lex->type|= REFRESH_SLOW_LOG; } + | BINARY LOGS_SYM + { Lex->type|= REFRESH_BINARY_LOG; } + | RELAY LOGS_SYM + { Lex->type|= REFRESH_RELAY_LOG; } | QUERY_SYM CACHE_SYM { Lex->type|= REFRESH_QUERY_CACHE_FREE; } | HOSTS_SYM @@ -11436,6 +11452,7 @@ keyword_sp: | ENUM {} | ENGINE_SYM {} | ENGINES_SYM {} + | ERROR_SYM {} | ERRORS {} | ESCAPE_SYM {} | EVENT_SYM {} @@ -11560,6 +11577,7 @@ keyword_sp: | REDO_BUFFER_SIZE_SYM {} | REDOFILE_SYM {} | REDUNDANT_SYM {} + | RELAY {} | RELAYLOG_SYM {} | RELAY_LOG_FILE_SYM {} | RELAY_LOG_POS_SYM {} |