Skip to content

Commit 34ab452

Browse files
authored andcommitted
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.
1 parent 46b67a3 commit 34ab452

File tree

9 files changed

+346
-11
lines changed

9 files changed

+346
-11
lines changed

include/mysql_com.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ enum enum_server_command
115115
thread */
116116
#define REFRESH_MASTER 128 /* Remove all bin logs in the index
117117
and truncate the index */
118+
#define REFRESH_ERROR_LOG 256 /* Rotate only the erorr log */
119+
#define REFRESH_ENGINE_LOG 512 /* Flush all storage engine logs */
120+
#define REFRESH_BINARY_LOG 1024 /* Flush the binary log */
121+
#define REFRESH_RELAY_LOG 2048 /* Flush the relay log */
122+
#define REFRESH_GENERAL_LOG 4096 /* Flush the general log */
123+
#define REFRESH_SLOW_LOG 8192 /* Flush the slow query log */
118124

119125
/* The following can't be set with mysql_refresh() */
120126
#define REFRESH_READ_LOCK 16384 /* Lock tables for read */
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
stop slave;
2+
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
3+
reset master;
4+
reset slave;
5+
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
6+
start slave;
7+
# Make sure the 'master_log.err-old' file does not
8+
# exist before execute 'flush error logs' statement.
9+
# Test if support 'flush error logs' statement.
10+
flush error logs;
11+
# Check the 'master_log.err-old' file is created
12+
# after executed 'flush error logs' statement.
13+
# Make sure binary logs was not be flushed
14+
# after execute 'flush error logs' statement.
15+
# Make sure relay logs was not be flushed
16+
# after execute 'flush error logs' statement.
17+
# Make sure the 'slave-relay-bin.000004' file does not
18+
# exist before execute 'flush relay logs' statement.
19+
# Test if support 'flush relay logs' statement.
20+
flush relay logs;
21+
# Check the 'slave-relay-bin.000004' file is created
22+
# after executed 'flush relay logs' statement.
23+
# Make sure binary logs was not be flushed
24+
# after execute 'flush relay logs' statement.
25+
# Test if support 'flush slow logs' statement.
26+
flush slow logs;
27+
# Make sure binary logs was not be flushed
28+
# after execute 'flush slow logs' statement.
29+
# Test if support 'flush general logs' statement.
30+
flush general logs;
31+
# Make sure binary logs was not be flushed
32+
# after execute 'flush general logs' statement.
33+
# Test if support 'flush engine logs' statement.
34+
flush engine logs;
35+
# Make sure binary logs was not be flushed
36+
# after execute 'flush engine logs' statement.
37+
# Make sure the 'master-bin.000002' file does not
38+
# exist before execute 'flush binary logs' statement.
39+
# Test if support 'flush binary logs' statement.
40+
flush binary logs;
41+
# Check the 'master-bin.000002' file is created
42+
# after executed 'flush binary logs' statement.
43+
# Make sure the 'slave-relay-bin.000007' file does not exist
44+
# exist before execute 'flush error logs, relay logs' statement.
45+
# Make sure the 'master_log.err-old' file does not exist
46+
# before execute 'flush error logs, relay logs' statement.
47+
# Test if support to combine all kinds of logs into one statement.
48+
flush error logs, relay logs;
49+
# Check the 'master_log.err-old' file is created
50+
# after executed 'flush error logs, relay logs' statement.
51+
# Make sure binary logs was not be flushed
52+
# after execute 'flush error logs, relay logs' statement.
53+
# Check the 'slave-relay-bin.000007' file is created after
54+
# execute 'flush error logs, relay logs' statement.
55+
# Make sure the 'slave-relay-bin.000008' and 'slave-relay-bin.000009'
56+
# files do not exist before execute 'flush error logs, relay logs'
57+
# statement.
58+
# Make sure the 'master_log.err-old' file does not exist
59+
# before execute 'flush logs' statement.
60+
# Test if 'flush logs' statement works fine and flush all the logs.
61+
flush logs;
62+
# Check the 'master_log.err-old' file is created
63+
# after executed 'flush logs' statement.
64+
# Check 'master-bin.000003' is created
65+
# after execute 'flush logs' statement.
66+
# Check the 'slave-relay-bin.000008' and 'slave-relay-bin.000009'
67+
# files are created after execute 'flush logs' statement.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--log-error=$MYSQLTEST_VARDIR/tmp/master_log.err
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
#
2+
# WL#5124
3+
# This test verifies if the 'flush individual logs' statement
4+
# works fine.
5+
#
6+
7+
--source include/master-slave.inc
8+
--source include/have_binlog_format_statement.inc
9+
connection master;
10+
11+
# Test 'flush error logs' statement.
12+
--echo # Make sure the 'master_log.err-old' file does not
13+
--echo # exist before execute 'flush error logs' statement.
14+
--error 1
15+
file_exists $MYSQLTEST_VARDIR/tmp/master_log.err-old;
16+
17+
--echo # Test if support 'flush error logs' statement.
18+
flush error logs;
19+
20+
--echo # Check the 'master_log.err-old' file is created
21+
--echo # after executed 'flush error logs' statement.
22+
file_exists $MYSQLTEST_VARDIR/tmp/master_log.err-old;
23+
file_exists $MYSQLTEST_VARDIR/tmp/master_log.err;
24+
25+
--echo # Make sure binary logs was not be flushed
26+
--echo # after execute 'flush error logs' statement.
27+
--error 1
28+
file_exists $MYSQLTEST_VARDIR/mysqld.1/data/master-bin.000002;
29+
30+
sync_slave_with_master;
31+
--echo # Make sure relay logs was not be flushed
32+
--echo # after execute 'flush error logs' statement.
33+
--error 1
34+
file_exists $MYSQLTEST_VARDIR/mysqld.2/data/slave-relay-bin.000004;
35+
36+
37+
# Test 'flush relay logs' statement.
38+
--echo # Make sure the 'slave-relay-bin.000004' file does not
39+
--echo # exist before execute 'flush relay logs' statement.
40+
--error 1
41+
file_exists $MYSQLTEST_VARDIR/mysqld.2/data/slave-relay-bin.000004;
42+
43+
connection master;
44+
--echo # Test if support 'flush relay logs' statement.
45+
flush relay logs;
46+
47+
sync_slave_with_master;
48+
--echo # Check the 'slave-relay-bin.000004' file is created
49+
--echo # after executed 'flush relay logs' statement.
50+
file_exists $MYSQLTEST_VARDIR/mysqld.2/data/slave-relay-bin.000004;
51+
52+
connection master;
53+
--echo # Make sure binary logs was not be flushed
54+
--echo # after execute 'flush relay logs' statement.
55+
--error 1
56+
file_exists $MYSQLTEST_VARDIR/mysqld.1/data/master-bin.000002;
57+
58+
59+
# Test 'flush slow logs' statement.
60+
--echo # Test if support 'flush slow logs' statement.
61+
flush slow logs;
62+
63+
--echo # Make sure binary logs was not be flushed
64+
--echo # after execute 'flush slow logs' statement.
65+
--error 1
66+
file_exists $MYSQLTEST_VARDIR/mysqld.1/data/master-bin.000002;
67+
68+
69+
# Test 'flush general logs' statement.
70+
--echo # Test if support 'flush general logs' statement.
71+
flush general logs;
72+
73+
--echo # Make sure binary logs was not be flushed
74+
--echo # after execute 'flush general logs' statement.
75+
--error 1
76+
file_exists $MYSQLTEST_VARDIR/mysqld.1/data/master-bin.000002;
77+
78+
79+
# Test 'flush engine logs' statement.
80+
--echo # Test if support 'flush engine logs' statement.
81+
flush engine logs;
82+
83+
--echo # Make sure binary logs was not be flushed
84+
--echo # after execute 'flush engine logs' statement.
85+
--error 1
86+
file_exists $MYSQLTEST_VARDIR/mysqld.1/data/master-bin.000002;
87+
88+
89+
# Test 'flush binary logs' statement.
90+
--echo # Make sure the 'master-bin.000002' file does not
91+
--echo # exist before execute 'flush binary logs' statement.
92+
--error 1
93+
file_exists $MYSQLTEST_VARDIR/mysqld.1/data/master-bin.000002;
94+
95+
--echo # Test if support 'flush binary logs' statement.
96+
flush binary logs;
97+
98+
--echo # Check the 'master-bin.000002' file is created
99+
--echo # after executed 'flush binary logs' statement.
100+
file_exists $MYSQLTEST_VARDIR/mysqld.1/data/master-bin.000002;
101+
file_exists $MYSQLTEST_VARDIR/mysqld.1/data/master-bin.000001;
102+
103+
104+
# Test 'flush error logs, relay logs' statement
105+
sync_slave_with_master;
106+
--echo # Make sure the 'slave-relay-bin.000007' file does not exist
107+
--echo # exist before execute 'flush error logs, relay logs' statement.
108+
--error 1
109+
file_exists $MYSQLTEST_VARDIR/mysqld.2/data/slave-relay-bin.000007;
110+
111+
connection master;
112+
remove_file $MYSQLTEST_VARDIR/tmp/master_log.err-old;
113+
114+
--echo # Make sure the 'master_log.err-old' file does not exist
115+
--echo # before execute 'flush error logs, relay logs' statement.
116+
--error 1
117+
file_exists $MYSQLTEST_VARDIR/tmp/master_log.err-old;
118+
119+
--echo # Test if support to combine all kinds of logs into one statement.
120+
flush error logs, relay logs;
121+
122+
--echo # Check the 'master_log.err-old' file is created
123+
--echo # after executed 'flush error logs, relay logs' statement.
124+
file_exists $MYSQLTEST_VARDIR/tmp/master_log.err-old;
125+
file_exists $MYSQLTEST_VARDIR/tmp/master_log.err;
126+
127+
--echo # Make sure binary logs was not be flushed
128+
--echo # after execute 'flush error logs, relay logs' statement.
129+
--error 1
130+
file_exists $MYSQLTEST_VARDIR/mysqld.1/data/master-bin.000003;
131+
132+
sync_slave_with_master;
133+
--echo # Check the 'slave-relay-bin.000007' file is created after
134+
--echo # execute 'flush error logs, relay logs' statement.
135+
file_exists $MYSQLTEST_VARDIR/mysqld.2/data/slave-relay-bin.000007;
136+
137+
138+
# Test 'flush logs' statement
139+
--echo # Make sure the 'slave-relay-bin.000008' and 'slave-relay-bin.000009'
140+
--echo # files do not exist before execute 'flush error logs, relay logs'
141+
--echo # statement.
142+
--error 1
143+
file_exists $MYSQLTEST_VARDIR/mysqld.2/data/slave-relay-bin.000008;
144+
--error 1
145+
file_exists $MYSQLTEST_VARDIR/mysqld.2/data/slave-relay-bin.000009;
146+
147+
connection master;
148+
remove_file $MYSQLTEST_VARDIR/tmp/master_log.err-old;
149+
150+
--echo # Make sure the 'master_log.err-old' file does not exist
151+
--echo # before execute 'flush logs' statement.
152+
--error 1
153+
file_exists $MYSQLTEST_VARDIR/tmp/master_log.err-old;
154+
155+
--echo # Test if 'flush logs' statement works fine and flush all the logs.
156+
flush logs;
157+
158+
--echo # Check the 'master_log.err-old' file is created
159+
--echo # after executed 'flush logs' statement.
160+
file_exists $MYSQLTEST_VARDIR/tmp/master_log.err-old;
161+
file_exists $MYSQLTEST_VARDIR/tmp/master_log.err;
162+
163+
--echo # Check 'master-bin.000003' is created
164+
--echo # after execute 'flush logs' statement.
165+
file_exists $MYSQLTEST_VARDIR/mysqld.1/data/master-bin.000003;
166+
167+
sync_slave_with_master;
168+
--echo # Check the 'slave-relay-bin.000008' and 'slave-relay-bin.000009'
169+
--echo # files are created after execute 'flush logs' statement.
170+
file_exists $MYSQLTEST_VARDIR/mysqld.2/data/slave-relay-bin.000008;
171+
file_exists $MYSQLTEST_VARDIR/mysqld.2/data/slave-relay-bin.000009;
172+

sql/lex.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ static SYMBOL symbols[] = {
189189
{ "ENGINE", SYM(ENGINE_SYM)},
190190
{ "ENGINES", SYM(ENGINES_SYM)},
191191
{ "ENUM", SYM(ENUM)},
192+
{ "ERROR", SYM(ERROR_SYM)},
192193
{ "ERRORS", SYM(ERRORS)},
193194
{ "ESCAPE", SYM(ESCAPE_SYM)},
194195
{ "ESCAPED", SYM(ESCAPED)},
@@ -223,6 +224,7 @@ static SYMBOL symbols[] = {
223224
{ "FULL", SYM(FULL)},
224225
{ "FULLTEXT", SYM(FULLTEXT_SYM)},
225226
{ "FUNCTION", SYM(FUNCTION_SYM)},
227+
{ "GENERAL", SYM(GENERAL)},
226228
{ "GEOMETRY", SYM(GEOMETRY_SYM)},
227229
{ "GEOMETRYCOLLECTION",SYM(GEOMETRYCOLLECTION)},
228230
{ "GET_FORMAT", SYM(GET_FORMAT)},
@@ -429,6 +431,7 @@ static SYMBOL symbols[] = {
429431
{ "REDUNDANT", SYM(REDUNDANT_SYM)},
430432
{ "REFERENCES", SYM(REFERENCES)},
431433
{ "REGEXP", SYM(REGEXP)},
434+
{ "RELAY", SYM(RELAY)},
432435
{ "RELAYLOG", SYM(RELAYLOG_SYM)},
433436
{ "RELAY_LOG_FILE", SYM(RELAY_LOG_FILE_SYM)},
434437
{ "RELAY_LOG_POS", SYM(RELAY_LOG_POS_SYM)},
@@ -481,6 +484,7 @@ static SYMBOL symbols[] = {
481484
{ "SIGNED", SYM(SIGNED_SYM)},
482485
{ "SIMPLE", SYM(SIMPLE_SYM)},
483486
{ "SLAVE", SYM(SLAVE)},
487+
{ "SLOW", SYM(SLOW)},
484488
{ "SNAPSHOT", SYM(SNAPSHOT_SYM)},
485489
{ "SMALLINT", SYM(SMALLINT)},
486490
{ "SOCKET", SYM(SOCKET_SYM)},

sql/log.cc

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,54 @@ bool LOGGER::flush_logs(THD *thd)
965965
}
966966

967967

968+
/**
969+
Close and reopen the slow log (with locks).
970+
971+
@returns FALSE.
972+
*/
973+
bool LOGGER::flush_slow_log()
974+
{
975+
/*
976+
Now we lock logger, as nobody should be able to use logging routines while
977+
log tables are closed
978+
*/
979+
logger.lock_exclusive();
980+
981+
/* Reopen slow log file */
982+
if (opt_slow_log)
983+
file_log_handler->get_mysql_slow_log()->reopen_file();
984+
985+
/* End of log flush */
986+
logger.unlock();
987+
988+
return 0;
989+
}
990+
991+
992+
/**
993+
Close and reopen the general log (with locks).
994+
995+
@returns FALSE.
996+
*/
997+
bool LOGGER::flush_general_log()
998+
{
999+
/*
1000+
Now we lock logger, as nobody should be able to use logging routines while
1001+
log tables are closed
1002+
*/
1003+
logger.lock_exclusive();
1004+
1005+
/* Reopen general log file */
1006+
if (opt_log)
1007+
file_log_handler->get_mysql_log()->reopen_file();
1008+
1009+
/* End of log flush */
1010+
logger.unlock();
1011+
1012+
return 0;
1013+
}
1014+
1015+
9681016
/*
9691017
Log slow query with all enabled log event handlers
9701018

sql/log.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,8 @@ class LOGGER
570570
void init_base();
571571
void init_log_tables();
572572
bool flush_logs(THD *thd);
573+
bool flush_slow_log();
574+
bool flush_general_log();
573575
/* Perform basic logger cleanup. this will leave e.g. error log open. */
574576
void cleanup_base();
575577
/* Free memory. Nothing could be logged after this function is called */

0 commit comments

Comments
 (0)