Bug #338 REPAIR table USE_FRM results in data loss if killed.
Submitted: 28 Apr 2003 3:18 Modified: 28 Apr 2003 15:31
Reporter: Peter Zaitsev (Basic Quality Contributor) Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: MyISAM storage engine Severity:S1 (Critical)
Version:4.0.13 OS:Linux (Linux)
Assigned to: CPU Architecture:Any

[28 Apr 2003 3:18] Peter Zaitsev
Description:
Killing MySQL server while  REPAIR TABLE X USE_FRM is in progress results in data loss.

Suspect: It might be related not to USE_FRM but to other "repair with keycache" as well.

The data seems to be on the place but can't be reached:

-rw-rw----    1 pz       users    28140000 2003-04-28 14:06 reptest.MYD
-rw-rw----    1 pz       users        1024 2003-04-28 14:08 reptest.MYI
-rw-rw----    1 pz       users    12058624 2003-04-28 14:07 reptest.TMD

mysql> select count(*) from reptest;
+----------+
| count(*) |
+----------+
|        0 |
+----------+
1 row in set (0.00 sec)

mysql> select * from reptest limit 1;
Empty set (0.00 sec)

Repair table can be used in such state to recover table but running
ALTER TABLE will result in complete loss of the data.

How to repeat:
CREATE TABLE `reptest` (
  `c` char(20) NOT NULL default '',
  KEY `c` (`c`)
) TYPE=MyISAM 

Fill table with enough data to be able to kill server while repair is running.
The following file can be used for populating:

#include <stdio.h>

#define MAX_VALUE 10000000

#define VALUES_INSERT 10000

#define VALUES_TO_INSERT (10*1000*1000)

main()
{
  int records=0;
  int i;
  int value;

  while (records<VALUES_TO_INSERT)
  {
    /* Prepare single insert */
    printf("INSERT INTO reptest VALUES ");
    for(i=0;i<VALUES_INSERT;i++)
    {
      value=random()%MAX_VALUE;
      if (i==VALUES_INSERT-1)
        printf("(%d)",value);
      else
        printf("(%d),",value);

    }
    printf(";\n");
    records+=VALUES_INSERT;
  }

Run  "repair table reptest use_frm"

kill server running "killall -9 mysqld"
[28 Apr 2003 15:31] Michael Widenius
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.mysql.com/documentation/ and the instructions on
how to report a bug at http://bugs.mysql.com/how-to-report.php

Sorry, but there is no way easily way to fix this;  We just have to document this behaviour.