MySQL Forums
Forum List  »  InnoDB

Does Innodb have U-Lock ?
Posted by: SeWoong Jeon
Date: September 23, 2008 02:38AM

Hi , I'm using MySQL Enterprise 5.0.40.
I have some problem about Innodb deadlock.

(Trx1) UPDATE tb_sample SET cnt=cnt+1 WHERE pk=10
(Trx2) UPDATE tb_sample SET cnt=0 WHERE pk=10

Trx1 get S-Lock for read "cnt"
Trx2 request X-Lock, but wait for end of Trx1
Trx1 request X-Lock for update, but wait for end of Trx2
--> DeadLock!! Trx2 was roll-backed by Innodb

MSSQL use U-Lock to prevent such situration of deadlock in repeatable read or serializable transaction.
http://msdn.microsoft.com/en-us/library/ms175519.aspx

Doesn't Innodb have U-Lock?
If InnoDB doesn't have U-Lock, I think Trx1 have to get X-Lock first not S-Lock.
How can I solve this deadlock problem?

===================================================
this is my real deadlock message
Primary of "buddylist" table is "userid + buddyid"
===================================================

*** (1) TRANSACTION:
TRANSACTION 0 1340575717, ACTIVE 0 sec, process no 12769, OS thread id 1262823776 starting index read
mysql tables in use 1, locked 1
LOCK WAIT 2 lock struct(s), heap size 368
MySQL thread id 648655934, query id 7991043214 192.168.1.80 was updating
DELETE FROM MyDB.buddylist WHERE userid='aaa@domain.com' AND buddyid='bbb@domain.com' AND (btype='1' OR btype='2' OR btype='3')
*** (1) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 669 page no 226142 n bits 248 index `PRIMARY` of table `MyDB/buddylist` trx id 0 1340575717 lock_mode X locks rec but not gap waiting
Record lock, heap no 163 PHYSICAL RECORD: n_fields 6; compact format; info bits 0
0: len 19; hex 726a73646c32303430406e617665722e636f6d; asc aaa@domain.com;; 1: len 18; hex 676f766c34323037406e617665722e636f6d; asc bbb@domain.com;; 2: len 6; hex 00004aee94ad; asc J ;; 3: len 7; hex 000000002d24b6; asc -$ ;; 4: len 1; hex 81; asc ;; 5: len 8; hex 80001243736601be; asc Csf ;;

*** (2) TRANSACTION:
TRANSACTION 0 1340575719, ACTIVE 0 sec, process no 12769, OS thread id 1297701216 starting index read, thread declared inside InnoDB 500
mysql tables in use 1, locked 1
3 lock struct(s), heap size 1216
MySQL thread id 648655935, query id 7991043224 192.168.1.79 was Updating
UPDATE MyDB.buddylist SET btype=btype|4 WHERE userid='aaa@domain.com' AND buddyid='bbb@domain.com'
*** (2) HOLDS THE LOCK(S):
RECORD LOCKS space id 669 page no 226142 n bits 248 index `PRIMARY` of table `MyDB/buddylist` trx id 0 1340575719 lock mode S locks rec but not gap
Record lock, heap no 163 PHYSICAL RECORD: n_fields 6; compact format; info bits 0
0: len 19; hex 726a73646c32303430406e617665722e636f6d; asc aaa@domain.com;; 1: len 18; hex 676f766c34323037406e617665722e636f6d; asc bbb@domain.com;; 2: len 6; hex 00004aee94ad; asc J ;; 3: len 7; hex 000000002d24b6; asc -$ ;; 4: len 1; hex 81; asc ;; 5: len 8; hex 80001243736601be; asc Csf ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 669 page no 226142 n bits 248 index `PRIMARY` of table `MyDB/buddylist` trx id 0 1340575719 lock_mode X locks rec but not gap waiting
Record lock, heap no 163 PHYSICAL RECORD: n_fields 6; compact format; info bits 0
0: len 19; hex 726a73646c32303430406e617665722e636f6d; asc aaa@domain.com;; 1: len 18; hex 676f766c34323037406e617665722e636f6d; asc bbb@domain.com;; 2: len 6; hex 00004aee94ad; asc J ;; 3: len 7; hex 000000002d24b6; asc -$ ;; 4: len 1; hex 81; asc ;; 5: len 8; hex 80001243736601be; asc Csf ;;

*** WE ROLL BACK TRANSACTION (2)



Edited 5 time(s). Last edit at 09/23/2008 08:59AM by SeWoong Jeon.

Options: ReplyQuote


Subject
Views
Written By
Posted
Does Innodb have U-Lock ?
2337
September 23, 2008 02:38AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.