scribbling
Mysql DB(innodb) 에서 deadlock 발생 및 처리
'김용환'
2012. 8. 17. 19:58
대용량 서비스플랫폼 인데, 여러 개의 Table을 포함한 처리를 한 Session에서 길게 잡은 것이 가장 큰 실수였다.
대용량 서비스에서는 DB 사용시에는 Transaction을 과감하게 빼야 할 듯.
<서비스 확인>
java의 mysql driver에서 아래와 같이 출력.
com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Deadlock found when trying to get lock; try restarting transaction
<Mysql DB>
mysql> SHOW ENGINE INNODB STATUS\G
------------------------
LATEST DETECTED DEADLOCK
------------------------
1. Transaction
1. wating the lock
2. Transaction
2. holds the lock
<해결>
1. DB Session을 아주 짧게 하는 처리로 작업.
2. Where절의 순서를 교체 (insert intention waiting 방지)
=> 더 이상의 deadlock은 발생하지 않음.
참고 자료
http://dev.mysql.com/doc/refman/5.0/en/innodb-monitors.html
Real MySQL - 이성욱