###############################################################################
# Description: Checks if DDL and DML statements are correctly logged by
#              servers and slave servers according to log-slave-updates,
#              and independent of their settings on the particular MySQLD
#              acting in the slave role
#
# Testing scenario: Cluster 1 replicates to Cluster 2
#   Key : BL = log-bin, LSU = log-slave-updates
#
#                       BL                        BL
#  cluster 1 [  srv_master  srv_master1  srv_master2  ]
#                   |----------+------------
#                   v          v           v
#  cluster 2 [  srv_slave  srv_slave1  srv_slave2 ]
#                                  BL     BL LSU  
#
#  - First replicate via srv_slave and check all nodes' Binlog contents
#  - Second replicate via srv_slave1 and check all nodes' Binlog contents
#  - Third replicate via srv_slave2 and check all nodes' Binlog contents
#
# Makes use of suite/ndb_rpl/t/ndb_rpl_multi_binlog_update.inc
# Originally motivated by bug#45756
###############################################################################

--source include/have_ndb.inc
--source include/have_log_bin.inc

###############################################################################
#                           Configuring Environment
###############################################################################

# setup _no_ replication to start with, but with all 6 servers included
--let $rpl_topology= none
--let $rpl_server_count= 6
--let $rpl_skip_reset_master_and_slave=1
--source include/rpl_init.inc
--let $rpl_skip_reset_master_and_slave=0

--echo *** Configuring connections ***
--let $rpl_connection_name= srv_master
--let $rpl_server_number= 1
--source include/rpl_connect.inc

--let $rpl_connection_name= srv_master1
--let $rpl_server_number= 2
--source include/rpl_connect.inc

--let $rpl_connection_name= srv_master2
--let $rpl_server_number= 3
--source include/rpl_connect.inc

--let $rpl_connection_name= srv_slave
--let $rpl_server_number= 4
--source include/rpl_connect.inc

--let $rpl_connection_name= srv_slave1
--let $rpl_server_number= 5
--source include/rpl_connect.inc

--let $rpl_connection_name= srv_slave2
--let $rpl_server_number= 6
--source include/rpl_connect.inc

--echo *** Waiting for each cluster to startup ***

# Check schema op binlogging enabled between servers on cluster1
--let $source_server=srv_master
--let $dest_server=srv_master2
source suite/ndb_rpl/t/wait_schema_logging.inc;

--let $source_server=srv_master1
--let $dest_server=srv_master
source suite/ndb_rpl/t/wait_schema_logging.inc;

--let $source_server=srv_master1
--let $dest_server=srv_master2
source suite/ndb_rpl/t/wait_schema_logging.inc;

--let $source_server=srv_master2
--let $dest_server=srv_master
source suite/ndb_rpl/t/wait_schema_logging.inc;

# Check schema op binlogging enabled between servers on cluster2
--let $source_server=srv_slave
--let $dest_server=srv_slave1
source suite/ndb_rpl/t/wait_schema_logging.inc;

--let $source_server=srv_slave
--let $dest_server=srv_slave2
source suite/ndb_rpl/t/wait_schema_logging.inc;

--let $source_server=srv_slave1
--let $dest_server=srv_slave2
source suite/ndb_rpl/t/wait_schema_logging.inc;

--let $source_server=srv_slave2
--let $dest_server=srv_slave1
source suite/ndb_rpl/t/wait_schema_logging.inc;

# Reset state of all Binlogging nodes
--disable_query_log
connection srv_master;
--disable_warnings
RESET MASTER;
--enable_warnings

connection srv_master2;
--disable_warnings
RESET MASTER;
--enable_warnings

connection srv_slave1;
--disable_warnings
RESET MASTER;
--enable_warnings

connection srv_slave2;
--disable_warnings
RESET MASTER;
--enable_warnings
--enable_query_log



--echo *** Configuring replication via Slave ***
--let $rpl_connection_name= srv_slave
--source include/rpl_connection.inc

--let $rpl_topology= 1->4
--source include/rpl_change_topology.inc

--source include/start_slave.inc

# Run the test script
--let $which_slave=srv_slave
--source suite/ndb_rpl/t/ndb_rpl_multi_binlog_update.inc

--source include/stop_slave.inc

# Reset state of all Binlogging nodes
--disable_query_log
connection srv_master;
--disable_warnings
RESET MASTER;
--enable_warnings

connection srv_master2;
--disable_warnings
RESET MASTER;
--enable_warnings

connection srv_slave1;
--disable_warnings
RESET MASTER;
--enable_warnings

connection srv_slave2;
--disable_warnings
RESET MASTER;
--enable_warnings
--enable_query_log



--echo *** Configuring replication via Slave1 ***
--let $rpl_connection_name= srv_slave1
--source include/rpl_connection.inc

--let $rpl_topology= 1->4,1->5
--source include/rpl_change_topology.inc

--source include/start_slave.inc

# Run the test script
--let $which_slave=srv_slave1
--source suite/ndb_rpl/t/ndb_rpl_multi_binlog_update.inc

--source include/stop_slave.inc

# Reset state of all Binlogging nodes
--disable_query_log
connection srv_master;
--disable_warnings
RESET MASTER;
--enable_warnings

connection srv_master2;
--disable_warnings
RESET MASTER;
--enable_warnings

connection srv_slave1;
--disable_warnings
RESET MASTER;
--enable_warnings

connection srv_slave2;
--disable_warnings
RESET MASTER;
--enable_warnings
--enable_query_log



--echo *** Configuring replication via Slave2 ***
--let $rpl_connection_name= srv_slave2
--source include/rpl_connection.inc

--let $rpl_topology= 1->4,1->5,1->6
--source include/rpl_change_topology.inc

--source include/start_slave.inc

# Run the test script
--let $which_slave=srv_slave2
--source suite/ndb_rpl/t/ndb_rpl_multi_binlog_update.inc

--source include/stop_slave.inc



# Cleanup and reset replication settings to how
# they where when test started
--let $rpl_topology= none
--source include/rpl_change_topology.inc
