Home » Performance » MySQL » mysql tables crashing
| Re: mysql tables crashing [message #1845 is a reply to message #1697 ] |
Fri, 14 September 2007 15:45   |
allworknoplay Messages: 58 Registered: September 2007 Location: New York |
Member |
|
|
Ok here is one of my codes...
INSERT INTO data_day (device_id,timestamp,data_type,object,actual,gdata) VALUES ('".$device_id."','".$timestamp."','disk','".$VLetter."','1',' ".$PercentUsedDisk."')
The first 4 obviously are the ones in question, and the last 2 (actual,gdata) could be of any value, that doesn't and shouldn't have any affect on the INSERTS....
|
|
|
| Re: mysql tables crashing [message #1846 is a reply to message #1697 ] |
Fri, 14 September 2007 15:48   |
 |
jcn50 Messages: 44 Registered: September 2007 |
Member |
|
|
If you don't really need to have 4 seperated columns, you could merge columns device_id,timestamp,data_type,object into a single UNIQUE column (let's call it "merged").
You will separate the values by a separator (let's pick up the semicolon).
So your "merged" column's data could look like this:
1175214041;1189629601;disk;C
I have no other suggestion for now (at the mySQL level) I could think of (yet).
Enjoy the Net!
|
|
| | |
| Re: mysql tables crashing [message #1849 is a reply to message #1845 ] |
Fri, 14 September 2007 15:53   |
 |
jcn50 Messages: 44 Registered: September 2007 |
Member |
|
|
| allworknoplay wrote on Fri, 14 September 2007 19:45 | Ok here is one of my codes...
INSERT INTO data_day (device_id,timestamp,data_type,object,actual,gdata) VALUES ('".$device_id."','".$timestamp."','disk','".$VLetter."','1',' ".$PercentUsedDisk."')
The first 4 obviously are the ones in question, and the last 2 (actual,gdata) could be of any value, that doesn't and shouldn't have any affect on the INSERTS....
|
I bet you won't have a lot of completed INSERTs, because data_type is not UNIQUE on this line of the script!
How many results do you have for this query?
SELECT * FROM data_day WHERE data_type = "disk";
Enjoy the Net!
|
|
| | | |
| Re: mysql tables crashing [message #1853 is a reply to message #1851 ] |
Fri, 14 September 2007 16:14   |
allworknoplay Messages: 58 Registered: September 2007 Location: New York |
Member |
|
|
| jcn50 wrote on Fri, 14 September 2007 16:07 |
2.5 million rows?! Wow, DELETE QUICK is a must ... Because after each DELETE, your indexes are rebuilt! That's a waste of resources.
I hope your mySQL server automatically locks the table "data_day", because if you have an INSERT when the INDEX is being rebuilt, you are likely to have a bunch of crashes!
|
Yes!!!
That's what I'm talking about!!! There's so much to know about the little things, I wasn't formally trained in mysql so I don't know all the little details...but I've been using it for years..
Anyways...
I think you have hit the nail on the head awhile back already
about the DELETE QUICK syntax.
I didn't know the ramifications and what mysql does on DELETES.
So wait, if normal DELETES cause mysql to rebuild the INDEX, the DELETE QUICK leaves the INDEX alone? And if so, that's ok?
Also, there is no table locking! I don't do anything or tell mysql to do any kind of table locking...
It is VERY VERY much possible that INSERTS are occuring while the DELETES are taking place....
The only time the table locks is when I do a REPAIR table...
|
|
| |
| Re: mysql tables crashing [message #1855 is a reply to message #1853 ] |
Fri, 14 September 2007 16:19   |
 |
jcn50 Messages: 44 Registered: September 2007 |
Member |
|
|
| allworknoplay wrote on Fri, 14 September 2007 20:14 | [So wait, if normal DELETES cause mysql to rebuild the INDEX, the DELETE QUICK leaves the INDEX alone? And if so, that's ok?
|
As per the mySQL documentation:
http://dev.mysql.com/doc/refman/5.0/en/delete.html
"If you are going to delete many rows from a table, it might be faster to use DELETE QUICK followed by OPTIMIZE TABLE. This rebuilds the index rather than performing many index block merge operations."
So I bet it's no problem, if you add OPTIMIZE TABLE at the end of your cron job.
Enjoy the Net!
|
|
| |
| Re: mysql tables crashing [message #1857 is a reply to message #1856 ] |
Fri, 14 September 2007 16:31   |
 |
jcn50 Messages: 44 Registered: September 2007 |
Member |
|
|
| allworknoplay wrote on Fri, 14 September 2007 20:25 | Also, do you think the UNSET variable is necessary?
I use it in my other program that has over 2000 lines of code. I just want to release any memory PHP is using and avoid and possible overlapping of variables..
|
If your script does something else that this DELETE QUICK thereafter, yes it could help. Otherwise, if it's only a cron job that run 1 time each day (a "short script" as you call it) the variables will be unset anyway at the end of the script's execution.
If you use $query_day and $result_day again later, it's a waste of time because you destroy the memory allocated by it, and you re-create a memory space again after.
I guess UNSET is usefull if your script is running for, let's say, a week...
[Updated on: Fri, 14 September 2007 16:34] Enjoy the Net!
|
|
| | | | |
| Re: mysql tables crashing [message #1862 is a reply to message #1861 ] |
Fri, 14 September 2007 16:44   |
allworknoplay Messages: 58 Registered: September 2007 Location: New York |
Member |
|
|
| jcn50 wrote on Fri, 14 September 2007 16:42 |
| allworknoplay wrote on Fri, 14 September 2007 20:38 | Not to derail the topic, but how well do you know PHP?
|
Well, I use it very much, also doing PHP executable for Windows. But I didn't upgrade myself to PHP5 yet ... Also, I never used the object-oriented programming (for me the code should be sequential).
|
Ok I mainly use PHP on linux. Played with it a couple times on windows but it is absolutely integral to our systems on linux platform.
I don't use PHP with OO either, my take on it is, why complicate things more just to say you are using OO?
As you can see from my delete script code, it's a couple of lines
and that's it. Why use OO for that?
Most of my programs are from top to bottom, so I don't see a need to use PHP in OO form at all...
|
|
|
| Re: mysql tables crashing [message #1863 is a reply to message #1858 ] |
Fri, 14 September 2007 16:45   |
 |
jcn50 Messages: 44 Registered: September 2007 |
Member |
|
|
| allworknoplay wrote on Fri, 14 September 2007 20:35 | This script runs every 30 mins, so the optimize table if I ran it, would lock up the table for however long it takes to optimize it...maybe 1 minute?
I am wondering if I use the DELETE QUICK on this script, and then at midnight I run another script that optimizes the table?
This way I don't try to optimize the table every 30 mins which might wreak havoc...
|
I don't really know about the time to optimize the table... However when you use DELETE only, the OPTIMIZE TABLE is silent and made each time. So you can add only one OPTIMIZE TABLE after your 30 min scripts .
One question is: are you sure your script's execution's time is < 30 min??...
[Updated on: Fri, 14 September 2007 16:49] Enjoy the Net!
|
|
| | | | |
| Re: mysql tables crashing [message #1868 is a reply to message #1697 ] |
Fri, 14 September 2007 17:04   |
 |
jcn50 Messages: 44 Registered: September 2007 |
Member |
|
|
OK, when I think about it, the crash may come from the "thread_concurrency" variable set to >1.
* Imagine that you have one of your script is running a lot of DELETE queries;
* At the same time, another script is running a lot of INSERT queries.
Crash can occurs when an INSERT query occurs while rebuilding the INDEXes: the server will miss some inserted keys, ending with more rows than the number of keys.
mysql> check table data_day;
+--------------------+-------+----------+------------------- ------------+
| Table | Op | Msg_type | Msg_text |
+--------------------+-------+----------+------------------- ------------+
| collector.data_day | check | warning | Table is marked as crashed |
| collector.data_day | check | error | Found 2434089 keys of 2434281 |
| collector.data_day | check | error | Corrupt |
+--------------------+-------+----------+------------------- ------------+
This is the only logical case I could think of!
As we said earlier, the advantage of using DELETE QUICK is that the INDEX is not rebuilt. Also, when you run OPTIMIZE TABLE, the entire table will be locked, as per mySQL documentation:
http://dev.mysql.com/doc/refman/5.0/en/optimize-table.html
So my #1 suggestion will be to set thread_concurrency to 1, even if you have 2 CPUs...
Also, previous mySQL version (< v5) didn't have this thread_concurrency variable!...
[Updated on: Fri, 14 September 2007 17:11] Enjoy the Net!
|
|
| |
| Re: mysql tables crashing [message #1870 is a reply to message #1868 ] |
Fri, 14 September 2007 17:09   |
allworknoplay Messages: 58 Registered: September 2007 Location: New York |
Member |
|
|
| jcn50 wrote on Fri, 14 September 2007 17:04 | OK, when I think about it, the crash may come from the "thread_concurrency" variable set to >1.
* Imagine that you have one of your script is running a lot of DELETE queries;
* At the same time, another script is running a lot of INSERT queries.
Crash can occurs when an INSERT query occurs while rebuilding the INDEXes: the server will miss some inserted keys, ending with more rows that the number of keys.
mysql> check table data_day;
+--------------------+-------+----------+------------------- ------------+
| Table | Op | Msg_type | Msg_text |
+--------------------+-------+----------+------------------- ------------+
| collector.data_day | check | warning | Table is marked as crashed |
| collector.data_day | check | error | Found 2434089 keys of 2434281 |
| collector.data_day | check | error | Corrupt |
+--------------------+-------+----------+------------------- ------------+
This is the only logical case I could think of!
As we said earlier, the advantage of using DELETE QUICK is that the INDEX is not rebuilt. Also, when you run OPTIMIZE TABLE, the entire table will be locked, as per mySQL documentation:
http://dev.mysql.com/doc/refman/5.0/en/optimize-table.html
So my #1 suggestion will be to set thread_concurrency to 1, even if you have 2 CPUs...
Also, previous mySQL version (< v5) didn't have this thread_concurrency variable!...
|
That sounds like the best answer/solutions so far.
This is what I will do, change the thread_concurrency to 1.
And use DELETE QUICK in all my programs, starting with all
my garbage cleanup scripts..
Then we can see how stable this son of a gun can be!!!
I will do these first, and if the crash still happens, I will drop by INDEX on the ID column....
My SQL version is: 5.0.21
|
|
| |
| Re: mysql tables crashing [message #1872 is a reply to message #1869 ] |
Fri, 14 September 2007 17:18   |
 |
jcn50 Messages: 44 Registered: September 2007 |
Member |
|
|
| allworknoplay wrote on Fri, 14 September 2007 21:06 | I have NO IDEA what this means...
DELETE QUICK is not useful when deleted values lead to underfilled index blocks spanning a range of index values for which new inserts occur again. In this case, use of QUICK can lead to wasted space in the index that remains unreclaimed. Here is an example of such a scenario:
|
I guess it have some relation with "contiguous space use".
It's the same as "disk optimization".
INDEX:
0: data
1: data
2: data
DELETE QUICK 1;
NEW INDEX:
0: data
2: data
=> result: no more "1: data" in the INDEX, INDEX not optimized, INDEX having a "hole" at line #2.
[Updated on: Fri, 14 September 2007 17:19] Enjoy the Net!
|
|
| | |
| Re: mysql tables crashing [message #1878 is a reply to message #1697 ] |
Sat, 15 September 2007 12:04   |
 |
jcn50 Messages: 44 Registered: September 2007 |
Member |
|
|
Ok, don't forget to change the thread_concurrency to 1 too.
Enjoy the Net!
|
|
|
| Re: mysql tables crashing [message #1879 is a reply to message #1878 ] |
Sat, 15 September 2007 12:16   |
allworknoplay Messages: 58 Registered: September 2007 Location: New York |
Member |
|
|
| jcn50 wrote on Sat, 15 September 2007 12:04 | Ok, don't forget to change the thread_concurrency to 1 too.
|
I made a boo-boo. I repaired the table and changed my script to DELETE QUICK.
Walked away, made some coffee, 20 mins later I came back and I got an email again my table got corrupted. This time it was FAST. Usually 2-3 days, but never within 20 mins of REPAIRING a table.
So I said, that's it, I am dropping this INDEX because it's causing too many problems..
Low and behold, I forgot to clear out my mysql error log file, so when my script ran, it emailed me because it thought the table was corrupted!!!
The key is to drink coffee first!!!
So now I have a DELETE QUICK AND I dropped the Index on the ID column.
Now if the table never gets corrupted again, I will not know which one was the actual solution!!!!!!
|
|
|
| Re: mysql tables crashing [message #1880 is a reply to message #1697 ] |
Mon, 17 September 2007 10:06   |
 |
jcn50 Messages: 44 Registered: September 2007 |
Member |
|
|
How is the debugging doing?
Enjoy the Net!
|
|
| | | |
| Re: mysql tables crashing [message #1888 is a reply to message #1878 ] |
Tue, 18 September 2007 10:18   |
Peter Messages: 405 Registered: August 2006 |
Senior Member Super Guru |
|
|
thread_concurrency makes no difference on Linux.
It is also just a hint to the scheduler on how to schedule threads - it has nothing to do with a way MySQL runs threads internally.
Now you've tot the bug - I'd try to get our repeatable test case and get it to bugs.mysql.com
I know there ARE MyISAM corruption bugs out where.
Peter Zaitsev, MySQL Performance Expert
MySQL Performance Blog - http://www.mysqlperformanceblog.com
MySQL Consulting http://www.mysqlperformanceblog.com/mysql-consulting/
|
|
| | | |
Goto Forum:
Current Time: Sun Jul 5 21:57:45 EDT 2009
Total time taken to generate the page: 0.01525 seconds |