--source include/have_rocksdb.inc
--source include/have_debug_sync.inc
--source include/count_sessions.inc

set debug_sync='RESET';
set global rocksdb_debug_ttl_read_filter_ts = -10;

--connect (conn1, localhost, root,,)
--let $conn1_id = `SELECT CONNECTION_ID()`
connection default;

# MyRocks does not support gap locks in REPEATABLE-READ mode
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;

CREATE TABLE t1 (id INT, value INT, KEY (id), KEY (value)) ENGINE=ROCKSDB;
CREATE TABLE t2 (id INT, value INT) ENGINE=ROCKSDB;
CREATE TABLE t3 (id INT, kp1 INT, PRIMARY KEY (id), KEY(kp1)) ENGINE=ROCKSDB COMMENT='ttl_duration=1';

INSERT INTO t1 VALUES (1,1), (2,2), (3,3), (4,4), (5,5);
INSERT INTO t2 SELECT * FROM t1;
INSERT INTO t3 SELECT * FROM t1;

connection conn1;
set debug_sync='rocksdb.check_flags_rmi SIGNAL parked WAIT_FOR go';
send SELECT value FROM t1 WHERE value = 3;

connection default;
set debug_sync='now WAIT_FOR parked';
--echo KILL QUERY \$conn1_id;
--disable_query_log
eval KILL QUERY $conn1_id;
--enable_query_log
set debug_sync='now SIGNAL go';

connection conn1;
--error ER_QUERY_INTERRUPTED
--reap

set debug_sync='RESET';

connection conn1;
set debug_sync='rocksdb.check_flags_rmi_scan SIGNAL parked WAIT_FOR go';
send SELECT DISTINCT(id) FROM t1 WHERE value = 5 AND id IN (1, 3, 5);

connection default;
set debug_sync='now WAIT_FOR parked';
--echo KILL QUERY \$conn1_id;
--disable_query_log
eval KILL QUERY $conn1_id;
--enable_query_log
set debug_sync='now SIGNAL go';

connection conn1;
--error ER_QUERY_INTERRUPTED
--reap

set debug_sync='RESET';

connection conn1;
set debug_sync='rocksdb.check_flags_inwd SIGNAL parked WAIT_FOR go';
send SELECT value FROM t1 WHERE value > 3;

connection default;
set debug_sync='now WAIT_FOR parked';
--echo KILL QUERY \$conn1_id;
--disable_query_log
eval KILL QUERY $conn1_id;
--enable_query_log
set debug_sync='now SIGNAL go';

connection conn1;
--error ER_QUERY_INTERRUPTED
--reap

set debug_sync='RESET';

connection conn1;
set debug_sync='rocksdb.check_flags_rnwd SIGNAL parked WAIT_FOR go';
send SELECT id FROM t2;

connection default;
set debug_sync='now WAIT_FOR parked';
--echo KILL QUERY \$conn1_id;
--disable_query_log
eval KILL QUERY $conn1_id;
--enable_query_log
set debug_sync='now SIGNAL go';

connection conn1;
--error ER_QUERY_INTERRUPTED
--reap

set debug_sync='RESET';


connection conn1;
set debug_sync='rocksdb.check_flags_ser SIGNAL parked WAIT_FOR go';
send SELECT kp1 FROM t3 ORDER BY kp1;

connection default;
set debug_sync='now WAIT_FOR parked';
--echo KILL QUERY \$conn1_id;
--disable_query_log
eval KILL QUERY $conn1_id;
--enable_query_log
set debug_sync='now SIGNAL go';

connection conn1;
--error ER_QUERY_INTERRUPTED
--reap

connection default;
--disconnect conn1

set debug_sync='RESET';

set global rocksdb_debug_ttl_read_filter_ts = DEFAULT;

DROP TABLE t1;
DROP TABLE t2;
DROP TABLE t3;

--source include/wait_until_count_sessions.inc
