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

#
# Test that ROLLBACK TO SAVEPOINT works correctly with streaming replication
#

--connection node_1
CREATE TABLE t1 (f1 INTEGER, f2 VARCHAR(10)) ENGINE=InnoDB;
SET SESSION wsrep_trx_fragment_size = 1;
SET AUTOCOMMIT=OFF;
START TRANSACTION;
INSERT INTO t1 VALUES (1, 'a');
INSERT INTO t1 VALUES (2, 'a');
INSERT INTO t1 VALUES (3, 'a');
INSERT INTO t1 VALUES (4, 'a');
INSERT INTO t1 VALUES (5, 'a');
--connection node_2
SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
--let $wait_condition = SELECT COUNT(*) > 0 FROM t1;
--source include/wait_condition.inc

--connection node_1
SAVEPOINT s1;
INSERT INTO t1 VALUES (11, 'b');
INSERT INTO t1 VALUES (12, 'b');
INSERT INTO t1 VALUES (13, 'b');
INSERT INTO t1 VALUES (14, 'b');
INSERT INTO t1 VALUES (15, 'b');

--connection node_2
--let $wait_condition = SELECT COUNT(*) > 5 FROM t1;
--source include/wait_condition.inc

--connection node_1
ROLLBACK TO SAVEPOINT s1;

INSERT INTO t1 VALUES (21, 'c');
INSERT INTO t1 VALUES (22, 'c');
INSERT INTO t1 VALUES (23, 'c');
INSERT INTO t1 VALUES (24, 'c');
INSERT INTO t1 VALUES (25, 'c');

--connection node_2
SELECT COUNT(*) = 5 FROM t1 WHERE f2 = 'a';
SELECT COUNT(*) = 0 FROM t1 WHERE f2 = 'b';
SELECT COUNT(*) = 5 FROM t1 WHERE f2 = 'c';

--connection node_1
COMMIT;
DROP TABLE t1;
