summaryrefslogtreecommitdiff
path: root/storage/tokudb/mysql-test/tokudb/t/i_s_tokudb_lock_waits_released.test
blob: 0f712000527aa8577bc9926ee894e4bfb070b547 (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
# verify that information_schema.tokudb_locks gets populated with locks, information_schema.tokudb_lock_waits gets
# populated with 1 lock_wait and all transactions are present in information_schema.tokudb_trx for 2 clients

source include/have_tokudb.inc;
set default_storage_engine='tokudb';
set tokudb_prelock_empty=false;
disable_warnings;
drop table if exists t;
enable_warnings;

create table t (id int primary key);

# verify that txn_a insert (1) blocks txn_b insert (1) and txn_b gets a duplicate key error

# should be empty
select trx_id,trx_mysql_thread_id from information_schema.tokudb_trx;
select * from information_schema.tokudb_locks;
select * from information_schema.tokudb_lock_waits;

connect (conn_a,localhost,root,,);
set autocommit=0;
set tokudb_prelock_empty=OFF; # disable the bulk loader
insert into t values (1);

connect (conn_b,localhost,root,,);
set autocommit=0;
send insert into t values (1);

# should find the presence of a lock on 1st transaction
connection default;
let $wait_condition= select count(*)=1 from information_schema.processlist where info='insert into t values (1)' and state='update';
source include/wait_condition.inc;
real_sleep 1; # delay a little to shorten the update -> write row -> lock wait race

replace_column 1 TRX_ID 2 MYSQL_ID; 
replace_result $datadir ./;
select * from information_schema.tokudb_locks;

# should find the presence of a lock_wait on the 2nd transaction
replace_column 1 REQUEST_TRX_ID 2 BLOCK_TRX_ID 6 LOCK_WAITS_START_TIME;
replace_result $datadir ./;
select * from information_schema.tokudb_lock_waits;

# should find the presence of two transactions
replace_column 1 TRX_ID 2 MYSQL_ID;
select trx_id,trx_mysql_thread_id from information_schema.tokudb_trx;

connection conn_a;
commit;
# verify that the lock on the 1st transaction is released and replaced by the lock for the 2nd transaction
replace_column 1 TRX_ID 2 MYSQL_ID;
replace_result $datadir ./;
select * from information_schema.tokudb_locks;
select * from information_schema.tokudb_lock_waits;

connection conn_b;
--error 1062 # duplicate key
reap;
commit;

connection default;
disconnect conn_a;
disconnect conn_b;

# verify that txn_a replace (1) blocks txn_b replace (1) and txn_b eventually gets the lock on (1) and completes

# verify that the lock on the 2nd transaction has been released
# should be be empty
select trx_id,trx_mysql_thread_id from information_schema.tokudb_trx;
select * from information_schema.tokudb_locks;
select * from information_schema.tokudb_lock_waits;

connect (conn_a,localhost,root,,);
set autocommit=0;
set tokudb_prelock_empty=OFF; # disable the bulk loader
replace into t values (1);

connect (conn_b,localhost,root,,);
set autocommit=0;
send replace into t values (1);

# should find the presence of a lock on 1st transaction
connection default;
let $wait_condition= select count(*)=1 from information_schema.processlist where info='replace into t values (1)' and state='update';
source include/wait_condition.inc;
real_sleep 1; # delay a little to shorten the update -> write row -> lock wait race

replace_column 1 TRX_ID 2 MYSQL_ID; 
replace_result $datadir ./;
select * from information_schema.tokudb_locks;

# should find the presence of a lock_wait on the 2nd transaction
replace_column 1 REQUEST_TRX_ID 2 BLOCK_TRX_ID 6 LOCK_WAITS_START_TIME;
replace_result $datadir ./;
select * from information_schema.tokudb_lock_waits;

# should find the presence of two transactions
replace_column 1 TRX_ID 2 MYSQL_ID;
select trx_id,trx_mysql_thread_id from information_schema.tokudb_trx;

connection conn_a;
commit;
# verify that the lock on the 1st transaction is released and replaced by the lock for the 2nd transaction
replace_column 1 TRX_ID 2 MYSQL_ID;
replace_result $datadir ./;
select * from information_schema.tokudb_locks;
select * from information_schema.tokudb_lock_waits;

connection conn_b;
reap;
commit;

connection default;
disconnect conn_a;
disconnect conn_b;

# verify that the lock on the 2nd transaction has been released
# should be be empty
select trx_id,trx_mysql_thread_id from information_schema.tokudb_trx;
select * from information_schema.tokudb_locks;
select * from information_schema.tokudb_lock_waits;

drop table t;