| 1 |
--echo #Test for Intention Shared lock |
| 2 |
|
| 3 |
-- connect (con1,localhost,root,,) |
| 4 |
-- connect (con2,localhost,root,,) |
| 5 |
-- connect (con3,localhost,root,,) |
| 6 |
|
| 7 |
--disable_warnings |
| 8 |
drop table if exists t1_is; |
| 9 |
--enable_warnings |
| 10 |
|
| 11 |
--connection con1 |
| 12 |
use test; |
| 13 |
create table t1_is (id integer, x integer, PRIMARY KEY (id)) engine=INNODB; |
| 14 |
insert into t1_is values (0,0),(1,1); |
| 15 |
SET autocommit=0; |
| 16 |
begin; |
| 17 |
select * from t1_is where id=0 FOR SHARE; |
| 18 |
|
| 19 |
--connection con2 |
| 20 |
begin; |
| 21 |
select * from t1_is; |
| 22 |
--send |
| 23 |
update t1_is set x = 2 where id = 0; |
| 24 |
|
| 25 |
--connection con3 |
| 26 |
|
| 27 |
# |
| 28 |
# WARNING |
| 29 |
# ======= |
| 30 |
# |
| 31 |
# Spurious failures possible on column LOCK_DATA |
| 32 |
# |
| 33 |
# One one hand, for the innodb storage engine, |
| 34 |
# the server returns the LOCK_DATA column using |
| 35 |
# 'best effort', without guarantees. |
| 36 |
# See in innodb: |
| 37 |
# - Innodb_data_lock_iterator::scan_trx() |
| 38 |
# - p_s_fill_lock_data() |
| 39 |
# - buf_page_try_get() |
| 40 |
# |
| 41 |
# In short, if the page is in the buffer pool, |
| 42 |
# LOCK_DATA for the record is returned. |
| 43 |
# However, if the page is not in the buffer pool, |
| 44 |
# the code just returns LOCK_DATA = NULL |
| 45 |
# instead of re-loading the page from disk just |
| 46 |
# to read LOCK_DATA. |
| 47 |
# |
| 48 |
# On the other hand, the point of this test |
| 49 |
# is to inspect LOCK_DATA returned in the |
| 50 |
# performance schema, to make sure the proper |
| 51 |
# record lock is printed. |
| 52 |
# |
| 53 |
# Note that a NULL is a valid result, not a failure. |
| 54 |
# |
| 55 |
# Due to connection con2 doing a select, |
| 56 |
# the hope is that this test produces predictable results. |
| 57 |
|
| 58 |
# Wait for con2 to block |
| 59 |
let $wait_condition= SELECT COUNT(*) = 1 FROM performance_schema.data_locks |
| 60 |
where object_name="t1_is" and lock_type = "RECORD" |
| 61 |
and lock_mode = "X,REC_NOT_GAP" and lock_status = "WAITING"; |
| 62 |
--source include/wait_condition.inc |
| 63 |
|
| 64 |
begin; |
| 65 |
|
| 66 |
select object_schema, object_name, lock_type, lock_mode, lock_status, lock_data |
| 67 |
from performance_schema.data_locks |
| 68 |
where object_name="t1_is" |
| 69 |
order by lock_type, lock_mode, lock_status, lock_data; |
| 70 |
|
| 71 |
# Repeat |
| 72 |
select object_schema, object_name, lock_type, lock_mode, lock_status, lock_data |
| 73 |
from performance_schema.data_locks |
| 74 |
where object_name="t1_is" |
| 75 |
order by lock_type, lock_mode, lock_status, lock_data; |
| 76 |
|
| 77 |
select count(*) into @health_check |
| 78 |
from performance_schema.data_locks where object_name="t1_is"; |
| 79 |
|
| 80 |
commit; |
| 81 |
|
| 82 |
# |
| 83 |
# Somehow Intention Shared / Shared locks |
| 84 |
# are not always reported, causing spurious test failures. |
| 85 |
# Dumping debug data to help diagnosis. |
| 86 |
# |
| 87 |
|
| 88 |
if (`select @health_check != 4`) |
| 89 |
{ |
| 90 |
--echo "TEST FAILED, DUMPING DATA TO DEBUG" |
| 91 |
select @health_check; |
| 92 |
select * from performance_schema.data_locks; |
| 93 |
select * from performance_schema.data_lock_waits; |
| 94 |
} |
| 95 |
|
| 96 |
--connection con1 |
| 97 |
commit; |
| 98 |
|
| 99 |
--connection con2 |
| 100 |
--reap |
| 101 |
commit; |
| 102 |
|
| 103 |
--connection default |
| 104 |
drop table t1_is; |
| 105 |
|
| 106 |
--disconnect con1 |
| 107 |
--disconnect con2 |
| 108 |
--disconnect con3 |
| 109 |
|