Page MenuHomePhabricator

Log the query that caused a lock timeout
Open, LowPublic

Description

I suspect this is not possible but no harm in trying: it would be great if the error log about some DB query timing out due to a lock could automatically include what was the other query that caused the lock. DB error logs contain a bunch of information about the failing query (stack trace, sanitized query text) but in the case of lock timeouts, more often than not it's the locking query and not the locked query that's problematic, and there is no information about that at all, so identifying it tends to take a considerable amount of time.

Maybe something like SHOW ENGINE INNODB STATUS or innodb_print_all_deadlocks could be used to get locking query info into the error logs?

See also: T195792: Add support for setting individual query timeout in wikimedia/rdbms

Event Timeline

I don't think "interactive logging" would be easy to implement- the query knows if it cannot continue or if it reaches a timeout, but it is not notified of who handles the row locks. There could be, however, queries of heuristics causes with processlist or some of the suggestions mentioned.

However, on T195578 there could be global monitoring that could be useful (but I am not sure if it is enabled).