| 1 |
# |
| 2 |
# WL#9237: Add a new variable binlog_expire_logs_seconds |
| 3 |
|
| 4 |
# Here we will test purging of binary logs when either one or both of these variables are set |
| 5 |
# - binlog_expire_logs_seconds |
| 6 |
# - expire_logs_days |
| 7 |
|
| 8 |
# The three scenarios being tested for are: |
| 9 |
# 1. FLUSH LOGS |
| 10 |
# 2. Rotation of logs because of binlog growing bigger than max_binlog_size |
| 11 |
# 3. Server restart |
| 12 |
# |
| 13 |
# Usuage: --let $binlog_expire_logs_seconds= |
| 14 |
# --let $expire_logs_days= |
| 15 |
# |
| 16 |
# --source suite/binlog/include/binlog_expire_logs_seconds.inc |
| 17 |
|
| 18 |
--let $expire_logs_seconds= `SELECT @@global.binlog_expire_logs_seconds + @@global.expire_logs_days * 24 * 60 * 60` |
| 19 |
|
| 20 |
CREATE TABLE t1(s LONGBLOB ); |
| 21 |
|
| 22 |
--let $max_binlog_size_save= `SELECT @@GLOBAL.MAX_BINLOG_SIZE` |
| 23 |
|
| 24 |
--let $case= 0 |
| 25 |
|
| 26 |
while ($case < 3) |
| 27 |
{ |
| 28 |
--echo Case:$case |
| 29 |
--let $first_binlog_file= query_get_value(SHOW MASTER STATUS, File, 1) |
| 30 |
|
| 31 |
# rotates the log, thence the first log will be closed, and depending upon |
| 32 |
# the expire time the purge will/will not happen. |
| 33 |
|
| 34 |
FLUSH LOGS; |
| 35 |
|
| 36 |
INSERT INTO t1 VALUES('a'); |
| 37 |
|
| 38 |
--let $second_binlog_file= query_get_value(SHOW MASTER STATUS, File, 1) |
| 39 |
|
| 40 |
FLUSH LOGS; |
| 41 |
|
| 42 |
|
| 43 |
# This is done to avoid time out in cases where the expire time is more. |
| 44 |
# What we do is in those cases modify the timestamp of the oldest log file |
| 45 |
# to be the same as expire time so when we execute the next flush log command |
| 46 |
# the oldest log will be purged. |
| 47 |
|
| 48 |
# Only change the timestamp of binlog file when the expire_logs_seconds which is the total |
| 49 |
# time for expiring log is greater than 30 seconds |
| 50 |
|
| 51 |
if ($expire_logs_seconds > 30) |
| 52 |
{ |
| 53 |
--let _EXPIRE_TIME= `SELECT $expire_logs_seconds + 60` |
| 54 |
--let _FIRST_BINLOG_FILE= $MYSQLD_DATADIR/$first_binlog_file |
| 55 |
--perl |
| 56 |
use strict; |
| 57 |
use warnings; |
| 58 |
my $expire_time = $ENV{'_EXPIRE_TIME'}; |
| 59 |
my $first_binlog_file = $ENV{'_FIRST_BINLOG_FILE'}; |
| 60 |
my $epoch = (stat($first_binlog_file))[9]; |
| 61 |
my $mtime = $epoch - $expire_time; |
| 62 |
utime $mtime, $mtime, $first_binlog_file; |
| 63 |
EOF |
| 64 |
} |
| 65 |
|
| 66 |
# Checking this ensures that nothing is purged so far. |
| 67 |
--file_exists $MYSQLD_DATADIR/$first_binlog_file |
| 68 |
|
| 69 |
if ($case == 0) |
| 70 |
{ |
| 71 |
--echo #### 1. FLUSH LOGS |
| 72 |
|
| 73 |
FLUSH LOGS; |
| 74 |
} |
| 75 |
if ($case == 1) |
| 76 |
{ |
| 77 |
--echo #### 2. Binlog_size > max_binlog_size |
| 78 |
|
| 79 |
SET @@GLOBAL.MAX_BINLOG_SIZE= 4096; |
| 80 |
|
| 81 |
INSERT INTO t1 (s) VALUES (REPEAT('s',50000)); |
| 82 |
} |
| 83 |
if ($case == 2) |
| 84 |
{ |
| 85 |
--echo #### 3. Server restart |
| 86 |
|
| 87 |
--let $restart_parameters=restart:--binlog_expire_logs_seconds=$expire_logs_seconds |
| 88 |
--source include/restart_mysqld.inc |
| 89 |
} |
| 90 |
|
| 91 |
if ($expire_logs_seconds != 0) |
| 92 |
{ |
| 93 |
--error 1 |
| 94 |
--file_exists $MYSQLD_DATADIR/$first_binlog_file |
| 95 |
} |
| 96 |
if ($expire_logs_seconds == 0) |
| 97 |
{ |
| 98 |
--file_exists $MYSQLD_DATADIR/$first_binlog_file |
| 99 |
} |
| 100 |
--file_exists $MYSQLD_DATADIR/$second_binlog_file |
| 101 |
|
| 102 |
--inc $case |
| 103 |
RESET MASTER; |
| 104 |
} |
| 105 |
--echo ##### Cleanup ##### |
| 106 |
--eval SET @@GLOBAL.MAX_BINLOG_SIZE= $max_binlog_size_save; |
| 107 |
DROP TABLE t1; |
| 108 |
RESET MASTER; |
| 109 |
|