###############################################################################
# Bug#17812024  MTS IS NOT ABLE TO REPRODUCE BINLOGS AS RELAY LOGS
# Problem: When a binarylog is used as a relaylog (transfer binarylogs to
# Slave machine to avoid I/O thread reading delay), MTS is unable to operate
# on that kind of relaylog.

# Steps to Reproduce:
#  1) Prepare a binary log with some 3 sample GTIDs
#  2) Make that binary log as relay log
#  3) Set slave_parallel_workers to 1 and start worker thread
#  4) Make sure everything is replicated
###############################################################################

--source include/have_gtid.inc
--source include/have_binlog_format_statement.inc
--source include/master-slave.inc
# Initial setup
--let $MYSQLD_MASTER_DATADIR= `select @@datadir`
--connection slave
--let $MYSQLD_SLAVE_DATADIR= `select @@datadir`
--source include/stop_slave_sql.inc

# Step-1: Prepare a binary log with 3 sample GTIDs
--connection master
CREATE TABLE t1(i INT);
INSERT INTO t1 values (1);
INSERT INTO t1 values (2);
--source include/sync_slave_io_with_master.inc

# Step-2: Make that binary log as relay log
--remove_file $MYSQLD_SLAVE_DATADIR/slave-relay-bin.000001
--copy_file $MYSQLD_MASTER_DATADIR/master-bin.000001 $MYSQLD_SLAVE_DATADIR/slave-relay-bin.000001

# Step-3: Now start worker thread with that relay log(binary log as relay log)
# and see that worker thread does not have issues in completing it.
SET @save.slave_parallel_workers=@@global.slave_parallel_workers;
SET @@global.slave_parallel_workers=1;

SET @save.slave_transaction_retries=@@global.slave_transaction_retries;
SET @@global.slave_transaction_retries=0;
--source include/start_slave_sql.inc

# Step-4: Make sure everything is replicated
--connection master
--source include/sync_slave_sql_with_master.inc
--let diff_tables=master:t1,slave:t1
--source include/diff_tables.inc

# Cleanup
--connection master
DROP TABLE t1;
--connection slave
--source include/stop_slave_sql.inc
SET @@global.slave_parallel_workers=@save.slave_parallel_workers;
SET @@global.slave_transaction_retries=@save.slave_transaction_retries;
--source include/start_slave_sql.inc
--source include/rpl_end.inc
