diff options
author | unknown <msvensson@shellback.> | 2006-04-11 12:12:48 +0200 |
---|---|---|
committer | unknown <msvensson@shellback.> | 2006-04-11 12:12:48 +0200 |
commit | 79a2debe460d7e22e9a7f5a4b549e8fe72b982e5 (patch) | |
tree | 3025fcbb9060c95f5987f7c84e265eba192ec47f | |
parent | e10f0d9b98e8a5107b2021d20aabc8bfb1ff1188 (diff) | |
download | mariadb-git-79a2debe460d7e22e9a7f5a4b549e8fe72b982e5.tar.gz |
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
mysql-test/r/csv.result:
Add more test to see that the table can be used after repair
mysql-test/t/csv.test:
Add more test to see that the table can be used after repair
storage/csv/ha_tina.cc:
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
-rw-r--r-- | mysql-test/r/csv.result | 30 | ||||
-rw-r--r-- | mysql-test/t/csv.test | 23 | ||||
-rw-r--r-- | storage/csv/ha_tina.cc | 28 |
3 files changed, 76 insertions, 5 deletions
diff --git a/mysql-test/r/csv.result b/mysql-test/r/csv.result index 70eaac2eb4e..3adcc895474 100644 --- a/mysql-test/r/csv.result +++ b/mysql-test/r/csv.result @@ -5085,6 +5085,36 @@ Table Op Msg_type Msg_text 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); diff --git a/mysql-test/t/csv.test b/mysql-test/t/csv.test index 63c76e79fc7..9ba99167ab9 100644 --- a/mysql-test/t/csv.test +++ b/mysql-test/t/csv.test @@ -1477,8 +1477,29 @@ CREATE TABLE test_repair_table5 ( 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" diff --git a/storage/csv/ha_tina.cc b/storage/csv/ha_tina.cc index 537e5b1bcc4..810292488fa 100644 --- a/storage/csv/ha_tina.cc +++ b/storage/csv/ha_tina.cc @@ -451,6 +451,7 @@ static int free_share(TINA_SHARE *share) 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 @@ int ha_tina::repair(THD* thd, HA_CHECK_OPT* check_opt) 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 @@ int ha_tina::repair(THD* thd, HA_CHECK_OPT* check_opt) 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); |