Thanks for the reply. On 9/3/2019 4:27 PM, Sergei Golubchik wrote:
Hi, mariadb!
On Sep 03, mariadb@biblestuph.com wrote:
Can someone fill me in as to what's happening behind the scenes when a thread has the state "Unlocking tables?"
It literally does just that, unlock tables. There's nothing that could cause a long wait, as far as I can see.
I looked here but did not see it listed:
https://mariadb.com/kb/en/library/general-thread-states/
Specifically, I sometimes see threads spending a lot of time in this state, and am looking to do some troubleshooting as to the cause of the delay. I.E., what could cause a thread to be delayed while in that state.
What statement spends a lot of time in this state? May be the table unlocking was long done, but some rogue code didn't reset the state.
The most common statements I see waiting in this state are multi-record inserts (with thousands of records).
What other threads are doing at this time? "Unlocking tables" should be fast, but still there are some mutex locks there, so if another thread got stuck holding that mutex (I don't see how, but still), it might've blocked unlocking.
An example from this past weekend: INSERT IGNORE INTO t1 .... The thread appeared to sit in Unlocking tables for at least 17 seconds (not dreadful, but enough to throw the feeder app out of whack, since it normally only takes a few seconds to complete). The only other thread I see that was busy the entire time the problem thread was in "Unlocking tables" is: Query-Repair by sorting ALTER TABLE t2 ENABLE KEYS Note that they were working on different tables. The ALTER TABLE t2 started before, and finished after the INSERT IGNORE INTO t1 executed. Other queries came and went during the time, or sat sleeping. I don't see anything trying to do anything with t2, but admittedly my data is not perfectly granular (there may been things that completely executed between my data logs). The problem query was followed by another just like it (different data set being entered, but same table) that sat in Unlocking Tables for at least 10 seconds. "Normally" these inserts take a second each, if that. Again, only the ALTER TABLE t2 was running the whole time.
They're (currently) MyISAM tables if it makes a difference.
It does. With InnoDB it's a bit more complicated.
And I should mention we also have concurrent_insert set to ALWAYS (2). A possible factor? Dan
Regards, Sergei VP of MariaDB Server Engineering and security@mariadb.org