-
2024.07.04~06 deadlock detectionTIL 2024. 7. 7. 00:36
https://dev.mysql.com/blog-archive/innodb-data-locking-part-3-deadlocks/
MySQL :: InnoDB Data Locking – Part 3 "Deadlocks"
In this blog series, I’m describing how InnoDB locks data (tables and rows) in order to provide illusion to clients that their queries are executed one after another, and how this was improved in recent releases. In InnoDB Data Locking – Part 1 “In
dev.mysql.com
음 읽고 있는데 많이 길다.
읽은 부분까지를 보면.. mysql은 WFG를 사용하고 있고, node가 추가될 때마다 감지가 작동한다.
node라고 하면 자원을 요청하는 lock을 의미하는 거 같다.
이로 인해 그래프 탐색 알고리즘이 쓰이고 있다.
자원순환고리가 있을 때 데드락이라고 판단한다.
또 트랜잭션을 끊어서 발생시킬 경우 최종 결과가 의도대로 되지 않을 수 있으니 원하는 자원은 트랜잭션이 시작하고 다 선점해야 한다는 이야기도 있다.
https://github.com/google/mysql/blob/master/sql/mdl.cc
mysql/sql/mdl.cc at master · google/mysql
Automatically exported from code.google.com/p/google-mysql - google/mysql
github.com
mysql 코드인데 acquire_lock 부분을 보면 find_deadlock를 호출한다. find_deadlock은 while(1)로 돌고 있는 것을 확인할 수 있다.
new edge가 추가되면 그때 그래프 탐색을 해서 자원 순환고리를 찾는 거 같다.여기서 노드(점)는 자원을 에지(화살표)는 자원 요청으로 생각된다. 아래의 글을 보면 T는 R의 자원을 대기하고 이후 R은 T에게 에세스된다.
에지는 2개니 위의 둘을 의미하는 거 같다.
그럼 새로운 에지가 추가되면 데드락 감지가 이뤄진다는 것이니. 자원을 점유하고자 할 때 에지가 생기고 데드락 탐지를 한다는 것이다.
아마 락을 잡을 때만 발생하지 않을까. -> mysql 코드를 보면 맞다. acquire_lock 을 할 때 find_deadlock을 호출.
mysql WFG에 대해 더 검색을 해보면..
아래의 글에서는 lasted deadlock 조회 시 mysql 5.6 버전에서는 데드락을 감지하면서 데드락 사이클을 기록하지 않고 첫 번째와 마지막 트랜잭션만을 기록한다고 설명한다.
https://www.tencentcloud.com/document/product/1035/48632
Tencent Cloud
Tencent is a leading influencer in industries such as social media, mobile payments, online video, games, music, and more. Leverage Tencent's vast ecosystem of key products across various verticals as well as its extensive expertise and networks to gain a
www.tencentcloud.com
데드락 감지는 os관련 자료도 많이 찾을 수 있다. 여기서 deadlock detection은 주기적으로 호출한다고 하는데..
위의 mysql은 어차피 데드락 사이클은 새로운 에지가 추가될 때 생기는 것이니 그때 감지한다는 것이다.
뭐가 되었든 장단점이 있다.
https://velog.io/@dahyeon/Chapter-8-Deadlocks
Chapter 8: Deadlocks
System consists of resourcesResource types $R_1$, $R_2$, . . ., $R_m$CPU cycles, memory space, I/O devicesEach resource type $R_i$ has $W_i$ instances
velog.io
https://dev.mysql.com/doc/refman/8.4/en/innodb-parameters.html#sysvar_innodb_lock_wait_timeout innodb_lock_wait_timeout 설정은 lock을 기다리다 롤백하는 시간인데 deadlock 탐지가 아닌 단순 오랜 시간 자원 점유 때문에 문제가 발생할 때 사용되는 설정이다. deadlock_detecttion설정이 켜져 있다면 deadlock cycle감지가 아닌 대기시간 만료 때 에러가 발생한다는 것. 꺼져있다면 deadlock cycle감지 없이 wait time만 보고 에러를 내는 거 같다.
만료이기 때문에 에러 문구가 다르다.
innodb_lock_wait_timeout 으로 인한 에러는
ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction이고
deadlock detection에 의한 것은
ERROR 1213 (40001): Deadlock found when trying to get lock; try restarting transaction이 되겠다.
'TIL' 카테고리의 다른 글
2024.07.09 locking Introduction (0) 2024.07.09 2024.07.07 How to Minimize and Handle Deadlocks (0) 2024.07.07 2024.07.01 wait-for-graph (0) 2024.07.01 2024.06.30 (0) 2024.06.30 2024.06.29 deadlock (0) 2024.06.29