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