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