|
| 1 | +# BUG#34582: FLUSH LOGS does not close and reopen the binlog index |
| 2 | +# file |
| 3 | +# |
| 4 | +# WHAT |
| 5 | +# ==== |
| 6 | +# |
| 7 | +# We want to test that FLUSH LOGS closes and reopens binlog index |
| 8 | +# file. |
| 9 | +# |
| 10 | +# HOW |
| 11 | +# === |
| 12 | +# |
| 13 | +# PREPARE: |
| 14 | +# 1. create some binlog events |
| 15 | +# 2. show index content, binlog events and binlog contents |
| 16 | +# for mysql-bin.000001 |
| 17 | +# 3. copy the mysql-bin.000001 to mysql-bin-b34582.000001 |
| 18 | +# 4. change the index file so that mysql-bin.000001 is replaced |
| 19 | +# with mysql-bin-b34582.000001 |
| 20 | +# 5. FLUSH the logs so that new index is closed and reopened |
| 21 | +# |
| 22 | +# ASSERTIONS: |
| 23 | +# 1. index file contents shows mysql-bin-b34582.000001 and |
| 24 | +# mysql-bin.000002 |
| 25 | +# 1. show binary logs shows current index entries |
| 26 | +# 2. binlog contents for mysql-bin-b34582.000001 are displayed |
| 27 | +# 3. Purge binlogs up to the latest one succeeds |
| 28 | +# 4. SHOW BINARY LOGS presents the latest one only after purging |
| 29 | +# 5. Purged binlogs files don't exist in the filesystem |
| 30 | +# 6. Not purged binlog file exists in the filesystem |
| 31 | +# |
| 32 | +# CLEAN UP: |
| 33 | +# 1. RESET MASTER |
| 34 | +# |
| 35 | + |
| 36 | +-- source include/have_log_bin.inc |
| 37 | + |
| 38 | +RESET MASTER; |
| 39 | + |
| 40 | +-- let $datadir= $MYSQLTEST_VARDIR/log |
| 41 | +-- let $index=$datadir/master-bin.index |
| 42 | +-- chmod 0666 $index |
| 43 | + |
| 44 | +# action: issue one command so that binlog gets some event |
| 45 | +CREATE TABLE t1 (a int); |
| 46 | + |
| 47 | +-- echo ### assertion: index file contains regular entries |
| 48 | +-- replace_regex /[\\\/].*master/MYSQLD_DATADIR\/master/ |
| 49 | +-- eval SET @index=LOAD_FILE('$index') |
| 50 | +if (`SELECT convert(@@version_compile_os using latin1) |
| 51 | + IN ('Win32','Win64','Windows')`) |
| 52 | +{ |
| 53 | + -- disable_query_log |
| 54 | + -- disable_result_log |
| 55 | + -- let $a= `SELECT REPLACE (@index, '$datadir\', '')` |
| 56 | + -- enable_result_log |
| 57 | + -- enable_query_log |
| 58 | + |
| 59 | + -- echo $a |
| 60 | + |
| 61 | +} |
| 62 | +if (!`SELECT convert(@@version_compile_os using latin1) |
| 63 | + IN ('Win32','Win64','Windows')`) |
| 64 | +{ |
| 65 | + -- disable_query_log |
| 66 | + -- disable_result_log |
| 67 | + -- let $a= `SELECT REPLACE (@index, '$datadir/', '')` |
| 68 | + -- enable_result_log |
| 69 | + -- enable_query_log |
| 70 | + |
| 71 | + -- echo $a |
| 72 | +} |
| 73 | + |
| 74 | +--echo ### assertion: show original binlogs |
| 75 | +-- source include/show_binary_logs.inc |
| 76 | + |
| 77 | +--echo ### assertion: binlog contents from regular entries |
| 78 | +-- source include/show_binlog_events.inc |
| 79 | + |
| 80 | +# action: copy binlogs to other names and change entries in index file |
| 81 | +-- copy_file $datadir/master-bin.000001 $datadir/master-bin-b34582.000001 |
| 82 | +-- let newbinfile=$datadir/master-bin-b34582.000001 |
| 83 | +let INDEX_FILE=$index; |
| 84 | +perl; |
| 85 | +$newbinfile= $ENV{'newbinfile'}; |
| 86 | +$file= $ENV{'INDEX_FILE'}; |
| 87 | +open(FILE, ">$file") || die "Unable to open $file."; |
| 88 | +truncate(FILE,0); |
| 89 | +print FILE $newbinfile . "\n"; |
| 90 | +close ($file); |
| 91 | +EOF |
| 92 | + |
| 93 | +# action: should cause rotation, and creation of new binlogs |
| 94 | +FLUSH LOGS; |
| 95 | + |
| 96 | +# file is not used anymore - remove it (mysql closed on flush logs). |
| 97 | +-- remove_file $datadir/master-bin.000001 |
| 98 | + |
| 99 | +-- echo ### assertion: index file contains renamed binlog and the new one |
| 100 | +-- replace_regex /[\\\/].*master/MYSQLD_DATADIR\/master/ |
| 101 | +-- eval SET @index=LOAD_FILE('$index') |
| 102 | +if (`SELECT convert(@@version_compile_os using latin1) |
| 103 | + IN ('Win32','Win64','Windows')`) |
| 104 | +{ |
| 105 | + -- disable_query_log |
| 106 | + -- disable_result_log |
| 107 | + -- let $a= `SELECT REPLACE (@index, '$datadir\', '')` |
| 108 | + -- enable_result_log |
| 109 | + -- enable_query_log |
| 110 | + |
| 111 | + -- echo $a |
| 112 | + |
| 113 | +} |
| 114 | +if (!`SELECT convert(@@version_compile_os using latin1) |
| 115 | + IN ('Win32','Win64','Windows')`) |
| 116 | +{ |
| 117 | + -- disable_query_log |
| 118 | + -- disable_result_log |
| 119 | + -- let $a= `SELECT REPLACE (@index, '$datadir/', '')` |
| 120 | + -- enable_result_log |
| 121 | + -- enable_query_log |
| 122 | + |
| 123 | + -- echo $a |
| 124 | +} |
| 125 | + |
| 126 | +-- echo ### assertion: original binlog content still exists, despite we |
| 127 | +-- echo ### renamed and changed the index file |
| 128 | +-- source include/show_binlog_events.inc |
| 129 | + |
| 130 | +-- echo ### assertion: user changed binlog index shows correct entries |
| 131 | +-- source include/show_binary_logs.inc |
| 132 | + |
| 133 | +DROP TABLE t1; |
| 134 | + |
| 135 | +-- echo ### assertion: purging binlogs up to binlog created after instrumenting index file should work |
| 136 | +-- let $current_binlog= query_get_value(SHOW MASTER STATUS, File, 1) |
| 137 | +-- eval PURGE BINARY LOGS TO '$current_binlog' |
| 138 | + |
| 139 | +-- echo ### assertion: show binary logs should only contain latest binlog |
| 140 | +-- source include/show_binary_logs.inc |
| 141 | + |
| 142 | +-- echo ### assertion: assert that binlog files were indeed purged (using file_exists calls) |
| 143 | +-- error 1 |
| 144 | +-- file_exists $datadir/master-bin-b34852.000001 |
| 145 | + |
| 146 | +-- echo ### assertion: assert that not purged binlog file exists |
| 147 | +-- file_exists $datadir/$current_binlog |
| 148 | + |
| 149 | +-- echo ### assertion: show index file contents and these should match show binary logs issued above |
| 150 | +-- replace_regex /[\\\/].*master/MYSQLD_DATADIR\/master/ |
| 151 | +-- eval SET @index=LOAD_FILE('$index') |
| 152 | +if (`SELECT convert(@@version_compile_os using latin1) |
| 153 | + IN ('Win32','Win64','Windows')`) |
| 154 | +{ |
| 155 | + -- disable_query_log |
| 156 | + -- disable_result_log |
| 157 | + -- let $a= `SELECT REPLACE (@index, '$datadir\', '')` |
| 158 | + -- enable_result_log |
| 159 | + -- enable_query_log |
| 160 | + |
| 161 | + -- echo $a |
| 162 | + |
| 163 | +} |
| 164 | +if (!`SELECT convert(@@version_compile_os using latin1) |
| 165 | + IN ('Win32','Win64','Windows')`) |
| 166 | +{ |
| 167 | + -- disable_query_log |
| 168 | + -- disable_result_log |
| 169 | + -- let $a= `SELECT REPLACE (@index, '$datadir/', '')` |
| 170 | + -- enable_result_log |
| 171 | + -- enable_query_log |
| 172 | + |
| 173 | + -- echo $a |
| 174 | +} |
| 175 | + |
| 176 | +RESET MASTER; |
0 commit comments