故障排除一致"SQLException:超出锁定等待超时"

Rob*_*ell 9 mysql locking transactions jdbc quartz-scheduler

我有一个运行Quartz 1.6.1 w/persistent job store的应用程序,MySQL 5.1作为DB.这个应用程序用于在Tomcat6中启动.在某些时候,它开始在每次启动时抛出以下异常:

- MisfireHandler: Error handling misfires: Failure obtaining db row lock: Lock wait timeout exceeded; try restarting transaction
org.quartz.impl.jdbcjobstore.LockException: Failure obtaining db row lock: Lock wait timeout exceeded; try restarting transaction [See nested exception: java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction]
    at org.quartz.impl.jdbcjobstore.StdRowLockSemaphore.executeSQL(StdRowLockSemaphore.java:112)
    at org.quartz.impl.jdbcjobstore.DBSemaphore.obtainLock(DBSemaphore.java:112)
    at org.quartz.impl.jdbcjobstore.JobStoreSupport.doRecoverMisfires(JobStoreSupport.java:3075)
    at org.quartz.impl.jdbcjobstore.JobStoreSupport$MisfireHandler.manage(JobStoreSupport.java:3838)
    at org.quartz.impl.jdbcjobstore.JobStoreSupport$MisfireHandler.run(JobStoreSupport.java:3858)
Caused by: java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2542)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1734)
    at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1885)
    at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:76)
    at org.quartz.impl.jdbcjobstore.StdRowLockSemaphore.executeSQL(StdRowLockSemaphore.java:92)
    ... 4 more
Run Code Online (Sandbox Code Playgroud)

我应该提到这个应用程序还利用JPA w/Hibernate使用C3P0进行数据源连接池.在JPA完成更新架构后,将始终直接抛出此异常.

首先,我升级到Quartz 1.6.5并且异常消失,但应用程序似乎已冻结.日志中的最后一件事 - 过去的例外 - 是:

...hbm2ddl stuff...
2969 [Thread-1] INFO org.hibernate.tool.hbm2ddl.SchemaUpdate - schema update complete
- Handling 6 trigger(s) that missed their scheduled fire-time.
Run Code Online (Sandbox Code Playgroud)

什么都没有,并且webapp没有服务请求; 他们只是无限期地挂起来.

当我在异常之后立即使用SHOW INNODB STATUS运行mysql命令行客户端时,它会一直显示两个可疑事务:

----------
SEMAPHORES
----------
OS WAIT ARRAY INFO: reservation count 49, signal count 49
Mutex spin waits 0, rounds 2100, OS waits 0
RW-shared spins 115, OS waits 49; RW-excl spins 0, OS waits 0
------------
TRANSACTIONS
------------
Trx id counter 0 165688
Purge done for trx's n:o < 0 165685 undo n:o < 0 0
History list length 12
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION 0 0, not started, OS thread id 5012
MySQL thread id 8, query id 1798 localhost 127.0.0.1 root
SHOW INNODB STATUS
---TRANSACTION 0 165687, ACTIVE 300 sec, OS thread id 3772
2 lock struct(s), heap size 320, 1 row lock(s)
MySQL thread id 30, query id 1795 localhost 127.0.0.1 my_app
---TRANSACTION 0 165685, ACTIVE 360 sec, OS thread id 5460
2 lock struct(s), heap size 320, 1 row lock(s), undo log entries 1
MySQL thread id 34, query id 1680 localhost 127.0.0.1 my_app
Run Code Online (Sandbox Code Playgroud)

我正在寻找有关如何进一步调查此问题的指导.也许如果我能以某种方式识别这两个交易的所有者,或者他们锁定了哪些资源?

更新:我删除了qrtz_simple_triggers表中的所有行没有问题.然后我尝试在qrtz_triggers表上执行相同操作,我的MySQL客户端抛出了"超出锁定等待超时"错误.此时我停止了我的(仍悬空)应用程序,然后能够删除qrtz_triggers表的所有行.完成此操作后,我能够成功启动我的应用程序.

看起来我需要记录一个新的Quartz错误,但是我希望能够向他们提供更多有关这里真正hapenning的信息.因此,根据原始问题,我该如何解决这些类型的问题?

小智 1

您是否尝试过运行
show processlist

show full processlist
从 mysql 命令行?这些通常会显示锁定查询的完整 sql。它还将显示进程运行该查询的时间。它可能会帮助您更接近答案。