| 1 |
# ==== Purpose ==== |
| 2 |
# |
| 3 |
# This test file includes test cases for the feature that automatically |
| 4 |
# purges binary log files according to some time criteria. |
| 5 |
# |
| 6 |
# ==== Requirements ==== |
| 7 |
# |
| 8 |
# See inline. |
| 9 |
# |
| 10 |
# ==== References ==== |
| 11 |
# |
| 12 |
# WL#14930: Add a new variable binlog_expire_logs_auto_purge |
| 13 |
# |
| 14 |
|
| 15 |
# Test in this file is binlog format agnostic, thus no need to rerun |
| 16 |
# it for every format. |
| 17 |
--source include/have_binlog_format_row.inc |
| 18 |
--source include/not_windows.inc |
| 19 |
--source include/not_binlog_transaction_compression_on.inc |
| 20 |
|
| 21 |
--let $saved_binlog_expire_logs_seconds= `SELECT @@GLOBAL.binlog_expire_logs_seconds` |
| 22 |
--let $saved_expire_logs_days= `SELECT @@GLOBAL.expire_logs_days` |
| 23 |
--let $saved_binlog_expire_logs_auto_purge= `SELECT @@GLOBAL.binlog_expire_logs_auto_purge` |
| 24 |
--let $MYSQLD_DATADIR= `SELECT @@datadir` |
| 25 |
--let $retention_time_in_seconds = 3 |
| 26 |
--let $sleep_time_in_seconds = `SELECT $retention_time_in_seconds * 2` |
| 27 |
|
| 28 |
SET @@global.expire_logs_days = 0; |
| 29 |
|
| 30 |
# |
| 31 |
# ASSERT: If binlog_expire_logs_auto_purge is set to OFF, then the server |
| 32 |
# MUST not purge automatically any binary log file, independently of |
| 33 |
# binlog_expire_logs_seconds value. |
| 34 |
# |
| 35 |
|
| 36 |
# disable automatic purge |
| 37 |
SET @@global.binlog_expire_logs_auto_purge = OFF; |
| 38 |
# create new log file |
| 39 |
--let $first_binlog_file= query_get_value(SHOW MASTER STATUS, File, 1) |
| 40 |
FLUSH LOGS; |
| 41 |
--let $second_binlog_file= query_get_value(SHOW MASTER STATUS, File, 1) |
| 42 |
FLUSH LOGS; |
| 43 |
# set a low expiration window |
| 44 |
--eval SET GLOBAL binlog_expire_logs_seconds=$retention_time_in_seconds |
| 45 |
|
| 46 |
# sleep |
| 47 |
--sleep $sleep_time_in_seconds |
| 48 |
|
| 49 |
# force a rotation, so that auto purge has a chance to try to kick in |
| 50 |
FLUSH LOGS; |
| 51 |
|
| 52 |
--file_exists $MYSQLD_DATADIR/$first_binlog_file |
| 53 |
--file_exists $MYSQLD_DATADIR/$second_binlog_file |
| 54 |
|
| 55 |
# |
| 56 |
# ASSERT: If binlog_expire_logs_auto_purge is set to ON, then the server |
| 57 |
# MUST purge automatically binary log files according to the |
| 58 |
# binlog_expire_logs_seconds setting. |
| 59 |
# |
| 60 |
SET @@global.binlog_expire_logs_auto_purge = ON; |
| 61 |
|
| 62 |
# since we have already slept sometime in the previous assertion |
| 63 |
# on rotation the files shall be deleted because they have already |
| 64 |
# aged the expiration time |
| 65 |
FLUSH LOGS; |
| 66 |
--error 1 |
| 67 |
--file_exists $MYSQLD_DATADIR/$first_binlog_file |
| 68 |
--error 1 |
| 69 |
--file_exists $MYSQLD_DATADIR/$second_binlog_file |
| 70 |
|
| 71 |
# |
| 72 |
# ASSERT: If binlog_expire_logs_auto_purge is set to ON and both |
| 73 |
# binlog_expire_logs_seconds and expire_logs_days are set to 0, |
| 74 |
# then binary log files SHALL NOT be automatically purged. |
| 75 |
# |
| 76 |
|
| 77 |
# Set automatic purge period to 0 and verify that files |
| 78 |
# are not purged |
| 79 |
SET @@global.binlog_expire_logs_auto_purge = ON; |
| 80 |
SET @@global.binlog_expire_logs_seconds = 0; |
| 81 |
|
| 82 |
# create new log file |
| 83 |
--let $first_binlog_file= query_get_value(SHOW MASTER STATUS, File, 1) |
| 84 |
FLUSH LOGS; |
| 85 |
--let $second_binlog_file= query_get_value(SHOW MASTER STATUS, File, 1) |
| 86 |
FLUSH LOGS; |
| 87 |
|
| 88 |
# sleep |
| 89 |
--sleep $sleep_time_in_seconds |
| 90 |
|
| 91 |
# force a rotation, so that auto purge has a chance to try to kick in |
| 92 |
# but it won't purge because the purge window is configured to be 0 |
| 93 |
# seconds |
| 94 |
FLUSH LOGS; |
| 95 |
|
| 96 |
--file_exists $MYSQLD_DATADIR/$first_binlog_file |
| 97 |
--file_exists $MYSQLD_DATADIR/$second_binlog_file |
| 98 |
|
| 99 |
# |
| 100 |
# ASSERT: If binlog_expire_logs_auto_purge is set to OFF, PURGE BINARY |
| 101 |
# LOGS TO SHALL NOT be affected by the option. |
| 102 |
# |
| 103 |
|
| 104 |
SET @@global.binlog_expire_logs_auto_purge = OFF; |
| 105 |
|
| 106 |
# create new log file |
| 107 |
--let $first_binlog_file= query_get_value(SHOW MASTER STATUS, File, 1) |
| 108 |
FLUSH LOGS; |
| 109 |
--let $second_binlog_file= query_get_value(SHOW MASTER STATUS, File, 1) |
| 110 |
FLUSH LOGS; |
| 111 |
|
| 112 |
--replace_result $second_binlog_file SECOND_BINLOG_FILE |
| 113 |
--eval PURGE BINARY LOGS TO '$second_binlog_file' |
| 114 |
|
| 115 |
# file must have been purged |
| 116 |
--error 1 |
| 117 |
--file_exists $MYSQLD_DATADIR/$first_binlog_file |
| 118 |
|
| 119 |
# |
| 120 |
# ASSERT: If binlog_expire_logs_auto_purge is set to OFF, PURGE BINARY |
| 121 |
# LOGS BEFORE SHALL NOT be affected by the option. |
| 122 |
# |
| 123 |
|
| 124 |
SET @@global.binlog_expire_logs_auto_purge = OFF; |
| 125 |
SET @@global.binlog_expire_logs_auto_purge = 0; |
| 126 |
|
| 127 |
# create new log file |
| 128 |
--let $first_binlog_file= query_get_value(SHOW MASTER STATUS, File, 1) |
| 129 |
FLUSH LOGS; |
| 130 |
--let $second_binlog_file= query_get_value(SHOW MASTER STATUS, File, 1) |
| 131 |
FLUSH LOGS; |
| 132 |
|
| 133 |
# just sleep a couple of seconds to not have the statement issued |
| 134 |
# at the "same time" the files were created/rotated. |
| 135 |
--sleep 2 |
| 136 |
--let $date=`select NOW()` |
| 137 |
# sleep a couple of seconds more before rotating, so that we |
| 138 |
# do not risk purging the active log (which would happen If |
| 139 |
# rotation was fast enough to happen whithin the NOW() second) |
| 140 |
# and then it would issue a warning, causing the test to fail |
| 141 |
# sporadically |
| 142 |
--sleep 2 |
| 143 |
FLUSH LOGS; |
| 144 |
--replace_result $date DATE |
| 145 |
--eval PURGE BINARY LOGS BEFORE '$date' |
| 146 |
FLUSH LOGS; |
| 147 |
|
| 148 |
# files must have been purged |
| 149 |
--error 1 |
| 150 |
--file_exists $MYSQLD_DATADIR/$first_binlog_file |
| 151 |
|
| 152 |
# files must have been purged |
| 153 |
--error 1 |
| 154 |
--file_exists $MYSQLD_DATADIR/$second_binlog_file |
| 155 |
|
| 156 |
# clean up |
| 157 |
--eval SET GLOBAL binlog_expire_logs_seconds=$saved_binlog_expire_logs_seconds |
| 158 |
--eval SET GLOBAL binlog_expire_logs_auto_purge=$saved_binlog_expire_logs_auto_purge |
| 159 |
--eval SET GLOBAL expire_logs_days=$saved_expire_logs_days |
| 160 |
RESET MASTER; |