#
# This test kills the slave while a Streaming Replication transaction is in progress
# and after a fragment has already been applied on the slave. It is expected that 
# after the slave restarts, the cluster will continue to be consistent even if ROLLBACK
# is issued on the SR transaction after restart.
#

--source include/galera_cluster.inc
--source include/have_innodb.inc

--connect node_3, 127.0.0.1, root, , test, $NODE_MYPORT_3

# Save original auto_increment_offset values.
--let $node_1=node_1
--let $node_2=node_2
--let $node_3=node_3
--source ../galera/include/auto_increment_offset_save.inc

--connection node_1

--let $wsrep_trx_fragment_size_orig = `SELECT @@wsrep_trx_fragment_size`
SET SESSION wsrep_trx_fragment_size = 1;
SET AUTOCOMMIT=OFF;
START TRANSACTION;

CREATE TABLE t1 (f1 INTEGER PRIMARY KEY) ENGINE=InnoDB;
INSERT INTO t1 VALUES (1);
INSERT INTO t1 VALUES (2);
INSERT INTO t1 VALUES (3);
INSERT INTO t1 VALUES (4);
INSERT INTO t1 VALUES (5);

--connection node_2
SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
--let $wait_condition = SELECT COUNT(*) > 0 FROM t1;
--source include/wait_condition.inc

--source include/kill_galera.inc

--connection node_1
INSERT INTO t1 VALUES (6);
INSERT INTO t1 VALUES (7);
INSERT INTO t1 VALUES (8);
INSERT INTO t1 VALUES (9);
INSERT INTO t1 VALUES (10);

--connection node_2
--source include/start_mysqld.inc

--connection node_1
INSERT INTO t1 VALUES (11);
INSERT INTO t1 VALUES (12);
INSERT INTO t1 VALUES (13);
INSERT INTO t1 VALUES (14);
INSERT INTO t1 VALUES (15);

--connection node_2

SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
--let $wait_condition = SELECT COUNT(*) = 15 FROM t1;
--source include/wait_condition.inc

SELECT COUNT(*) = 15 FROM mysql.wsrep_streaming_log;

--connection node_1
ROLLBACK;

SELECT COUNT(*) = 0 FROM mysql.wsrep_streaming_log;

--connection node_2
SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
SELECT COUNT(*) = 0 FROM t1;
SELECT COUNT(*) = 0 FROM mysql.wsrep_streaming_log;

SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
SELECT COUNT(*) = 0 FROM t1;
SELECT COUNT(*) = 0 FROM mysql.wsrep_streaming_log;

DROP TABLE t1;

--source ../galera/include/auto_increment_offset_restore.inc
