Commit 5dda66cf authored by Luis Soares's avatar Luis Soares

BUG#11745230

Refactored the test case: hardened and extended it. Created test inc file
to abstract the task of relocating binlogs.

Also, disabled it on windows for not cluttering the test case any further, 
as it depends heavily on doing filesystem operations and path handling.

mysql-test/include/relocate_binlogs.inc:
  Auxiliar include file that performs the relocation of binary logs
  listed in an index file.
parent 297d21b6
# ==== Purpose ====
#
# Relocates the relay logs and index file from
# a directory into another. The logs relocated
# are the one listed in the index file.
#
# ==== Usage ====
#
# [--let $relocate_disable_query_log= 1]
# [--let $rpl_debug= 1]
# [--let $relocate_is_windows= 0]
# [--let $relocate_recreate_index= 0]
# [--let $relocate_fix_relay_log_info= 0]
# --let $relocate_from= DIR
# --let $relocate_to= DIR
# --let $relocate_index_file= FNAME
# --source include/relocate_binlogs.inc
if ($relocate_disable_query_log)
{
--disable_query_log
}
--let $_path_separator=/
if ($relocate_is_windows)
{
--let $_path_separator=\
}
if ($relocate_index_file)
{
SET SQL_LOG_BIN=0;
CREATE TEMPORARY TABLE tmp(id INT AUTO_INCREMENT PRIMARY KEY, filename VARCHAR(1024));
--let $write_var=
--let $_index_file= $relocate_index_file
--let $_index_file_basename= `SELECT RIGHT(RTRIM("$_index_file"), LOCATE("$_path_separator",REVERSE(RTRIM("$_index_file"))) -1)`
--let $_from= $relocate_from
--let $_to= $relocate_into
# chmod to allow the following LOAD DATA
--chmod 0666 $_index_file
--eval LOAD DATA INFILE '$_index_file' INTO TABLE tmp (filename)
--let $count= `SELECT count(*) FROM tmp`
while ($count)
{
--let $_filename= `select filename from tmp where id=$count`
--let $_filename= `SELECT RIGHT(RTRIM("$_filename"), LOCATE("$_path_separator",REVERSE(RTRIM("$_filename"))) -1)`
--move_file $_from/$_filename $_to/$_filename
if ($relocate_recreate_index)
{
if ($relocate_is_windows)
{
--let $_write_var=$_to\$_filename\n
}
if (!$relocate_is_windows)
{
--let $_write_var=$_to/$_filename\n
}
if (!$write_var)
{
--let $write_var=$_write_var
}
if (!`SELECT STRCMP('$write_var', '$_write_var') = 0`)
{
--let $write_var=$_write_var$write_var
}
}
--dec $count
}
if (!$relocate_recreate_index)
{
--move_file $_index_file $_to/$_index_file_basename
}
if ($relocate_recreate_index)
{
--let $write_to_file= $_to/$_index_file_basename
--source include/write_var_to_file.inc
--remove_file $_index_file
}
DROP TEMPORARY TABLE tmp;
if ($relocate_fix_relay_log_info)
{
CREATE TEMPORARY TABLE tmp(id INT AUTO_INCREMENT PRIMARY KEY, entry VARCHAR(1024));
--let $write_var=
# chmod to allow the following LOAD DATA
--chmod 0666 $relocate_fix_relay_log_info
--eval LOAD DATA INFILE '$relocate_fix_relay_log_info' INTO TABLE tmp (entry)
--let $count= `SELECT count(*) FROM tmp`
--let $_curr_entry= `SELECT entry FROM tmp WHERE id=1`
--let $_curr_entry_basename= `SELECT RIGHT(RTRIM("$_curr_entry"), LOCATE("$_path_separator",REVERSE(RTRIM("$_curr_entry"))) -1)`
if ($relocate_is_windows)
{
--eval UPDATE tmp SET entry='$_to\$_curr_entry_basename' WHERE id=1
}
if (!$relocate_is_windows)
{
--eval UPDATE tmp SET entry='$_to/$_curr_entry_basename' WHERE id=1
}
--remove_file $relocate_fix_relay_log_info
while($count)
{
--let $_write_var= `SELECT entry FROM tmp WHERE id= $count`
--let $write_var=$_write_var\n$write_var
--dec $count
}
--let $write_to_file= $relocate_fix_relay_log_info
--source include/write_var_to_file.inc
DROP TEMPORARY TABLE tmp;
}
SET SQL_LOG_BIN=1;
}
if ($relocate_disable_query_log)
{
--enable_query_log
}
......@@ -15,12 +15,13 @@ include/rpl_stop_server.inc [server_number=1]
# Remove the unneeded master-bin.index file
# Restart master with log-bin option set to default
# Master has restarted successfully
# stop slave
include/stop_slave.inc
# Move the slave binlog and relay log files and index to the new place
# Shutdown slave
include/rpl_stop_server.inc [server_number=2]
# relocate binlogs
# relocate relay logs
# Restart slave with options log-bin, relay-log set to the new paths
# Slave has restarted successfully
# Slave server has restarted successfully
include/start_slave.inc
include/stop_slave.inc
FLUSH LOGS;
......@@ -33,3 +34,9 @@ FLUSH LOGS;
include/start_slave.inc
include/diff_tables.inc [master:t1,slave:t1]
DROP TABLE t1;
include/stop_slave.inc
include/rpl_stop_server.inc [server_number=2]
# remove tmpdir
# restarted with previous slave settings
include/start_slave.inc
include/rpl_end.inc
......@@ -21,12 +21,20 @@ source include/master-slave.inc;
# There is no need to run this test case on all binlog format
source include/have_binlog_format_row.inc;
# Since this test relies heavily on filesystem operations (like
# moving files around, backslashes and so forth) we avoid messing
# around with windows access violations for not cluttering the
# test case any further. It is prepared to support windows, but
# it is not 100% compliant.
--source include/not_windows.inc
connection master;
--let $master_datadir= `select @@datadir`
connection slave;
--let $slave_datadir= `select @@datadir`
connection master;
--let $tmpdir= $MYSQLTEST_VARDIR/tmp/rpl_binlog_index
--let $dirname= `select uuid()`
--let $tmpdir= $MYSQLTEST_VARDIR/tmp/$dirname
--mkdir $tmpdir
CREATE TABLE t1 (a INT);
......@@ -36,7 +44,6 @@ INSERT INTO t1 VALUES (1);
sync_slave_with_master;
#
# Test on master
#
......@@ -69,11 +76,11 @@ source include/rpl_start_server.inc;
--let $write_to_file= $master_datadir/master-bin.index
if ($is_windows)
{
--let $write_var= .\\master-bin.000001\n.\\master-bin.000002\n
--let $write_var= .\\\\master-bin.000001\n.\\\\master-bin.000002\n.\\\\master-bin.000003\n
}
if (!$is_windows)
{
--let $write_var= ./master-bin.000001\n./master-bin.000002\n
--let $write_var= ./master-bin.000001\n./master-bin.000002\n./master-bin.000003\n
}
--disable_query_log
source include/write_var_to_file.inc;
......@@ -86,6 +93,7 @@ source include/rpl_stop_server.inc;
--echo # Move back the master binlog files
--move_file $tmpdir/master-bin.000001 $master_datadir/master-bin.000001
--move_file $tmpdir/master-bin.000002 $master_datadir/master-bin.000002
--move_file $tmpdir/master-bin.000003 $master_datadir/master-bin.000003
--echo # Remove the unneeded master-bin.index file
--remove_file $tmpdir/master-bin.index
......@@ -99,41 +107,40 @@ source include/rpl_start_server.inc;
--echo # Master has restarted successfully
connection slave;
source include/stop_slave.inc;
--echo # stop slave
--source include/stop_slave.inc
--let $rpl_server_number= 2
--source include/rpl_stop_server.inc
--disable_query_log
# slave-relay-bin.* files can vary, so read the slave-relay-bin.index
# to figure out the slave-relay-bin.* files
CREATE TEMPORARY TABLE tmp (id INT AUTO_INCREMENT PRIMARY KEY, filename VARCHAR(1024));
# chmod to allow the following LOAD DATA
--chmod 0666 $slave_datadir/slave-relay-bin.index
--eval LOAD DATA INFILE '$slave_datadir/slave-relay-bin.index' INTO TABLE tmp (filename)
--let $count= `SELECT count(*) FROM tmp`
--echo # Move the slave binlog and relay log files and index to the new place
--move_file $slave_datadir/slave-bin.index $tmpdir/slave-bin.index
--move_file $slave_datadir/slave-bin.000001 $tmpdir/slave-bin.000001
--move_file $slave_datadir/slave-relay-bin.index $tmpdir/slave-relay-bin.index
while ($count)
{
--let $filename= `select filename from tmp where id=$count`
--move_file $slave_datadir/$filename $tmpdir/$filename
--dec $count
}
DROP TEMPORARY TABLE tmp;
--enable_query_log
# switch to master because the slave has been shutdown
# and relocate_binlogs requires a running server to do
# SQL operations
--connection master
--echo # Shutdown slave
--let $rpl_server_number=2
source include/rpl_stop_server.inc;
--let $relocate_disable_query_log= 1
--let $relocate_is_windows= $is_windows
--let $relocate_from=$slave_datadir
--let $relocate_into=$tmpdir
--echo # relocate binlogs
--let $relocate_index_file=$slave_datadir/slave-bin.index
--source include/relocate_binlogs.inc
--echo # relocate relay logs
--let $relocate_index_file=$slave_datadir/slave-relay-bin.index
--source include/relocate_binlogs.inc
--echo # Restart slave with options log-bin, relay-log set to the new paths
--let $rpl_server_parameters=--log-bin=$tmpdir/slave-bin --relay-log=$tmpdir/slave-relay-bin
--let $keep_include_silent=1
--let $rpl_server_number= 2
source include/rpl_start_server.inc;
--let $keep_include_silent=0
--echo # Slave has restarted successfully
source include/start_slave.inc;
--connection slave
--echo # Slave server has restarted successfully
--source include/start_slave.inc
--source include/stop_slave.inc
connection master;
......@@ -155,6 +162,48 @@ source include/diff_tables.inc;
connection master;
DROP TABLE t1;
sync_slave_with_master;
--sync_slave_with_master
--source include/stop_slave.inc
--let $rpl_server_number= 2
--source include/rpl_stop_server.inc
--connection master
--let $relocate_from=$tmpdir
--let $relocate_into=$slave_datadir
--let $relocate_recreate_index= 1
# binlogs
--let $relocate_index_file=$tmpdir/slave-bin.index
--source include/relocate_binlogs.inc
# relay logs
# since the complete fix for the relocation of logs is
# done in BUG#13428851 it does not help here to try
# to start the slave as it would fail (relay-log.info is
# tainted with the full path in the RELAY_LOG_FILE position).
# Instead, we reset the slave and let the test clean up.
--let $relocate_fix_relay_log_info= $slave_datadir/relay-log.info
--let $relocate_index_file=$tmpdir/slave-relay-bin.index
--source include/relocate_binlogs.inc
--echo # remove tmpdir
--remove_files_wildcard $tmpdir *
--rmdir $tmpdir
--echo # restarted with previous slave settings
--let $rpl_server_parameters=--log-bin=$slave_datadir/slave-bin --relay-log=$slave_datadir/slave-relay-bin
--let $keep_include_silent=1
--let $rpl_server_number= 2
--source include/rpl_start_server.inc
--let $keep_include_silent=0
--connection slave
# The slave will restart if we have fixed the relay-log.info
# correctly
--source include/start_slave.inc
--connection master
--source include/rpl_end.inc
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment