Debian Codegraph @

mysql-test/suite/rpl/t/rpl_sync.test

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