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

#
# Test KILL CONNECTION on a transaction that has already replicated some data via SR
#

SET SESSION wsrep_trx_fragment_size = 1;

CREATE TABLE t1 (f1 INTEGER) ENGINE=InnoDB;

SET AUTOCOMMIT=OFF;
START TRANSACTION;

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);

# Confirm that the transaction is SR-replicated
--connection node_2
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
--let $wait_condition = SELECT COUNT(*) > 0 FROM t1;
--source include/wait_condition.inc

# Kill the transaction by killing the entire connection

--connection node_1
--let $connection_id = `SELECT CONNECTION_ID()`
--connect node_1a, 127.0.0.1, root, , test, $NODE_MYPORT_1
--disable_query_log
--eval KILL CONNECTION $connection_id
--enable_query_log

# Confirm that the disconnection caused the updates made so far to be removed
--connection node_2
--let $wait_condition = SELECT COUNT(*) = 0 FROM t1;
--source include/wait_condition.inc

# Confirm that the transaction can be reissued in its entirety on the slave without a conflict

SET AUTOCOMMIT=OFF;
START TRANSACTION;

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);

COMMIT;

SELECT COUNT(*) = 5 FROM t1;

--connection node_1a
SELECT COUNT(*) = 5 FROM t1;

DROP TABLE t1;
