Rails版本: 2.3.8
我的应用程序在一天中许多时间里似乎会随机返回500错误,并在生产日志中对应一个条目:
ActiveRecord::StatementInvalid (Mysql::Error: Lock wait timeout exceeded; try restarting transaction: INSERT INTO `forum_posts` (`forum_topic_id`, `created_at`, `body`, `ancestry`, `updated_at`, `quote_limit`, `user_id`, `ancestry_depth`, `quote_root`) VALUES(1224783, '2011-01-24 19:18:38', 'Post body', '1285704', '2011-01-24 19:18:38', 1, 57931, 1, 1))
检查MySQL慢查询日志,显示以下条目:
# Time: 110124 11:19:29
# User@Host: db_user[db_user] @ localhost []
# Query_time: 51 Lock_time: 0 Rows_sent: 0 Rows_examined: 0
SET insert_id=0;
INSERT INTO `forum_posts` (`forum_topic_id`, `created_at`, `body`, `ancestry`, `updated_at`, `quote_limit`, `user_id`, `ancestry_depth`, `quote_root`) VALUES(1224783, '2011-01-24 19:18:38', 'Post body', '1285704', '2011-01-24 19:18:38', 1, 57931, 1, 1);
根据Rails日志,ActiveRecord返回了一个错误,因为锁等待超时了。这个简单查询的长时间运行似乎也表明了这一点。问题在于,在慢查询日志中,我找不到任何实际需要长时间处理的查询 - 它们都类似于上面的示例。此外,在同一日志中,没有一个条目的
Lock_time
值大于0。这里有人知道是什么原因导致了这个明显的锁定,以及如何隔离它吗?我正在使用的当前工具似乎并没有帮助太多。
提前感谢。
show innodb status
显示任何长时间运行的事务吗?这可能会创建未在其他地方显示的隐式锁。 - Marc B