# WL#3584 GTID.
#
# Testing failover scenarios.

--source include/have_innodb.inc
--source include/have_binlog_format_mixed.inc
#
# Set up 3 server replication chain: M1 -> S2 -> S3.
# Remove S2 and show M1 -> S3 works.
#

--let $rpl_topology= 1->2->3
--source include/rpl_init.inc
--echo

--connection server_1
create table t1 (a int not null auto_increment, b int not null, primary key(a)) engine=innodb;
--source include/rpl_sync.inc

--connection server_3
--source include/stop_slave.inc

#--let $rpl_topology= 1->2, 1->3
#--source include/rpl_change_topology.inc
--replace_result $SERVER_MYPORT_1 SERVER_MYPORT_1
--eval change master to master_port=$SERVER_MYPORT_1;
--source include/start_slave.inc

--connection server_1
insert into t1 values (NULL, 1);
--let $sync_slave_connection= server_2
--source include/sync_slave_sql_with_master.inc

--connection server_1
--let $sync_slave_connection= server_3
--source include/sync_slave_sql_with_master.inc

--let $diff_tables= server_1:test.t1, server_2:test.t1, server_3:test.t1
--source include/diff_tables.inc

#
# remove master, and set up S2 -> S3 link
# S3 proves to fail over S2 the new master.
# --let $rpl_topology= 2->3
#
--connection server_3
--source include/stop_slave.inc

--connection server_1
insert into t1 values (NULL, 2); # won't be seen by S3 until it connects to S2

--let $sync_slave_connection= server_2
--source include/sync_slave_sql_with_master.inc
--source include/stop_slave.inc

--connection server_3
--replace_result $SERVER_MYPORT_2 SERVER_MYPORT_2
--eval change master to master_port=$SERVER_MYPORT_2
--source include/start_slave.inc

--connection server_2
--let $sync_slave_connection= server_3
--source include/sync_slave_sql_with_master.inc

--let $diff_tables= server_1:test.t1, server_2:test.t1, server_3:test.t1
--source include/diff_tables.inc

# Restore M1 -> S2 -> S3

--connection server_2
--replace_result $SERVER_MYPORT_1 SERVER_MYPORT_1
--eval change master to master_port=$SERVER_MYPORT_1
--source include/start_slave.inc

#
# Clean up
#
--echo *** Clean up ***

--connection server_1
DROP TABLE t1;

--source include/rpl_sync.inc
--source include/rpl_end.inc
