Skip to content

Commit

Permalink
Port slow query log rotation
Browse files Browse the repository at this point in the history
Summary:
This diff is a combination of the following two commits from Percona:
percona/percona-server@725a238c
percona/percona-server@85c461c8

Adds two new variables `max_slowlog_size` and `max_slowlog_files` as documented here:
https://www.percona.com/doc/percona-server/LATEST/flexibility/slowlog_rotation.html

Reviewed By: hermanlee

Differential Revision: D5394337

fbshipit-source-id: 746c6bf
  • Loading branch information
lth authored and facebook-github-bot committed Jul 11, 2017
1 parent d99f329 commit 3445f81
Show file tree
Hide file tree
Showing 14 changed files with 410 additions and 10 deletions.
11 changes: 11 additions & 0 deletions mysql-test/r/mysqld--help-notwin-profiling.result
Expand Up @@ -589,6 +589,15 @@ The following options may be given as the first argument:
--max-seeks-for-key=#
Limit assumed max number of seeks when looking up rows
based on a key
--max-slowlog-files=#
Maximum number of slow query log files. Used with
--max-slowlog-size this can be used to limit the total
amount of disk space used for the slow query log. Default
is 0, don't limit.
--max-slowlog-size=#
Slow query log will be rotated automatically when the
size exceeds this value. The default is 0, don't limit
the size.
--max-sort-length=# The number of bytes to use when sorting BLOB or TEXT
values (only the first max_sort_length bytes of each
value are used; the rest are ignored)
Expand Down Expand Up @@ -1906,6 +1915,8 @@ max-prepared-stmt-count 16382
max-relay-log-size 0
max-running-queries 0
max-seeks-for-key 18446744073709551615
max-slowlog-files 0
max-slowlog-size 0
max-sort-length 1024
max-sp-recursion-depth 0
max-tmp-tables 32
Expand Down
11 changes: 11 additions & 0 deletions mysql-test/r/mysqld--help-notwin.result
Expand Up @@ -589,6 +589,15 @@ The following options may be given as the first argument:
--max-seeks-for-key=#
Limit assumed max number of seeks when looking up rows
based on a key
--max-slowlog-files=#
Maximum number of slow query log files. Used with
--max-slowlog-size this can be used to limit the total
amount of disk space used for the slow query log. Default
is 0, don't limit.
--max-slowlog-size=#
Slow query log will be rotated automatically when the
size exceeds this value. The default is 0, don't limit
the size.
--max-sort-length=# The number of bytes to use when sorting BLOB or TEXT
values (only the first max_sort_length bytes of each
value are used; the rest are ignored)
Expand Down Expand Up @@ -1904,6 +1913,8 @@ max-prepared-stmt-count 16382
max-relay-log-size 0
max-running-queries 0
max-seeks-for-key 18446744073709551615
max-slowlog-files 0
max-slowlog-size 0
max-sort-length 1024
max-sp-recursion-depth 0
max-tmp-tables 32
Expand Down
21 changes: 21 additions & 0 deletions mysql-test/r/percona_bug1416582.result
@@ -0,0 +1,21 @@
SET @old_max_slowlog_size = @@global.max_slowlog_size;
SET @old_slow_query_log = @@global.slow_query_log;
SET @old_slow_query_log_file = @@global.slow_query_log_file;
SET @old_long_query_time = @@long_query_time;
SET GLOBAL max_slowlog_size=10240000;
SET long_query_time=0;
SET GLOBAL slow_query_log_file='MYSQLTEST_VARDIR/abcd';
SET GLOBAL slow_query_log=1;
SET GLOBAL slow_query_log=0;
SET GLOBAL slow_query_log=1;
SET GLOBAL slow_query_log=0;
SET GLOBAL slow_query_log=1;
FLUSH LOGS;
FLUSH LOGS;
FLUSH LOGS;
slow query log files count:
1
SET @@global.max_slowlog_size = @old_max_slowlog_size;
SET @@global.slow_query_log = @old_slow_query_log;
SET @@global.slow_query_log_file = @old_slow_query_log_file;
SET @@long_query_time = @old_long_query_time;
21 changes: 21 additions & 0 deletions mysql-test/r/percona_slowlog_size_limits.result
@@ -0,0 +1,21 @@
SET @old_slow_query_log = @@global.slow_query_log;
SET @old_log_output = @@global.log_output;
SET @old_slow_query_log_file = @@global.slow_query_log_file;
SET @old_max_slowlog_size = @@global.max_slowlog_size;
SET @old_max_slowlog_files = @@global.max_slowlog_files;
SET @old_long_query_time = @@long_query_time;
SET GLOBAL slow_query_log=1;
SET GLOBAL log_output=FILE;
SET GLOBAL max_slowlog_size=4096;
SET GLOBAL max_slowlog_files=5;
SET long_query_time=0;
SET GLOBAL slow_query_log_file='MYSQLTEST_VARDIR/abcd';
5
SET GLOBAL slow_query_log_file='MYSQLTEST_VARDIR/zxcv';
5
SET @@global.slow_query_log = @old_slow_query_log;
SET @@global.log_output = @old_log_output;
SET @@global.slow_query_log_file = @old_slow_query_log_file;
SET @@global.max_slowlog_size = @old_max_slowlog_size;
SET @@global.max_slowlog_files = @old_max_slowlog_files;
SET @@long_query_time = @old_long_query_time;
30 changes: 30 additions & 0 deletions mysql-test/suite/sys_vars/r/max_slowlog_files_basic.result
@@ -0,0 +1,30 @@
SET @old = @@global.max_slowlog_files;
SET GLOBAL max_slowlog_files = 0;
SELECT @@global.max_slowlog_files;
@@global.max_slowlog_files
0
SET GLOBAL max_slowlog_files = 4096;
SELECT @@global.max_slowlog_files;
@@global.max_slowlog_files
4096
SET GLOBAL max_slowlog_files = 1000;
SELECT @@global.max_slowlog_files;
@@global.max_slowlog_files
1000
SET GLOBAL max_slowlog_files = -1;
Warnings:
Warning 1292 Truncated incorrect max_slowlog_files value: '-1'
SELECT @@global.max_slowlog_files;
@@global.max_slowlog_files
0
SET GLOBAL max_slowlog_files = 102400;
SELECT @@global.max_slowlog_files;
@@global.max_slowlog_files
102400
SET GLOBAL max_slowlog_files = 102401;
Warnings:
Warning 1292 Truncated incorrect max_slowlog_files value: '102401'
SELECT @@global.max_slowlog_files;
@@global.max_slowlog_files
102400
SET @@global.max_slowlog_files = @old;
32 changes: 32 additions & 0 deletions mysql-test/suite/sys_vars/r/max_slowlog_size_basic.result
@@ -0,0 +1,32 @@
SET @old = @@global.max_slowlog_size;
SET GLOBAL max_slowlog_size = 0;
SELECT @@global.max_slowlog_size;
@@global.max_slowlog_size
0
SET GLOBAL max_slowlog_size = 4096;
SELECT @@global.max_slowlog_size;
@@global.max_slowlog_size
4096
SET GLOBAL max_slowlog_size = 1000;
Warnings:
Warning 1292 Truncated incorrect max_slowlog_size value: '1000'
SELECT @@global.max_slowlog_size;
@@global.max_slowlog_size
0
SET GLOBAL max_slowlog_size = -1;
Warnings:
Warning 1292 Truncated incorrect max_slowlog_size value: '-1'
SELECT @@global.max_slowlog_size;
@@global.max_slowlog_size
0
SET GLOBAL max_slowlog_size = 1024*1024*1024;
SELECT @@global.max_slowlog_size;
@@global.max_slowlog_size
1073741824
SET GLOBAL max_slowlog_size = 1024*1024*1024+1;
Warnings:
Warning 1292 Truncated incorrect max_slowlog_size value: '1073741825'
SELECT @@global.max_slowlog_size;
@@global.max_slowlog_size
1073741824
SET @@global.max_slowlog_size = @old;
18 changes: 18 additions & 0 deletions mysql-test/suite/sys_vars/t/max_slowlog_files_basic.test
@@ -0,0 +1,18 @@
#
# Test max_slowlog_files
#

SET @old = @@global.max_slowlog_files;
SET GLOBAL max_slowlog_files = 0;
SELECT @@global.max_slowlog_files;
SET GLOBAL max_slowlog_files = 4096;
SELECT @@global.max_slowlog_files;
SET GLOBAL max_slowlog_files = 1000;
SELECT @@global.max_slowlog_files;
SET GLOBAL max_slowlog_files = -1;
SELECT @@global.max_slowlog_files;
SET GLOBAL max_slowlog_files = 102400;
SELECT @@global.max_slowlog_files;
SET GLOBAL max_slowlog_files = 102401;
SELECT @@global.max_slowlog_files;
SET @@global.max_slowlog_files = @old;
18 changes: 18 additions & 0 deletions mysql-test/suite/sys_vars/t/max_slowlog_size_basic.test
@@ -0,0 +1,18 @@
#
# Test max_slowlog_size
#

SET @old = @@global.max_slowlog_size;
SET GLOBAL max_slowlog_size = 0;
SELECT @@global.max_slowlog_size;
SET GLOBAL max_slowlog_size = 4096;
SELECT @@global.max_slowlog_size;
SET GLOBAL max_slowlog_size = 1000;
SELECT @@global.max_slowlog_size;
SET GLOBAL max_slowlog_size = -1;
SELECT @@global.max_slowlog_size;
SET GLOBAL max_slowlog_size = 1024*1024*1024;
SELECT @@global.max_slowlog_size;
SET GLOBAL max_slowlog_size = 1024*1024*1024+1;
SELECT @@global.max_slowlog_size;
SET @@global.max_slowlog_size = @old;
38 changes: 38 additions & 0 deletions mysql-test/t/percona_bug1416582.test
@@ -0,0 +1,38 @@
#
# Bug 1416582: Slow query log is rotated before it should
# when using max_slowlog_size
#

SET @old_max_slowlog_size = @@global.max_slowlog_size;
SET @old_slow_query_log = @@global.slow_query_log;
SET @old_slow_query_log_file = @@global.slow_query_log_file;
SET @old_long_query_time = @@long_query_time;
SET GLOBAL max_slowlog_size=10240000;
SET long_query_time=0;

--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
eval SET GLOBAL slow_query_log_file='$MYSQLTEST_VARDIR/abcd';

# start/stop slog log should not cause log number increment
SET GLOBAL slow_query_log=1;
SET GLOBAL slow_query_log=0;
SET GLOBAL slow_query_log=1;
SET GLOBAL slow_query_log=0;
SET GLOBAL slow_query_log=1;

# FLUSH LOGS should not cause log number increment
FLUSH LOGS;
FLUSH LOGS;
FLUSH LOGS;

--echo slow query log files count:
perl;
my @files = <$ENV{'MYSQLTEST_VARDIR'}/abcd*>;
printf "%d\n", scalar(@files);
EOF


SET @@global.max_slowlog_size = @old_max_slowlog_size;
SET @@global.slow_query_log = @old_slow_query_log;
SET @@global.slow_query_log_file = @old_slow_query_log_file;
SET @@long_query_time = @old_long_query_time;
60 changes: 60 additions & 0 deletions mysql-test/t/percona_slowlog_size_limits.test
@@ -0,0 +1,60 @@
#
# Test slowlog size limiting and rotation
#

SET @old_slow_query_log = @@global.slow_query_log;
SET @old_log_output = @@global.log_output;
SET @old_slow_query_log_file = @@global.slow_query_log_file;
SET @old_max_slowlog_size = @@global.max_slowlog_size;
SET @old_max_slowlog_files = @@global.max_slowlog_files;
SET @old_long_query_time = @@long_query_time;

SET GLOBAL slow_query_log=1;
SET GLOBAL log_output=FILE;
SET GLOBAL max_slowlog_size=4096;
SET GLOBAL max_slowlog_files=5;
SET long_query_time=0;

--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
eval SET GLOBAL slow_query_log_file='$MYSQLTEST_VARDIR/abcd';

# avoid 1000 selects 1 in .result
let $i=1000;
disable_query_log;
disable_result_log;
while($i) {
eval select $i;
dec $i;
}
enable_query_log;
enable_result_log;

perl;
my @files = <$ENV{'MYSQLTEST_VARDIR'}/abcd*>;
printf "%d\n", scalar(@files);
EOF


--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
eval SET GLOBAL slow_query_log_file='$MYSQLTEST_VARDIR/zxcv';

let $i=1000;
disable_query_log;
disable_result_log;
while($i) {
eval select $i;
dec $i;
}
enable_query_log;
enable_result_log;
perl;
my @files = <$ENV{'MYSQLTEST_VARDIR'}/zxcv*>;
printf "%d\n", scalar(@files);
EOF

SET @@global.slow_query_log = @old_slow_query_log;
SET @@global.log_output = @old_log_output;
SET @@global.slow_query_log_file = @old_slow_query_log_file;
SET @@global.max_slowlog_size = @old_max_slowlog_size;
SET @@global.max_slowlog_files = @old_max_slowlog_files;
SET @@long_query_time = @old_long_query_time;

1 comment on commit 3445f81

@laurynas-biveinis
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a heads up that a straightforward port from Percona Server is probably affected by https://bugs.launchpad.net/percona-server/+bug/1288232 (slowlog rotation and expiration doesn't work with the default slow query log name)

Please sign in to comment.