1# MariaDB: including the below too many times causes really long argv list
2# in win_main()'s argument which blows up some limit on Windows.
3# Comment it out:
4#--source include/have_rocksdb.inc
5--source include/have_debug_sync.inc
6
7--source include/count_sessions.inc
8
9# Usage:
10#
11# let $order = ASC;  # or DESC
12# let $comment = "rev:cf2";  # or ""
13# --source suite/rocksdb/t/rocksdb_concurrent_delete.inc
14
15let $first_row = -1; # Error this should never happen
16if ($order == 'ASC')
17{
18  let $first_row = 1;
19  let $middle_row = 3;
20  let $end_row = 5;
21}
22if ($order == 'DESC')
23{
24  let $first_row = 5;
25  let $middle_row = 3;
26  let $end_row = 1;
27}
28
29connect (con, localhost, root,,);
30connection default;
31eval SET SESSION TRANSACTION ISOLATION LEVEL $isolation_level;
32
33SET debug_sync='RESET';
34
35eval CREATE TABLE t1 (pk INT PRIMARY KEY COMMENT $comment, a INT);
36INSERT INTO t1 VALUES(1,1), (2,2), (3,3), (4,4), (5,5);
37
38# This will cause the SELECT to block after finding the first row, but
39# before locking and reading it.
40--echo --PK first row delete
41connection con;
42eval SET SESSION TRANSACTION ISOLATION LEVEL $isolation_level;
43SET debug_sync='rocksdb_concurrent_delete SIGNAL parked WAIT_FOR go';
44send_eval SELECT * FROM t1 order by t1.pk $order FOR UPDATE;
45
46# While that connection is waiting, delete the first row (the one con
47# is about to lock and read
48connection default;
49SET debug_sync='now WAIT_FOR parked';
50eval DELETE FROM t1 WHERE pk = $first_row;
51
52# Signal the waiting select to continue
53SET debug_sync='now SIGNAL go';
54
55# Now get the results from the select.  The first entry (1,1) (or (3,3) when
56# using reverse ordering) should be missing.  Prior to the fix the SELECT
57# would have returned: "1815: Internal error: NotFound:"
58connection con;
59reap;
60
61# Deleting a middle row
62--echo --PK middle row delete
63SET debug_sync='rocksdb_concurrent_delete SIGNAL parked WAIT_FOR go';
64send_eval SELECT * FROM t1 order by t1.pk $order FOR UPDATE;
65
66connection default;
67SET debug_sync='now WAIT_FOR parked';
68eval DELETE FROM t1 WHERE pk = $middle_row;
69SET debug_sync='now SIGNAL go';
70
71connection con;
72if ($isolation_level == "REPEATABLE READ")
73{
74  --error ER_LOCK_DEADLOCK
75  reap;
76}
77if ($isolation_level == "READ COMMITTED")
78{
79  reap;
80}
81
82# Deleting the end row
83--echo --PK end row delete
84SET debug_sync='rocksdb_concurrent_delete SIGNAL parked WAIT_FOR go';
85send_eval SELECT * FROM t1 order by t1.pk $order FOR UPDATE;
86
87connection default;
88SET debug_sync='now WAIT_FOR parked';
89eval DELETE FROM t1 WHERE pk = $end_row;
90SET debug_sync='now SIGNAL go';
91
92connection con;
93if ($isolation_level == "REPEATABLE READ")
94{
95  --error ER_LOCK_DEADLOCK
96  reap;
97}
98if ($isolation_level == "READ COMMITTED")
99{
100  reap;
101}
102
103
104# Cleanup
105connection default;
106disconnect con;
107set debug_sync='RESET';
108drop table t1;
109--source include/wait_until_count_sessions.inc
110