Bug #51327 MyISAM table is automatically repaired on ALTER even if myisam-recover is OFF
Submitted: 19 Feb 2010 14:34 Modified: 12 May 2010 1:15
Reporter: Mattias Jonsson Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: MyISAM storage engine Severity:S3 (Non-critical)
Version:mysql-next-mr OS:Any
Assigned to: Jon Olav Hauglid CPU Architecture:Any
Tags: regression

[19 Feb 2010 14:34] Mattias Jonsson
Description:
If running ALTER on a corrupt myisam table and myisam-recover is OFF the table is still recovered

How to repeat:
in mysql-next-mr-bugfixing (magne.mahre@sun.com-20100218171039-tt1ps9j28zcobxs1):

let $MYSQLD_DATADIR = `SELECT @@datadir`;
--echo # Test that we can exchange a crashed partition with a table
SHOW VARIABLES LIKE '%myisam%recover%';
CREATE TABLE t (a INT, KEY (a)) ENGINE=MyISAM;
INSERT INTO t VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10), (11);
FLUSH TABLES;
--echo # replacing t.MYI with a corrupt + unclosed one created by doing:
--echo # 'create table t1 (a int key(a))' head -c1024 t1.MYI > corrupt_t1.MYI 
--remove_file $MYSQLD_DATADIR/test/t.MYI
--copy_file std_data/corrupt_t1.MYI $MYSQLD_DATADIR/test/t.MYI
CHECK TABLE t;
ALTER TABLE t ENGINE = MyISAM;
DROP TABLE t;

gives:
# Test that we can exchange a crashed partition with a table
SHOW VARIABLES LIKE '%myisam%recover%';
Variable_name	Value
myisam_recover_options	OFF
CREATE TABLE t (a INT, KEY (a)) ENGINE=MyISAM;
INSERT INTO t VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10), (11);
FLUSH TABLES;
# replacing t.MYI with a corrupt + unclosed one created by doing:
# 'create table t1 (a int key(a))' head -c1024 t1.MYI > corrupt_t1.MYI 
CHECK TABLE t;
Table	Op	Msg_type	Msg_text
test.t	check	warning	1 client is using or hasn't closed the table properly
test.t	check	error	Size of indexfile is: 1024        Should be: 2048
test.t	check	warning	Size of datafile is: 77       Should be: 7
test.t	check	error	Corrupt
ALTER TABLE t ENGINE = MyISAM;
Warnings:
Error	145	Table './test/t' is marked as crashed and should be repaired
Error	1194	Table 't' is marked as crashed and should be repaired
Error	1034	Number of rows changed from 1 to 11
CHECK TABLE t;
Table	Op	Msg_type	Msg_text
test.t	check	status	OK
DROP TABLE t;

I.e. the ALTER TABLE automatically repaired the table, but in 5.1 ALTER TABLE fails:
mysqltest: At line 12: query 'ALTER TABLE t ENGINE = MyISAM' failed: 145: Table './test/t' is marked as crashed and should be repaired

Suggested fix:
My guess is that it is related to sql_base.cc:
2889	        (void) ot_ctx->request_backoff_action(Open_table_context::OT_REPAIR);

together with
4528	        if (ot_ctx.can_recover_from_failed_open())

and not using auto_repair() or checking myisam_recover_options
[3 Mar 2010 10:32] Sveta Smirnova
Thank you for the report.

Verified as described. Not repeatable with 5.1
[13 Apr 2010 14:06] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/105521

2999 Jon Olav Hauglid	2010-04-13
      Bug #51327 MyISAM table is automatically repaired on ALTER
                 even if myisam-recover is OFF
      
      The problem was that a corrupted MyISAM table was auto repaired
      by ALTER TABLE even if the myisam_recover_options server variable
      (or myisam_recover option) was set to OFF.
      
      The reason was that the auto_repair() function, which is supposed
      to say if auto repair is to be used, did not use the server variable
      setting correctly. This bug was a regression introduced by WL#4738.
      
      This patch fixes the problem by making sure auto_repair() returns
      FALSE if myisam_recover_options is set to OFF.
      
      Test case added to myisam.test.
[14 Apr 2010 8:05] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/105601

3001 Jon Olav Hauglid	2010-04-14
      Bug #51327 MyISAM table is automatically repaired on ALTER
                 even if myisam-recover is OFF
      
      The problem was that a corrupted MyISAM table was auto repaired
      even if the myisam_recover_options server variable (or the 
      myisam_recover option) was set to OFF.
      
      The reason was that the auto_repair() function, which is supposed
      to say if auto repair is to be used, did not use the server variable
      setting correctly. This bug was a regression introduced by WL#4738.
      
      This patch fixes the problem by making sure auto_repair() returns
      FALSE if myisam_recover_options is set to OFF.
      
      Test case added to myisam.test.
[15 Apr 2010 7:16] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/105689

3001 Jon Olav Hauglid	2010-04-15
      Bug #51327 MyISAM table is automatically repaired on ALTER
                 even if myisam-recover is OFF
      
      The problem was that a corrupted MyISAM table was auto repaired
      even if the myisam_recover_options server variable (or the 
      myisam_recover option) was set to OFF.
      
      The reason was that the auto_repair() function, which is supposed
      to say if auto repair is to be used, did not use the server variable
      setting correctly. This bug was a regression introduced by WL#4738.
      
      This patch fixes the problem by making sure auto_repair() returns
      FALSE if myisam_recover_options is set to OFF.
      
      Test case added to myisam.test.
[15 Apr 2010 7:17] Jon Olav Hauglid
Pushed to mysql-trunk-runtime (Ver 5.5.4-m3).
[27 Apr 2010 9:46] Bugs System
Pushed into 6.0.14-alpha (revid:alik@sun.com-20100427094135-5s49ecp3ckson6e2) (version source revid:alik@sun.com-20100427093843-uekr85qkd7orx12t) (merge vers: 6.0.14-alpha) (pib:16)
[27 Apr 2010 9:48] Bugs System
Pushed into 5.5.5-m3 (revid:alik@sun.com-20100427093804-a2k3rrjpwu5jegu8) (version source revid:alik@sun.com-20100427093804-a2k3rrjpwu5jegu8) (merge vers: 5.5.5-m3) (pib:16)
[27 Apr 2010 9:50] Bugs System
Pushed into mysql-next-mr (revid:alik@sun.com-20100427094036-38frbg3famdlvjup) (version source revid:alik@sun.com-20100427093825-92wc8b22d4yg34ju) (pib:16)
[12 May 2010 1:15] Paul DuBois
Noted in 5.5.5, 6.0.14 changelogs.

Corrupt MyISAM tables were automatically repaired even when
myisam_recover_options was set to OFF.