forked from facebook/mysql-5.6
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FB8-118: Port slow query log rotation (facebook#1015) (facebook#1015)
Summary: Jira issue: https://jira.percona.com/browse/FB8-118 Reference Patch: facebook@3445f81 Porting notes: 1. fixed PS-1484: slowlog rotation and expiration doesn't work with the default slow query log name 2. `max_slowlog_files` was replaced with `slowlog_space_limit` ---------- facebook@3445f81 ---------- 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 Originally Reviewed By: hermanlee Pull Request resolved: facebook#1015 Reference Patch: facebook@b857c4840db Differential Revision: D15158133
- Loading branch information
Showing
13 changed files
with
988 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# ==== Purpose ==== | ||
# | ||
# Assert that number of files matching given $file_spec is equal to expected. | ||
# | ||
# ==== Usage ==== | ||
# | ||
# --let file_spec = PATH_REGEX | ||
# --let expected_number = INTEGER | ||
# --source include/assert_number_of_files.inc | ||
# | ||
# Parameters: | ||
# $file_spec | ||
# The path with wildcards e.g. $MYSQLTEST_VARDIR/abcd* | ||
# | ||
# $expected_number | ||
# The expected number of files | ||
|
||
if ($VALGRIND_TEST) | ||
{ | ||
--sleep 5 | ||
} | ||
|
||
--perl | ||
use strict; | ||
my $dir = $ENV{'MYSQL_TMP_DIR'} or die "MYSQL_TMP_DIR not set"; | ||
my $file_spec = $ENV{'file_spec'} or die "file_spec not set"; | ||
my @files = <$ENV{'file_spec'}>; | ||
open (OUTPUT, ">$dir/number_of_files.inc") ; | ||
print OUTPUT "--let \$number_of_files = ", scalar(@files), "\n"; | ||
close (OUTPUT); | ||
EOF | ||
--source $MYSQL_TMP_DIR/number_of_files.inc | ||
--remove_file $MYSQL_TMP_DIR/number_of_files.inc | ||
|
||
|
||
if ($expected_number != $number_of_files) | ||
{ | ||
--echo ====================== Test assertion failed: ====================== | ||
--echo The number of files ($number_of_files) is different that expected $expected_number | ||
--echo ==================================================================== | ||
--die Test assertion failed in assert_number_of_files.inc | ||
} | ||
|
||
--echo include/assert_number_of_files.inc [The number of files matches expected $expected_number] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
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_slowlog_space_limit = @@global.slowlog_space_limit; | ||
SET long_query_time = 0; | ||
SET GLOBAL log_output = FILE; | ||
SET GLOBAL slow_query_log = 1; | ||
# Case 1 (PS-1484): Test if slowlog_space_limit is working correctly | ||
# with the default slow query log name | ||
SET GLOBAL max_slowlog_size = 4096; | ||
SET GLOBAL slowlog_space_limit = @@global.max_slowlog_size * 3; | ||
include/assert_number_of_files.inc [The number of files matches expected 3] | ||
# Case 2 (Bug 1416582): Slow query log is rotated before it should | ||
# when using max_slowlog_size | ||
SET GLOBAL max_slowlog_size = 10240000; | ||
SET GLOBAL slow_query_log_file = 'MYSQLTEST_VARDIR/abcd'; | ||
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; | ||
include/assert.inc [Slow query log number should not be incremented and log should be abcd.000001] | ||
# Case 3: Test if each slow_query_log_file call rotates slow log | ||
SET GLOBAL slow_query_log_file = 'MYSQLTEST_VARDIR/zxcv'; | ||
SET GLOBAL slow_query_log_file = 'MYSQLTEST_VARDIR/abcd'; | ||
SET GLOBAL slow_query_log_file = 'MYSQLTEST_VARDIR/zxcv'; | ||
include/assert.inc [Slow query log should be zxcv.000002] | ||
SET GLOBAL slow_query_log_file = 'MYSQLTEST_VARDIR/abcd'; | ||
include/assert.inc [Slow query log should be abcd.000003] | ||
# Case 4: Test if slowlog_space_limit is working correctly | ||
SET GLOBAL max_slowlog_size = 4096; | ||
SET GLOBAL slowlog_space_limit = @@global.max_slowlog_size * 5; | ||
SET GLOBAL slow_query_log_file = 'MYSQLTEST_VARDIR/abcd'; | ||
include/assert_number_of_files.inc [The number of files matches expected 5] | ||
SET GLOBAL slow_query_log_file = 'MYSQLTEST_VARDIR/zxcv'; | ||
include/assert_number_of_files.inc [The number of files matches expected 5] | ||
SET GLOBAL slow_query_log_file = 'MYSQLTEST_VARDIR/abcd'; | ||
include/assert_number_of_files.inc [The number of files matches expected 5] | ||
# Case 5: Rotating log but should not delete previous logs | ||
SET GLOBAL slow_query_log_file = 'MYSQLTEST_VARDIR/abcd'; | ||
SET GLOBAL slow_query_log_file = 'MYSQLTEST_VARDIR/abcd'; | ||
include/assert_number_of_files.inc [The number of files matches expected 7] | ||
# Case 6: Calling "SET slowlog_space_limit" should reduce number of logs | ||
SET GLOBAL max_slowlog_size = 4096; | ||
SET GLOBAL slowlog_space_limit = @@global.max_slowlog_size * 2; | ||
include/assert_number_of_files.inc [The number of files matches expected 4] | ||
# Case 7: Delete all small logs with max_slowlog_size = 0 | ||
SET GLOBAL max_slowlog_size = 0; | ||
SET GLOBAL slowlog_space_limit = 4096; | ||
include/assert_number_of_files.inc [The number of files matches expected 1] | ||
# Case 8: Rotate log should delete previous log | ||
SET GLOBAL max_slowlog_size = 10240000; | ||
SET GLOBAL slow_query_log_file = 'MYSQLTEST_VARDIR/abcd'; | ||
include/assert_number_of_files.inc [The number of files matches expected 1] | ||
# Case 9: Check if disable max_slowlog_size is working correctly | ||
SET GLOBAL max_slowlog_size = 0; | ||
SET GLOBAL slow_query_log_file = 'MYSQLTEST_VARDIR/abcd'; | ||
include/assert_number_of_files.inc [The number of files matches expected 2] | ||
include/assert.inc [Slow query log should stay as abcd] | ||
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.slowlog_space_limit = @old_slowlog_space_limit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,206 @@ | ||
############################################################################# | ||
# ==== Purpose ==== # | ||
# # | ||
# Check if global integer $VARIABLE_NAME returns errors if it's outside a # | ||
# range between $VARIABLE_MIN_VALUE (default: 0) and $VARIABLE_MAX_VALUE. # | ||
# # | ||
# Additionally we check the behaviour of this variable for: # | ||
# * Default values # | ||
# * Valid and invalid values # | ||
# * Scope and access method # | ||
# # | ||
# References: http://dev.mysql.com/doc/refman/8.0/en/ # | ||
# server-system-variables.html # | ||
# # | ||
# ==== Usage ==== # | ||
# # | ||
# --let $VARIABLE_NAME = 'NAME' # | ||
# --let $VARIABLE_MAX_VALUE = NUMBER # | ||
# [--let $VARIABLE_MIN_VALUE = NUMBER ] # | ||
# [--let $VARIABLE_BLOCK_SIZE = NUMBER ] # | ||
# --source suite/sys_vars/inc/check_global_integer.inc # | ||
# # | ||
# ==== Examples ==== # | ||
# # | ||
# --let $VARIABLE_NAME = slowlog_space_limit # | ||
# --let $VARIABLE_MAX_VALUE = 18446744073709551615 # | ||
# --source suite/sys_vars/inc/check_global_integer.inc # | ||
# # | ||
# --let $VARIABLE_NAME = slave_pending_jobs_size_max # | ||
# --let $VARIABLE_MIN_VALUE = 1024 # | ||
# --let $VARIABLE_BLOCK_SIZE = 1024 # | ||
# --let $VARIABLE_MAX_VALUE = 18446744073709551615 # | ||
# --source suite/sys_vars/inc/check_global_integer.inc # | ||
############################################################################# | ||
|
||
################################################################ | ||
# Initialize auxiliary varaibles # | ||
################################################################ | ||
|
||
--let $GLOBAL_VAR_NAME = @@global.$VARIABLE_NAME | ||
--let $SESSION_VAR_NAME = @@session.$VARIABLE_NAME | ||
|
||
--let $CHECK_MIN_VALUE = 0 | ||
if ($VARIABLE_MIN_VALUE) | ||
{ | ||
--let $CHECK_MIN_VALUE = $VARIABLE_MIN_VALUE | ||
} | ||
|
||
--let $CHECK_BLOCK_SIZE = 1 | ||
if ($VARIABLE_BLOCK_SIZE) | ||
{ | ||
--let $CHECK_BLOCK_SIZE = $VARIABLE_BLOCK_SIZE | ||
} | ||
--let $CHECK_MIN_VALUE_PLUS_BLOCK_SIZE = `SELECT $CHECK_MIN_VALUE + $CHECK_BLOCK_SIZE` | ||
|
||
################################################################ | ||
# Saving initial values of $VARIABLE_NAME variable in # | ||
# a temporary variable # | ||
################################################################ | ||
|
||
--eval SET @save_original_variable = $GLOBAL_VAR_NAME | ||
SELECT @save_original_variable; | ||
|
||
################################################################ | ||
# Display the DEFAULT value of $VARIABLE_NAME # | ||
################################################################ | ||
|
||
--eval SET $GLOBAL_VAR_NAME = $CHECK_MIN_VALUE_PLUS_BLOCK_SIZE | ||
--eval SET $GLOBAL_VAR_NAME = DEFAULT | ||
--eval SELECT $GLOBAL_VAR_NAME | ||
|
||
--error ER_GLOBAL_VARIABLE | ||
--eval SET $SESSION_VAR_NAME = $CHECK_MIN_VALUE + 2 | ||
--error ER_GLOBAL_VARIABLE | ||
--eval SET $SESSION_VAR_NAME = DEFAULT | ||
--error ER_INCORRECT_GLOBAL_LOCAL_VAR | ||
--eval SELECT $SESSION_VAR_NAME | ||
|
||
################################################################ | ||
# Check if NULL or empty value is accepted # | ||
################################################################ | ||
|
||
--error ER_WRONG_TYPE_FOR_VAR | ||
--eval SET $GLOBAL_VAR_NAME = NULL | ||
|
||
--error ER_WRONG_TYPE_FOR_VAR | ||
--eval SET $GLOBAL_VAR_NAME = '' | ||
|
||
--error ER_WRONG_TYPE_FOR_VAR | ||
--eval SET $GLOBAL_VAR_NAME = ' ' | ||
|
||
--error ER_GLOBAL_VARIABLE | ||
--eval SET $SESSION_VAR_NAME = NULL | ||
|
||
--error ER_GLOBAL_VARIABLE | ||
--eval SET $SESSION_VAR_NAME = '' | ||
|
||
--error ER_GLOBAL_VARIABLE | ||
--eval SET $SESSION_VAR_NAME = ' ' | ||
|
||
############################################################################# | ||
# Change the value of $VARIABLE_NAME to a valid value for GLOBAL scope # | ||
############################################################################# | ||
|
||
--eval SET $GLOBAL_VAR_NAME = $CHECK_MIN_VALUE | ||
--eval SELECT $GLOBAL_VAR_NAME | ||
|
||
--eval SET $GLOBAL_VAR_NAME = $CHECK_MIN_VALUE_PLUS_BLOCK_SIZE | ||
--eval SELECT $GLOBAL_VAR_NAME | ||
|
||
if ($CHECK_MIN_VALUE == 0) | ||
{ | ||
if ($CHECK_BLOCK_SIZE == 1) | ||
{ | ||
--eval SET $GLOBAL_VAR_NAME = TRUE | ||
--eval SELECT $GLOBAL_VAR_NAME | ||
|
||
--eval SET $GLOBAL_VAR_NAME = FALSE | ||
--eval SELECT $GLOBAL_VAR_NAME | ||
} | ||
} | ||
|
||
--eval SET $GLOBAL_VAR_NAME = $VARIABLE_MAX_VALUE | ||
--eval SELECT $GLOBAL_VAR_NAME | ||
|
||
--eval SET $GLOBAL_VAR_NAME = DEFAULT | ||
--eval SELECT $GLOBAL_VAR_NAME | ||
|
||
############################################################################# | ||
# Change the value of $VARIABLE_NAME to an invalid value for GLOBAL scope # | ||
############################################################################# | ||
|
||
--eval SET $GLOBAL_VAR_NAME = -$CHECK_MIN_VALUE_PLUS_BLOCK_SIZE | ||
--eval SELECT $GLOBAL_VAR_NAME | ||
|
||
--error ER_WRONG_TYPE_FOR_VAR | ||
--eval SET $GLOBAL_VAR_NAME = 'ABC' | ||
--eval SELECT $GLOBAL_VAR_NAME | ||
|
||
--error ER_WRONG_TYPE_FOR_VAR | ||
--eval SET $GLOBAL_VAR_NAME = ON | ||
--eval SELECT $GLOBAL_VAR_NAME | ||
|
||
--error ER_WRONG_TYPE_FOR_VAR | ||
--eval SET $GLOBAL_VAR_NAME = 'OFF' | ||
--eval SELECT $GLOBAL_VAR_NAME | ||
|
||
--error ER_WRONG_TYPE_FOR_VAR | ||
--eval SET $GLOBAL_VAR_NAME = $CHECK_MIN_VALUE_PLUS_BLOCK_SIZE.14 | ||
--eval SELECT $GLOBAL_VAR_NAME | ||
|
||
--error ER_WRONG_TYPE_FOR_VAR | ||
--eval SET $GLOBAL_VAR_NAME = NONE | ||
--eval SELECT $GLOBAL_VAR_NAME | ||
|
||
if ($VARIABLE_MAX_VALUE == 18446744073709551615) | ||
{ | ||
--error ER_WRONG_TYPE_FOR_VAR | ||
} | ||
--eval SET $GLOBAL_VAR_NAME = -$VARIABLE_MAX_VALUE | ||
--eval SELECT $GLOBAL_VAR_NAME | ||
|
||
if ($VARIABLE_MAX_VALUE == 18446744073709551615) | ||
{ | ||
--error ER_DATA_OUT_OF_RANGE | ||
} | ||
--eval SET $GLOBAL_VAR_NAME = $VARIABLE_MAX_VALUE + 1 | ||
--eval SELECT $GLOBAL_VAR_NAME | ||
|
||
############################################################################# | ||
# Check if the value in GLOBAL Table matches value in variable # | ||
############################################################################# | ||
|
||
--let $assert_text= Must return 1 | ||
--let $assert_cond= $GLOBAL_VAR_NAME = VARIABLE_VALUE FROM performance_schema.global_variables WHERE VARIABLE_NAME="$VARIABLE_NAME" | ||
--source include/assert.inc | ||
|
||
############################################################################# | ||
# Check if $VARIABLE_NAME variable can be accessed with and without @@ sign # | ||
############################################################################# | ||
|
||
--eval SET GLOBAL $VARIABLE_NAME = $CHECK_MIN_VALUE_PLUS_BLOCK_SIZE | ||
--eval SET $GLOBAL_VAR_NAME = $CHECK_MIN_VALUE_PLUS_BLOCK_SIZE | ||
|
||
--error ER_PARSE_ERROR | ||
--eval SET global.$VARIABLE_NAME = $CHECK_MIN_VALUE_PLUS_BLOCK_SIZE | ||
|
||
--error ER_GLOBAL_VARIABLE | ||
--eval SET @@$VARIABLE_NAME = $CHECK_MIN_VALUE_PLUS_BLOCK_SIZE | ||
|
||
--error ER_GLOBAL_VARIABLE | ||
--eval SET $VARIABLE_NAME = $CHECK_MIN_VALUE_PLUS_BLOCK_SIZE | ||
|
||
--error ER_UNKNOWN_TABLE | ||
--eval SELECT global.$VARIABLE_NAME | ||
|
||
--error ER_BAD_FIELD_ERROR | ||
--eval SELECT GLOBAL $VARIABLE_NAME | ||
|
||
--eval SELECT @@$VARIABLE_NAME | ||
|
||
############################################################################# | ||
# Restoring the original value of $VARIABLE_NAME variable # | ||
############################################################################# | ||
|
||
--eval SET $GLOBAL_VAR_NAME = @save_original_variable |
Oops, something went wrong.