Bug #71580 | FLUSH TABLES WITH READ LOCK hangs when many clients run SELECT FOR UPDATE twice | ||
---|---|---|---|
Submitted: | 4 Feb 2014 9:02 | Modified: | 6 Feb 2014 17:01 |
Reporter: | Sadao Hiratsuka | Email Updates: | |
Status: | Verified | Impact on me: | |
Category: | MySQL Server: Locking | Severity: | S2 (Serious) |
Version: | 5.6.16, 5.5.36 | OS: | Any |
Assigned to: | CPU Architecture: | Any | |
Tags: | flush tables with read lock, select for update |
[4 Feb 2014 9:02]
Sadao Hiratsuka
[4 Feb 2014 9:03]
Sadao Hiratsuka
test program to reproduce problem
Attachment: ConcurrentSelectForUpdate.java (application/octet-stream, text), 1.83 KiB.
[4 Feb 2014 20:38]
Sveta Smirnova
Thank you for the report. Verified as described. Actually SELECT queries fail after innodb_lock_wait_timeout ends, then FLUSH TABLES succeeds, but it is still strange why queries can not be finished in turn.
[6 Feb 2014 0:50]
Sadao Hiratsuka
Here is a minimized test case. session1> BEGIN; session1> SELECT * FROM t WHERE id = 1 FOR UPDATE; session2> BEGIN; session2> SELECT * FROM t WHERE id = 1 FOR UPDATE; -- session 2 waits for session 1 session3> FLUSH TABLES WITH READ LOCK; -- session 3 waits for session 2 session1> SELECT * FROM t WHERE id = 2 FOR UPDATE -- session 1 waits for session 3 It seems deadlock. Is it a bug ? or an expected behavior ?
[6 Feb 2014 14:05]
Ståle Deraas
Posted by developer: This can be resolved through the lock timeout in InnoDB/SQL-layer: http://dev.mysql.com/doc/refman/5.6/en/innodb-parameters.html#sysvar_innodb_lock_wait_time...
[6 Feb 2014 17:01]
Sadao Hiratsuka
I think session 1 and session 2 should not fail by timeout. When session 3 takes a global read lock normally, other sessions wait until the lock is released, and do not fail by timeout. In this 3-way deadlock situation, if innodb_lock_wait_timeout is set to large value, session 1 & 2 wait infinitely. Or if innodb_lock_wait_timeout is set to small value, session 1 & 2 fail by timeout.