1# ==== Purpose ==== 2# 3# Test that server can work fine after moving binlog or relay log 4# files to another directory and setting binlog or relay log paths to 5# the new path. 6# 7# ==== Method ==== 8# 9# Start replication, and then shutdown the master, move the binary 10# logs and the log index file to a another directory and then restart 11# the server with option to set the new binlog directory. After master 12# restarted successfully, do the similar on slave to check the relay 13# log of slave. 14# 15# ==== Reference ==== 16# 17# BUG#12133 master.index file keeps mysqld from starting if bin log has been moved 18# BUG#42576 Relay logs in relay-log.info&localhost-relay-bin.index not processed after move 19 20source include/master-slave.inc; 21# There is no need to run this test case on all binlog format 22source include/have_binlog_format_row.inc; 23 24# Since this test relies heavily on filesystem operations (like 25# moving files around, backslashes and so forth) we avoid messing 26# around with windows access violations for not cluttering the 27# test case any further. It is prepared to support windows, but 28# it is not 100% compliant. 29--source include/not_windows.inc 30 31connection master; 32--let $master_datadir= `select @@datadir` 33connection slave; 34--let $slave_datadir= `select @@datadir` 35connection master; 36--let $dirname= `select uuid()` 37--let $tmpdir= $MYSQLTEST_VARDIR/tmp/$dirname 38--mkdir $tmpdir 39 40CREATE TABLE t1 (a INT); 41# flush to generate one more binlog file. 42FLUSH BINARY LOGS; 43INSERT INTO t1 VALUES (1); 44 45sync_slave_with_master; 46--source include/stop_slave.inc 47# 48# Test on master 49# 50connection master; 51--echo # Shutdown master 52--let $rpl_server_number=1 53source include/rpl_stop_server.inc; 54 55--echo # Move the master binlog files and the index file to a new place 56--move_file $master_datadir/master-bin.000001 $tmpdir/master-bin.000001 57--move_file $master_datadir/master-bin.000002 $tmpdir/master-bin.000002 58--move_file $master_datadir/master-bin.index $tmpdir/master-bin.index 59 60--echo # Restart master with log-bin option set to the new path 61--let $rpl_server_parameters=--log-bin=$tmpdir/master-bin --log-bin-index=$tmpdir/master-bin 62--let $keep_include_silent=1 63source include/rpl_start_server.inc; 64--let $keep_include_silent=0 65 66--echo # Master has restarted successfully 67--connection slave 68--source include/start_slave.inc 69--connection master 70# 71# Test master can handle old format with directory path in index file 72# 73--let $is_windows= `select convert(@@version_compile_os using latin1) in ('Win32', 'Win64', 'Windows')` 74 75# write_var_to_file.inc will call SELECT INTO DUMPFILE, which has to be 76# done before shutdown the server 77--echo # Create the master-bin.index file with the old format 78--let $write_to_file= $master_datadir/master-bin.index 79if ($is_windows) 80{ 81 --let $write_var= .\\\\master-bin.000001\n.\\\\master-bin.000002\n.\\\\master-bin.000003\n 82} 83if (!$is_windows) 84{ 85 --let $write_var= ./master-bin.000001\n./master-bin.000002\n./master-bin.000003\n 86} 87--disable_query_log 88source include/write_var_to_file.inc; 89--enable_query_log 90--sync_slave_with_master 91--source include/stop_slave.inc 92 93--connection master 94--echo # Shutdown master 95--let $rpl_server_number=1 96source include/rpl_stop_server.inc; 97 98--echo # Move back the master binlog files 99--move_file $tmpdir/master-bin.000001 $master_datadir/master-bin.000001 100--move_file $tmpdir/master-bin.000002 $master_datadir/master-bin.000002 101--move_file $tmpdir/master-bin.000003 $master_datadir/master-bin.000003 102 103--echo # Remove the unneeded master-bin.index file 104--remove_file $tmpdir/master-bin.index 105 106--echo # Restart master with log-bin option set to default 107--let $rpl_server_parameters=--log-bin=$master_datadir/master-bin --log-bin-index=$master_datadir/master-bin 108--let $keep_include_silent=1 109source include/rpl_start_server.inc; 110--let $keep_include_silent=0 111 112--echo # Master has restarted successfully 113--connection slave 114--source include/start_slave.inc 115 116--connection master 117--sync_slave_with_master 118--echo # stop slave 119--source include/stop_slave.inc 120--let $rpl_server_number= 2 121--source include/rpl_stop_server.inc 122 123# switch to master because the slave has been shutdown 124# and relocate_binlogs requires a running server to do 125# SQL operations 126--connection master 127 128--let $relocate_disable_query_log= 1 129--let $relocate_is_windows= $is_windows 130--let $relocate_from=$slave_datadir 131--let $relocate_into=$tmpdir 132 133--echo # relocate binlogs 134--let $relocate_index_file=$slave_datadir/slave-bin.index 135--source include/relocate_binlogs.inc 136 137--echo # relocate relay logs 138--let $relocate_index_file=$slave_datadir/slave-relay-bin.index 139--source include/relocate_binlogs.inc 140 141--echo # Restart slave with options log-bin, relay-log set to the new paths 142--let $rpl_server_parameters=--log-bin=$tmpdir/slave-bin --relay-log=$tmpdir/slave-relay-bin --relay-log-index=$tmpdir/slave-relay-bin.index 143--let $keep_include_silent=1 144--let $rpl_server_number= 2 145source include/rpl_start_server.inc; 146--let $keep_include_silent=0 147 148--connection slave 149 150--echo # Slave server has restarted successfully 151--source include/start_slave.inc 152--source include/stop_slave.inc 153 154connection master; 155FLUSH LOGS; 156INSERT INTO t1 VALUES (2); 157INSERT INTO t1 VALUES (2); 158INSERT INTO t1 VALUES (2); 159INSERT INTO t1 VALUES (2); 160 161FLUSH LOGS; 162 163connection slave; 164FLUSH LOGS; 165--source include/start_slave.inc 166connection master; 167sync_slave_with_master; 168--let $diff_tables= master:t1,slave:t1 169source include/diff_tables.inc; 170 171connection master; 172DROP TABLE t1; 173--sync_slave_with_master 174--source include/stop_slave.inc 175--let $rpl_server_number= 2 176--source include/rpl_stop_server.inc 177 178--connection master 179 180--let $relocate_from=$tmpdir 181--let $relocate_into=$slave_datadir 182--let $relocate_recreate_index= 1 183 184# binlogs 185--let $relocate_index_file=$tmpdir/slave-bin.index 186--source include/relocate_binlogs.inc 187 188# relay logs 189 190# since the complete fix for the relocation of logs is 191# done in BUG#13428851 it does not help here to try 192# to start the slave as it would fail (relay-log.info is 193# tainted with the full path in the RELAY_LOG_FILE position). 194# Instead, we reset the slave and let the test clean up. 195--let $relocate_fix_relay_log_info= $slave_datadir/relay-log.info 196--let $relocate_index_file=$tmpdir/slave-relay-bin.index 197--source include/relocate_binlogs.inc 198 199--echo # remove tmpdir 200--remove_files_wildcard $tmpdir * 201--rmdir $tmpdir 202 203--echo # restarted with previous slave settings 204--let $rpl_server_parameters=--log-bin=$slave_datadir/slave-bin --relay-log=$slave_datadir/slave-relay-bin --relay-log-index=$slave_datadir/slave-relay-bin.index 205--let $keep_include_silent=1 206--let $rpl_server_number= 2 207--source include/rpl_start_server.inc 208--let $keep_include_silent=0 209 210--connection slave 211 212# The slave will restart if we have fixed the relay-log.info 213# correctly 214--source include/start_slave.inc 215 216--connection master 217--source include/rpl_end.inc 218