| 1 |
# |
| 2 |
# This file creates various kinds of prepared XA transactions, |
| 3 |
# manipulates their connection state and examines how their prepared |
| 4 |
# status behave while the transaction is disconnected, killed or |
| 5 |
# the server kisses it shutdown. |
| 6 |
# The file can be sourced multiple times |
| 7 |
# param $restart_number (as the number of inclusion) adjusts |
| 8 |
# verification logics. |
| 9 |
# |
| 10 |
# param [in] $conn_number Total number of connection each performing |
| 11 |
# one insert into table. |
| 12 |
# param [in] $commit_number Number of commits from either. |
| 13 |
# side of the server restart. |
| 14 |
# param [in] $rollback_number The same as the above just for rollback. |
| 15 |
# param [in] $term_number Number of transaction that are terminated |
| 16 |
# before server restarts |
| 17 |
# param [in] $killed_number Instead of disconnect make some |
| 18 |
# connections killed when their |
| 19 |
# transactions got prepared. |
| 20 |
# param [in] $server_disconn_number Make some connections disconnected |
| 21 |
# by shutdown rather than actively |
| 22 |
# param [in] $post_restart_conn_number Number a "warmup" connection |
| 23 |
# after server restart, they all commit |
| 24 |
# param [out] restart_number Counter to be incremented at the end of the test |
| 25 |
# |
| 26 |
|
| 27 |
# The test consists of three sections: |
| 28 |
# I. Corner cases check |
| 29 |
# II. Regular case check |
| 30 |
# III. Post server-restart verification |
| 31 |
|
| 32 |
|
| 33 |
# |
| 34 |
# I. Corner cases of |
| 35 |
# |
| 36 |
# A. XA with an update to a temp table |
| 37 |
# B. XA with SELECT |
| 38 |
# C. XA empty |
| 39 |
# Demonstrate their XA status upon prepare and how they react on disconnect and |
| 40 |
# shutdown. |
| 41 |
# In each of A,B,C three prepared transactions are set up. |
| 42 |
# trx1 is for disconnection, trx2 for shutdown, trx3 for being killed. |
| 43 |
# The A case additionally contains some XA prohibited state transaction check. |
| 44 |
# |
| 45 |
# D. Prove that not prepared XA remains to be cleared out by disconnection. |
| 46 |
# |
| 47 |
|
| 48 |
# |
| 49 |
# A. The temp table only prepared XA recovers only formally to |
| 50 |
# let post recovery XA COMMIT or XA ROLLBACK with no effect. |
| 51 |
|
| 52 |
--let $type = tmp |
| 53 |
--let $index = 1 |
| 54 |
--let $sql_init1 = SET @@sql_log_bin = OFF |
| 55 |
--let $sql_init2 = CREATE TEMPORARY TABLE tmp$index (a int) ENGINE=innodb |
| 56 |
--let $sql_doit = INSERT INTO tmp$index SET a=$index |
| 57 |
--source suite/binlog/include/binlog_xa_prepare_connection.inc |
| 58 |
|
| 59 |
--let $index = 2 |
| 60 |
--source suite/binlog/include/binlog_xa_prepare_connection.inc |
| 61 |
|
| 62 |
--let $index = 3 |
| 63 |
--source suite/binlog/include/binlog_xa_prepare_connection.inc |
| 64 |
--let $conn3_id=`SELECT connection_id()` |
| 65 |
|
| 66 |
# |
| 67 |
# Various prohibited XA state changes to test here: |
| 68 |
# |
| 69 |
|
| 70 |
--connection default |
| 71 |
# Stealing is not allowed |
| 72 |
--error ER_XAER_NOTA |
| 73 |
--eval XA COMMIT 'trx1$type' |
| 74 |
--error ER_XAER_NOTA |
| 75 |
--eval XA ROLLBACK 'trx1$type' |
| 76 |
|
| 77 |
# Before disconnect: creating a duplicate is not allowed |
| 78 |
--error ER_XAER_DUPID |
| 79 |
--eval XA START 'trx1$type' |
| 80 |
|
| 81 |
# Manipulate now the prepared transactions. |
| 82 |
# Two to terminate, one to leave out. |
| 83 |
--let $terminate_with = XA COMMIT |
| 84 |
--let $num_trx_prepared = $index |
| 85 |
--source suite/binlog/include/binlog_xa_prepare_disconnect.inc |
| 86 |
|
| 87 |
# |
| 88 |
# B. "Read-only" (select) prepared XA recovers only formally to |
| 89 |
# let post recovery XA COMMIT or XA ROLLBACK with no effect. |
| 90 |
# |
| 91 |
--let $type=ro |
| 92 |
--let $index = 1 |
| 93 |
--let $sql_init1 = |
| 94 |
--let $sql_init2 = |
| 95 |
--let $sql_doit = SELECT * from t ORDER BY a |
| 96 |
--source suite/binlog/include/binlog_xa_prepare_connection.inc |
| 97 |
|
| 98 |
--let $index = 2 |
| 99 |
--source suite/binlog/include/binlog_xa_prepare_connection.inc |
| 100 |
|
| 101 |
--let $index = 3 |
| 102 |
--source suite/binlog/include/binlog_xa_prepare_connection.inc |
| 103 |
--let $conn3_id=`SELECT connection_id()` |
| 104 |
|
| 105 |
--let $terminate_with = XA ROLLBACK |
| 106 |
# two three above section prepared transaction were terminated. |
| 107 |
--inc $num_trx_prepared |
| 108 |
--source suite/binlog/include/binlog_xa_prepare_disconnect.inc |
| 109 |
|
| 110 |
# |
| 111 |
# C. Empty prepared XA recovers only formally to |
| 112 |
# let post recovery XA COMMIT or XA ROLLBACK with no effect. |
| 113 |
# |
| 114 |
--let $type=empty |
| 115 |
--let $index = 1 |
| 116 |
--let $sql_init1 = |
| 117 |
--let $sql_init2 = |
| 118 |
--let $sql_doit = |
| 119 |
--source suite/binlog/include/binlog_xa_prepare_connection.inc |
| 120 |
|
| 121 |
--let $index = 2 |
| 122 |
--source suite/binlog/include/binlog_xa_prepare_connection.inc |
| 123 |
|
| 124 |
--let $index = 3 |
| 125 |
--source suite/binlog/include/binlog_xa_prepare_connection.inc |
| 126 |
--let $conn3_id=`SELECT connection_id()` |
| 127 |
|
| 128 |
--let $terminate_with = XA COMMIT |
| 129 |
--inc $num_trx_prepared |
| 130 |
--source suite/binlog/include/binlog_xa_prepare_disconnect.inc |
| 131 |
|
| 132 |
# |
| 133 |
# D. Not prepared XA disconnects to be cleared out, |
| 134 |
# no effect on data left as well. |
| 135 |
# Few more prohibited XA state transactions is checked out. |
| 136 |
# |
| 137 |
--let $type=unprepared |
| 138 |
--let $prev_count=`SELECT count(*) from t` |
| 139 |
|
| 140 |
--connect(conn1$type, 127.0.0.1,root,,test,$MASTER_MYPORT,) |
| 141 |
--eval XA START 'trx1$type' |
| 142 |
INSERT INTO t set a=0; |
| 143 |
--eval XA END 'trx1$type' |
| 144 |
|
| 145 |
--error ER_XAER_RMFAIL |
| 146 |
INSERT INTO t set a=0; |
| 147 |
--error ER_XAER_RMFAIL |
| 148 |
--eval XA START 'trx1$type' |
| 149 |
--error ER_XAER_RMFAIL |
| 150 |
--eval XA START 'trx1$type' |
| 151 |
|
| 152 |
--disconnect conn1$type |
| 153 |
|
| 154 |
--connection default |
| 155 |
# No such transactions |
| 156 |
--error ER_XAER_NOTA |
| 157 |
--eval XA COMMIT 'trx1$type' |
| 158 |
if (`SELECT count(*) > $prev_count from t`) |
| 159 |
{ |
| 160 |
--echo *** Unexpected commit to the table. *** |
| 161 |
--die |
| 162 |
} |
| 163 |
|
| 164 |
# |
| 165 |
# II. Regular case. |
| 166 |
# |
| 167 |
# Prepared transactions get disconnected in three ways: |
| 168 |
# actively, being killed and by the server shutdown. |
| 169 |
# |
| 170 |
--let $i=0 |
| 171 |
while ($i < $conn_number) |
| 172 |
{ |
| 173 |
--connect (conn$i, 127.0.0.1,root,,test,$MASTER_MYPORT,) |
| 174 |
--let $conn_id=`SELECT connection_id()` |
| 175 |
--disable_reconnect |
| 176 |
SET @@binlog_format = STATEMENT; |
| 177 |
if (`SELECT $i % 2`) |
| 178 |
{ |
| 179 |
SET @@binlog_format = ROW; |
| 180 |
} |
| 181 |
--eval XA START 'trx_$i' |
| 182 |
--eval INSERT INTO t SET a=$i |
| 183 |
--eval XA END 'trx_$i' |
| 184 |
--eval XA PREPARE 'trx_$i' |
| 185 |
|
| 186 |
--let $disc_via_kill=`SELECT $conn_number - $i <= $killed_number` |
| 187 |
if (!$disc_via_kill) |
| 188 |
{ |
| 189 |
--let $disc_via_shutdown=`SELECT $conn_number - $i <= $killed_number + $server_disconn_number` |
| 190 |
if (!$disc_via_shutdown) |
| 191 |
{ |
| 192 |
--disconnect conn$i |
| 193 |
} |
| 194 |
} |
| 195 |
if ($disc_via_kill) |
| 196 |
{ |
| 197 |
--connection default |
| 198 |
--replace_result $conn_id CONN_ID |
| 199 |
--eval KILL CONNECTION $conn_id |
| 200 |
} |
| 201 |
|
| 202 |
if (!$disc_via_shutdown) |
| 203 |
{ |
| 204 |
--connection default |
| 205 |
--let $wait_condition= SELECT count(*) = 0 FROM v_processlist WHERE PROCESSLIST_ID = $conn_id |
| 206 |
--source include/wait_condition.inc |
| 207 |
} |
| 208 |
--inc $i |
| 209 |
} |
| 210 |
|
| 211 |
# [0, $rollback_number - 1] are rolled back now |
| 212 |
--connection default |
| 213 |
|
| 214 |
--let $i=0 |
| 215 |
while ($i < $rollback_number) |
| 216 |
{ |
| 217 |
--eval XA ROLLBACK 'trx_$i' |
| 218 |
|
| 219 |
--inc $i |
| 220 |
} |
| 221 |
|
| 222 |
# [$rollback_number, $rollback_number + $commit_number - 1] get committed |
| 223 |
while ($i < $term_number) |
| 224 |
{ |
| 225 |
--eval XA COMMIT 'trx_$i' |
| 226 |
|
| 227 |
--inc $i |
| 228 |
} |
| 229 |
|
| 230 |
--source include/$how_to_restart |
| 231 |
|
| 232 |
# |
| 233 |
# III. Post server-restart verification. |
| 234 |
# It concludes survived XA:s with a number of commits and rollbacks |
| 235 |
# as configured in the 1st part to check expected results in the end. |
| 236 |
# Cleanup section consists of explicit disconnect (for killed, or |
| 237 |
# not disconnected before shutdown). |
| 238 |
# |
| 239 |
|
| 240 |
# New XA can be prepared and committed |
| 241 |
--let $k = 0 |
| 242 |
while ($k < $post_restart_conn_number) |
| 243 |
{ |
| 244 |
--connect (conn_restart_$k, 127.0.0.1,root,,test,$MASTER_MYPORT,) |
| 245 |
--let $conn_id=`SELECT connection_id()` |
| 246 |
--eval XA START 'new_trx_$k' |
| 247 |
--eval INSERT INTO t SET a=$k |
| 248 |
--eval XA END 'new_trx_$k' |
| 249 |
--eval XA PREPARE 'new_trx_$k' |
| 250 |
|
| 251 |
--disconnect conn_restart_$k |
| 252 |
|
| 253 |
--connection default |
| 254 |
--let $wait_condition= SELECT count(*) = 0 FROM v_processlist WHERE PROCESSLIST_ID = $conn_id |
| 255 |
--source include/wait_condition.inc |
| 256 |
|
| 257 |
--inc $k |
| 258 |
} |
| 259 |
|
| 260 |
--connection default |
| 261 |
--let $k = 0 |
| 262 |
while ($k < $post_restart_conn_number) |
| 263 |
{ |
| 264 |
--eval XA COMMIT 'new_trx_$k' |
| 265 |
--inc $k |
| 266 |
} |
| 267 |
|
| 268 |
# |
| 269 |
# Symmetrically to the pre-restart, the resurrected trx:s are committed |
| 270 |
# [$term_number, $term_number + $commit_number - 1] |
| 271 |
# and the rest is rolled back. |
| 272 |
# |
| 273 |
--let $i = $term_number |
| 274 |
|
| 275 |
while ($i < `SELECT $term_number + $commit_number`) |
| 276 |
{ |
| 277 |
# Expected to fail |
| 278 |
--error ER_XAER_DUPID |
| 279 |
--eval XA START 'trx_$i' |
| 280 |
--eval XA COMMIT 'trx_$i' |
| 281 |
--inc $i |
| 282 |
} |
| 283 |
|
| 284 |
while ($i < $conn_number) |
| 285 |
{ |
| 286 |
# Expected to fail |
| 287 |
--error ER_XAER_DUPID |
| 288 |
--eval XA START 'trx_$i' |
| 289 |
--eval XA ROLLBACK 'trx_$i' |
| 290 |
--inc $i |
| 291 |
} |
| 292 |
|
| 293 |
# |
| 294 |
# Verification of correct results of recovered XA transaction handling: |
| 295 |
# |
| 296 |
SELECT * FROM t; |
| 297 |
|
| 298 |
--let $type=tmp |
| 299 |
--disconnect conn2$type |
| 300 |
--disconnect conn3$type |
| 301 |
--let $type=ro |
| 302 |
--disconnect conn2$type |
| 303 |
--disconnect conn3$type |
| 304 |
--let $type=empty |
| 305 |
--disconnect conn2$type |
| 306 |
--disconnect conn3$type |
| 307 |
|
| 308 |
--let $i= $conn_number |
| 309 |
--let $k= 0 |
| 310 |
--let $expl_disconn_number = `SELECT $killed_number + $server_disconn_number` |
| 311 |
while ($k < $expl_disconn_number) |
| 312 |
{ |
| 313 |
--connection default |
| 314 |
--error ER_XAER_NOTA |
| 315 |
--eval XA ROLLBACK 'trx_$i' |
| 316 |
|
| 317 |
--dec $i |
| 318 |
--disconnect conn$i |
| 319 |
|
| 320 |
--inc $k |
| 321 |
} |
| 322 |
|
| 323 |
--inc $restart_number |