{"id":2341,"date":"2015-12-07T11:25:49","date_gmt":"2015-12-07T11:25:49","guid":{"rendered":"http:\/\/kedar.nitty-witty.com\/?p=2341"},"modified":"2023-04-28T04:13:35","modified_gmt":"2023-04-28T04:13:35","slug":"corrupted-crashed-myisam-mysql_repair_threads-stuck-repair-with-n-threads","status":"publish","type":"post","link":"https:\/\/kedar.nitty-witty.com\/blog\/corrupted-crashed-myisam-mysql_repair_threads-stuck-repair-with-n-threads","title":{"rendered":"corrupted \/ crashed MyISAM + mysql_repair_threads = stuck &#8220;Repair with N threads&#8221;"},"content":{"rendered":"\n<p>In this post we&#8217;re going to look at how changing MySQL variable mysql_repair_threads for betterment of a repair table command became root cause of an instance reboot. Also how repair with n threads message tracks down to this.<\/p>\n\n\n\n<p>MyISAM is notorious for table crashes and always need a table repair as a quick remedy.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<pre class=\"wp-block-preformatted\"> Table 'myisam_table' is marked as crashed and should be repaired.\n<\/pre>\n<\/blockquote>\n\n\n\n<p>After seeing above error we quickly jump on to one of the following<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<pre class=\"wp-block-preformatted\"> repair table myisam_table\n myisamchk -r -q myisam_table\n<\/pre>\n<\/blockquote>\n\n\n\n<p>Ofcourse there are more options but that&#8217;s not something we&#8217;re talking here.<\/p>\n\n\n\n<p>Once this become regular and\/or table is large, we look forward to speedup the operation. Then stands out one variable that comes as a ray of hope: mysql_repair_threads<br>As MySQL documentation says <i>&#8220;for value greater than 1, MyISAM table indexes are created in parallel (each index in its own thread) during the Repair by sorting process.&#8221;<\/i><\/p>\n\n\n\n<!--more-->\n\n\n\n<p>&#8220;woohoo&#8230; let&#8217;s repair in parallel threads&#8221;<\/p>\n\n\n\n<p>and people are quickly tempted to use it ignoring an important line right below it: <i><b>&#8220;Multi-threaded repair is still beta-quality code&#8221;.<\/b><\/i><\/p>\n\n\n\n<p>You might see &#8220;Repair with N threads&#8221; in processlist output but is it actually helping?<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<pre class=\"wp-block-preformatted\">mysql&gt; show processlist;\n+-----------+------------------+-------------------+---------+---------+----------+----------------------------------+------------------------------------------------------------------------------------------------------+\n| Id        | User             | Host              | db      | Command | Time     | State                            | Info                                                                                                 |\n+-----------+------------------+-------------------+---------+---------+----------+----------------------------------+------------------------------------------------------------------------------------------------------+\n...\n| 224316896 | root             | localhost         | my_db | Query  |     85 | Repair with 2 threads            | repair table XXX                                                                       |\n...\n<\/pre>\n<\/blockquote>\n\n\n\n<p>This is what happened recently when someone issued repair table on one of the crashed table and the query wouldn&#8217;t finish even after an hour! As you can note processlist message of <strong>Repair with 2 threads<\/strong> is our hint of the change in myisam_repair_threads value.<\/p>\n\n\n\n<p>Repair operation went on for more than estimated time while the table in question was not even 50M and system was well-fed with CPU &amp; RAM.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<pre class=\"wp-block-preformatted\">mysql&gt; show table status like 'XXX'\\G\n*************************** 1. row ***************************\n           Name: XXX\n         Engine: MyISAM\n        Version: 10\n     Row_format: Dynamic\n           Rows: 1872\n Avg_row_length: 13147\n    Data_length: 32025064\nMax_data_length: 281474976710655\n   Index_length: 145408\n      Data_free: 7413408\n Auto_increment: 28173\n...\n<\/pre>\n<\/blockquote>\n\n\n\n<p>Finally the repair was killed, but it remained in Killed state for more than the anticipated time:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<pre class=\"wp-block-preformatted\">mysql&gt; show processlist;\n+-----------+------------------+-------------------+---------+---------+----------+----------------------------------+------------------------------------------------------------------------------------------------------+\n| Id        | User             | Host              | db      | Command | Time     | State                            | Info                                                                                                 |\n+-----------+------------------+-------------------+---------+---------+----------+----------------------------------+------------------------------------------------------------------------------------------------------+\n...\n| 224316896 | root             | localhost         | my_db | Killed  |     4009 | Repair with 2 threads            | repair table XXX                                                                       |\n...\n<\/pre>\n<\/blockquote>\n\n\n\n<p>(That&#8217;s too much)<\/p>\n\n\n\n<p>Note that in this case, the only thing odd I found is &#8220;myisam_repair_threads&#8221;:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<pre class=\"wp-block-preformatted\">mysql&gt; show global variables like '%repair%';\n+-----------------------+-------+\n| Variable_name         | Value |\n+-----------------------+-------+\n| myisam_repair_threads | 32    |\n+-----------------------+-------+\n1 row in set (0.00 sec)\n<\/pre>\n<\/blockquote>\n\n\n\n<p>Because the server needed a quick resolution, it was concluded to reboot MySQL (as it was slave and feasible).<\/p>\n\n\n\n<p>Changed my.cnf to set myisam_repair_threads to default (1) and rebooted MySQL.<\/p>\n\n\n\n<p>Later the repair table command then finished in 6 sec. (Much better with single thread, isn&#8217;t it?)<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<pre class=\"wp-block-preformatted\">mysql&gt; repair table XXX;\n+---------------------------+--------+----------+----------+\n| Table                     | Op     | Msg_type | Msg_text |\n+---------------------------+--------+----------+----------+\n| my_db.XXX | repair | status   | OK       |\n+---------------------------+--------+----------+----------+\n1 row in set (6.58 sec)\n<\/pre>\n<\/blockquote>\n\n\n\n<p>&#8220;Luckily&#8221; it was slave that faced the issue!<\/p>\n\n\n\n<p>Now, myisam_repair_threads is The Only beta quality variable listed on MySQL documentation. The variable myisam_repair_threads is in beta quality since ages and the latest MySQL 5.7 is no good for that too.<\/p>\n\n\n\n<p>There is already a <a href=\"https:\/\/bugs.mysql.com\/bug.php?id=25648\" target=\"_blank\" rel=\"nofollow noopener\">bug<\/a> report conveying the risk. I looked at MariaDB &amp; Percona. Neither mariaDB mention &#8220;beta&#8221; around this feature (not sure if they&#8217;ve a fix!!) nor I see any mention of this in Percona MySQL documentation. I&#8217;d rather remove it than putting it in beta for so long and risking production instances!<\/p>\n\n\n\n<p>Anyways, time for conclusion?<br><span style=\"text-decoration: underline;\">Do not increase myisam_repair_threads from it&#8217;s sensible default 1. Do not use it at all. Just forget it!<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"This post explains on the usage of mysql_repair_threads for repairing myisam table &#038; the processlist status Repair with N threads\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,377],"tags":[410,408,412,409,411,413],"class_list":{"0":"post-2341","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-mysql","7":"category-mysql-articles","8":"tag-corrupt","9":"tag-myisam","10":"tag-mysql_repair_threads","11":"tag-repair","12":"tag-repair-with-n-threads","13":"tag-repair-with-threads"},"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/posts\/2341","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/comments?post=2341"}],"version-history":[{"count":12,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/posts\/2341\/revisions"}],"predecessor-version":[{"id":2841,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/posts\/2341\/revisions\/2841"}],"wp:attachment":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/media?parent=2341"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/categories?post=2341"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/tags?post=2341"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}