| 1 |
# |
| 2 |
# This include file is used by more than one test suite |
| 3 |
# (currently binlog and binlog_encryption). |
| 4 |
# Please check all dependent tests after modifying it |
| 5 |
# |
| 6 |
|
| 7 |
--source include/have_innodb.inc |
| 8 |
--source include/have_debug.inc |
| 9 |
--source include/have_debug_sync.inc |
| 10 |
--source include/have_binlog_format_row.inc |
| 11 |
--source include/have_perfschema.inc |
| 12 |
# Valgrind does not work well with test that crashes the server |
| 13 |
--source include/not_valgrind.inc |
| 14 |
|
| 15 |
# (We do not need to restore these settings, as we crash the server). |
| 16 |
SET GLOBAL max_binlog_size= 4096; |
| 17 |
SET GLOBAL innodb_flush_log_at_trx_commit= 1; |
| 18 |
RESET MASTER; |
| 19 |
|
| 20 |
CREATE TABLE t1 (a INT PRIMARY KEY, b MEDIUMTEXT) ENGINE=Innodb; |
| 21 |
# Insert some data to force a couple binlog rotations (3), so we get some |
| 22 |
# normal binlog checkpoints before starting the test. |
| 23 |
INSERT INTO t1 VALUES (100, REPEAT("x", 4100)); |
| 24 |
# Wait for the master-bin.000002 binlog checkpoint to appear. |
| 25 |
--let $wait_for_all= 0 |
| 26 |
--let $show_statement= SHOW BINLOG EVENTS IN "master-bin.000002" |
| 27 |
--let $field= Info |
| 28 |
--let $condition= = "master-bin.000002" |
| 29 |
--source include/wait_show_condition.inc |
| 30 |
INSERT INTO t1 VALUES (101, REPEAT("x", 4100)); |
| 31 |
--let $wait_for_all= 0 |
| 32 |
--let $show_statement= SHOW BINLOG EVENTS IN "master-bin.000003" |
| 33 |
--let $field= Info |
| 34 |
--let $condition= = "master-bin.000003" |
| 35 |
--source include/wait_show_condition.inc |
| 36 |
INSERT INTO t1 VALUES (102, REPEAT("x", 4100)); |
| 37 |
--let $wait_for_all= 0 |
| 38 |
--let $show_statement= SHOW BINLOG EVENTS IN "master-bin.000004" |
| 39 |
--let $field= Info |
| 40 |
--let $condition= = "master-bin.000004" |
| 41 |
--source include/wait_show_condition.inc |
| 42 |
|
| 43 |
# Now start a bunch of transactions that span multiple binlog |
| 44 |
# files. Leave then in the state prepared-but-not-committed in the engine |
| 45 |
# and crash the server. Check that crash recovery is able to recover all |
| 46 |
# of them. |
| 47 |
# |
| 48 |
# We use debug_sync to get all the transactions into the prepared state before |
| 49 |
# we commit any of them. This is because the prepare step flushes the InnoDB |
| 50 |
# redo log - including any commits made before, so recovery would become |
| 51 |
# unnecessary, decreasing the value of this test. |
| 52 |
# |
| 53 |
# We arrange to have con1 with a prepared transaction in master-bin.000004, |
| 54 |
# con2 and con3 with a prepared transaction in master-bin.000005, and a new |
| 55 |
# empty master-bin.000006. So the latest binlog checkpoint should be |
| 56 |
# master-bin.000006. |
| 57 |
|
| 58 |
connect(con1,localhost,root,,); |
| 59 |
# First wait after prepare and before write to binlog. |
| 60 |
SET DEBUG_SYNC= "ha_commit_trans_before_log_and_order SIGNAL con1_wait WAIT_FOR con1_cont"; |
| 61 |
# Then complete InnoDB commit in memory (but not commit checkpoint / write to |
| 62 |
# disk), and hang until crash, leaving a transaction to be XA recovered. |
| 63 |
SET DEBUG_SYNC= "commit_after_group_release_commit_ordered SIGNAL con1_ready WAIT_FOR _ever"; |
| 64 |
send INSERT INTO t1 VALUES (1, REPEAT("x", 4100)); |
| 65 |
|
| 66 |
connection default; |
| 67 |
SET DEBUG_SYNC= "now WAIT_FOR con1_wait"; |
| 68 |
|
| 69 |
connect(con2,localhost,root,,); |
| 70 |
SET DEBUG_SYNC= "ha_commit_trans_before_log_and_order SIGNAL con2_wait WAIT_FOR con2_cont"; |
| 71 |
SET DEBUG_SYNC= "commit_after_group_release_commit_ordered SIGNAL con2_ready WAIT_FOR _ever"; |
| 72 |
send INSERT INTO t1 VALUES (2, NULL); |
| 73 |
|
| 74 |
connection default; |
| 75 |
SET DEBUG_SYNC= "now WAIT_FOR con2_wait"; |
| 76 |
|
| 77 |
connect(con3,localhost,root,,); |
| 78 |
SET DEBUG_SYNC= "ha_commit_trans_before_log_and_order SIGNAL con3_wait WAIT_FOR con3_cont"; |
| 79 |
SET DEBUG_SYNC= "commit_after_group_release_commit_ordered SIGNAL con3_ready WAIT_FOR _ever"; |
| 80 |
send INSERT INTO t1 VALUES (3, REPEAT("x", 4100)); |
| 81 |
|
| 82 |
connection default; |
| 83 |
SET DEBUG_SYNC= "now WAIT_FOR con3_wait"; |
| 84 |
|
| 85 |
connect(con4,localhost,root,,); |
| 86 |
SET DEBUG_SYNC= "ha_commit_trans_before_log_and_order SIGNAL con4_wait WAIT_FOR con4_cont"; |
| 87 |
SET SESSION debug_dbug="+d,crash_commit_after_log"; |
| 88 |
send INSERT INTO t1 VALUES (4, NULL); |
| 89 |
|
| 90 |
connection default; |
| 91 |
SET DEBUG_SYNC= "now WAIT_FOR con4_wait"; |
| 92 |
|
| 93 |
SET DEBUG_SYNC= "now SIGNAL con1_cont"; |
| 94 |
SET DEBUG_SYNC= "now WAIT_FOR con1_ready"; |
| 95 |
SET DEBUG_SYNC= "now SIGNAL con2_cont"; |
| 96 |
SET DEBUG_SYNC= "now WAIT_FOR con2_ready"; |
| 97 |
SET DEBUG_SYNC= "now SIGNAL con3_cont"; |
| 98 |
SET DEBUG_SYNC= "now WAIT_FOR con3_ready"; |
| 99 |
|
| 100 |
# Check that everything is committed in binary log. |
| 101 |
--source include/show_binary_logs.inc |
| 102 |
--let $binlog_file= master-bin.000003 |
| 103 |
--let $binlog_start= 4 |
| 104 |
--source include/show_binlog_events.inc |
| 105 |
--let $binlog_file= master-bin.000004 |
| 106 |
--source include/show_binlog_events.inc |
| 107 |
--let $binlog_file= master-bin.000005 |
| 108 |
--source include/show_binlog_events.inc |
| 109 |
--let $binlog_file= master-bin.000006 |
| 110 |
--source include/show_binlog_events.inc |
| 111 |
|
| 112 |
|
| 113 |
# Check that server will not purge too much. |
| 114 |
PURGE BINARY LOGS TO "master-bin.000006"; |
| 115 |
--source include/show_binary_logs.inc |
| 116 |
|
| 117 |
# Now crash the server with one more transaction in prepared state. |
| 118 |
--write_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect |
| 119 |
wait-binlog_xa_recover.test |
| 120 |
EOF |
| 121 |
--error 0,2006,2013 |
| 122 |
SET DEBUG_SYNC= "now SIGNAL con4_cont"; |
| 123 |
connection con4; |
| 124 |
--error 2006,2013 |
| 125 |
reap; |
| 126 |
|
| 127 |
--append_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect |
| 128 |
restart-group_commit_binlog_pos.test |
| 129 |
EOF |
| 130 |
|
| 131 |
connection default; |
| 132 |
--enable_reconnect |
| 133 |
--source include/wait_until_connected_again.inc |
| 134 |
|
| 135 |
# Check that all transactions are recovered. |
| 136 |
SELECT a FROM t1 ORDER BY a; |
| 137 |
|
| 138 |
--echo Test that with multiple binlog checkpoints, recovery starts from the last one. |
| 139 |
SET GLOBAL max_binlog_size= 4096; |
| 140 |
SET GLOBAL innodb_flush_log_at_trx_commit= 1; |
| 141 |
RESET MASTER; |
| 142 |
|
| 143 |
# Rotate to binlog master-bin.000003 while delaying binlog checkpoints. |
| 144 |
# So we get multiple binlog checkpoints in master-bin.000003. |
| 145 |
# Then complete the checkpoints, crash, and check that we only scan |
| 146 |
# the necessary binlog file (ie. that we use the _last_ checkpoint). |
| 147 |
|
| 148 |
connect(con10,localhost,root,,); |
| 149 |
SET DEBUG_SYNC= "commit_after_group_release_commit_ordered SIGNAL con10_ready WAIT_FOR con10_cont"; |
| 150 |
send INSERT INTO t1 VALUES (10, REPEAT("x", 4100)); |
| 151 |
|
| 152 |
connection default; |
| 153 |
SET DEBUG_SYNC= "now WAIT_FOR con10_ready"; |
| 154 |
|
| 155 |
connect(con11,localhost,root,,); |
| 156 |
SET DEBUG_SYNC= "commit_after_group_release_commit_ordered SIGNAL con11_ready WAIT_FOR con11_cont"; |
| 157 |
send INSERT INTO t1 VALUES (11, REPEAT("x", 4100)); |
| 158 |
|
| 159 |
connection default; |
| 160 |
SET DEBUG_SYNC= "now WAIT_FOR con11_ready"; |
| 161 |
|
| 162 |
connect(con12,localhost,root,,); |
| 163 |
SET DEBUG_SYNC= "commit_after_group_release_commit_ordered SIGNAL con12_ready WAIT_FOR con12_cont"; |
| 164 |
send INSERT INTO t1 VALUES (12, REPEAT("x", 4100)); |
| 165 |
|
| 166 |
connection default; |
| 167 |
SET DEBUG_SYNC= "now WAIT_FOR con12_ready"; |
| 168 |
INSERT INTO t1 VALUES (13, NULL); |
| 169 |
|
| 170 |
--source include/show_binary_logs.inc |
| 171 |
--let $binlog_file= master-bin.000004 |
| 172 |
--let $binlog_start= 4 |
| 173 |
--source include/show_binlog_events.inc |
| 174 |
|
| 175 |
SET DEBUG_SYNC= "now SIGNAL con10_cont"; |
| 176 |
connection con10; |
| 177 |
reap; |
| 178 |
connection default; |
| 179 |
|
| 180 |
# We need to sync the test case with the background processing of the |
| 181 |
# commit checkpoint, otherwise we get nondeterministic results. |
| 182 |
let $wait_condition= select count(*) = 1 from performance_schema.threads where processlist_state = "Waiting for background binlog tasks"; |
| 183 |
--source include/wait_condition.inc |
| 184 |
|
| 185 |
SET DEBUG_SYNC= "now SIGNAL con12_cont"; |
| 186 |
connection con12; |
| 187 |
reap; |
| 188 |
connection default; |
| 189 |
|
| 190 |
SET DEBUG_SYNC= "now SIGNAL con11_cont"; |
| 191 |
connection con11; |
| 192 |
reap; |
| 193 |
|
| 194 |
connection default; |
| 195 |
# Wait for the last (master-bin.000004) binlog checkpoint to appear. |
| 196 |
--let $wait_for_all= 0 |
| 197 |
--let $show_statement= SHOW BINLOG EVENTS IN "master-bin.000004" |
| 198 |
--let $field= Info |
| 199 |
--let $condition= = "master-bin.000004" |
| 200 |
--source include/wait_show_condition.inc |
| 201 |
|
| 202 |
--echo Now crash the server |
| 203 |
# It is not too easy to test XA recovery, as it runs early during server |
| 204 |
# startup, before any connections can be made. |
| 205 |
# What we do is set a DBUG error insert which will crash if XA recovery |
| 206 |
# starts from any other binlog than master-bin.000004 (check the file |
| 207 |
# binlog_xa_recover-master.opt). Then we will fail here if XA recovery |
| 208 |
# would start from the wrong place. |
| 209 |
--write_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect |
| 210 |
wait-binlog_xa_recover.test |
| 211 |
EOF |
| 212 |
SET SESSION debug_dbug="+d,crash_commit_after_log"; |
| 213 |
--error 2006,2013 |
| 214 |
INSERT INTO t1 VALUES (14, NULL); |
| 215 |
|
| 216 |
--append_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect |
| 217 |
restart-group_commit_binlog_pos.test |
| 218 |
EOF |
| 219 |
|
| 220 |
connection default; |
| 221 |
--enable_reconnect |
| 222 |
--source include/wait_until_connected_again.inc |
| 223 |
|
| 224 |
# Check that all transactions are recovered. |
| 225 |
SELECT a FROM t1 ORDER BY a; |
| 226 |
|
| 227 |
|
| 228 |
--echo *** Check that recovery works if we crashed early during rotate, before |
| 229 |
--echo *** binlog checkpoint event could be written. |
| 230 |
|
| 231 |
SET GLOBAL max_binlog_size= 4096; |
| 232 |
SET GLOBAL innodb_flush_log_at_trx_commit= 1; |
| 233 |
RESET MASTER; |
| 234 |
|
| 235 |
# We need some initial data to reach binlog master-bin.000004. Otherwise |
| 236 |
# crash recovery fails due to the error insert used for previous test. |
| 237 |
INSERT INTO t1 VALUES (21, REPEAT("x", 4100)); |
| 238 |
INSERT INTO t1 VALUES (22, REPEAT("x", 4100)); |
| 239 |
# Wait for the master-bin.000003 binlog checkpoint to appear. |
| 240 |
--let $wait_for_all= 0 |
| 241 |
--let $show_statement= SHOW BINLOG EVENTS IN "master-bin.000003" |
| 242 |
--let $field= Info |
| 243 |
--let $condition= = "master-bin.000003" |
| 244 |
--source include/wait_show_condition.inc |
| 245 |
INSERT INTO t1 VALUES (23, REPEAT("x", 4100)); |
| 246 |
# Wait for the last (master-bin.000004) binlog checkpoint to appear. |
| 247 |
--let $wait_for_all= 0 |
| 248 |
--let $show_statement= SHOW BINLOG EVENTS IN "master-bin.000004" |
| 249 |
--let $field= Info |
| 250 |
--let $condition= = "master-bin.000004" |
| 251 |
--source include/wait_show_condition.inc |
| 252 |
|
| 253 |
--write_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect |
| 254 |
wait-binlog_xa_recover.test |
| 255 |
EOF |
| 256 |
SET SESSION debug_dbug="+d,crash_before_write_checkpoint_event"; |
| 257 |
--error 2006,2013 |
| 258 |
INSERT INTO t1 VALUES (24, REPEAT("x", 4100)); |
| 259 |
|
| 260 |
--append_file $MYSQLTEST_VARDIR/tmp/mysqld.1.expect |
| 261 |
restart-group_commit_binlog_pos.test |
| 262 |
EOF |
| 263 |
|
| 264 |
--enable_reconnect |
| 265 |
--source include/wait_until_connected_again.inc |
| 266 |
|
| 267 |
# Check that all transactions are recovered. |
| 268 |
SELECT a FROM t1 ORDER BY a; |
| 269 |
|
| 270 |
--source include/show_binary_logs.inc |
| 271 |
--let $binlog_file= master-bin.000004 |
| 272 |
--let $binlog_start= 4 |
| 273 |
--source include/show_binlog_events.inc |
| 274 |
|
| 275 |
# Cleanup |
| 276 |
connection default; |
| 277 |
DROP TABLE t1; |