master bug InnoDB Error unlock row could not find a 4 mode lock

Steven1981發表於2010-07-22

OS:RHEL5u4_X64
VER:MYSQL5.1.40

MASTER_ERROR.LOG 報錯:
100722 11:56:19 InnoDB: Error: unlock row could not find a 4 mode lock on the record
100722 11:56:19 InnoDB: Error: unlock row could not find a 4 mode lock on the record
100722 11:56:19 InnoDB: Error: unlock row could not find a 4 mode lock on the record

[@more@]


從錯誤看,非常像BUG 41756 :

但條件場景不太像,我們系統變數 innodb_locks_unsafe_for_binlog=OFF,而以上BUG innodb_locks_unsafe_for_binlog=ON 才出現。


但在我們的版本中可以用以下語句重現錯誤: 
drop table if exists tb1,tb2;
create table `tb2` (`a` int,`b` int) engine=innodb;
insert into `tb2` values (1,2),(1,2) ;
create table `tb1` (`a` int,`b` int primary key) engine=innodb;
insert into `tb1` values (1,1),(null,2),(1,3),(1,4);

select 1 from `tb1` natural join (select * from `tb2`) as `d` for update;

#報: 100722 12:13:11 InnoDB: Error: unlock row could not find a 5 mode lock on the record

select 1 from `tb1` natural join (select * from `tb2`) as `d` lock in share mode;

#報 :100722 12:17:39 InnoDB: Error: unlock row could not find a 4 mode lock on the record


MYSQL 解釋: 出現這個錯誤的主要原因是:
In JT_EQ_REF (join_read_key()) access method,
MySQL is calling unlock_row twice for the first table (tb1) for each SELECT.
The error message is displayed on the second call.
The MySQL layer is breaking the protocol by invoking unlock_row twice for the same row.  

這種情況主要是發生在需要多表關聯並加鎖的SQL中;
鷹眼應用中,需要加鎖的select只有類似於 insert .... select 這樣的語句。 詢問開發後有這樣的語句:
insert opsnodegroup
(nodegroup_id, nodegroup_name, modify_time) select
b.nodegroup_id,
b.nodegroup_name,
b.modify_time
from
ops_nodegroup b
left outer join
opsnodegroup a
on a.nodegroup_id = b.nodegroup_id
where
a.nodegroup_id is null
and b.nodegroup_type =39 ;

但這個語句的執行時間與報錯時間不符 ;手動執行也沒有報錯;

鷹眼應用中,還有update tab1 ,tab2 這樣的語句。 但這樣的語句比較多,也無法追查;


這個BUG如果是按以上原理分析,對應用沒有影響,只是在日誌裡報一個錯誤。
我也測試了,SQL語句只要有1行匹配住,就不會報錯;
在以下場景下,類似以下語句會報錯 ;
透過全表掃描搜尋tb1(驅動表) , 但在tb1中0行匹配;

select 1 from `tb1` natural join (select * from `tb2`) as `d` for update;
select 1 from `tb1` inner join (select * from `tb2`) as `d` on tb1.a=d.a and tb1.b=d.b for update;
update tb1 ,tb2 set tb1.a=5 where tb1.a=tb2.a and tb1.b=tb2.b;

報:InnoDB: Error: unlock row could not find a 5 mode lock on the record

以上BUG 在VERSION 5.1.41有修復;


後續繼續觀察。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/703656/viewspace-1035477/,如需轉載,請註明出處,否則將追究法律責任。

相關文章