1#
2# set up masters server_1 and server_3 with server_2 being a slave.
3#.
4include/rpl_init.inc [topology=1->2,3->2]
5Warnings:
6Note	####	Sending passwords in plain text without SSL/TLS is extremely insecure.
7Note	####	Storing MySQL user name or password information in the master info repository is not secure and is therefore not recommended. Please consider using the USER and PASSWORD connection options for START SLAVE; see the 'START SLAVE Syntax' in the MySQL Manual for more information.
8Warnings:
9Note	####	Sending passwords in plain text without SSL/TLS is extremely insecure.
10Note	####	Storing MySQL user name or password information in the master info repository is not secure and is therefore not recommended. Please consider using the USER and PASSWORD connection options for START SLAVE; see the 'START SLAVE Syntax' in the MySQL Manual for more information.
11#
12# Test case 1: 1.a) create a database and table db1.t1 on server_1
13#                   and insert values in the table.
14[connection server_1]
15CREATE DATABASE db1;
16CREATE TABLE db1.t1 ( a int);
17INSERT INTO db1.t1 VALUES (10);
18INSERT INTO db1.t1 VALUES (9);
19INSERT INTO db1.t1 VALUES (8);
20INSERT INTO db1.t1 VALUES (7);
21INSERT INTO db1.t1 VALUES (6);
22INSERT INTO db1.t1 VALUES (5);
23INSERT INTO db1.t1 VALUES (4);
24INSERT INTO db1.t1 VALUES (3);
25INSERT INTO db1.t1 VALUES (2);
26INSERT INTO db1.t1 VALUES (1);
27SHOW DATABASES;
28Database
29information_schema
30db1
31mtr
32mysql
33performance_schema
34sys
35test
36#
37# 1.b  create database and table db3.t1 on server_3
38#      and insert values in db3.t1
39[connection server_3]
40CREATE DATABASE db3;
41CREATE TABLE db3.t1 (a int);
42INSERT INTO db3.t1 VALUES (3*10);
43INSERT INTO db3.t1 VALUES (3*9);
44INSERT INTO db3.t1 VALUES (3*8);
45INSERT INTO db3.t1 VALUES (3*7);
46INSERT INTO db3.t1 VALUES (3*6);
47INSERT INTO db3.t1 VALUES (3*5);
48INSERT INTO db3.t1 VALUES (3*4);
49INSERT INTO db3.t1 VALUES (3*3);
50INSERT INTO db3.t1 VALUES (3*2);
51INSERT INTO db3.t1 VALUES (3*1);
52SHOW DATABASES;
53Database
54information_schema
55db3
56mtr
57mysql
58performance_schema
59sys
60test
61#
62# 1.c  sync the slave (server_2) with both masters (server_1 and server_3)
63#
64[connection server_1]
65include/sync_slave_sql_with_master.inc
66[connection server_3]
67include/sync_slave_sql_with_master.inc
68#
69# 1.d Check that slave has replicated from both masters.
70#  Slave should have databases db1 and db3 and tables.
71SHOW DATABASES;
72Database
73information_schema
74db1
75db3
76mtr
77mysql
78performance_schema
79sys
80test
81include/assert.inc [Slave should have 10 rows in db1.t1]
82include/assert.inc [Slave should have 10 rows in db3.t1]
83#
84# Stop slave (on server_2) for test case 2.
85#
86include/rpl_stop_slaves.inc
87#
88#  Test case 2: 2.a) Test that different tables in the same database
89#                    are replicated to the slave
90[connection server_1]
91CREATE DATABASE dbcommon;
92[connection server_2]
93include/start_slave.inc
94[connection server_1]
95include/sync_slave_sql_with_master.inc
96include/stop_slave.inc
97[connection server_1]
98CREATE TABLE dbcommon.t11(a int);
99INSERT INTO dbcommon.t11 values (11*10);
100INSERT INTO dbcommon.t11 values (11*9);
101INSERT INTO dbcommon.t11 values (11*8);
102INSERT INTO dbcommon.t11 values (11*7);
103INSERT INTO dbcommon.t11 values (11*6);
104INSERT INTO dbcommon.t11 values (11*5);
105INSERT INTO dbcommon.t11 values (11*4);
106INSERT INTO dbcommon.t11 values (11*3);
107INSERT INTO dbcommon.t11 values (11*2);
108INSERT INTO dbcommon.t11 values (11*1);
109[connection server_3]
110CREATE DATABASE IF NOT EXISTS dbcommon;
111CREATE TABLE dbcommon.t33(a int);
112INSERT INTO dbcommon.t33 values(33*10);
113INSERT INTO dbcommon.t33 values(33*9);
114INSERT INTO dbcommon.t33 values(33*8);
115INSERT INTO dbcommon.t33 values(33*7);
116INSERT INTO dbcommon.t33 values(33*6);
117INSERT INTO dbcommon.t33 values(33*5);
118INSERT INTO dbcommon.t33 values(33*4);
119INSERT INTO dbcommon.t33 values(33*3);
120INSERT INTO dbcommon.t33 values(33*2);
121INSERT INTO dbcommon.t33 values(33*1);
122#
123# 2.b Start replication from the masters
124#
125[connection server_2]
126include/rpl_start_slaves.inc
127#
128#  2.c sync the slave with both masters
129#
130[connection server_1]
131include/sync_slave_sql_with_master.inc
132[connection server_3]
133include/sync_slave_sql_with_master.inc
134#
135#  2.d Now check the data
136#
137SHOW DATABASES;
138Database
139information_schema
140db1
141db3
142dbcommon
143mtr
144mysql
145performance_schema
146sys
147test
148USE dbcommon;
149SHOW TABLES;
150Tables_in_dbcommon
151t11
152t33
153include/assert.inc [Slave should have 10 rows in dbcommon.t11]
154include/assert.inc [Slave should have 10 rows in dbcommon.t33]
155#
156# Test case 3: 3.a) Update nonconflicting data on the same table
157#                 and see if they are replicated to the slave.
158[connection server_1]
159CREATE TABLE dbcommon.t101(a int, PRIMARY KEY (a));
160[connection server_1]
161include/sync_slave_sql_with_master.inc
162#
163# Stop slave (on server_2) for test case 3.
164#
165include/rpl_stop_slaves.inc
166[connection server_1]
167INSERT INTO dbcommon.t101 values (101*10);
168INSERT INTO dbcommon.t101 values (101*9);
169INSERT INTO dbcommon.t101 values (101*8);
170INSERT INTO dbcommon.t101 values (101*7);
171INSERT INTO dbcommon.t101 values (101*6);
172INSERT INTO dbcommon.t101 values (101*5);
173INSERT INTO dbcommon.t101 values (101*4);
174INSERT INTO dbcommon.t101 values (101*3);
175INSERT INTO dbcommon.t101 values (101*2);
176INSERT INTO dbcommon.t101 values (101*1);
177[connection server_3]
178CREATE TABLE IF NOT EXISTS dbcommon.t101(a int, PRIMARY KEY (a));
179INSERT INTO dbcommon.t101 values(33*10);
180INSERT INTO dbcommon.t101 values(33*9);
181INSERT INTO dbcommon.t101 values(33*8);
182INSERT INTO dbcommon.t101 values(33*7);
183INSERT INTO dbcommon.t101 values(33*6);
184INSERT INTO dbcommon.t101 values(33*5);
185INSERT INTO dbcommon.t101 values(33*4);
186INSERT INTO dbcommon.t101 values(33*3);
187INSERT INTO dbcommon.t101 values(33*2);
188INSERT INTO dbcommon.t101 values(33*1);
189#
190#  3.b Start replication from the masters
191#
192[connection server_2]
193include/rpl_start_slaves.inc
194#
195# 3.c sync slave server with all the masters.
196#
197[connection server_1]
198include/sync_slave_sql_with_master.inc
199[connection server_3]
200include/sync_slave_sql_with_master.inc
201#
202#  check that data has been replicated to the slave.
203#
204USE dbcommon;
205SHOW TABLES;
206Tables_in_dbcommon
207t101
208t11
209t33
210include/assert.inc [Slave should have 20 rows in dbcommon.t101]
211#
212# Test case 4: Update tables on both masters with conflicting data
213#              In this case, slave shall stop on a SQL thread.
214# 4.a) Do an update on server_1 and sync with the slave.
215[connection server_1]
216INSERT INTO dbcommon.t101 values(1729);
217include/sync_slave_sql_with_master.inc
218# 4.b) Do a conflicting update on server_3 and check for conflicting error
219[connection server_3]
220INSERT INTO dbcommon.t101 values (1729);
221[connection server_2]
222call mtr.add_suppression("Slave SQL.*:.* 'Duplicate entry '1729' for key 'PRIMARY'' on query.*");
223call mtr.add_suppression("Slave SQL.*: Could not execute Write_rows event on table dbcommon.t101; Duplicate entry '1729' for key 'PRIMARY'*");
224call mtr.add_suppression("The slave coordinator and worker threads are stopped, possibly leaving data in inconsistent state");
225call mtr.add_suppression("Slave SQL.*:.* Duplicate entry '1729' for key 'PRIMARY', Error_code: 1062; handler error HA_ERR_FOUND_DUPP_KEY.*");
226include/wait_for_slave_sql_error.inc [errno=1062]
227include/assert.inc [Value returned by SSS and PS table for Last_Error_Number should be same.]
228DELETE FROM dbcommon.t101 where a=1729;
229include/start_slave.inc
230# channel 1
231[connection server_1]
232include/sync_slave_sql_with_master.inc
233# channel 3
234[connection server_3]
235include/sync_slave_sql_with_master.inc
236connection_server_1
237DROP DATABASE db1;
238DROP DATABASE dbcommon;
239include/sync_slave_sql_with_master.inc
240connection_server_3
241DROP DATABASE db3;
242DROP DATABASE IF EXISTS dbcommon;
243include/sync_slave_sql_with_master.inc
244include/rpl_end.inc
245RESET SLAVE ALL FOR CHANNEL  'channel_1';
246RESET SLAVE ALL FOR CHANNEL  'channel_3';
247