| 1 |
# |
| 2 |
# When handling the replication of an XA PREPARE, the commit phase is |
| 3 |
# bifurcated. First, the prepare is handled by the relevant storage engines. |
| 4 |
# Then second,the GTID slave state is updated as a separate autocommit |
| 5 |
# transaction. If the second stage fails, i.e. we are unable to update the |
| 6 |
# GTID slave state, then the slave should immediately quit in error, without |
| 7 |
# retry. |
| 8 |
# |
| 9 |
# This tests validates the above behavior by forcing a lock-wait timeout on |
| 10 |
# the GTID slave state table during the second part of XA PREPARE's commit, to |
| 11 |
# ensure that the appropriate error is reported and the transaction was never |
| 12 |
# retried. |
| 13 |
# |
| 14 |
# |
| 15 |
# References |
| 16 |
# MDEV-31038: Parallel Replication Breaks if XA PREPARE Fails Updating Slave |
| 17 |
# GTID State |
| 18 |
# |
| 19 |
source include/master-slave.inc; |
| 20 |
source include/have_binlog_format_row.inc; |
| 21 |
source include/have_innodb.inc; |
| 22 |
|
| 23 |
--connection slave |
| 24 |
--source include/stop_slave.inc |
| 25 |
|
| 26 |
set @save_par_thds= @@global.slave_parallel_threads; |
| 27 |
set @save_strict_mode= @@global.gtid_strict_mode; |
| 28 |
set @save_innodb_lock_wait_timeout= @@global.innodb_lock_wait_timeout; |
| 29 |
|
| 30 |
change master to master_use_gtid=slave_pos; |
| 31 |
set @@global.slave_parallel_threads= 4; |
| 32 |
set @@global.slave_parallel_mode= optimistic; |
| 33 |
set @@global.gtid_strict_mode=ON; |
| 34 |
|
| 35 |
set statement sql_log_bin=0 for alter table mysql.gtid_slave_pos engine=innodb; |
| 36 |
--source include/start_slave.inc |
| 37 |
|
| 38 |
--connection master |
| 39 |
create table t1 (a int primary key, b int) engine=innodb; |
| 40 |
insert t1 values (1,1); |
| 41 |
--source include/save_master_gtid.inc |
| 42 |
|
| 43 |
--connection slave |
| 44 |
--source include/sync_with_master_gtid.inc |
| 45 |
--source include/stop_slave.inc |
| 46 |
set @@global.innodb_lock_wait_timeout= 1; |
| 47 |
|
| 48 |
--let $retried_tx_initial= query_get_value(SHOW ALL SLAVES STATUS, Retried_transactions, 1) |
| 49 |
|
| 50 |
--connection master |
| 51 |
--let $gtid_domain_id=`SELECT @@GLOBAL.gtid_domain_id` |
| 52 |
--let $gtid_server_id=`SELECT @@GLOBAL.server_id` |
| 53 |
--let $xap_seq_no=100 |
| 54 |
--eval set @@session.gtid_seq_no=$xap_seq_no |
| 55 |
xa start '1'; |
| 56 |
update t1 set b=b+10 where a=1; |
| 57 |
xa end '1'; |
| 58 |
xa prepare '1'; |
| 59 |
--let $new_gtid= `SELECT @@global.gtid_binlog_pos` |
| 60 |
xa commit '1'; |
| 61 |
--source include/save_master_gtid.inc |
| 62 |
|
| 63 |
--connection slave1 |
| 64 |
BEGIN; |
| 65 |
--eval SELECT * FROM mysql.gtid_slave_pos WHERE seq_no=$xap_seq_no FOR UPDATE |
| 66 |
|
| 67 |
--connection slave |
| 68 |
--source include/start_slave.inc |
| 69 |
|
| 70 |
--let $slave_sql_errno= 1942 |
| 71 |
--source include/wait_for_slave_sql_error.inc |
| 72 |
|
| 73 |
# TODO: Remove after fixing MDEV-21777 |
| 74 |
# Stop the IO thread too, so the existing relay logs are force purged on slave |
| 75 |
# restart, as to not re-execute the already-prepared transaction |
| 76 |
--source include/stop_slave_io.inc |
| 77 |
|
| 78 |
--let $retried_tx_test= query_get_value(SHOW ALL SLAVES STATUS, Retried_transactions, 1) |
| 79 |
if ($retried_tx_initial != $retried_tx_test) |
| 80 |
{ |
| 81 |
--echo Transaction was retried when a failed XA PREPARE slave GTID update should lead to immediate slave stop without retry |
| 82 |
--die Transaction was retried when a failed XA PREPARE slave GTID update should lead to immediate slave stop without retry |
| 83 |
} |
| 84 |
|
| 85 |
--connection slave1 |
| 86 |
ROLLBACK; |
| 87 |
|
| 88 |
--echo # Cleanup |
| 89 |
|
| 90 |
--connection master |
| 91 |
drop table t1; |
| 92 |
|
| 93 |
--connection slave |
| 94 |
--echo # TODO: Remove after fixing MDEV-21777 |
| 95 |
--eval set @@global.gtid_slave_pos= "$new_gtid" |
| 96 |
set @@global.slave_parallel_threads= @save_par_thds; |
| 97 |
set @@global.gtid_strict_mode= @save_strict_mode; |
| 98 |
set @@global.innodb_lock_wait_timeout= @save_innodb_lock_wait_timeout; |
| 99 |
--source include/start_slave.inc |
| 100 |
|
| 101 |
--source include/rpl_end.inc |
| 102 |
--echo # End of rpl_xa_prepare_gtid_fail.test |