Fixing a Disk Space Alert at 3 AM
slashmili.org
slashmili.org
If you can't restart mysqld you have an architectural problem. Your database will go down sometimes and your system should be built to tolerate that.
I don't know how to ask this more precisely, but how are races and concurrent writes on both masters handled? Is it still "ACID safe" writing across the cluster, or would you use something like this as a hot-spare for promotion in case of failover only?
Restarting MySQL is a violent operation. For large databases, it can take several minutes. If I can avoid it, I do so, and this was a really clever workaround for an issue that indeed avoided a restart. That's a good thing.
That's not at all true. It's very common unix practice to open a file, delete it, and then use it for critical operations.
Creating then deleting a temporary file is very common technique to make sure that that for will be removed as soon as the application closes it, it also is used to make sure that nothing will tamper with it. I find amusing that author found a way to still tamper with it.
Now depending on what the file was used for either the corrupted files caused database to return corrupted data to the user, write corrupted data to the database, our in the best scenario return error to the application issuing the query.
That said it still doesn't prevent the author for modifying the file by referencing file descriptor.
Someone probably started running queries which were doing disk sorts. Look for abusive queries coming in and kill those, the temporary files will go away at that point. Based on the size of the files, simply looking for long running queries should be sufficient; if it's the backend for a web server, it's likely that the client and server have already given up on the query (or in the worst case, re-sent the debilitating query).
As stated by other users, truncating random files will cause more problems for MySQL than just restarting mysql. In fact, I'd recommend going in and restarting it now, to ensure that you're at a good state. Failing over to your slave (you do have a slave and failover procedure, right?) is less of a headache than trying to identify what problems were caused by manually truncating these sort files.
Finally, have a look at Skyline from Etsy[1]; a trend monitoring tool like this would have alerted you when the ramp started closer to 1am, well before this was suddenly an outage event.
Nothing really great leaps to mind to solve this in the general case. These sorts of correlated behaviors can really be jerks.
Having a daemon which kills off long running queries (such as ones with extensive disk sorts) can help as well, just be sure to follow up on the queries which were killed to fix the frontend or chastise the person doing `SELECT * FROM blob_table ORDER BY id`.
My approach would have been to kill the mysql worker process that keeps them alive. That way the program that started the query gets an error message, instead of whatever undefined behaviour you get by empying the files and surprising mysqld.
First of all... If you're getting paged on disk alerts at 3 in the morning,
you're doing it wrong. Write a script that checks every file system and
makes sure that X amount of free space is always present, adding free space
as-needed, and emailing you on the backend during business hours whenever
the volume group is nearing depletion.
I'm sorry, but no -- I'm not going to automate adding more disk to a VM, extending a volume group, and growing a filesystem. Not now, not ever. No way in hell.That needs to be done by a human after a backup has been tested and writes have been quiesced.
This is what grown-ups do. Storage is cheap. Downtime is not.
Then I don't want to grow up like you. Have fun recovering your corrupted filesystem.The "just add more to the pool" solution seems akin to the "solution" in the strip above.
And i have seen similar arguments for when a daemon or server goes down. Hook it up to a script that reboots it automatically (or fires up a new instance over and over and over) and go back to coding.
If something is broken, you should have enough automation to get it into a known good state without a human involved, while maintaining data consistency. Anything else should be automated, but you should still be around to babysit it while its going through the motions.
If you think you can automate everything and always trust it to work flawlessly, you haven't been around long enough for the edge cases.
And then you have some "clever" coder coming along with a fix for said edge case (that invariably create some new edge cases just outside the domain of the fix).
For expanding database volumes, for example, I have a system which first monitors the size of my current database systems. If they get too large, it will create a new virtual which is bigger, restores a current backup of the running system to it, verify that, put it into rotation, make sure that all current data is replicated, then remove the old system.
Frankly, doing this by hand would be highly error prone and dangerous. I say, script everything.
The substantive point you're making is fine, but would be better and clearer if you expanded on it a bit and dropped the indignation.
[0] http://gamesfromwithin.com
[1] http://www.dodgycoder.net/2012/02/coding-tricks-of-game-deve...
And as others have mentioned, having an open file descriptor to a deleted temp file is a classic unix pattern, truncating them is a horrific idea.
Still an interesting way to troubleshoot and alive the issue though. I'm sure during on-duty at 3am I wouldn't have come up with anything better.
Deleting those files while the server runs is an awesome way to "f@ck s*it up"! Do you really trust Mysql to behave nicely in that situation?
Add more disk space and point TMPDIR somewhere else than /tmp, /var/tmp or /usr/tmp!
[1] http://hacktracking.blogspot.nl/2013/06/closing-process-file...