9

我有一个运行 Quartz 1.6.1 w/persistent job store 的应用程序,使用 MySQL 5.1 作为数据库。该应用程序在 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

我应该提到这个应用程序还利用 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.

之后什么都没有,并且 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

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

更新:我毫无问题地删除了qrtz_simple_triggers表中的所有行。然后我尝试在qrtz_triggers表上做同样的事情,我的 MySQL 客户端抛出了“超过锁定等待超时”错误。此时我停止了我的(仍然挂起的)应用程序,然后能够删除qrtz_triggers表的所有行。完成此操作后,我就能够成功启动我的应用程序。

看来我需要记录一个新的 Quartz 错误,但我希望能够给他们更多关于这里实际发生的事情的信息。那么,根据最初的问题,我该如何解决这些类型的问题?

4

1 回答 1

1

您是否尝试过运行
show processlist

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

于 2012-03-29T20:37:02.517 回答