Commit ba9d750b authored by Michael Widenius's avatar Michael Widenius

Fix for LP#588599, mysqlbug#45377: ARCHIVE tables aren't discoverable after OPTIMIZE

Fix based on code from Stewart Smith

storage/archive/ha_archive.cc:
  Ensure that the frm definition is stored in optimized tables.
parent a35b4863
...@@ -1290,10 +1290,11 @@ int ha_archive::repair(THD* thd, HA_CHECK_OPT* check_opt) ...@@ -1290,10 +1290,11 @@ 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");
int rc= 0; int rc= 0;
azio_stream writer; azio_stream writer;
char writer_filename[FN_REFLEN]; char writer_filename[FN_REFLEN];
char* frm_string;
DBUG_ENTER("ha_archive::optimize");
init_archive_reader(); init_archive_reader();
...@@ -1304,12 +1305,28 @@ int ha_archive::optimize(THD* thd, HA_CHECK_OPT* check_opt) ...@@ -1304,12 +1305,28 @@ int ha_archive::optimize(THD* thd, HA_CHECK_OPT* check_opt)
share->archive_write_open= FALSE; share->archive_write_open= FALSE;
} }
if (!(frm_string= (char*) malloc(archive.frm_length)))
return ENOMEM;
azread_frm(&archive, frm_string);
/* Lets create a file to contain the new data */ /* Lets create a file to contain the new data */
fn_format(writer_filename, share->table_name, "", ARN, fn_format(writer_filename, share->table_name, "", ARN,
MY_REPLACE_EXT | MY_UNPACK_FILENAME); MY_REPLACE_EXT | MY_UNPACK_FILENAME);
if (!(azopen(&writer, writer_filename, O_CREAT|O_RDWR|O_BINARY))) if (!(azopen(&writer, writer_filename, O_CREAT|O_RDWR|O_BINARY)))
{
free(frm_string);
DBUG_RETURN(HA_ERR_CRASHED_ON_USAGE); DBUG_RETURN(HA_ERR_CRASHED_ON_USAGE);
}
rc= azwrite_frm(&writer, frm_string, archive.frm_length);
free(frm_string);
if (rc)
{
rc= HA_ERR_CRASHED_ON_USAGE;
goto error;
}
/* /*
An extended rebuild is a lot more effort. We open up each row and re-record it. An extended rebuild is a lot more effort. We open up each row and re-record it.
...@@ -1387,7 +1404,6 @@ int ha_archive::optimize(THD* thd, HA_CHECK_OPT* check_opt) ...@@ -1387,7 +1404,6 @@ int ha_archive::optimize(THD* thd, HA_CHECK_OPT* check_opt)
// make the file we just wrote be our data file // make the file we just wrote be our data file
rc = my_rename(writer_filename,share->data_file_name,MYF(0)); rc = my_rename(writer_filename,share->data_file_name,MYF(0));
DBUG_RETURN(rc); DBUG_RETURN(rc);
error: error:
DBUG_PRINT("ha_archive", ("Failed to recover, error was %d", rc)); DBUG_PRINT("ha_archive", ("Failed to recover, error was %d", rc));
......
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