MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
rpl_crash_safe.inc
1 # ==== Purpose ====
2 #
3 # This file is an engine to process commands like
4 # rpl_mixing_engines.inc. It has the same set of commands, and in
5 # addition the extra command 'recovery'. The 'configure' and 'clean'
6 # commands are also extended version of the same commands in
7 # rpl_mixing_engines.inc.
8 #
9 # ==== Usage ====
10 #
11 # --let $commands= command1 command2 ...
12 # --let $database_name= name
13 # --let $failure= d,debug_flag
14 # [--let $verbose= 1]
15 # --source include/rpl_mixing_engines.inc
16 #
17 # Parameters:
18 #
19 # $commands, $database_name, $verbose
20 # See rpl_mixing_engines.inc.
21 #
22 # $failure
23 # This debug symbol will be set. See the implementation for
24 # details.
25 #
26 # ==== Implementation ====
27 #
28 # This file has its own code for 'configure' and 'clean'. For other
29 # commands, this file first configures the server according to
30 # $failure, and then delegates the commands to rpl_mixing_engines.inc.
31 
32 #
33 # Creates tables used throughout the test and changes the type of the
34 # mysql.slave_relay_log_info to Innodb.
35 #
36 if ($commands == 'configure')
37 {
38  --sync_slave_with_master
39  --source include/stop_slave.inc
40  SHOW CREATE TABLE mysql.slave_relay_log_info;
41  SHOW CREATE TABLE mysql.slave_worker_info;
42  ALTER TABLE mysql.slave_relay_log_info ENGINE= Innodb;
43  ALTER TABLE mysql.slave_worker_info ENGINE= Innodb;
44  SHOW CREATE TABLE mysql.slave_relay_log_info;
45  SHOW CREATE TABLE mysql.slave_worker_info;
46  --source include/start_slave.inc
47 
48  connection master;
49  --source extra/rpl_tests/rpl_mixing_engines.inc
50 
51  --sync_slave_with_master
52  connection master;
53  --let $commands=
54 }
55 
56 #
57 # Cleans the test case by deleting all tables, triggers, procedures and
58 # functions that were created.
59 #
60 if ($commands == 'clean')
61 {
62  connection master;
63  --source extra/rpl_tests/rpl_mixing_engines.inc
64  --let $commands=
65 }
66 
67 #
68 # Executes the set of commands defined in $command by calling
69 # rpl_mixing_engines.inc
70 #
71 if ($commands != '')
72 {
73  #
74  # If an fault injection point was defined, stop the SQL THREAD and
75  # prepare the slave to be restarted. Otherwise, do nothing.
76  #
77  if ($failure != '')
78  {
79  connection slave;
80  STOP SLAVE SQL_THREAD;
81  source include/wait_for_slave_sql_to_stop.inc;
82  --eval SET GLOBAL debug="$failure";
83  --exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.2.expect
84  }
85 
86  #
87  # Prints the expected outcome after the recovery. Check the
88  # WL#4801 for further details.
89  #
90  connection master;
91  if ($failure != '')
92  {
93  --let $outcome= O2
94  if ($failure != 'd,crash_after_commit_and_update_pos')
95  {
96  if ($failure != 'd,crash_after_apply')
97  {
98  --let $outcome= O1
99  }
100  }
101  --echo FAILURE $failure and OUTCOME $outcome
102  }
103 
104  #
105  # Executes the set of commands defined in $command by calling
106  # rpl_mixing_engines.inc
107  #
108  connection master;
109  let $master_before= query_get_value(SHOW MASTER STATUS, Position, 1);
110  --source extra/rpl_tests/rpl_mixing_engines.inc
111  let $master_after= query_get_value(SHOW MASTER STATUS, Position, 1);
112 
113  #
114  # Restarts the SQL THREAD and waits for the SLAVE to be crashed and
115  # re-started.
116  #
117  connection master;
118  if ($failure != '')
119  {
120  connection slave;
121  --error 0, 2013
122  START SLAVE SQL_THREAD;
123  --source include/wait_until_disconnected.inc
124  --exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.2.expect
125  --let $rpl_server_number= 2
126  --source include/rpl_reconnect.inc
127  connection slave;
128  --let $slave_before= `SELECT master_log_pos FROM mysql.slave_relay_log_info`
129  START SLAVE;
130  source include/wait_for_slave_to_start.inc;
131  }
132 
133  #
134  # Syncs the slave with the master and checks if the slaves applied all
135  # changes from the master and is not out of sync.
136  #
137  connection master;
138  sync_slave_with_master;
139 
140  --let $slave_after= `SELECT master_log_pos FROM mysql.slave_relay_log_info`
141  if ($slave_after != $master_after)
142  {
143  --echo Slave is out of sync.
144  --echo MASTER_BEFORE $master_before MASTER_AFTER $master_after SLAVE_BEFORE $slave_before SLAVE_AFTER $slave_after
145  connection slave;
146  --source include/show_rpl_debug_info.inc
147  --die
148  }
149 }
150 
151 connection master;