| 1 |
# |
| 2 |
# This include file is used by more than one test suite |
| 3 |
# (currently rpl and binlog_encryption). |
| 4 |
# Please check all dependent tests after modifying it |
| 5 |
# |
| 6 |
|
| 7 |
######################################################################################## |
| 8 |
# This test verifies the options --sync-relay-log-info and --relay-log-recovery by |
| 9 |
# crashing the slave in two different situations: |
| 10 |
# (case-1) - Corrupt the relay log with changes which were not processed by |
| 11 |
# the SQL Thread and crashes it. |
| 12 |
# (case-2) - Corrupt the master.info with wrong coordinates and crashes it. |
| 13 |
# |
| 14 |
# Case 1: |
| 15 |
# 1 - Stops the SQL Thread |
| 16 |
# 2 - Inserts new records into the master. |
| 17 |
# 3 - Corrupts the relay-log.bin* which most likely has such changes. |
| 18 |
# 4 - Crashes the slave |
| 19 |
# 5 - Verifies if the slave is sync with the master which means that the information |
| 20 |
# loss was circumvented by the recovery process. |
| 21 |
# |
| 22 |
# Case 2: |
| 23 |
# 1 - Stops the SQL/IO Threads |
| 24 |
# 2 - Inserts new records into the master. |
| 25 |
# 3 - Corrupts the master.info with wrong coordinates. |
| 26 |
# 4 - Crashes the slave |
| 27 |
# 5 - Verifies if the slave is sync with the master which means that the information |
| 28 |
# loss was circumvented by the recovery process. |
| 29 |
######################################################################################## |
| 30 |
|
| 31 |
######################################################################################## |
| 32 |
# Configuring the environment |
| 33 |
######################################################################################## |
| 34 |
--echo =====Configuring the enviroment=======; |
| 35 |
--source include/not_embedded.inc |
| 36 |
--source include/not_valgrind.inc |
| 37 |
--source include/have_debug.inc |
| 38 |
--source include/have_innodb.inc |
| 39 |
--source include/not_crashrep.inc |
| 40 |
--source include/master-slave.inc |
| 41 |
|
| 42 |
call mtr.add_suppression('Attempting backtrace'); |
| 43 |
call mtr.add_suppression("Recovery from master pos .* and file master-bin.000001"); |
| 44 |
# Use innodb so we do not get "table should be repaired" issues. |
| 45 |
ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB; |
| 46 |
flush tables; |
| 47 |
CREATE TABLE t1(a INT, PRIMARY KEY(a)) engine=innodb; |
| 48 |
|
| 49 |
insert into t1(a) values(1); |
| 50 |
insert into t1(a) values(2); |
| 51 |
insert into t1(a) values(3); |
| 52 |
|
| 53 |
######################################################################################## |
| 54 |
# Case 1: Corrupt a relay-log.bin* |
| 55 |
######################################################################################## |
| 56 |
--echo =====Inserting data on the master but without the SQL Thread being running=======; |
| 57 |
sync_slave_with_master; |
| 58 |
|
| 59 |
connection slave; |
| 60 |
let $MYSQLD_SLAVE_DATADIR= `select @@datadir`; |
| 61 |
--replace_result $MYSQLD_SLAVE_DATADIR MYSQLD_SLAVE_DATADIR |
| 62 |
--copy_file $MYSQLD_SLAVE_DATADIR/master.info $MYSQLD_SLAVE_DATADIR/master.backup |
| 63 |
--source include/stop_slave_sql.inc |
| 64 |
|
| 65 |
connection master; |
| 66 |
insert into t1(a) values(4); |
| 67 |
insert into t1(a) values(5); |
| 68 |
insert into t1(a) values(6); |
| 69 |
|
| 70 |
--echo =====Removing relay log files and crashing/recoverying the slave=======; |
| 71 |
connection slave; |
| 72 |
--source include/stop_slave_io.inc |
| 73 |
|
| 74 |
let $file= query_get_value("SHOW SLAVE STATUS", Relay_Log_File, 1); |
| 75 |
|
| 76 |
--let FILE_TO_CORRUPT= $MYSQLD_SLAVE_DATADIR/$file |
| 77 |
perl; |
| 78 |
$file= $ENV{'FILE_TO_CORRUPT'}; |
| 79 |
open(FILE, ">$file") || die "Unable to open $file."; |
| 80 |
truncate(FILE,0); |
| 81 |
print FILE "failure"; |
| 82 |
close ($file); |
| 83 |
EOF |
| 84 |
|
| 85 |
--write_line restart $MYSQLTEST_VARDIR/tmp/mysqld.2.expect |
| 86 |
SET SESSION debug_dbug="d,crash_before_rotate_relaylog"; |
| 87 |
--error 2013 |
| 88 |
FLUSH LOGS; |
| 89 |
|
| 90 |
--let $rpl_server_number= 2 |
| 91 |
--source include/rpl_reconnect.inc |
| 92 |
|
| 93 |
--echo =====Dumping and comparing tables=======; |
| 94 |
--source include/start_slave.inc |
| 95 |
|
| 96 |
connection master; |
| 97 |
sync_slave_with_master; |
| 98 |
|
| 99 |
let $diff_tables=master:t1,slave:t1; |
| 100 |
source include/diff_tables.inc; |
| 101 |
|
| 102 |
######################################################################################## |
| 103 |
# Case 2: Corrupt a master.info |
| 104 |
######################################################################################## |
| 105 |
--echo =====Corrupting the master.info=======; |
| 106 |
connection slave; |
| 107 |
--source include/stop_slave.inc |
| 108 |
|
| 109 |
connection master; |
| 110 |
FLUSH LOGS; |
| 111 |
|
| 112 |
insert into t1(a) values(7); |
| 113 |
insert into t1(a) values(8); |
| 114 |
insert into t1(a) values(9); |
| 115 |
|
| 116 |
connection slave; |
| 117 |
let MYSQLD_SLAVE_DATADIR=`select @@datadir`; |
| 118 |
|
| 119 |
--perl |
| 120 |
use strict; |
| 121 |
use warnings; |
| 122 |
my $src= "$ENV{'MYSQLD_SLAVE_DATADIR'}/master.backup"; |
| 123 |
my $dst= "$ENV{'MYSQLD_SLAVE_DATADIR'}/master.info"; |
| 124 |
open(FILE, "<", $src) or die; |
| 125 |
my @content= <FILE>; |
| 126 |
close FILE; |
| 127 |
open(FILE, ">", $dst) or die; |
| 128 |
binmode FILE; |
| 129 |
print FILE @content; |
| 130 |
close FILE; |
| 131 |
EOF |
| 132 |
|
| 133 |
--write_line restart $MYSQLTEST_VARDIR/tmp/mysqld.2.expect |
| 134 |
SET SESSION debug_dbug="d,crash_before_rotate_relaylog"; |
| 135 |
--error 2013 |
| 136 |
FLUSH LOGS; |
| 137 |
|
| 138 |
--let $rpl_server_number= 2 |
| 139 |
--source include/rpl_reconnect.inc |
| 140 |
|
| 141 |
--echo =====Dumping and comparing tables=======; |
| 142 |
--source include/start_slave.inc |
| 143 |
|
| 144 |
connection master; |
| 145 |
sync_slave_with_master; |
| 146 |
|
| 147 |
let $diff_tables=master:t1,slave:t1; |
| 148 |
source include/diff_tables.inc; |
| 149 |
|
| 150 |
######################################################################################## |
| 151 |
# Clean up |
| 152 |
######################################################################################## |
| 153 |
--echo =====Clean up=======; |
| 154 |
connection master; |
| 155 |
drop table t1; |
| 156 |
|
| 157 |
--remove_file $MYSQLD_SLAVE_DATADIR/master.backup |
| 158 |
--source include/rpl_end.inc |
| 159 |
|