1################################################################################
2# Verify server behaviour when the same transaction is executed in parallel in
3# two servers.
4#
5# Test:
6# 0. The test requires two servers: M1 and M2.
7# 1. With both members ONLINE, create initial data.
8# 2. Executing the same update transaction on both server (almost) in parallel,
9#    one will be committed, the other will be aborted.
10# 3. Validate servers state is equal.
11# 4. Clean up.
12################################################################################
13--let $group_replication_group_name= 8a94f357-aab4-11df-86ab-c80aa9429999
14--source ../inc/have_group_replication_plugin.inc
15--source ../inc/group_replication.inc
16
17--connection server1
18--echo ############################################################
19--echo # 1. Execute some transactions on server1 and wait for group
20--echo #    to be synchronized.
21CREATE TABLE t1 (c1 INT NOT NULL PRIMARY KEY) ENGINE=InnoDB;
22INSERT INTO t1 VALUES (0);
23
24--let $sync_slave_connection= server2
25--source include/sync_slave_sql_with_master.inc
26
27--echo ############################################################
28--echo # 2. Executing the same transaction on both server (almost)
29--echo #    in parallel, one will be committed, the other will be
30--echo #    aborted.
31--disable_query_log
32--disable_result_log
33--let $include_silent= 1
34
35--let $value_old= 0
36--let $value_new= 1
37--let $transactions= 50
38while ($transactions > 0)
39{
40  --let $query= UPDATE t1 SET c1=$value_new WHERE c1=$value_old
41
42  --connection server1
43  --send_eval $query
44  --connection server2
45  --send_eval $query
46
47  --connection server1
48  --error 0, ER_TRANSACTION_ROLLBACK_DURING_COMMIT, ER_ERROR_DURING_COMMIT, ER_LOCK_DEADLOCK, ER_LOCK_WAIT_TIMEOUT
49  --reap
50  --connection server2
51  --error 0, ER_TRANSACTION_ROLLBACK_DURING_COMMIT, ER_ERROR_DURING_COMMIT, ER_LOCK_DEADLOCK, ER_LOCK_WAIT_TIMEOUT
52  --reap
53
54  # Sync both servers to ensure that next transaction does not fail
55  # with mismatch where clause.
56  --let $sync_slave_connection= server1
57  --source include/sync_slave_sql_with_master.inc
58  --let $sync_slave_connection= server2
59  --source include/sync_slave_sql_with_master.inc
60
61  --dec $transactions
62  --inc $value_old
63  --inc $value_new
64}
65--enable_query_log
66--enable_result_log
67--let $include_silent= 0
68
69--echo ############################################################
70--echo # 3. Validate servers state is equal.
71--let $diff_tables= server1:t1, server2:t1
72--source include/diff_tables.inc
73
74--connection server1
75--let $assert_text= 'There is only one row in table t1 on server 1'
76--let $assert_cond= [SELECT COUNT(*) AS count FROM t1, count, 1] = 1
77--source include/assert.inc
78--let $assert_text= 'There is a value 50 in table t1 on server 1'
79--let $assert_cond= [SELECT COUNT(*) AS count FROM t1 WHERE t1.c1 = 50, count, 1] = 1
80--source include/assert.inc
81
82--connection server2
83--let $assert_text= 'There is only one row in table t1 on server 2'
84--let $assert_cond= [SELECT COUNT(*) AS count FROM t1, count, 1] = 1
85--source include/assert.inc
86--let $assert_text= 'There is a value 50 in table t1 on server 2'
87--let $assert_cond= [SELECT COUNT(*) AS count FROM t1 WHERE t1.c1 = 50, count, 1] = 1
88--source include/assert.inc
89
90--echo ############################################################
91--echo # 4. Clean up.
92DROP TABLE t1;
93--source ../inc/group_replication_end.inc
94