Debian Codegraph @

mysql-test/suite/group_replication/t/gr_xa.test

raw
1 ################################################################################
2 # Validate that XA transactions do work on Group Replication.
3 #
4 # Test:
5 # 0. The test requires two servers: M1 and M2.
6 # 1. With both the members ONLINE. Create a table on M1.
7 # 2. Execute a XA transaction that does commit on M1.
8 # - Verify GTID_EXECUTED and data in table on M1.
9 # - Verify GTID_EXECUTED and data in table on M2.
10 # 3. Execute a XA transaction that does rollback.
11 # - Verify GTID_EXECUTED and data in table on M1.
12 # - Verify GTID_EXECUTED and data in table on M2.
13 # 4. Clean up.
14 ################################################################################
15 --source include/have_group_replication_plugin.inc
16 --source include/group_replication.inc
17
18 --echo
19 --echo ############################################################
20 --echo # 1. Create a table on the group.
21 --let $rpl_connection_name= server1
22 --source include/rpl_connection.inc
23 CREATE TABLE t1 (c1 INT NOT NULL PRIMARY KEY) ENGINE=InnoDB;
24 --source include/rpl_sync.inc
25
26
27 --echo
28 --echo ############################################################
29 --echo # 2. Execute a XA transaction that does commit.
30 --let $rpl_connection_name= server1
31 --source include/rpl_connection.inc
32 --let $expected_gtid_set= "$group_replication_group_name:1-5"
33
34 XA START 'trx1';
35 INSERT INTO t1 VALUES (1);
36 XA END 'trx1';
37 XA PREPARE 'trx1';
38
39 XA COMMIT 'trx1';
40 --source include/rpl_sync.inc
41
42 --echo
43 --echo # Check that GTID_EXECUTED on server 1 contains all
44 --echo # transactions.
45 --echo # Also check that data is on tables.
46 --let $rpl_connection_name= server1
47 --source include/rpl_connection.inc
48 --let $assert_text= GTID_EXECUTED must contain all committed GTIDs
49 --let $assert_cond= "[SELECT @@GLOBAL.GTID_EXECUTED]" = $expected_gtid_set
50 --source include/assert.inc
51
52 --let $assert_text= 'There is a value 1 in table t1'
53 --let $assert_cond= [SELECT COUNT(*) AS count FROM t1 WHERE t1.c1 = 1, count, 1] = 1
54 --source include/assert.inc
55
56 --echo
57 --echo # Check that GTID_EXECUTED on server 2 contains all
58 --echo # transactions.
59 --echo # Also check that data is on tables.
60 --let $rpl_connection_name= server2
61 --source include/rpl_connection.inc
62 --let $assert_text= GTID_EXECUTED must contain all committed GTIDs
63 --let $assert_cond= "[SELECT @@GLOBAL.GTID_EXECUTED]" = $expected_gtid_set
64 --source include/assert.inc
65
66 --let $assert_text= 'There is a value 1 in table t1'
67 --let $assert_cond= [SELECT COUNT(*) AS count FROM t1 WHERE t1.c1 = 1, count, 1] = 1
68 --source include/assert.inc
69
70
71 --echo
72 --echo ############################################################
73 --echo # 3. Execute a XA transaction that does rollback.
74 --let $rpl_connection_name= server1
75 --source include/rpl_connection.inc
76 --let $expected_gtid_set= "$group_replication_group_name:1-7"
77
78 XA START 'trx2';
79 INSERT INTO t1 VALUES (2);
80 XA END 'trx2';
81 XA PREPARE 'trx2';
82
83 XA ROLLBACK 'trx2';
84 --source include/rpl_sync.inc
85
86 --echo
87 --echo # Check that GTID_EXECUTED on server 1 contains all
88 --echo # transactions.
89 --echo # Also check that data is on tables.
90 --let $rpl_connection_name= server1
91 --source include/rpl_connection.inc
92 --let $assert_text= GTID_EXECUTED must contain all committed GTIDs
93 --let $assert_cond= "[SELECT @@GLOBAL.GTID_EXECUTED]" = $expected_gtid_set
94 --source include/assert.inc
95
96 --let $assert_text= 'There is a value 1 in table t1'
97 --let $assert_cond= [SELECT COUNT(*) AS count FROM t1 WHERE t1.c1 = 1, count, 1] = 1
98 --source include/assert.inc
99 --let $assert_text= 'There is no value 2 in table t1'
100 --let $assert_cond= [SELECT COUNT(*) AS count FROM t1 WHERE t1.c1 = 2, count, 1] = 0
101 --source include/assert.inc
102
103 --echo
104 --echo # Check that GTID_EXECUTED on server 2 contains all
105 --echo # transactions.
106 --echo # Also check that data is on tables.
107 --let $rpl_connection_name= server2
108 --source include/rpl_connection.inc
109 --let $assert_text= GTID_EXECUTED must contain all committed GTIDs
110 --let $assert_cond= "[SELECT @@GLOBAL.GTID_EXECUTED]" = $expected_gtid_set
111 --source include/assert.inc
112
113 --let $assert_text= 'There is a value 1 in table t1'
114 --let $assert_cond= [SELECT COUNT(*) AS count FROM t1 WHERE t1.c1 = 1, count, 1] = 1
115 --source include/assert.inc
116 --let $assert_text= 'There is no value 2 in table t1'
117 --let $assert_cond= [SELECT COUNT(*) AS count FROM t1 WHERE t1.c1 = 2, count, 1] = 0
118 --source include/assert.inc
119
120
121 --echo
122 --echo ############################################################
123 --echo # 4. Clean up.
124 --let $rpl_connection_name= server1
125 --source include/rpl_connection.inc
126 DROP TABLE t1;
127
128 --source include/group_replication_end.inc