mirror of
https://github.com/MariaDB/server.git
synced 2025-01-19 21:42:35 +01:00
Bug #18480 Windows file rename problems in archive storage engine
The problem was that the optimize code was not closing both the reader and writer streams before attempting to rename the file. This will not work on Windows where all file handles have to be closed before the file can be renamed, moved, or deleted. The fix was to move the close calls before the rename. We return the error code from my_rename in case of failure but we attempt to reopen the writers and readers even in the case of failure so that the table can still be usable.
This commit is contained in:
parent
34396a5d24
commit
e4a9adba0e
1 changed files with 14 additions and 7 deletions
|
@ -1239,7 +1239,7 @@ int ha_archive::repair(THD* thd, HA_CHECK_OPT* check_opt)
|
||||||
int ha_archive::optimize(THD* thd, HA_CHECK_OPT* check_opt)
|
int ha_archive::optimize(THD* thd, HA_CHECK_OPT* check_opt)
|
||||||
{
|
{
|
||||||
DBUG_ENTER("ha_archive::optimize");
|
DBUG_ENTER("ha_archive::optimize");
|
||||||
int rc;
|
int rc= 0;
|
||||||
azio_stream writer;
|
azio_stream writer;
|
||||||
char writer_filename[FN_REFLEN];
|
char writer_filename[FN_REFLEN];
|
||||||
|
|
||||||
|
@ -1342,7 +1342,20 @@ int ha_archive::optimize(THD* thd, HA_CHECK_OPT* check_opt)
|
||||||
azclose(&writer);
|
azclose(&writer);
|
||||||
share->dirty= FALSE;
|
share->dirty= FALSE;
|
||||||
share->forced_flushes= 0;
|
share->forced_flushes= 0;
|
||||||
|
|
||||||
|
// now we close both our writer and our reader for the rename
|
||||||
azclose(&(share->archive_write));
|
azclose(&(share->archive_write));
|
||||||
|
azclose(&archive);
|
||||||
|
|
||||||
|
// make the file we just wrote be our data file
|
||||||
|
rc = my_rename(writer_filename,share->data_file_name,MYF(0));
|
||||||
|
|
||||||
|
/*
|
||||||
|
now open the shared writer back up
|
||||||
|
we don't check rc here because we want to open the file back up even
|
||||||
|
if the optimize failed but we will return rc below so that we will
|
||||||
|
know it failed.
|
||||||
|
*/
|
||||||
DBUG_PRINT("info", ("Reopening archive data file"));
|
DBUG_PRINT("info", ("Reopening archive data file"));
|
||||||
if (!(azopen(&(share->archive_write), share->data_file_name,
|
if (!(azopen(&(share->archive_write), share->data_file_name,
|
||||||
O_WRONLY|O_APPEND|O_BINARY)))
|
O_WRONLY|O_APPEND|O_BINARY)))
|
||||||
|
@ -1352,21 +1365,15 @@ int ha_archive::optimize(THD* thd, HA_CHECK_OPT* check_opt)
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
my_rename(writer_filename,share->data_file_name,MYF(0));
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Now we need to reopen our read descriptor since it has changed.
|
Now we need to reopen our read descriptor since it has changed.
|
||||||
*/
|
*/
|
||||||
azclose(&archive);
|
|
||||||
if (!(azopen(&archive, share->data_file_name, O_RDONLY|O_BINARY)))
|
if (!(azopen(&archive, share->data_file_name, O_RDONLY|O_BINARY)))
|
||||||
{
|
{
|
||||||
rc= HA_ERR_CRASHED_ON_USAGE;
|
rc= HA_ERR_CRASHED_ON_USAGE;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DBUG_RETURN(0);
|
|
||||||
|
|
||||||
error:
|
error:
|
||||||
azclose(&writer);
|
azclose(&writer);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue