#
# set up masters server_1 and server_3 with server_2 being a slave.
#.
include/rpl_init.inc [topology=1->2,3->2]
Warnings:
Note	####	Sending passwords in plain text without SSL/TLS is extremely insecure.
Note	####	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.
Warnings:
Note	####	Sending passwords in plain text without SSL/TLS is extremely insecure.
Note	####	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.
#
# Test case 1: 1.a) create a database and table db1.t1 on server_1
#                   and insert values in the table.
[connection server_1]
CREATE DATABASE db1;
CREATE TABLE db1.t1 ( a int);
INSERT INTO db1.t1 VALUES (10);
INSERT INTO db1.t1 VALUES (9);
INSERT INTO db1.t1 VALUES (8);
INSERT INTO db1.t1 VALUES (7);
INSERT INTO db1.t1 VALUES (6);
INSERT INTO db1.t1 VALUES (5);
INSERT INTO db1.t1 VALUES (4);
INSERT INTO db1.t1 VALUES (3);
INSERT INTO db1.t1 VALUES (2);
INSERT INTO db1.t1 VALUES (1);
SHOW DATABASES;
Database
information_schema
db1
mtr
mysql
performance_schema
sys
test
#
# 1.b  create database and table db3.t1 on server_3
#      and insert values in db3.t1
[connection server_3]
CREATE DATABASE db3;
CREATE TABLE db3.t1 (a int);
INSERT INTO db3.t1 VALUES (3*10);
INSERT INTO db3.t1 VALUES (3*9);
INSERT INTO db3.t1 VALUES (3*8);
INSERT INTO db3.t1 VALUES (3*7);
INSERT INTO db3.t1 VALUES (3*6);
INSERT INTO db3.t1 VALUES (3*5);
INSERT INTO db3.t1 VALUES (3*4);
INSERT INTO db3.t1 VALUES (3*3);
INSERT INTO db3.t1 VALUES (3*2);
INSERT INTO db3.t1 VALUES (3*1);
SHOW DATABASES;
Database
information_schema
db3
mtr
mysql
performance_schema
sys
test
#
# 1.c  sync the slave (server_2) with both masters (server_1 and server_3)
#
[connection server_1]
include/sync_slave_sql_with_master.inc
[connection server_3]
include/sync_slave_sql_with_master.inc
#
# 1.d Check that slave has replicated from both masters.
#  Slave should have databases db1 and db3 and tables.
SHOW DATABASES;
Database
information_schema
db1
db3
mtr
mysql
performance_schema
sys
test
include/assert.inc [Slave should have 10 rows in db1.t1]
include/assert.inc [Slave should have 10 rows in db3.t1]
#
# Stop slave (on server_2) for test case 2.
#
include/rpl_stop_slaves.inc
#
#  Test case 2: 2.a) Test that different tables in the same database
#                    are replicated to the slave
[connection server_1]
CREATE DATABASE dbcommon;
[connection server_2]
include/start_slave.inc
[connection server_1]
include/sync_slave_sql_with_master.inc
include/stop_slave.inc
[connection server_1]
CREATE TABLE dbcommon.t11(a int);
INSERT INTO dbcommon.t11 values (11*10);
INSERT INTO dbcommon.t11 values (11*9);
INSERT INTO dbcommon.t11 values (11*8);
INSERT INTO dbcommon.t11 values (11*7);
INSERT INTO dbcommon.t11 values (11*6);
INSERT INTO dbcommon.t11 values (11*5);
INSERT INTO dbcommon.t11 values (11*4);
INSERT INTO dbcommon.t11 values (11*3);
INSERT INTO dbcommon.t11 values (11*2);
INSERT INTO dbcommon.t11 values (11*1);
[connection server_3]
CREATE DATABASE IF NOT EXISTS dbcommon;
CREATE TABLE dbcommon.t33(a int);
INSERT INTO dbcommon.t33 values(33*10);
INSERT INTO dbcommon.t33 values(33*9);
INSERT INTO dbcommon.t33 values(33*8);
INSERT INTO dbcommon.t33 values(33*7);
INSERT INTO dbcommon.t33 values(33*6);
INSERT INTO dbcommon.t33 values(33*5);
INSERT INTO dbcommon.t33 values(33*4);
INSERT INTO dbcommon.t33 values(33*3);
INSERT INTO dbcommon.t33 values(33*2);
INSERT INTO dbcommon.t33 values(33*1);
#
# 2.b Start replication from the masters
#
[connection server_2]
include/rpl_start_slaves.inc
#
#  2.c sync the slave with both masters
#
[connection server_1]
include/sync_slave_sql_with_master.inc
[connection server_3]
include/sync_slave_sql_with_master.inc
#
#  2.d Now check the data
#
SHOW DATABASES;
Database
information_schema
db1
db3
dbcommon
mtr
mysql
performance_schema
sys
test
USE dbcommon;
SHOW TABLES;
Tables_in_dbcommon
t11
t33
include/assert.inc [Slave should have 10 rows in dbcommon.t11]
include/assert.inc [Slave should have 10 rows in dbcommon.t33]
#
# Test case 3: 3.a) Update nonconflicting data on the same table
#                 and see if they are replicated to the slave.
[connection server_1]
CREATE TABLE dbcommon.t101(a int, PRIMARY KEY (a));
[connection server_1]
include/sync_slave_sql_with_master.inc
#
# Stop slave (on server_2) for test case 3.
#
include/rpl_stop_slaves.inc
[connection server_1]
INSERT INTO dbcommon.t101 values (101*10);
INSERT INTO dbcommon.t101 values (101*9);
INSERT INTO dbcommon.t101 values (101*8);
INSERT INTO dbcommon.t101 values (101*7);
INSERT INTO dbcommon.t101 values (101*6);
INSERT INTO dbcommon.t101 values (101*5);
INSERT INTO dbcommon.t101 values (101*4);
INSERT INTO dbcommon.t101 values (101*3);
INSERT INTO dbcommon.t101 values (101*2);
INSERT INTO dbcommon.t101 values (101*1);
[connection server_3]
CREATE TABLE IF NOT EXISTS dbcommon.t101(a int, PRIMARY KEY (a));
INSERT INTO dbcommon.t101 values(33*10);
INSERT INTO dbcommon.t101 values(33*9);
INSERT INTO dbcommon.t101 values(33*8);
INSERT INTO dbcommon.t101 values(33*7);
INSERT INTO dbcommon.t101 values(33*6);
INSERT INTO dbcommon.t101 values(33*5);
INSERT INTO dbcommon.t101 values(33*4);
INSERT INTO dbcommon.t101 values(33*3);
INSERT INTO dbcommon.t101 values(33*2);
INSERT INTO dbcommon.t101 values(33*1);
#
#  3.b Start replication from the masters
#
[connection server_2]
include/rpl_start_slaves.inc
#
# 3.c sync slave server with all the masters.
#
[connection server_1]
include/sync_slave_sql_with_master.inc
[connection server_3]
include/sync_slave_sql_with_master.inc
#
#  check that data has been replicated to the slave.
#
USE dbcommon;
SHOW TABLES;
Tables_in_dbcommon
t101
t11
t33
include/assert.inc [Slave should have 20 rows in dbcommon.t101]
#
# Test case 4: Update tables on both masters with conflicting data
#              In this case, slave shall stop on a SQL thread.
# 4.a) Do an update on server_1 and sync with the slave.
[connection server_1]
INSERT INTO dbcommon.t101 values(1729);
include/sync_slave_sql_with_master.inc
# 4.b) Do a conflicting update on server_3 and check for conflicting error
[connection server_3]
INSERT INTO dbcommon.t101 values (1729);
[connection server_2]
call mtr.add_suppression("Slave SQL.*:.* 'Duplicate entry '1729' for key 'PRIMARY'' on query.*");
call mtr.add_suppression("Slave SQL.*: Could not execute Write_rows event on table dbcommon.t101; Duplicate entry '1729' for key 'PRIMARY'*");
call mtr.add_suppression("The slave coordinator and worker threads are stopped, possibly leaving data in inconsistent state");
call mtr.add_suppression("Slave SQL.*:.* Duplicate entry '1729' for key 'PRIMARY', Error_code: 1062; handler error HA_ERR_FOUND_DUPP_KEY.*");
include/wait_for_slave_sql_error.inc [errno=1062]
include/assert.inc [Value returned by SSS and PS table for Last_Error_Number should be same.]
DELETE FROM dbcommon.t101 where a=1729;
include/start_slave.inc
# channel 1
[connection server_1]
include/sync_slave_sql_with_master.inc
# channel 3
[connection server_3]
include/sync_slave_sql_with_master.inc
connection_server_1
DROP DATABASE db1;
DROP DATABASE dbcommon;
include/sync_slave_sql_with_master.inc
connection_server_3
DROP DATABASE db3;
DROP DATABASE IF EXISTS dbcommon;
include/sync_slave_sql_with_master.inc
include/rpl_end.inc
RESET SLAVE ALL FOR CHANNEL  'channel_1';
RESET SLAVE ALL FOR CHANNEL  'channel_3';
