Commit 34ab4521 authored by 's avatar

WL#5142 FLUSH LOGS should take optional arguments for which log(s) to flush

Support for flushing individual logs, so that the user can
selectively flush a subset of the server logs.

Flush of individual logs is done according to the 
following syntax:

  FLUSH <log_category> LOGS;

The syntax is extended so that the user is able to flush a
subset of logs:

  FLUSH [log_category LOGS,];

where log_category is one of:
  SLOW
  ERROR
  BINARY
  ENGINE
  GENERAL
  RELAY.
parent 46b67a3b
......@@ -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 */
......
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.
--log-error=$MYSQLTEST_VARDIR/tmp/master_log.err
#
# 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;
......@@ -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)},
......
......@@ -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
......
......@@ -570,6 +570,8 @@ class LOGGER
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 */
......
......@@ -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)
......
......@@ -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 {}
......
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