List:Commits« Previous MessageNext Message »
From:Sergey Vojtovich Date:October 9 2009 4:16pm
Subject:bzr commit into mysql-5.1-bugteam branch (svoj:3146) Bug#47073
View as plain text  
#At file:///home/svoj/devel/bzr-mysql/mysql-5.1-bugteam-bug47073/ based on revid:mattias.jonsson@stripped

 3146 Sergey Vojtovich	2009-10-09
      BUG#47073 - valgrind errs, corruption,failed repair of partition,
                  low myisam_sort_buffer_size
      
      Repair by sort (default) or parallel repair of a MyISAM table
      (doesn't matter partitioned or not) as well as bulk inserts
      and enable indexes some times didn't failover to repair with
      key cache.
      
      The problem was that after unsuccessful attempt, data file was
      closed. Whereas repair with key cache requires open data file.
      Fixed by reopening data file.
      
      Also fixed a valgrind warning, which may appear during repair
      by sort or parallel repair with certain myisam_sort_buffer_size
      number of rows and length of an index entry (very dependent).
     @ mysql-test/r/myisam.result
        A test case for BUG#47073.
     @ mysql-test/t/myisam.test
        A test case for BUG#47073.
     @ storage/myisam/ha_myisam.cc
        Reverted fix for BUG25289. Not needed anymore.
     @ storage/myisam/mi_check.c
        Reopen data file, when repair by sort or parallel repair
        fails.
        
        When repair by sort is requested to rebuild data file, data file
        gets rebuilt while fixing first index. When rebuild is completed,
        info->dfile is pointing to temporary data file, original data file
        is closed.
        
        It may happen that repair has successfully fixed first index and
        rebuilt data file, but failed to fix second index. E.g.
        myisam_sort_buffer_size was big enough to fix first shorter index,
        but not enough to fix subsequent longer index.
        
        In this case we end up with info->dfile pointing to temporary file,
        which is removed and info->dfile is set to -1.
        
        Though repair by sort failed, the upper layer may still want to
        try repair with key cache. But it needs info->dfile pointing to
        valid data file.
     @ storage/myisam/sort.c
        When performing a copy of IO_CACHE structure, current_pos and
        current_end must be updated separatly to point to memory we're
        copying to (not to memory we're copying from).
        
        As t_file2 is always WRITE cache, proper members are write_pos
        and write_end accordingly.

    modified:
      mysql-test/r/myisam.result
      mysql-test/t/myisam.test
      storage/myisam/ha_myisam.cc
      storage/myisam/mi_check.c
      storage/myisam/sort.c
=== modified file 'mysql-test/r/myisam.result'
--- a/mysql-test/r/myisam.result	2009-09-21 09:58:15 +0000
+++ b/mysql-test/r/myisam.result	2009-10-09 16:16:29 +0000
@@ -2271,4 +2271,32 @@ checksum table t3;
 Table	Checksum
 test.t3	326284887
 drop table t1,t2,t3;
+CREATE TABLE t1(a INT, b CHAR(10), KEY(a), KEY(b));
+INSERT INTO t1 VALUES(1,'0'),(2,'0'),(3,'0'),(4,'0'),(5,'0'),
+(6,'0'),(7,'0');
+INSERT INTO t1 SELECT a+10,b FROM t1;
+INSERT INTO t1 SELECT a+20,b FROM t1;
+INSERT INTO t1 SELECT a+40,b FROM t1;
+INSERT INTO t1 SELECT a+80,b FROM t1;
+INSERT INTO t1 SELECT a+160,b FROM t1;
+INSERT INTO t1 SELECT a+320,b FROM t1;
+INSERT INTO t1 SELECT a+640,b FROM t1;
+INSERT INTO t1 SELECT a+1280,b FROM t1;
+INSERT INTO t1 SELECT a+2560,b FROM t1;
+INSERT INTO t1 SELECT a+5120,b FROM t1;
+SET myisam_sort_buffer_size=4;
+REPAIR TABLE t1;
+Table	Op	Msg_type	Msg_text
+test.t1	repair	error	myisam_sort_buffer_size is too small
+test.t1	repair	warning	Number of rows changed from 0 to 7168
+test.t1	repair	status	OK
+SET myisam_repair_threads=2;
+REPAIR TABLE t1;
+Table	Op	Msg_type	Msg_text
+test.t1	repair	error	myisam_sort_buffer_size is too small
+test.t1	repair	warning	Number of rows changed from # to 7168
+test.t1	repair	status	OK
+SET myisam_repair_threads=@@global.myisam_repair_threads;
+SET myisam_sort_buffer_size=@@global.myisam_sort_buffer_size;
+DROP TABLE t1;
 End of 5.1 tests

=== modified file 'mysql-test/t/myisam.test'
--- a/mysql-test/t/myisam.test	2009-09-21 09:58:15 +0000
+++ b/mysql-test/t/myisam.test	2009-10-09 16:16:29 +0000
@@ -1518,5 +1518,33 @@ CREATE TABLE t3 select * from t1;
 checksum table t3;
 drop table t1,t2,t3;
 
+
+#
+# BUG#47073 - valgrind errs, corruption,failed repair of partition,
+#             low myisam_sort_buffer_size
+#
+CREATE TABLE t1(a INT, b CHAR(10), KEY(a), KEY(b));
+INSERT INTO t1 VALUES(1,'0'),(2,'0'),(3,'0'),(4,'0'),(5,'0'),
+                     (6,'0'),(7,'0');
+INSERT INTO t1 SELECT a+10,b FROM t1;
+INSERT INTO t1 SELECT a+20,b FROM t1;
+INSERT INTO t1 SELECT a+40,b FROM t1;
+INSERT INTO t1 SELECT a+80,b FROM t1;
+INSERT INTO t1 SELECT a+160,b FROM t1;
+INSERT INTO t1 SELECT a+320,b FROM t1;
+INSERT INTO t1 SELECT a+640,b FROM t1;
+INSERT INTO t1 SELECT a+1280,b FROM t1;
+INSERT INTO t1 SELECT a+2560,b FROM t1;
+INSERT INTO t1 SELECT a+5120,b FROM t1;
+SET myisam_sort_buffer_size=4;
+REPAIR TABLE t1;
+SET myisam_repair_threads=2;
+# May report different values depending on threads activity.
+--replace_regex /changed from [0-9]+/changed from #/
+REPAIR TABLE t1;
+SET myisam_repair_threads=@@global.myisam_repair_threads;
+SET myisam_sort_buffer_size=@@global.myisam_sort_buffer_size;
+DROP TABLE t1;
+
 --echo End of 5.1 tests
 

=== modified file 'storage/myisam/ha_myisam.cc'
--- a/storage/myisam/ha_myisam.cc	2009-09-09 15:13:13 +0000
+++ b/storage/myisam/ha_myisam.cc	2009-10-09 16:16:29 +0000
@@ -1087,22 +1087,6 @@ int ha_myisam::repair(THD *thd, MI_CHECK
   ha_rows rows= file->state->records;
   DBUG_ENTER("ha_myisam::repair");
 
-  /*
-    Normally this method is entered with a properly opened table. If the
-    repair fails, it can be repeated with more elaborate options. Under
-    special circumstances it can happen that a repair fails so that it
-    closed the data file and cannot re-open it. In this case file->dfile
-    is set to -1. We must not try another repair without an open data
-    file. (Bug #25289)
-  */
-  if (file->dfile == -1)
-  {
-    sql_print_information("Retrying repair of: '%s' failed. "
-                          "Please try REPAIR EXTENDED or myisamchk",
-                          table->s->path.str);
-    DBUG_RETURN(HA_ADMIN_FAILED);
-  }
-
   param.db_name=    table->s->db.str;
   param.table_name= table->alias;
   param.tmpfile_createflag = O_RDWR | O_TRUNC;

=== modified file 'storage/myisam/mi_check.c'
--- a/storage/myisam/mi_check.c	2009-09-28 13:55:01 +0000
+++ b/storage/myisam/mi_check.c	2009-10-09 16:16:29 +0000
@@ -2561,8 +2561,9 @@ err:
       VOID(my_close(new_file,MYF(0)));
       VOID(my_raid_delete(param->temp_filename,share->base.raid_chunks,
 			  MYF(MY_WME)));
-      if (info->dfile == new_file)
-	info->dfile= -1;
+      if (info->dfile == new_file) /* Retry with key cache */
+        if (unlikely(mi_open_datafile(info, share, name, -1)))
+          param->retry_repair= 0; /* Safety */
     }
     mi_mark_crashed_on_repair(info);
   }
@@ -3095,8 +3096,9 @@ err:
       VOID(my_close(new_file,MYF(0)));
       VOID(my_raid_delete(param->temp_filename,share->base.raid_chunks,
 			  MYF(MY_WME)));
-      if (info->dfile == new_file)
-	info->dfile= -1;
+      if (info->dfile == new_file) /* Retry with key cache */
+        if (unlikely(mi_open_datafile(info, share, name, -1)))
+          param->retry_repair= 0; /* Safety */
     }
     mi_mark_crashed_on_repair(info);
   }

=== modified file 'storage/myisam/sort.c'
--- a/storage/myisam/sort.c	2009-08-28 16:21:54 +0000
+++ b/storage/myisam/sort.c	2009-10-09 16:16:29 +0000
@@ -788,7 +788,11 @@ static int NEAR_F merge_many_buff(MI_SOR
 cleanup:
   close_cached_file(to_file);                   /* This holds old result */
   if (to_file == t_file)
+  {
     *t_file=t_file2;                            /* Copy result file */
+    t_file->current_pos= &t_file->write_pos;
+    t_file->current_end= &t_file->write_end;
+  }
 
   DBUG_RETURN(*maxbuffer >= MERGEBUFF2);        /* Return 1 if interrupted */
 } /* merge_many_buff */


Attachment: [text/bzr-bundle] bzr/svoj@sun.com-20091009161629-t0wiaxie4s75jpgy.bundle
Thread
bzr commit into mysql-5.1-bugteam branch (svoj:3146) Bug#47073Sergey Vojtovich9 Oct
  • Re: bzr commit into mysql-5.1-bugteam branch (svoj:3146) Bug#47073Sergei Golubchik16 Oct
    • Re: bzr commit into mysql-5.1-bugteam branch (svoj:3146) Bug#47073Sergey Vojtovich19 Oct