summaryrefslogtreecommitdiff
path: root/mysql-test/suite/binlog/t/binlog_expire_logs_seconds.test
blob: bb53f2c41308b4df7250c8b2ebb969719fed2704 (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
110
111
112
113
114
115
116
117
118
119
120
121
122
#
# WL#9236: Add a new variable binlog_expire_logs_seconds
#
# ==== Purpose ====
# The test case test the following:
#
# 1. If binlog_expire_logs_seconds = 0 and expire_logs_days = 0, no purge happens.
#
# 2. In all the below listed cases it purges the binary logs older than the timeout
#    and keeps the binary logs newer than the timeout.
#
#    2.1. binlog_expire_logs_seconds > 0 and expire_logs_days > 0
#    2.2. binlog_expire_logs_seconds > 0 and expire_logs_days = 0
#    2.3. binlog_expire_logs_seconds = 0 and expire_logs_days > 0
#    2.4. binlog_expire_logs_seconds = 1, testing smallest value
#    2.5. binlog_expire_logs_seconds = 8553600, testing max value 99days
#
# Additional tests for the boundaries of expire_logs_days already
# exist on the sys_vars.expire_logs_days_basic test case.

# Test in this file is binlog format agnostic, thus no need
# to rerun it for every format.
--source include/have_binlog_format_row.inc
--source include/not_windows.inc

--let $saved_expire_logs_days= `SELECT @@GLOBAL.expire_logs_days`
--let $saved_binlog_expire_logs_seconds= `SELECT @@GLOBAL.binlog_expire_logs_seconds`
# Set the datadir
--let $MYSQLD_DATADIR= `SELECT @@datadir`

--echo ####
--echo #### 1. When binlog_expire_logs_seconds == 0 and expire_logs_days == 0
--echo ####    no purge should happen

SET GLOBAL binlog_expire_logs_seconds= 0;
SET GLOBAL expire_logs_days= 0;

# This will test the expire period for three scenarios, described in the .inc file.
--source suite/binlog/include/binlog_expire_logs_seconds.inc

--echo ####
--echo #### 2.1: binlog_expire_logs_seconds > 0 and expire_logs_days > 0
--echo ####      expire_logs_days=1.5 and binlog_expire_logs_seconds=86400
--echo ####      Since binlog_expire_logs_seconds is set later
--echo ####      expire_logs_days value will be overridden should be
--echo ####      '0.000347222'
--echo ####

# Here we will test both with smaller values and larger values

--echo Testing with smaller values of binlog_expire_logs_seconds

SET GLOBAL expire_logs_days= 1.5;
SET GLOBAL binlog_expire_logs_seconds= 30 ;
SELECT @@expire_logs_days as 'Expected_0.000347222';
SELECT @@binlog_expire_logs_seconds as Expected_30;

--let $expire_logs_seconds= `SELECT @@global.binlog_expire_logs_seconds`

--let $first_binlog_file= query_get_value(SHOW MASTER STATUS, File, 1)
FLUSH LOGS;

--sleep $expire_logs_seconds

--let $second_binlog_file= query_get_value(SHOW MASTER STATUS, File, 1)
FLUSH LOGS;

# The sleep is in two parts to ensure a time gap between first_binlog_file
# and second_binlog_file, by doing that we can check that one is purged and
# another isn't.
# sleep for n seconds here, n < $expire_logs_seconds
--sleep 3
FLUSH LOGS;

--error 1
--file_exists $MYSQLD_DATADIR/$first_binlog_file

--file_exists $MYSQLD_DATADIR/$second_binlog_file

RESET MASTER;
--echo ####
--echo #### 2.2: binlog_expire_logs_seconds = 43200  and expire_logs_days = 0
--echo ####

SET GLOBAL expire_logs_days=0;
SET GLOBAL binlog_expire_logs_seconds=43200;
SELECT @@expire_logs_days as 'Expected_0.5';
SELECT @@binlog_expire_logs_seconds as Expected_43200;

# This will test the expire period for three scenarios, described in the .inc file.

--source suite/binlog/include/binlog_expire_logs_seconds.inc

--echo ####
--echo #### 2.3: binlog_expire_logs_seconds == 0 and expire_logs_days > 0
--echo ####

SET GLOBAL binlog_expire_logs_seconds= 0;
SET GLOBAL expire_logs_days= 1;
SELECT @@expire_logs_days as Expected_1;
SELECT @@binlog_expire_logs_seconds as Expected_86400;

# This will test the expire period for three scenarios, described in the .inc file.
--source suite/binlog/include/binlog_expire_logs_seconds.inc

--echo ####
--echo #### 2.4: binlog_expire_logs_seconds = 1
--echo ####
SET GLOBAL binlog_expire_logs_seconds= 1;
SELECT @@expire_logs_days;
SELECT @@binlog_expire_logs_seconds as Expected_1;

--echo ####
--echo #### 2.5. binlog_expire_logs_seconds = 8553600, testing max value 99days
--echo ####
SET GLOBAL binlog_expire_logs_seconds= 8553600;
SELECT @@expire_logs_days;
SELECT @@binlog_expire_logs_seconds as Expected_8553600;

# reset the variables
--eval SET GLOBAL binlog_expire_logs_seconds= $saved_binlog_expire_logs_seconds
--eval SET GLOBAL expire_logs_days= $saved_expire_logs_days