Commit a68d2e3a authored by msvensson@shellback's avatar msvensson@shellback

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
parent c5a23958
......@@ -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);
......
......@@ -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"
......
......@@ -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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment