File: binlog_expire_logs_auto_purge.test

package info (click to toggle)
mysql-8.0 8.0.43-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,924 kB
  • sloc: cpp: 4,684,605; ansic: 412,450; pascal: 108,398; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; sh: 24,181; python: 21,816; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,076; makefile: 2,194; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (160 lines) | stat: -rw-r--r-- 5,080 bytes parent folder | download
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# ==== Purpose ====
#
# This test file includes test cases for the feature that automatically
# purges binary log files according to some time criteria.
#
# ==== Requirements ====
#
# See inline.
#
# ==== References ====
#
# WL#14930: Add a new variable binlog_expire_logs_auto_purge
#

# 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
--source include/not_binlog_transaction_compression_on.inc

--let $saved_binlog_expire_logs_seconds= `SELECT @@GLOBAL.binlog_expire_logs_seconds`
--let $saved_expire_logs_days= `SELECT @@GLOBAL.expire_logs_days`
--let $saved_binlog_expire_logs_auto_purge= `SELECT @@GLOBAL.binlog_expire_logs_auto_purge`
--let $MYSQLD_DATADIR= `SELECT @@datadir`
--let $retention_time_in_seconds = 3
--let $sleep_time_in_seconds = `SELECT $retention_time_in_seconds * 2`

SET @@global.expire_logs_days = 0;

#
# ASSERT: If binlog_expire_logs_auto_purge is set to OFF, then the server
#         MUST not purge automatically any binary log file, independently of
#         binlog_expire_logs_seconds value.
#

# disable automatic purge
SET @@global.binlog_expire_logs_auto_purge = OFF;
# create new log file
--let $first_binlog_file= query_get_value(SHOW MASTER STATUS, File, 1)
FLUSH LOGS;
--let $second_binlog_file= query_get_value(SHOW MASTER STATUS, File, 1)
FLUSH LOGS;
# set a low expiration window
--eval SET GLOBAL binlog_expire_logs_seconds=$retention_time_in_seconds

# sleep
--sleep $sleep_time_in_seconds

# force a rotation, so that auto purge has a chance to try to kick in
FLUSH LOGS;

--file_exists $MYSQLD_DATADIR/$first_binlog_file
--file_exists $MYSQLD_DATADIR/$second_binlog_file

#
# ASSERT: If binlog_expire_logs_auto_purge is set to ON, then the server
#         MUST purge automatically binary log files according to the
#         binlog_expire_logs_seconds setting.
#
SET @@global.binlog_expire_logs_auto_purge = ON;

# since we have already slept sometime in the previous assertion
# on rotation the files shall be deleted because they have already
# aged the expiration time
FLUSH LOGS;
--error 1
--file_exists $MYSQLD_DATADIR/$first_binlog_file
--error 1
--file_exists $MYSQLD_DATADIR/$second_binlog_file

#
# ASSERT: If binlog_expire_logs_auto_purge is set to ON and both
#         binlog_expire_logs_seconds and expire_logs_days are set to 0,
#         then binary log files SHALL NOT be automatically purged.
#

# Set automatic purge period to 0 and verify that files
# are not purged
SET @@global.binlog_expire_logs_auto_purge = ON;
SET @@global.binlog_expire_logs_seconds = 0;

# create new log file
--let $first_binlog_file= query_get_value(SHOW MASTER STATUS, File, 1)
FLUSH LOGS;
--let $second_binlog_file= query_get_value(SHOW MASTER STATUS, File, 1)
FLUSH LOGS;

# sleep
--sleep $sleep_time_in_seconds

# force a rotation, so that auto purge has a chance to try to kick in
# but it won't purge because the purge window is configured to be 0
# seconds
FLUSH LOGS;

--file_exists $MYSQLD_DATADIR/$first_binlog_file
--file_exists $MYSQLD_DATADIR/$second_binlog_file

#
# ASSERT: If binlog_expire_logs_auto_purge is set to OFF, PURGE BINARY
#         LOGS TO SHALL NOT be affected by the option.
#

SET @@global.binlog_expire_logs_auto_purge = OFF;

# create new log file
--let $first_binlog_file= query_get_value(SHOW MASTER STATUS, File, 1)
FLUSH LOGS;
--let $second_binlog_file= query_get_value(SHOW MASTER STATUS, File, 1)
FLUSH LOGS;

--replace_result $second_binlog_file SECOND_BINLOG_FILE
--eval PURGE BINARY LOGS TO '$second_binlog_file'

# file must have been purged
--error 1
--file_exists $MYSQLD_DATADIR/$first_binlog_file

#
# ASSERT: If binlog_expire_logs_auto_purge is set to OFF, PURGE BINARY
#         LOGS BEFORE SHALL NOT be affected by the option.
#

SET @@global.binlog_expire_logs_auto_purge = OFF;
SET @@global.binlog_expire_logs_auto_purge = 0;

# create new log file
--let $first_binlog_file= query_get_value(SHOW MASTER STATUS, File, 1)
FLUSH LOGS;
--let $second_binlog_file= query_get_value(SHOW MASTER STATUS, File, 1)
FLUSH LOGS;

# just sleep a couple of seconds to not have the statement issued
# at the "same time" the files were created/rotated.
--sleep 2
--let $date=`select NOW()`
# sleep a couple of seconds more before rotating, so that we
# do not risk purging the active log (which would happen If
# rotation was fast enough to happen whithin the NOW() second)
# and then it would issue a warning, causing the test to fail
# sporadically
--sleep 2
FLUSH LOGS;
--replace_result $date DATE
--eval PURGE BINARY LOGS BEFORE '$date'
FLUSH LOGS;

# files must have been purged
--error 1
--file_exists $MYSQLD_DATADIR/$first_binlog_file

# files must have been purged
--error 1
--file_exists $MYSQLD_DATADIR/$second_binlog_file

# clean up
--eval SET GLOBAL binlog_expire_logs_seconds=$saved_binlog_expire_logs_seconds
--eval SET GLOBAL binlog_expire_logs_auto_purge=$saved_binlog_expire_logs_auto_purge
--eval SET GLOBAL expire_logs_days=$saved_expire_logs_days
RESET MASTER;