# # Test Galera as a replica to a MySQL async replication # # The galera/galera_2node_slave.cnf describes the setup of the nodes # --source include/force_restart.inc --source include/galera_cluster.inc --source include/have_innodb.inc --source include/have_sequence.inc # As node #3 is not a Galera node, and galera_cluster.inc does not open connetion to it # we open the node_3 connection here --connect node_3, 127.0.0.1, root, , test, $NODE_MYPORT_3 create user repl@'%' identified by 'repl'; grant all on *.* to repl@'%'; ALTER TABLE mysql.gtid_slave_pos ENGINE=InnoDB; --let $node_1 = node_1 --let $node_2 = node_2 --source include/auto_increment_offset_save.inc --connection node_2 --disable_query_log --eval CHANGE MASTER TO master_host='127.0.0.1', master_user='repl', master_password='repl', master_port=$NODE_MYPORT_3, master_use_gtid=slave_pos; --enable_query_log START SLAVE; --connection node_3 CREATE TABLE t1 (id bigint primary key, msg varchar(100)) engine=innodb; --disable_query_log INSERT INTO t1 SELECT seq, 'test' from seq_1_to_10000; --enable_query_log SELECT COUNT(*) AS EXPECT_10000 FROM t1; --connection 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(*) = 10000 FROM t1; --source include/wait_condition.inc SELECT COUNT(*) > 0 AS EXPECT_1 FROM mysql.gtid_slave_pos; SELECT COUNT(*) AS EXPECT_10000 FROM t1; --connection node_1 --let $wait_condition = SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1'; --source include/wait_condition.inc --let $wait_condition = SELECT COUNT(*) = 10000 FROM t1; --source include/wait_condition.inc SELECT COUNT(*) > 0 AS EXPECT_1 FROM mysql.gtid_slave_pos; SELECT COUNT(*) AS EXPECT_10000 FROM t1; --connection node_2 --echo # Verify that graceful shutdown succeeds. --source include/shutdown_mysqld.inc --echo # Force SST --remove_file $MYSQLTEST_VARDIR/mysqld.2/data/grastate.dat --connection node_1 --echo # Waiting until node_2 is not part of cluster anymore --let $wait_condition = SELECT VARIABLE_VALUE = 1 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; --source include/wait_condition.inc --let $wait_condition = SELECT VARIABLE_VALUE = 'Primary' FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_status'; --source include/wait_condition.inc --connection node_2 --echo # Start node_2 again --source include/start_mysqld.inc --echo ¤ Wait until node_2 is back on cluster --let $wait_condition = SELECT VARIABLE_VALUE = 'Primary' FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_status'; --source include/wait_condition.inc --let $wait_condition = SELECT VARIABLE_VALUE = 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; --source include/wait_condition.inc --let $wait_condition = SELECT VARIABLE_VALUE = 'ON' FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_ready'; --source include/wait_condition.inc --connection node_2 SELECT COUNT(*) > 0 AS EXPECT_1 FROM mysql.gtid_slave_pos; SELECT COUNT(*) AS EXPECT_10000 FROM t1; --connection node_1 SELECT COUNT(*) > 0 AS EXPECT_1 FROM mysql.gtid_slave_pos; SELECT COUNT(*) AS EXPECT_10000 FROM t1; --connection node_3 SELECT COUNT(*) AS EXPECT_10000 FROM t1; # # Cleanup # --connection node_3 drop table t1; --connection node_2 --let $wait_condition = SELECT COUNT(*) = 0 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1'; --source include/wait_condition.inc --connection node_1 --let $wait_condition = SELECT COUNT(*) = 0 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1'; --source include/wait_condition.inc # # Case 2 : While slave is down add writes to master # --connection node_3 CREATE TABLE t1 (id bigint primary key, msg varchar(100)) engine=innodb; --disable_query_log INSERT INTO t1 SELECT seq, 'test' from seq_1_to_10000; --enable_query_log SELECT COUNT(*) AS EXPECT_10000 FROM t1; --connection 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(*) = 10000 FROM t1; --source include/wait_condition.inc SELECT COUNT(*) > 0 AS EXPECT_1 FROM mysql.gtid_slave_pos; SELECT COUNT(*) AS EXPECT_10000 FROM t1; --connection node_1 --let $wait_condition = SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1'; --source include/wait_condition.inc --let $wait_condition = SELECT COUNT(*) = 10000 FROM t1; --source include/wait_condition.inc SELECT COUNT(*) > 0 AS EXPECT_1 FROM mysql.gtid_slave_pos; SELECT COUNT(*) AS EXPECT_10000 FROM t1; --connection node_2 --echo # Verify that graceful shutdown succeeds. --source include/shutdown_mysqld.inc --echo # Force SST --remove_file $MYSQLTEST_VARDIR/mysqld.2/data/grastate.dat --connection node_1 --echo # Waiting until node_2 is not part of cluster anymore --let $wait_condition = SELECT VARIABLE_VALUE = 1 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; --source include/wait_condition.inc --let $wait_condition = SELECT VARIABLE_VALUE = 'Primary' FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_status'; --source include/wait_condition.inc # Add writes to master --connection node_3 --disable_query_log INSERT INTO t1 SELECT seq, 'test' from seq_20001_to_30000; --enable_query_log SELECT COUNT(*) AS EXPECT_20000 FROM t1; --connection node_2 --echo # Start node_2 again --source include/start_mysqld.inc --echo ¤ Wait until node_2 is back on cluster --let $wait_condition = SELECT VARIABLE_VALUE = 'Primary' FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_status'; --source include/wait_condition.inc --let $wait_condition = SELECT VARIABLE_VALUE = 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size'; --source include/wait_condition.inc --let $wait_condition = SELECT VARIABLE_VALUE = 'ON' FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_ready'; --source include/wait_condition.inc --connection node_2 --let $wait_condition = SELECT COUNT(*) = 20000 FROM t1; --source include/wait_condition.inc SELECT COUNT(*) > 0 AS EXPECT_1 FROM mysql.gtid_slave_pos; SELECT COUNT(*) AS EXPECT_20000 FROM t1; --connection node_1 --let $wait_condition = SELECT COUNT(*) = 20000 FROM t1; --source include/wait_condition.inc SELECT COUNT(*) > 0 AS EXPECT_1 FROM mysql.gtid_slave_pos; SELECT COUNT(*) AS EXPECT_20000 FROM t1; --connection node_3 SELECT COUNT(*) AS EXPECT_20000 FROM t1; # # Cleanup # --connection node_3 drop table t1; --connection node_2 --let $wait_condition = SELECT COUNT(*) = 0 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1'; --source include/wait_condition.inc --connection node_1 --let $wait_condition = SELECT COUNT(*) = 0 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 't1'; --source include/wait_condition.inc --connection node_2 STOP SLAVE; RESET SLAVE ALL; --connection node_3 RESET MASTER; --connection node_1 --disconnect node_3 --source include/auto_increment_offset_restore.inc --source include/galera_end.inc --echo # End of test