| 1 |
# ==== Purpose ==== |
| 2 |
# |
| 3 |
# Used by scripts testing XA crash recovery, it provides functions to be |
| 4 |
# used with testing of crashes while executing XA transactions. |
| 5 |
# |
| 6 |
# ==== Parameters ==== |
| 7 |
# |
| 8 |
# Check each function description. |
| 9 |
# |
| 10 |
# ==== References ==== |
| 11 |
# |
| 12 |
# WL#11300: Crash-safe XA + binary log |
| 13 |
# |
| 14 |
# Related tests; |
| 15 |
# see extra/xa_crash_safe_tests/setup.inc |
| 16 |
# |
| 17 |
|
| 18 |
# The value for the table column, it will be incremented with each call to |
| 19 |
# $exec_xa_transaction_body |
| 20 |
# |
| 21 |
--let $value_to_insert = 3 |
| 22 |
|
| 23 |
# ==== Purpose ==== |
| 24 |
# |
| 25 |
# Executes an XA transaction up until after `XA END`. The XID and the |
| 26 |
# connection used to execute the XA statements are dependent of the |
| 27 |
# `$iteration` parameter, which will be used as a suffix for both. |
| 28 |
# |
| 29 |
# ==== Usage ==== |
| 30 |
# |
| 31 |
# --let $iteration = [NUMBER] |
| 32 |
# [--let $skip_init_connection = 0|1] |
| 33 |
# --source $exec_xa_transaction_body |
| 34 |
# |
| 35 |
# $iteration |
| 36 |
# Counter for the execution iteration step the caller is at. It will be |
| 37 |
# used as a suffix for both the XID and the connection on which the XA |
| 38 |
# transaction is executed |
| 39 |
# |
| 40 |
# $skip_init_connection |
| 41 |
# Whether or not the conenction should be initialized. It's 0 by default. |
| 42 |
# |
| 43 |
--let $exec_xa_transaction_body = $MYSQLTEST_VARDIR/tmp/xa_crash_safe_tests_exec_xa_for_sync_point.inc |
| 44 |
--write_file $exec_xa_transaction_body PROCEDURE |
| 45 |
if ($iteration == '') { |
| 46 |
--die ERROR: function $exec_xa_transaction_body needs 'interation' parameter |
| 47 |
} |
| 48 |
--let $init_connection = 1 |
| 49 |
if ($skip_init_connection == 1) { |
| 50 |
--let $init_connection = 0 |
| 51 |
} |
| 52 |
if ($init_connection == 1) { |
| 53 |
--connect(con$iteration, localhost, root,,) |
| 54 |
} |
| 55 |
--connection con$iteration |
| 56 |
--let $xid = 'xid$iteration' |
| 57 |
--eval XA START $xid |
| 58 |
--eval INSERT INTO t1 VALUES ($value_to_insert) |
| 59 |
--eval XA END $xid |
| 60 |
--inc $value_to_insert |
| 61 |
#END OF |
| 62 |
PROCEDURE |
| 63 |
|
| 64 |
# ==== Purpose ==== |
| 65 |
# |
| 66 |
# Rolls back XA transactions for which XID data is 'xid$suffix' and $start |
| 67 |
# <= $suffix < $end. |
| 68 |
# |
| 69 |
# ==== Usage ==== |
| 70 |
# |
| 71 |
# --let $start = [NUMBER] |
| 72 |
# --let $end = [NUMBER] |
| 73 |
# --source $clean_up_xa_transactions |
| 74 |
# |
| 75 |
# $start |
| 76 |
# The integer value to start iterating from, while adding it as the |
| 77 |
# suffix of the XID to be rolled back. |
| 78 |
# |
| 79 |
# $end |
| 80 |
# The integer value to stop iterating at, while adding it as the suffix |
| 81 |
# of the XID to be rolled back. |
| 82 |
# |
| 83 |
--let $clean_up_xa_transactions = $MYSQLTEST_VARDIR/tmp/xa_crash_safe_tests_clean_up_xa_transactions.inc |
| 84 |
--write_file $clean_up_xa_transactions PROCEDURE |
| 85 |
if ($start == '') { |
| 86 |
--die ERROR: function $clean_up_xa_transactions needs 'start' index parameter |
| 87 |
} |
| 88 |
if ($stop == '') { |
| 89 |
--die ERROR: function $clean_up_xa_transactions needs 'stop' index parameter |
| 90 |
} |
| 91 |
--let $m = $start |
| 92 |
while ($m != $stop) { |
| 93 |
--let $xid = 'xid$m' |
| 94 |
--eval XA ROLLBACK $xid |
| 95 |
--inc $m |
| 96 |
} |
| 97 |
#END OF |
| 98 |
PROCEDURE |
| 99 |
|
| 100 |
# ==== Purpose ==== |
| 101 |
# |
| 102 |
# Tests that the server behaves as expected and outputs the expected error |
| 103 |
# messages when an error is returned by SEs while processing normal |
| 104 |
# transactions, during the server recovery. |
| 105 |
# |
| 106 |
# ==== Implementation ==== |
| 107 |
# |
| 108 |
# Repeat for every possible error returned by SE during recovery: |
| 109 |
# 1. Start a transaction. |
| 110 |
# 2. Setup a conditional sync point for timestamp for the `COMMIT` |
| 111 |
# statement and execute up until that sync point. |
| 112 |
# 3. Kill the server. |
| 113 |
# 4. Restart server passing debug symbols that will simulate SEs returning |
| 114 |
# a given error and expect crash during start. |
| 115 |
# 5. Find in the server log the error message corresponding to the |
| 116 |
# simulated error. |
| 117 |
# 6. Restart the server without the debug symbols. |
| 118 |
# |
| 119 |
# ==== Usage ==== |
| 120 |
# |
| 121 |
# --let $action = <commit|rollback> |
| 122 |
# --let $sync_point = STRING |
| 123 |
# --let $xa_errors = JSON_ARRAY |
| 124 |
# --let $nth_iteration = INT |
| 125 |
# --source $error_on_recovery_for_normal_transaction |
| 126 |
# |
| 127 |
# $action |
| 128 |
# The action being taken when the server crashes. |
| 129 |
# |
| 130 |
# $sync_point |
| 131 |
# The conditional sync point for timestamps to setup, for the server to |
| 132 |
# pause at, before being killed. |
| 133 |
# |
| 134 |
# $xa_errors |
| 135 |
# The list of possible XA errors returned by SEs during transaction |
| 136 |
# recovery. |
| 137 |
# |
| 138 |
# $nth_iteration |
| 139 |
# The nth iteration over testing scenarios, used to insert different |
| 140 |
# values on the test table. |
| 141 |
# |
| 142 |
--let $error_on_recovery_for_normal_transaction = $MYSQLTEST_VARDIR/tmp/xa_crash_safe_tests_error_on_recovery_for_normal_transaction.inc |
| 143 |
--write_file $error_on_recovery_for_normal_transaction PROCEDURE |
| 144 |
if ($action == '') { |
| 145 |
--die ERROR: function $error_on_recovery_for_normal_transaction needs 'action' parameter with possible values [commit|rollback] |
| 146 |
} |
| 147 |
if ($sync_point == '') { |
| 148 |
--die ERROR: function $error_on_recovery_for_normal_transaction needs 'sync_point' parameter |
| 149 |
} |
| 150 |
if ($xa_errors == '') { |
| 151 |
--die ERROR: function $error_on_recovery_for_normal_transaction needs 'xa_errors' list of errors parameter |
| 152 |
} |
| 153 |
if ($nth_iteration == '') { |
| 154 |
--die ERROR: function $error_on_recovery_for_normal_transaction needs 'k' index parameter |
| 155 |
} |
| 156 |
|
| 157 |
--let $json_array = $xa_errors |
| 158 |
--source $json_xa_error_list_start |
| 159 |
while (!$json_xa_error_list_done) { |
| 160 |
--let $xa_error = $json_xa_error_list_value |
| 161 |
--let $xa_error_lc = `SELECT LOWER("$xa_error")` |
| 162 |
|
| 163 |
--connect(con1, localhost, root,,) |
| 164 |
--connection con1 |
| 165 |
|
| 166 |
--eval BEGIN; INSERT INTO t1 VALUES ($nth_iteration) |
| 167 |
|
| 168 |
--let $auxiliary_connection = default |
| 169 |
--let $statement_connection = con1 |
| 170 |
--let $statement = COMMIT |
| 171 |
--source include/execute_to_conditional_timestamp_sync_point.inc |
| 172 |
--source include/kill_mysqld.inc |
| 173 |
--source extra/xa_crash_safe_tests/cleanup_connection.inc |
| 174 |
|
| 175 |
--let $debug_point = xa_recovery_error_$xa_error_lc,xa_recovery_error_reporting |
| 176 |
--let $restart_parameters=--debug=+d,$debug_point |
| 177 |
--source include/start_mysqld_expecting_crash.inc |
| 178 |
|
| 179 |
--let $grep_file = $MYSQLTEST_VARDIR/log/mysqld.1.err |
| 180 |
--let $grep_pattern = .*Failed to $action transaction .* in InnoDB, with failure code $xa_error.* |
| 181 |
--source include/wait_for_pattern_in_file.inc |
| 182 |
|
| 183 |
--let $restart_parameters = restart: |
| 184 |
--source include/start_mysqld.inc |
| 185 |
|
| 186 |
--inc $nth_iteration |
| 187 |
--source $json_xa_error_list_next |
| 188 |
} |
| 189 |
#END OF |
| 190 |
PROCEDURE |
| 191 |
|
| 192 |
# ==== Purpose ==== |
| 193 |
# |
| 194 |
# Tests that the server behaves as expected and outputs the expected error |
| 195 |
# messages when an error is returned by SEs while processing XA |
| 196 |
# transactions, during the server recovery. |
| 197 |
# |
| 198 |
# ==== Implementation ==== |
| 199 |
# |
| 200 |
# Repeat for every possible error returned by SE during recovery: |
| 201 |
# 1. Start a transaction. |
| 202 |
# 2. Setup a conditional sync point for timestamp for the statement |
| 203 |
# associated with the provided `$action` and execute up until that sync |
| 204 |
# point. |
| 205 |
# 3. Kill the server. |
| 206 |
# 4. Restart server passing debug symbols that will simulate SEs returning |
| 207 |
# a given error and expect crash during start. |
| 208 |
# 5. Find in the server log the error message corresponding to the |
| 209 |
# simulated error. |
| 210 |
# 6. Restart the server without the debug symbols. |
| 211 |
# |
| 212 |
# ==== Usage ==== |
| 213 |
# |
| 214 |
# --let $action = <prepare|commit|rollback> |
| 215 |
# --let $sync_point = STRING |
| 216 |
# --let $xa_errors = JSON_ARRAY |
| 217 |
# --let $nth_iteration = INT |
| 218 |
# [--let $xa_opt = one phase] |
| 219 |
# [--let $expected_recovery = <none|prepare|commit|rollback>] |
| 220 |
# --source $error_on_recovery_for_normal_transaction |
| 221 |
# |
| 222 |
# $action |
| 223 |
# The action being taken when the server crashes. |
| 224 |
# |
| 225 |
# $sync_point |
| 226 |
# The conditional sync point for timestamps to setup, for the server to |
| 227 |
# pause at, before being killed. |
| 228 |
# |
| 229 |
# $xa_errors |
| 230 |
# The list of possible XA errors returned by SEs during transaction |
| 231 |
# recovery. |
| 232 |
# |
| 233 |
# $nth_iteration |
| 234 |
# The nth iteration over testing scenarios, used to insert different |
| 235 |
# values on the test table and to generate different XIDs. |
| 236 |
# |
| 237 |
# $xa_opt |
| 238 |
# Optional parameter for the `XA COMMIT` statement (one phase). |
| 239 |
# |
| 240 |
# $expected_recovery |
| 241 |
# Optional parameter for when the expected state after recovery is |
| 242 |
# different from the performed action: |
| 243 |
# - none: no action was attempted at recovery and no transaction |
| 244 |
# needing recovery was found. |
| 245 |
# - prepare: recovery should've attempted to prepare the transaction. |
| 246 |
# - commit: recovery should've attempted to commit the transaction. |
| 247 |
# - rollback: recovery should've attempted to rollback the transaction. |
| 248 |
# |
| 249 |
--let $error_on_recovery_for_xa_transaction = $MYSQLTEST_VARDIR/tmp/xa_crash_safe_tests_error_on_recovery_for_xa_transaction.inc |
| 250 |
--write_file $error_on_recovery_for_xa_transaction PROCEDURE |
| 251 |
if ($action == '') { |
| 252 |
--die ERROR: function $error_on_recovery_for_xa_transaction needs 'action' parameter with possible values [prepare|commit|rollback] |
| 253 |
} |
| 254 |
if ($sync_point == '') { |
| 255 |
--die ERROR: function $error_on_recovery_for_xa_transaction needs 'sync_point' parameter |
| 256 |
} |
| 257 |
if ($xa_errors == '') { |
| 258 |
--die ERROR: function $error_on_recovery_for_xa_transaction needs 'xa_errors' list of errors parameter |
| 259 |
} |
| 260 |
if ($nth_iteration == '') { |
| 261 |
--die ERROR: function $error_on_recovery_for_xa_transaction needs 'k' index parameter |
| 262 |
} |
| 263 |
--let $_expected_recovery = $action |
| 264 |
if ($expected_recovery != '') { |
| 265 |
--let $_expected_recovery = $expected_recovery |
| 266 |
} |
| 267 |
|
| 268 |
--let $json_array = $xa_errors |
| 269 |
--source $json_xa_error_list_start |
| 270 |
while (!$json_xa_error_list_done) { |
| 271 |
--let $xa_error = $json_xa_error_list_value |
| 272 |
--let $xa_error_lc = `SELECT LOWER("$xa_error")` |
| 273 |
|
| 274 |
--connect(con1, localhost, root,,) |
| 275 |
--connection con1 |
| 276 |
|
| 277 |
--let $xid = `SELECT CONCAT("X'", LOWER(HEX('blxre$nth_iteration')), "',X'',1")` |
| 278 |
--eval XA START $xid |
| 279 |
--eval INSERT INTO t1 VALUES ($nth_iteration) |
| 280 |
--eval XA END $xid |
| 281 |
if (`SELECT '$action' <> 'prepare' AND '$xa_opt' <> 'one phase'`) { |
| 282 |
--eval XA PREPARE $xid |
| 283 |
} |
| 284 |
|
| 285 |
--let $auxiliary_connection = default |
| 286 |
--let $statement_connection = con1 |
| 287 |
--let $statement = XA $action $xid $xa_opt |
| 288 |
--source include/execute_to_conditional_timestamp_sync_point.inc |
| 289 |
--source include/kill_mysqld.inc |
| 290 |
--source extra/xa_crash_safe_tests/cleanup_connection.inc |
| 291 |
|
| 292 |
--let $debug_point = xa_recovery_error_$xa_error_lc,xa_recovery_error_reporting |
| 293 |
--let $restart_parameters=--debug=+d,$debug_point |
| 294 |
--source include/start_mysqld_expecting_crash.inc |
| 295 |
|
| 296 |
if ($_expected_recovery != 'none') { |
| 297 |
--let $grep_file = $MYSQLTEST_VARDIR/log/mysqld.1.err |
| 298 |
--let $grep_pattern = .*Failed to $_expected_recovery XA transaction $xid in InnoDB, with failure code $xa_error.* |
| 299 |
--source include/wait_for_pattern_in_file.inc |
| 300 |
} |
| 301 |
|
| 302 |
--let $restart_parameters = |
| 303 |
--source include/start_mysqld.inc |
| 304 |
|
| 305 |
if (`SELECT ('$action' = 'prepare' OR '$action' = 'commit') AND '$_expected_recovery' = 'prepare'`) { |
| 306 |
--eval XA COMMIT $xid |
| 307 |
} |
| 308 |
if (`SELECT '$action' = 'rollback' AND '$_expected_recovery' = 'prepare'`) { |
| 309 |
--eval XA ROLLBACK $xid |
| 310 |
} |
| 311 |
if ($_expected_recovery == 'none') { |
| 312 |
--let $expected_prepared_xa_count = 0 |
| 313 |
--source extra/xa_crash_safe_tests/assert_xa_recover.inc |
| 314 |
} |
| 315 |
|
| 316 |
--inc $nth_iteration |
| 317 |
--source $json_xa_error_list_next |
| 318 |
} |
| 319 |
#END OF |
| 320 |
PROCEDURE |