| 1 |
############################################################################### |
| 2 |
# Validate that XA transactions can be prepared on a group primary (server1) |
| 3 |
# and committed on a different primary (server2) after a failover. |
| 4 |
# Also validate that the old primary (server1) can rejoin the group as a |
| 5 |
# secondary and commit the XA transaction that it did prepare. |
| 6 |
# Both situations happen while the old primary (server1) keep the |
| 7 |
# client session that did the XA PREPATE active. |
| 8 |
# |
| 9 |
# Test: |
| 10 |
# 0. The test requires two servers: M1 and M2. |
| 11 |
# 1. Bootstrap a group with server1 as the primary. |
| 12 |
# 2. Join server2 to the group. |
| 13 |
# 3. Do the XA PREPARE on the initial primary (server1) |
| 14 |
# 4. server1 will leave the group, server2 will be elected |
| 15 |
# primary. |
| 16 |
# The client session that did the XA PREPARE will remain |
| 17 |
# active. |
| 18 |
# 5. server2 is the new primary, the XA transaction will be |
| 19 |
# resumed on it. |
| 20 |
# This mimics a load balancer behavior. |
| 21 |
# 6. server1 rejoins the group, now as a secondary, it will |
| 22 |
# receive the XA COMMIT through distributed recovery. |
| 23 |
# 7. Clean up. |
| 24 |
############################################################################### |
| 25 |
--let $rpl_group_replication_single_primary_mode=1 |
| 26 |
--let $rpl_skip_group_replication_start= 1 |
| 27 |
--source include/have_group_replication_plugin.inc |
| 28 |
--source include/group_replication.inc |
| 29 |
|
| 30 |
--let $option_name = xa_detach_on_prepare |
| 31 |
--let $option_value = 1 |
| 32 |
--source include/only_with_option.inc |
| 33 |
|
| 34 |
--echo |
| 35 |
--echo ############################################################ |
| 36 |
--echo # 1. Bootstrap a group with server1 as the primary. |
| 37 |
--let $rpl_connection_name= server1 |
| 38 |
--source include/rpl_connection.inc |
| 39 |
--source include/start_and_bootstrap_group_replication.inc |
| 40 |
CREATE TABLE t1 (c1 INT NOT NULL PRIMARY KEY); |
| 41 |
|
| 42 |
|
| 43 |
--echo |
| 44 |
--echo ############################################################ |
| 45 |
--echo # 2. Join server2 to the group. |
| 46 |
--let $rpl_connection_name= server2 |
| 47 |
--source include/rpl_connection.inc |
| 48 |
--source include/start_group_replication.inc |
| 49 |
|
| 50 |
|
| 51 |
--echo |
| 52 |
--echo ############################################################ |
| 53 |
--echo # 3. Do the XA PREPARE on the initial primary (server1) |
| 54 |
--let $rpl_connection_name= server1 |
| 55 |
--source include/rpl_connection.inc |
| 56 |
FLUSH LOGS; |
| 57 |
XA START '1'; |
| 58 |
INSERT INTO t1 VALUES (1); |
| 59 |
XA END '1'; |
| 60 |
XA PREPARE '1'; |
| 61 |
--source include/rpl_sync.inc |
| 62 |
|
| 63 |
|
| 64 |
--echo |
| 65 |
--echo ############################################################ |
| 66 |
--echo # 4. server1 will leave the group, server2 will be elected |
| 67 |
--echo # primary. |
| 68 |
--echo # The client session that did the XA PREPARE will remain |
| 69 |
--echo # active. |
| 70 |
--let $rpl_connection_name= server1 |
| 71 |
--source include/rpl_connection.inc |
| 72 |
--source include/stop_group_replication.inc |
| 73 |
|
| 74 |
|
| 75 |
--echo |
| 76 |
--echo ############################################################ |
| 77 |
--echo # 5. server2 is the new primary, the XA transaction will be |
| 78 |
--echo # resumed on it. |
| 79 |
--echo # This mimics a load balancer behavior. |
| 80 |
--let $rpl_connection_name= server2 |
| 81 |
--source include/rpl_connection.inc |
| 82 |
XA COMMIT '1'; |
| 83 |
|
| 84 |
--let $assert_text= 'There is a value 1 in table t1' |
| 85 |
--let $assert_cond= [SELECT COUNT(*) AS count FROM t1 WHERE t1.c1 = 1, count, 1] = 1 |
| 86 |
--source include/assert.inc |
| 87 |
|
| 88 |
|
| 89 |
--echo |
| 90 |
--echo ############################################################ |
| 91 |
--echo # 6. server1 rejoins the group, now as a secondary, it will |
| 92 |
--echo # receive the XA COMMIT through distributed recovery. |
| 93 |
--let $rpl_connection_name= server1 |
| 94 |
--source include/rpl_connection.inc |
| 95 |
--source include/start_group_replication.inc |
| 96 |
|
| 97 |
--let $assert_text= 'There is a value 1 in table t1' |
| 98 |
--let $assert_cond= [SELECT COUNT(*) AS count FROM t1 WHERE t1.c1 = 1, count, 1] = 1 |
| 99 |
--source include/assert.inc |
| 100 |
|
| 101 |
|
| 102 |
--echo |
| 103 |
--echo ############################################################ |
| 104 |
--echo # 7. Clean up. |
| 105 |
--let $rpl_connection_name= server2 |
| 106 |
--source include/rpl_connection.inc |
| 107 |
DROP TABLE t1; |
| 108 |
|
| 109 |
--source include/group_replication_end.inc |