summaryrefslogtreecommitdiff
path: root/storage/rocksdb/mysql-test/rocksdb/t/deadlock_tracking.test
blob: d2abcb3b63b46c0ba0a8884123aafa98fa7066e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
set @prior_lock_wait_timeout = @@rocksdb_lock_wait_timeout; 
set @prior_deadlock_detect = @@rocksdb_deadlock_detect; 
set @prior_max_latest_deadlocks = @@rocksdb_max_latest_deadlocks; 
set global rocksdb_deadlock_detect = on; 
set global rocksdb_lock_wait_timeout = 10000;
--echo # Clears deadlock buffer of any prior deadlocks.
set global rocksdb_max_latest_deadlocks = 0;
set global rocksdb_max_latest_deadlocks = @prior_max_latest_deadlocks;
let $engine = rocksdb;

--source include/count_sessions.inc
connect (con1,localhost,root,,);
let $con1= `SELECT CONNECTION_ID()`;

connect (con2,localhost,root,,);
let $con2= `SELECT CONNECTION_ID()`;

connect (con3,localhost,root,,);
let $con3= `SELECT CONNECTION_ID()`;

connection default;
eval create table t (i int primary key) engine=$engine;
insert into t values (1), (2), (3);
--replace_regex /[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/TIMESTAMP/ /WAITING KEY: [0-9a-f]{16}/KEY/ /TRANSACTIONID: [0-9]*/TXN_ID/
show engine rocksdb transaction status;

echo Deadlock #1;
--source include/simple_deadlock.inc
connection default;
--replace_regex /[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/TIMESTAMP/ /WAITING KEY: [0-9a-f]{16}/KEY/ /TRANSACTIONID: [0-9]*/TXN_ID/
show engine rocksdb transaction status;

echo Deadlock #2;
--source include/simple_deadlock.inc
connection default;
--replace_regex /[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/TIMESTAMP/ /WAITING KEY: [0-9a-f]{16}/KEY/ /TRANSACTIONID: [0-9]*/TXN_ID/
show engine rocksdb transaction status;
set global rocksdb_max_latest_deadlocks = 10;

echo Deadlock #3;
--source include/simple_deadlock.inc
connection default;
--replace_regex /[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/TIMESTAMP/ /WAITING KEY: [0-9a-f]{16}/KEY/ /TRANSACTIONID: [0-9]*/TXN_ID/
show engine rocksdb transaction status;
set global rocksdb_max_latest_deadlocks = 1;
--replace_regex /[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/TIMESTAMP/ /WAITING KEY: [0-9a-f]{16}/KEY/ /TRANSACTIONID: [0-9]*/TXN_ID/
show engine rocksdb transaction status;

connection con3;
set rocksdb_deadlock_detect_depth = 2;

echo Deadlock #4;
connection con1;
begin; 
select * from t where i=1 for update;

connection con2;
begin; 
select * from t where i=2 for update;

connection con3;
begin; 
select * from t where i=3 for update;

connection con1;
send select * from t where i=2 for update;

connection con2;
let $wait_condition = select count(*) = 1 from information_schema.rocksdb_trx
where thread_id = $con1 and waiting_key != "";
--source include/wait_condition.inc

send select * from t where i=3 for update;

connection con3;
let $wait_condition = select count(*) = 1 from information_schema.rocksdb_trx
where thread_id = $con2 and waiting_key != "";
--source include/wait_condition.inc

--error ER_LOCK_DEADLOCK
select * from t where i=1 for update;
rollback;

connection con2;
reap; 
rollback;

connection con1;
reap; 
rollback;

connection default;
set global rocksdb_max_latest_deadlocks = 5;
--replace_regex /[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/TIMESTAMP/ /WAITING KEY: [0-9a-f]{16}/KEY/ /TRANSACTIONID: [0-9]*/TXN_ID/
show engine rocksdb transaction status;

echo Deadlock #5;
connection con1;
begin; 
select * from t where i=1 for update;

connection con2;
begin; 
select * from t where i=2 for update;

connection con3;
begin; 
select * from t where i=3 lock in share mode;

connection con1;
select * from t where i=100 for update;
select * from t where i=101 for update;
send select * from t where i=2 for update;

connection con2;
let $wait_condition = select count(*) = 1 from information_schema.rocksdb_trx
where thread_id = $con1 and waiting_key != "";
--source include/wait_condition.inc

select * from t where i=3 lock in share mode;
select * from t where i=200 for update;
select * from t where i=201 for update;

--error ER_LOCK_DEADLOCK
select * from t where i=1 lock in share mode;
rollback;

connection con1;
reap; 
rollback;

connection con3;
rollback;

connection default;
--replace_regex /[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/TIMESTAMP/ /WAITING KEY: [0-9a-f]{16}/KEY/ /TRANSACTIONID: [0-9]*/TXN_ID/
show engine rocksdb transaction status;

disconnect con1;
disconnect con2;
disconnect con3;

set global rocksdb_lock_wait_timeout = @prior_lock_wait_timeout; 
set global rocksdb_deadlock_detect = @prior_deadlock_detect;
drop table t;
--replace_regex /[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/TIMESTAMP/ /WAITING KEY: [0-9a-f]{16}/KEY/ /TRANSACTIONID: [0-9]*/TXN_ID/ /INDEX_ID: [0-9a-f]*/IDX_ID/
show engine rocksdb transaction status;
set global rocksdb_max_latest_deadlocks = 0;
--echo # Clears deadlock buffer of any existent deadlocks.
set global rocksdb_max_latest_deadlocks = @prior_max_latest_deadlocks;
--replace_regex /[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/TIMESTAMP/ /WAITING KEY: [0-9a-f]{16}/KEY/ /TRANSACTIONID: [0-9]*/TXN_ID/ /INDEX_ID: [0-9a-f]*/IDX_ID/
show engine rocksdb transaction status;
--source include/wait_until_count_sessions.inc