You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Possible cause for occasional DB update failure during site update #111
During the site update process, the mysql command that repopulates the DB with the new data computed by the site update program occasionally gets stuck. This seems to happen near the beginning in the series of DROP TABLEs. A guess: if this happens when one of the tables is actively in use by a process on the web front end, things get into a bad state.
The site update process switches the default DB to the backup right before the DB update. Then it does the same thing to switch back before updating the backup DB. It's certainly possible that users are actively querying the DB from the web front end during this time.
Idea: can we wait for all DB reads in process to complete before starting the series of DROP TABLEs?
How to wait? Read and write locks? But what happens there if a process hangs? Wait until the "process list" is empty? Same possible problem. Maybe the easiest temporary answer is a short delay (10 seconds? 30 seconds?) between the switch of the default DB in tm.conf and the start of the ingestion of the new .sql file to allow in-process queries time to finish? This doesn't "fix" the problem,. but it makes it much less likely to show up and only involves a couple new lines in the localupdate.sh script.
Maybe the easiest temporary answer is a short delay (10 seconds? 30 seconds?)
Timer are usually a bad idea. I think the maximum process time is when one loads a map of all regions (worldwide!). I sometimes load a map of all (central) European regions and it takes about 5 minutes (backend only). If you want a delay it should be.... 10 minutes? And it should not be possible to sent new requests. You would need a lock.
But maybe I got you wrong. How long should requests being blocked? As long as your famous "red update in progress message" is visible on the site (minutes) or just for some seconds at the beginning?
If it's possible (flags available) I would wait till all current requests are processed. "Process list" empty. If a process hangs I would kill it after a while (less than 60s). The user should get the "red update in progress message".
Requests on the site would not be blocked at all. The timer delay in the site update process (or better yet, as you point out, the wait for all read locks to be released before claiming a write lock). The idea is that the delay would allow ongoing requests to complete, but any new requests (new page loads) would be made using the backup DB.
With siteupdate.py failures pretty rare now, one way to do this would be to switch over to the backup DB before launching siteupdate.py. That gives several minutes for any site DB accesses to complete and new ones to switch to the backup DB before the primary DB gets updated. The switch back to primary is now done immediately after the primary DB repopulation is complete, so some other delay woudl be needed there.
The DB update got stuck tonight even though I switched to the DB copy well before the DB was being updated. So, I checked to see what "show processlist" would tell, and it shows a bunch of queries stuck in "user sleep":
+-------+---------+-----------+---------------+---------+-------+------------+------------------------------------------------------------------------------------------------------+
| Id | User | Host | db | Command | Time | State | Info |
+-------+---------+-----------+---------------+---------+-------+------------+------------------------------------------------------------------------------------------------------+
| 2119 | travmap | localhost | travelmapping | Query | 75342 | User sleep | SELECT * FROM routes LEFT JOIN systems ON systems.systemName = routes.systemName WHERE routes.system |
| 2896 | travmap | localhost | travelmapping | Query | 70328 | User sleep | SELECT * FROM routes LEFT JOIN systems ON systems.systemName = routes.systemName WHERE routes.system |
| 3966 | travmap | localhost | travelmapping | Query | 65486 | User sleep | SELECT * FROM routes LEFT JOIN systems ON systems.systemName = routes.systemName WHERE routes.system |
| 4784 | travmap | localhost | travelmapping | Query | 60519 | User sleep | SELECT * FROM routes LEFT JOIN systems ON systems.systemName = routes.systemName WHERE routes.system |
| 8995 | travmap | localhost | travelmapping | Query | 44720 | User sleep | SELECT * FROM routes LEFT JOIN systems ON systems.systemName = routes.systemName WHERE routes.system |
| 9871 | travmap | localhost | travelmapping | Query | 39346 | User sleep | SELECT * FROM routes LEFT JOIN systems ON systems.systemName = routes.systemName WHERE routes.system |
| 10540 | travmap | localhost | travelmapping | Query | 33711 | User sleep | SELECT * FROM routes LEFT JOIN systems ON systems.systemName = routes.systemName WHERE routes.system |
| 11636 | travmap | localhost | travelmapping | Query | 24101 | User sleep | SELECT * FROM routes LEFT JOIN systems ON systems.systemName = routes.systemName WHERE routes.system |
| 12495 | travmap | localhost | travelmapping | Query | 16900 | User sleep | SELECT * FROM routes LEFT JOIN systems ON systems.systemName = routes.systemName WHERE routes.system |
| 12959 | travmap | localhost | travelmapping | Query | 12866 | User sleep | SELECT * FROM routes LEFT JOIN systems ON systems.systemName = routes.systemName WHERE routes.system |
| 13297 | travmap | localhost | travelmapping | Query | 8730 | User sleep | SELECT * FROM routes LEFT JOIN systems ON systems.systemName = routes.systemName WHERE routes.system |
| 13920 | travmap | localhost | travelmapping | Query | 4437 | User sleep | SELECT * FROM routes LEFT JOIN systems ON systems.systemName = routes.systemName WHERE routes.system |
| 14672 | travmap | localhost | travelmapping | Query | 0 | starting | show processlist |
+-------+---------+-----------+---------------+---------+-------+------------+------------------------------------------------------------------------------------------------------+
So it appears that any kind of delay or lock would not work in general, since those are queries that appear to be stuck forever. This is why restarting mysqld has done the trick when I have encountered this in the past.
It seems what must happen is to check for these kinds of sleeping queries and kill them before the DB update is attempted.
Tonight's test: when I launched the update, I checked to see if there were any "user sleep" processes, and there were. I killed them manually in mysql. The site update then worked fine.
It's interesting that the only ones that go into that sleep occur from the query on that one line.
Thought: Insert sql queries into the start of the TravelMapping.sql file that kills any existing processes (I don't know how possible this is).
Complication: The processes run as mysql user "travmap" which has very limited permissions (read only to the DB), but the site update process ingests the new SQL file as "travmapadmin" which can do things like drop tables.
I went weeks without having to kill a "User Sleep" query but had to kill 2 of them today when I launched a bonus afternoon update. No idea what is different about today, other than maybe someone visited a page or used a set of options that had not been used in a while by anyone.
Activity
jteresco commentedon Oct 27, 2018
How to wait? Read and write locks? But what happens there if a process hangs? Wait until the "process list" is empty? Same possible problem. Maybe the easiest temporary answer is a short delay (10 seconds? 30 seconds?) between the switch of the default DB in tm.conf and the start of the ingestion of the new .sql file to allow in-process queries time to finish? This doesn't "fix" the problem,. but it makes it much less likely to show up and only involves a couple new lines in the localupdate.sh script.
michihdeu commentedon Oct 27, 2018
Timer are usually a bad idea. I think the maximum process time is when one loads a map of all regions (worldwide!). I sometimes load a map of all (central) European regions and it takes about 5 minutes (backend only). If you want a delay it should be.... 10 minutes? And it should not be possible to sent new requests. You would need a lock.
But maybe I got you wrong. How long should requests being blocked? As long as your famous "red update in progress message" is visible on the site (minutes) or just for some seconds at the beginning?
If it's possible (flags available) I would wait till all current requests are processed. "Process list" empty. If a process hangs I would kill it after a while (less than 60s). The user should get the "red update in progress message".
jteresco commentedon Oct 27, 2018
Requests on the site would not be blocked at all. The timer delay in the site update process (or better yet, as you point out, the wait for all read locks to be released before claiming a write lock). The idea is that the delay would allow ongoing requests to complete, but any new requests (new page loads) would be made using the backup DB.
With siteupdate.py failures pretty rare now, one way to do this would be to switch over to the backup DB before launching siteupdate.py. That gives several minutes for any site DB accesses to complete and new ones to switch to the backup DB before the primary DB gets updated. The switch back to primary is now done immediately after the primary DB repopulation is complete, so some other delay woudl be needed there.
michihdeu commentedon Oct 27, 2018
Ok, thanks. I think it's needed on the way to automated updates.
jteresco commentedon Oct 28, 2018
The DB update got stuck tonight even though I switched to the DB copy well before the DB was being updated. So, I checked to see what "show processlist" would tell, and it shows a bunch of queries stuck in "user sleep":
The only place we have a query that looks like that is https://github.com/TravelMapping/Web/blob/2114464c81e34e78654b61678b3189022df353ea/hb/index.php#L350 in the Highway Browser code.
So it appears that any kind of delay or lock would not work in general, since those are queries that appear to be stuck forever. This is why restarting mysqld has done the trick when I have encountered this in the past.
It seems what must happen is to check for these kinds of sleeping queries and kill them before the DB update is attempted.
jteresco commentedon Oct 29, 2018
Tonight's test: when I launched the update, I checked to see if there were any "user sleep" processes, and there were. I killed them manually in mysql. The site update then worked fine.
It's interesting that the only ones that go into that sleep occur from the query on that one line.
Thought: Insert sql queries into the start of the TravelMapping.sql file that kills any existing processes (I don't know how possible this is).
Complication: The processes run as mysql user "travmap" which has very limited permissions (read only to the DB), but the site update process ingests the new SQL file as "travmapadmin" which can do things like drop tables.
Reorder and add earning message about mysql user sleep processes. Tem…
jteresco commentedon Dec 12, 2018
I went weeks without having to kill a "User Sleep" query but had to kill 2 of them today when I launched a bonus afternoon update. No idea what is different about today, other than maybe someone visited a page or used a set of options that had not been used in a while by anyone.
jteresco commentedon Aug 30, 2019
A different query accumulated a lot of "User Sleep" SQL processes today that I had to kill to get tonight's site update to proceed:
jteresco commentedon Dec 31, 2022
I haven't had this error occur in years. Closing.
yakra commentedon Dec 31, 2022
Know if it ever happened after you switched to the primary & copy two-DB model?
jteresco commentedon Jan 1, 2023
I think the two-DB model was already in place for a while when this still used to happen.