# # Test two primary nodes async replication to Galera cluster # # primary1 primary2 # #3 #4 # | | # | async replication v # +-------------------+ +----------------+ # | | # v v # galera replica <------galera replication-------->galera node_2 # #1 #2 # # Test outline # # - Create user for async replication and table with rows in both primaries # - Verify that tables and rows are replicated to all Galera nodes # - Verify that gtid position is same in all Galera nodes # # The galera/galera_2nodes_as_replica_2primary.cnf describes the setup of the nodes # --source include/force_restart.inc --source include/galera_cluster.inc --source include/have_innodb.inc # As node #3 and #4 are not a Galera node, and galera_cluster.inc does not open connetion to it # we open the connections here --connect primary1, 127.0.0.1, root, , test, $NODE_MYPORT_3 --connect primary2, 127.0.0.1, root, , test, $NODE_MYPORT_4 --connection primary1 --echo # Primary1 creating user for replication create user repl@'%' identified by 'repl'; grant all on *.* to repl@'%'; --connection primary2 --echo # Primary2 creating user for replication create user repl2@'%' identified by 'repl2'; grant all on *.* to repl2@'%'; --connect replica, 127.0.0.1, root, , test, $NODE_MYPORT_1 --let $node_1 = replica --let $node_2 = node_2 --let $node_3 = primary1 --let $node_4 = primary2 --source include/auto_increment_offset_save.inc --connection replica --echo # Galera replica changing master to primary1 SET @@default_master_connection='stream1'; --disable_query_log --eval CHANGE MASTER 'stream1' TO master_host='127.0.0.1', master_user='repl', master_password='repl', master_ssl_verify_server_cert=0, master_port=$NODE_MYPORT_3, master_use_gtid=slave_pos; --enable_query_log --echo # Primary node changing master to primary2 SET @@default_master_connection='stream2'; --disable_query_log --eval CHANGE MASTER 'stream2' TO master_host='127.0.0.1', master_user='repl2', master_password='repl2', master_ssl_verify_server_cert=0, master_port=$NODE_MYPORT_4, master_use_gtid=slave_pos; --enable_query_log START ALL SLAVES; --connection primary1 --echo # Primary 1: Creating table and populating it with data CREATE TABLE t1 (id bigint auto_increment primary key, msg varchar(100)) engine=innodb; --disable_query_log --echo # Intentionally generate 1k GTID-events --let $inserts=1000 --let $count=0 --disable_query_log while($count < $inserts) { --eval insert into t1 values (NULL,'test1') --inc $count } --enable_query_log SELECT COUNT(*) AS EXPECT_1000 FROM t1; --connection primary2 --echo # Primary 2: Creating table and populating it with data CREATE TABLE t2 (id bigint auto_increment primary key, msg varchar(100)) engine=innodb; --echo # Intentionally generate 1k GTID-events --let $inserts=1000 --let $count=0 --disable_query_log while($count < $inserts) { --eval insert into t2 values (NULL,'test1') --inc $count } --enable_query_log SELECT COUNT(*) AS EXPECT_1000 FROM t2; --connection replica --echo # Waiting for data to replicate to node_1 --let $wait_condition = SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1'; --let $wait_condition_on_error_output = SHOW ALL SLAVES STATUS; --source include/wait_condition_with_debug.inc --let $wait_condition = SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't2'; --let $wait_condition_on_error_output = SHOW ALL SLAVES STATUS; --source include/wait_condition_with_debug.inc --let $wait_condition = SELECT COUNT(*) = 1000 FROM t1; --source include/wait_condition.inc --let $wait_condition = SELECT COUNT(*) = 1000 FROM t2; --source include/wait_condition.inc SELECT COUNT(*) AS EXPECT_1000 FROM t1; SELECT COUNT(*) AS EXPECT_1000 FROM t2; SELECT COUNT(*) > 0 AS EXPECT_1 FROM mysql.gtid_slave_pos; SELECT COUNT(*) < 1000 AS EXPECT_1 FROM mysql.gtid_slave_pos; SELECT @@gtid_slave_pos,@@gtid_binlog_pos,@@gtid_current_pos; --connection node_2 --echo # Waiting for data to replicate to node_2 --let $wait_condition = SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1'; --source include/wait_condition.inc --let $wait_condition = SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't2'; --source include/wait_condition.inc --let $wait_condition = SELECT COUNT(*) = 1000 FROM t1; --source include/wait_condition.inc --let $wait_condition = SELECT COUNT(*) = 1000 FROM t2; --source include/wait_condition.inc SELECT COUNT(*) AS EXPECT_1000 FROM t1; SELECT COUNT(*) AS EXPECT_1000 FROM t2; SELECT COUNT(*) > 0 AS EXPECT_1 FROM mysql.gtid_slave_pos; SELECT COUNT(*) < 1000 AS EXPECT_1 FROM mysql.gtid_slave_pos; SELECT @@gtid_slave_pos,@@gtid_binlog_pos,@@gtid_current_pos; # # Cleanup # --connection primary1 drop table t1; --connection primary2 drop table t2; --echo # Wait until drop table is replicated on Galera --connection replica --let $wait_condition = SELECT COUNT(*) = 0 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1'; --source include/wait_condition.inc --let $wait_condition = SELECT COUNT(*) = 0 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't2'; --source include/wait_condition.inc --connection node_2 --let $wait_condition = SELECT COUNT(*) = 0 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1'; --source include/wait_condition.inc --let $wait_condition = SELECT COUNT(*) = 0 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't2'; --source include/wait_condition.inc --connection replica STOP ALL SLAVES; RESET SLAVE ALL; --connection primary1 RESET MASTER; --connection primary2 RESET MASTER; --source include/auto_increment_offset_restore.inc --connection node_1 --disconnect primary1 --disconnect primary2 --disconnect replica --source include/galera_end.inc --echo # End of test