持续出现“SQLException: Lock wait timeout exceeded”的故障排除

9

我有一个应用程序,运行Quartz 1.6.1,并使用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

我应该提到,这个应用程序还使用了使用C3P0进行数据源连接池的JPA w/Hibernate。这个异常总是在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.

如果没有任何跟随的东西,且 Web 应用程序不服务请求,则它们会无限期挂起。

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

----------
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 bug,但我想能够提供更多关于实际发生情况的信息。因此,根据最初的问题,我该如何解决这些问题?
1个回答

1
你尝试过在mysql命令行中运行以下语句吗?
show processlist
或者
show full processlist
这些语句通常会显示锁定查询的完整SQL,还会显示该查询已运行的时间。它可能会帮助你更接近答案。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接