| 1 |
# ==== Purpose ==== |
| 2 |
# |
| 3 |
# The purpose of this test is to check that crashing the replica while there |
| 4 |
# are several XA transactions executing up until several points of `XA |
| 5 |
# PREPARE/COMMIT/ROLLBACK` statements, will result in consistency between |
| 6 |
# SE and TC after recovery is finished. |
| 7 |
# |
| 8 |
# ==== Requirements ==== |
| 9 |
# |
| 10 |
# R1. When crashing in the middle of an XA transaction and after recovery, |
| 11 |
# storage engine and transaction coordinator MUST be in sync. |
| 12 |
# |
| 13 |
# For a more detailed list of requirements for the expected state for each |
| 14 |
# of the sync points, check the `Requirements` section for the tests listed |
| 15 |
# in `Related tests` section of `extra/xa_crash_safe_tests/setup.inc`. |
| 16 |
# |
| 17 |
# ==== Implementation ==== |
| 18 |
# |
| 19 |
# 1) Execute several `XA PREPARE` statements up until: |
| 20 |
# a) Before preparing in the SEs. |
| 21 |
# b) Before preparing in the TC. |
| 22 |
# c) Before setting the transaction as prepared in TC. |
| 23 |
# d) After writing to the TC log. |
| 24 |
# 2) Kill the replica and restart it. |
| 25 |
# 3) Check that: |
| 26 |
# a) SE recovery rolled back the transaction executed in 1.a) |
| 27 |
# b) XA recovery rolled back the transaction executed in 1.b) |
| 28 |
# c) XA recovery left in prepared state transaction executed in 1.b) and |
| 29 |
# 1.c) |
| 30 |
# 4) Clean up pending transactions |
| 31 |
# 5) Execute several `XA COMMIT` statements up until: |
| 32 |
# a) Before starting the commit process. |
| 33 |
# b) Before invoking the before commit hook. |
| 34 |
# c) Before committing in SEs. |
| 35 |
# 6) Kill the replica and restart it. |
| 36 |
# 7) Check that: |
| 37 |
# a) XA recovery left in prepared state transaction executed in 5.a) and |
| 38 |
# 5.b) |
| 39 |
# b) XA recovery committed the transaction executed in 5.c) |
| 40 |
# 8) Clean up pending transactions |
| 41 |
# 9) Execute several `XA ROLLBACK` statements up until: |
| 42 |
# a) Before starting the rollback process. |
| 43 |
# b) Before invoking the before commit hook. |
| 44 |
# c) Before rolling back in SEs. |
| 45 |
# 10) Kill the replica and restart it. |
| 46 |
# 11) Check that: |
| 47 |
# a) XA recovery left in prepared state transaction executed in 9.a) and |
| 48 |
# 9.b) |
| 49 |
# b) XA recovery rlled back the transaction executed in 9.c) |
| 50 |
# 12) Clean up pending transactions |
| 51 |
# 13) Execute several `XA COMMIT ... ONE PHASE` statements up until: |
| 52 |
# a) Before preparing in SEs. |
| 53 |
# b) Before invoking the before commit hook. |
| 54 |
# c) Before committing in SEs. |
| 55 |
# 14) Kill the replica and restart it. |
| 56 |
# 15) Check that: |
| 57 |
# a) SE recovery rolled back the transaction executed in 13.a) |
| 58 |
# b) XA recovery rolled back the transaction executed in 13.b) |
| 59 |
# c) XA recovery committed transaction executed in 13.c) |
| 60 |
# |
| 61 |
# ==== References ==== |
| 62 |
# |
| 63 |
# WL#11300: Crash-safe XA + binary log |
| 64 |
# |
| 65 |
# Related tests; |
| 66 |
# see extra/xa_crash_safe_tests/setup.inc |
| 67 |
# |
| 68 |
--source include/have_binlog_format_row.inc |
| 69 |
--source include/not_valgrind.inc |
| 70 |
--source include/have_debug.inc |
| 71 |
--source include/have_debug_sync.inc |
| 72 |
--let $option_name = replica_parallel_type |
| 73 |
--let $option_value = 'LOGICAL_CLOCK' |
| 74 |
--source include/only_with_option.inc |
| 75 |
--let $option_name = replica_parallel_workers |
| 76 |
--let $option_operator = != |
| 77 |
--let $option_value = 0 |
| 78 |
--source include/only_with_option.inc |
| 79 |
# Sync point `after_writing_to_tc_log` only exercised when BCG is enabled |
| 80 |
--let $option_name = binlog_order_commits |
| 81 |
--let $option_value = 1 |
| 82 |
--source include/only_with_option.inc |
| 83 |
--let $rpl_skip_start_slave = 1 |
| 84 |
--source include/master-slave.inc |
| 85 |
--let $rpl_skip_start_slave = |
| 86 |
|
| 87 |
--source include/rpl_connection_slave.inc |
| 88 |
let $sysvars_to_save = [ |
| 89 |
"GLOBAL.replica_preserve_commit_order", |
| 90 |
"GLOBAL.replica_parallel_workers" |
| 91 |
]; |
| 92 |
--source include/save_sysvars.inc |
| 93 |
SET @@GLOBAL.replica_preserve_commit_order = 0; |
| 94 |
SET @@GLOBAL.replica_parallel_workers = 4; |
| 95 |
--source include/start_slave.inc |
| 96 |
|
| 97 |
--source include/rpl_connection_master.inc |
| 98 |
--let $xid = 'xid0' |
| 99 |
--source extra/xa_crash_safe_tests/setup.inc |
| 100 |
# Include $exec_xa_transaction_body and $clean_up_xa_transactions |
| 101 |
--source extra/xa_crash_safe_tests/utility_functions.inc |
| 102 |
|
| 103 |
# 1) Execute several `XA PREPARE` statements up until: |
| 104 |
--let $debug_point = set_commit_parent_100 |
| 105 |
--source include/add_debug_point.inc |
| 106 |
--let $iteration = 1 |
| 107 |
while ($iteration != 5) { |
| 108 |
--source $exec_xa_transaction_body |
| 109 |
--let $timestamp = $iteration |
| 110 |
--let $auxiliary_connection = slave |
| 111 |
--let $statement_connection = con$iteration |
| 112 |
--let $statement = XA PREPARE $xid |
| 113 |
# 1.a) Before preparing in the SEs. |
| 114 |
if ($iteration == 1) { |
| 115 |
--let $sync_point = before_prepare_in_engines |
| 116 |
} |
| 117 |
# 1.b) Before preparing in the TC. |
| 118 |
if ($iteration == 2) { |
| 119 |
--let $sync_point = after_ha_prepare_low |
| 120 |
} |
| 121 |
# 1.c) Before setting the transaction as prepared in TC. |
| 122 |
|
| 123 |
if ($iteration == 3) { |
| 124 |
--let $sync_point = before_set_prepared_in_tc |
| 125 |
} |
| 126 |
# 1.d) After writing to the TC log. |
| 127 |
# |
| 128 |
if ($iteration == 4) { |
| 129 |
--let $sync_point = after_writing_to_tc_log |
| 130 |
} |
| 131 |
--source include/execute_to_conditional_timestamp_sync_point.inc |
| 132 |
--disconnect con$iteration |
| 133 |
--inc $iteration |
| 134 |
} |
| 135 |
|
| 136 |
# 2) Kill the server and restart it. |
| 137 |
--source include/rpl_connection_slave.inc |
| 138 |
--source include/kill_mysqld.inc |
| 139 |
--let $restart_parameters=restart:--replica-preserve-commit-order=0 |
| 140 |
--source include/start_mysqld.inc |
| 141 |
--source include/rpl_reconnect.inc |
| 142 |
|
| 143 |
# 3) Check that: |
| 144 |
# 3.a) SE recovery rolled back the transaction executed in 1.a) |
| 145 |
# |
| 146 |
--let $assert_select = Rolling back trx with id %, 1 rows to undo |
| 147 |
--source extra/xa_crash_safe_tests/assert_se_recovery_message.inc |
| 148 |
|
| 149 |
# 3.b) XA recovery rolled back the transaction executed in 1.b) |
| 150 |
# 3.c) XA recovery left in prepared state transaction executed in 1.b) and |
| 151 |
# 1.c) |
| 152 |
--let $assert_select = Successfully rolled back 1, prepared 2 XA transaction |
| 153 |
--source extra/xa_crash_safe_tests/assert_recovery_message.inc |
| 154 |
--let $expected_prepared_xa_count = 2 |
| 155 |
--source extra/xa_crash_safe_tests/assert_xa_recover.inc |
| 156 |
|
| 157 |
# 4) Clean up pending transactions |
| 158 |
# |
| 159 |
--source include/start_slave.inc |
| 160 |
--source include/rpl_connection_master.inc |
| 161 |
--source include/sync_slave_sql_with_master.inc |
| 162 |
--source include/rpl_connection_master.inc |
| 163 |
--let $start = 1 |
| 164 |
--let $stop = 5 |
| 165 |
--source $clean_up_xa_transactions |
| 166 |
--source include/sync_slave_sql_with_master.inc |
| 167 |
|
| 168 |
# 5) Execute several `XA COMMIT` statements up until: |
| 169 |
# |
| 170 |
--source include/rpl_connection_master.inc |
| 171 |
while ($iteration != 8) { |
| 172 |
--source $exec_xa_transaction_body |
| 173 |
--eval XA PREPARE $xid |
| 174 |
--inc $iteration |
| 175 |
} |
| 176 |
--source include/sync_slave_sql_with_master.inc |
| 177 |
--let $iteration = 5 |
| 178 |
while ($iteration != 8) { |
| 179 |
--let $xid = 'xid$iteration' |
| 180 |
--let $timestamp = $iteration |
| 181 |
--let $auxiliary_connection = slave |
| 182 |
--let $statement_connection = con$iteration |
| 183 |
--let $statement = XA COMMIT $xid |
| 184 |
# 5.a) Before starting the commit process. |
| 185 |
# |
| 186 |
if ($iteration == 5) { |
| 187 |
--let $sync_point = before_commit_xa_trx |
| 188 |
} |
| 189 |
# 5.b) Before invoking the before commit hook. |
| 190 |
# |
| 191 |
if ($iteration == 6) { |
| 192 |
--let $sync_point = before_invoke_before_commit_hook |
| 193 |
} |
| 194 |
# 5.c) Before committing in SEs. |
| 195 |
# |
| 196 |
if ($iteration == 7) { |
| 197 |
--let $sync_point = before_commit_in_engines |
| 198 |
} |
| 199 |
--source include/execute_to_conditional_timestamp_sync_point.inc |
| 200 |
--disconnect con$iteration |
| 201 |
--inc $iteration |
| 202 |
} |
| 203 |
|
| 204 |
# 6) Kill the server and restart it. |
| 205 |
# |
| 206 |
--source include/rpl_connection_slave.inc |
| 207 |
--source include/kill_mysqld.inc |
| 208 |
--let $restart_parameters=restart:--replica-preserve-commit-order=0 |
| 209 |
--source include/start_mysqld.inc |
| 210 |
--source include/rpl_reconnect.inc |
| 211 |
|
| 212 |
# 7) Check that: |
| 213 |
# 7.a) XA recovery left in prepared state transaction executed in 5.a) and |
| 214 |
# 5.b) |
| 215 |
# 7.b) XA recovery committed the transaction executed in 5.c) |
| 216 |
# |
| 217 |
--let $assert_select = Successfully committed 1, prepared 2 XA transaction |
| 218 |
--source extra/xa_crash_safe_tests/assert_recovery_message.inc |
| 219 |
--let $expected_prepared_xa_count = 2 |
| 220 |
--source extra/xa_crash_safe_tests/assert_xa_recover.inc |
| 221 |
|
| 222 |
# 8) Clean up pending transactions |
| 223 |
# |
| 224 |
--source include/start_slave.inc |
| 225 |
--source include/rpl_connection_master.inc |
| 226 |
--source include/sync_slave_sql_with_master.inc |
| 227 |
|
| 228 |
# 9) Execute several `XA ROLLBACK` statements up until: |
| 229 |
# |
| 230 |
while ($iteration != 11) { |
| 231 |
--source $exec_xa_transaction_body |
| 232 |
--eval XA PREPARE $xid |
| 233 |
--inc $iteration |
| 234 |
} |
| 235 |
--source include/sync_slave_sql_with_master.inc |
| 236 |
--let $iteration = 8 |
| 237 |
while ($iteration != 11) { |
| 238 |
--let $xid = 'xid$iteration' |
| 239 |
--let $timestamp = $iteration |
| 240 |
--let $auxiliary_connection = slave |
| 241 |
--let $statement_connection = con$iteration |
| 242 |
--let $statement = XA ROLLBACK $xid |
| 243 |
# 9.a) Before starting the rollback process. |
| 244 |
# |
| 245 |
if ($iteration == 8) { |
| 246 |
--let $sync_point = before_rollback_xa_trx |
| 247 |
} |
| 248 |
# 9.b) Before invoking the before commit hook. |
| 249 |
# |
| 250 |
if ($iteration == 9) { |
| 251 |
--let $sync_point = before_invoke_before_commit_hook |
| 252 |
} |
| 253 |
# 9.c) Before rolling back in SEs. |
| 254 |
# |
| 255 |
if ($iteration == 10) { |
| 256 |
--let $sync_point = before_rollback_in_engines |
| 257 |
} |
| 258 |
--source include/execute_to_conditional_timestamp_sync_point.inc |
| 259 |
--disconnect con$iteration |
| 260 |
--inc $iteration |
| 261 |
} |
| 262 |
|
| 263 |
# 10) Kill the server and restart it. |
| 264 |
# |
| 265 |
--source include/rpl_connection_slave.inc |
| 266 |
--source include/kill_mysqld.inc |
| 267 |
--let $restart_parameters=restart:--replica-preserve-commit-order=0 |
| 268 |
--source include/start_mysqld.inc |
| 269 |
--source include/rpl_reconnect.inc |
| 270 |
|
| 271 |
# 11) Check that: |
| 272 |
# 11.a) XA recovery left in prepared state transaction executed in 9.a) and |
| 273 |
# 9.b) |
| 274 |
# 11.b) XA recovery rlled back the transaction executed in 9.c) |
| 275 |
# |
| 276 |
--let $assert_select = Successfully rolled back 1, prepared 2 XA transaction |
| 277 |
--source extra/xa_crash_safe_tests/assert_recovery_message.inc |
| 278 |
--let $expected_prepared_xa_count = 2 |
| 279 |
--source extra/xa_crash_safe_tests/assert_xa_recover.inc |
| 280 |
|
| 281 |
# 12) Clean up pending transactions |
| 282 |
# |
| 283 |
--source include/start_slave.inc |
| 284 |
--source include/rpl_connection_master.inc |
| 285 |
# First event after replica start is executed by the coordinator thread, |
| 286 |
# force it |
| 287 |
UPDATE t1 SET c1 = 200 WHERE c1 = 2; |
| 288 |
--source include/sync_slave_sql_with_master.inc |
| 289 |
|
| 290 |
# 13) Execute several `XA COMMIT ... ONE PHASE` statements up until: |
| 291 |
# |
| 292 |
while ($iteration != 14) { |
| 293 |
--source $exec_xa_transaction_body |
| 294 |
--let $timestamp = $iteration |
| 295 |
--let $auxiliary_connection = slave |
| 296 |
--let $statement_connection = con$iteration |
| 297 |
--let $statement = XA COMMIT $xid ONE PHASE |
| 298 |
# 13.a) Before preparing in SEs. |
| 299 |
# |
| 300 |
if ($iteration == 11) { |
| 301 |
--let $sync_point = before_prepare_in_engines |
| 302 |
} |
| 303 |
# 13.b) Before invoking the before commit hook. |
| 304 |
# |
| 305 |
if ($iteration == 12) { |
| 306 |
--let $sync_point = before_invoke_before_commit_hook |
| 307 |
} |
| 308 |
# 13.c) Before committing in SEs. |
| 309 |
# |
| 310 |
if ($iteration == 13) { |
| 311 |
--let $sync_point = before_commit_in_engines |
| 312 |
} |
| 313 |
--source include/execute_to_conditional_timestamp_sync_point.inc |
| 314 |
--disconnect con$iteration |
| 315 |
--inc $iteration |
| 316 |
} |
| 317 |
|
| 318 |
# 14) Kill the server and restart it. |
| 319 |
# |
| 320 |
--source include/rpl_connection_slave.inc |
| 321 |
--source include/kill_mysqld.inc |
| 322 |
--let $restart_parameters=restart:--replica-preserve-commit-order=0 |
| 323 |
--source include/start_mysqld.inc |
| 324 |
--source include/rpl_reconnect.inc |
| 325 |
|
| 326 |
# 15) Check that: |
| 327 |
# |
| 328 |
# 15.a) SE recovery rolled back the transaction executed in 13.a) |
| 329 |
# |
| 330 |
--let $assert_select = Rolling back trx with id %, 1 rows to undo |
| 331 |
--source extra/xa_crash_safe_tests/assert_se_recovery_message.inc |
| 332 |
|
| 333 |
# 15.b) XA recovery rolled back the transaction executed in 13.b) |
| 334 |
# 15.c) XA recovery committed transaction executed in 13.c) |
| 335 |
# |
| 336 |
--let $assert_select = Successfully committed 1, rolled back 1 XA transaction |
| 337 |
--source extra/xa_crash_safe_tests/assert_recovery_message.inc |
| 338 |
--let $expected_prepared_xa_count = 0 |
| 339 |
--source extra/xa_crash_safe_tests/assert_xa_recover.inc |
| 340 |
|
| 341 |
--source include/restore_sysvars.inc |
| 342 |
--source include/start_slave.inc |
| 343 |
|
| 344 |
--source include/rpl_connection_master.inc |
| 345 |
--let $debug_point = set_commit_parent_100 |
| 346 |
--source include/remove_debug_point.inc |
| 347 |
DROP TABLE t1; |
| 348 |
--source extra/xa_crash_safe_tests/end_utility_functions.inc |
| 349 |
--source include/rpl_end.inc |