List:Commits« Previous MessageNext Message »
From:msvensson Date:April 11 2006 10:13am
Subject:bk commit into 5.1 tree (msvensson:1.2310)
View as plain text  
Below is the list of changes that have just been committed into a local
5.1 repository of msvensson. When msvensson does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet
  1.2310 06/04/11 12:12:48 msvensson@shellback. +3 -0
  Close share->data_file in before renaming in ha_tina::repair
  Open and seek to end of data_file after rename 
  Fix comment for when file does not need repair.
  Set share->mapped_file to NULL always when it's been unmapped 
  Add test to see that file can be used after repair

  storage/csv/ha_tina.cc
    1.41 06/04/11 12:12:41 msvensson@shellback. +24 -4
    Close share->data_file in before renaming in ha_tina::repair
    Open and seek to end after rename
    Fix comment for when file does not need repair.
    Set share->mapped_file to NULL always when it's been unmapped 

  mysql-test/t/csv.test
    1.12 06/04/11 12:12:41 msvensson@shellback. +22 -1
    Add more test to see that the table can be used after repair

  mysql-test/r/csv.result
    1.9 06/04/11 12:12:40 msvensson@shellback. +30 -0
    Add more test to see that the table can be used after repair

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	msvensson
# Host:	shellback.
# Root:	C:/mysql/my51-bug17368

--- 1.8/mysql-test/r/csv.result	2006-03-29 04:28:50 +02:00
+++ 1.9/mysql-test/r/csv.result	2006-04-11 12:12:40 +02:00
@@ -5085,6 +5085,36 @@
 test.test_repair_table5	repair	status	OK
 SELECT * FROM test_repair_table5;
 num	magic_no	company_name	founded
+INSERT INTO test_repair_table5 VALUES (1, 102, "CORRECT", 1876);
+SELECT * FROM test_repair_table5;
+num	magic_no	company_name	founded
+1	0102	CORRECT	1876
+FLUSH TABLES;
+CHECK TABLE test_repair_table5;
+Table	Op	Msg_type	Msg_text
+test.test_repair_table5	check	error	Corrupt
+REPAIR TABLE test_repair_table5;
+Table	Op	Msg_type	Msg_text
+test.test_repair_table5	repair	status	OK
+SELECT * FROM test_repair_table5;
+num	magic_no	company_name	founded
+1	0102	CORRECT	1876
+INSERT INTO test_repair_table5 VALUES (1, 102, "CORRECT2", 1876);
+SELECT * FROM test_repair_table5;
+num	magic_no	company_name	founded
+1	0102	CORRECT	1876
+1	0102	CORRECT2	1876
+FLUSH TABLES;
+CHECK TABLE test_repair_table5;
+Table	Op	Msg_type	Msg_text
+test.test_repair_table5	check	error	Corrupt
+REPAIR TABLE test_repair_table5;
+Table	Op	Msg_type	Msg_text
+test.test_repair_table5	repair	status	OK
+SELECT * FROM test_repair_table5;
+num	magic_no	company_name	founded
+1	0102	CORRECT	1876
+1	0102	CORRECT2	1876
 DROP TABLE test_repair_table5;
 create table t1 (a int) engine=csv;
 insert t1 values (1);

--- 1.11/mysql-test/t/csv.test	2006-03-30 14:30:07 +02:00
+++ 1.12/mysql-test/t/csv.test	2006-04-11 12:12:41 +02:00
@@ -1477,8 +1477,29 @@
 CHECK TABLE test_repair_table5;
 REPAIR TABLE test_repair_table5;
 SELECT * FROM test_repair_table5;
-DROP TABLE test_repair_table5;
+INSERT INTO test_repair_table5 VALUES (1, 102, "CORRECT", 1876);
+SELECT * FROM test_repair_table5;
+
+# Corrupt a table -- put a row with wrong # of columns at end of file
+--exec perl -e 'print "\"1\",\"101\",\"IBM\"\n";' >> $MYSQLTEST_VARDIR/master-data/test/test_repair_table5.CSV
+
+FLUSH TABLES;
+CHECK TABLE test_repair_table5;
+REPAIR TABLE test_repair_table5;
+# The correct record inserted should still be in the file
+SELECT * FROM test_repair_table5;
+INSERT INTO test_repair_table5 VALUES (1, 102, "CORRECT2", 1876);
+SELECT * FROM test_repair_table5;
 
+# Corrupt table again -- put a row with wrong # of columns at end of file
+--exec perl -e 'print "\"1\",\"101\",\"IBM\"\n";' >> $MYSQLTEST_VARDIR/master-data/test/test_repair_table5.CSV
+
+FLUSH TABLES;
+CHECK TABLE test_repair_table5;
+REPAIR TABLE test_repair_table5;
+# The two correct records inserted should still be in the file
+SELECT * FROM test_repair_table5;
+DROP TABLE test_repair_table5;
 
 #
 # BUG#13406 - incorrect amount of "records deleted"

--- 1.40/storage/csv/ha_tina.cc	2006-04-06 11:38:42 +02:00
+++ 1.41/storage/csv/ha_tina.cc	2006-04-11 12:12:41 +02:00
@@ -451,6 +451,7 @@
       result_code= 1;
     if (share->mapped_file)
       my_munmap(share->mapped_file, share->file_stat.st_size);
+    share->mapped_file= NULL;
     result_code= my_close(share->data_file,MYF(0));
     hash_delete(&tina_open_tables, (byte*) share);
     thr_lock_delete(&share->lock);
@@ -1228,9 +1229,10 @@
 
   my_free((char*)buf, MYF(0));
 
-  /* The file is ok */
   if (rc == HA_ERR_END_OF_FILE)
   {
+    /* All rows were read ok until end of file, the file does not need repair. */
+
     /*
       If rows_recorded != rows_repaired, we should update
       rows_recorded value to the current amount of rows.
@@ -1258,11 +1260,29 @@
 
   if (my_munmap(share->mapped_file, share->file_stat.st_size))
     DBUG_RETURN(-1);
-
-  my_rename(repaired_fname, share->data_file_name, MYF(0));
-
   /* We set it to null so that get_mmap() won't try to unmap it */
   share->mapped_file= NULL;
+
+  /*
+    Close the "to"-file before renaming
+    On Windows one cannot rename a file, which descriptor
+    is still open. EACCES will be returned when trying to delete 
+    the "to"-file in my_rename()
+  */
+  my_close(share->data_file,MYF(0));
+
+  if (my_rename(repaired_fname, share->data_file_name, MYF(0)))
+    DBUG_RETURN(-1);
+
+  /* Open the file again, it should now be repaired */
+  if ((share->data_file= my_open(share->data_file_name, O_RDWR|O_APPEND,
+                                   MYF(0))) == -1)
+     DBUG_RETURN(-1);
+
+  /* Seek to end of file, any inserts will be appended there */
+  if (my_seek(share->data_file, 0, SEEK_END, MYF(0)) == MY_FILEPOS_ERROR)
+    DBUG_RETURN(-1);
+
   if (get_mmap(share, 0) > 0)
     DBUG_RETURN(-1);
 

Thread
bk commit into 5.1 tree (msvensson:1.2310)msvensson11 Apr