Академический Документы
Профессиональный Документы
Культура Документы
We've recently witnessed behavior from MySQL whereby locks are not released. There
are two theories as to why this is happening:
1.MySQL just sucks and gets its lock structures confused
2.Our applications are starting transactions, taking out locks, then leaving the
transaction uncommitted.
The next time this comes up, it's probably worth it to capture the output of SHOW
ENGINE INNODB STATUS to determine if there is a long-running transaction causing
the problem.
The initial symptom is basically a lot of queries throwing errors about lock wait
timeouts. To trace the issue, first use innotop to see if there are locks hanging
out for a long time:
Notice, in this example, that process 818829 has been holding locks on the Tablets
table for over 5 minutes. This lines up with the errors that are complaining that
they're timing out trying to get a lock on the Tablets table.
Next, see if that process is actually doing anything that would justify holding the
lock that long:
Notice that process 818829 has been sleeping for 401 seconds. Suspicious.
It would appear that killing 818829 releases the lock and allows things to return
to normal. However, this doesn't help us understand the problem.
The next time this situation occurs, we should capture the output of SHOW ENGINE
INNODB STATUS and determine whether the offending process is stuck because of a bug
in MySQL, or whether the application has started a transaction, then forgotten
about it. I suspect that it's a bug in MySQL, since the last time this happened,
@Jon Burkhart investigated and determined that the queries under suspicious weren't
running in explicit transactions.