Commit 3373a7ed authored by Aditya A's avatar Aditya A

Bug#13548704 ALGORITHM USED FOR DROPPING PARTITIONED TABLE CAN LEAD

             TO INCONSISTENCY 
[Merge from 5.1]
parents 9f3ceb97 5f3c0a45
...@@ -106,8 +106,8 @@ test.t1 check Error Incorrect information in file: './test/t1.frm' ...@@ -106,8 +106,8 @@ test.t1 check Error Incorrect information in file: './test/t1.frm'
test.t1 check error Corrupt test.t1 check error Corrupt
SELECT * FROM t1; SELECT * FROM t1;
ERROR HY000: Failed to read from the .par file ERROR HY000: Failed to read from the .par file
# Note that it is currently impossible to drop a partitioned table # Note that we will remove the frm file when we detect that
# without the .par file # .par file has been deleted.
DROP TABLE t1; DROP TABLE t1;
ERROR 42S02: Unknown table 't1' ERROR 42S02: Unknown table 't1'
# #
......
...@@ -86,11 +86,10 @@ FLUSH TABLES; ...@@ -86,11 +86,10 @@ FLUSH TABLES;
CHECK TABLE t1; CHECK TABLE t1;
--error ER_FAILED_READ_FROM_PAR_FILE --error ER_FAILED_READ_FROM_PAR_FILE
SELECT * FROM t1; SELECT * FROM t1;
--echo # Note that it is currently impossible to drop a partitioned table --echo # Note that we will remove the frm file when we detect that
--echo # without the .par file --echo # .par file has been deleted.
--error ER_BAD_TABLE_ERROR --error ER_BAD_TABLE_ERROR
DROP TABLE t1; DROP TABLE t1;
--remove_file $MYSQLD_DATADIR/test/t1.frm
--remove_file $MYSQLD_DATADIR/test/t1#P#p0.MYI --remove_file $MYSQLD_DATADIR/test/t1#P#p0.MYI
--remove_file $MYSQLD_DATADIR/test/t1#P#p0.MYD --remove_file $MYSQLD_DATADIR/test/t1#P#p0.MYD
......
...@@ -1930,15 +1930,15 @@ char *ha_partition::update_table_comment(const char *comment) ...@@ -1930,15 +1930,15 @@ char *ha_partition::update_table_comment(const char *comment)
names of the partitions and the underlying storage engines. names of the partitions and the underlying storage engines.
*/ */
uint ha_partition::del_ren_cre_table(const char *from, int ha_partition::del_ren_cre_table(const char *from,
const char *to, const char *to,
TABLE *table_arg, TABLE *table_arg,
HA_CREATE_INFO *create_info) HA_CREATE_INFO *create_info)
{ {
int save_error= 0; int save_error= 0;
int error; int error= HA_ERR_INTERNAL_ERROR;
char from_buff[FN_REFLEN], to_buff[FN_REFLEN], from_lc_buff[FN_REFLEN], char from_buff[FN_REFLEN], to_buff[FN_REFLEN], from_lc_buff[FN_REFLEN],
to_lc_buff[FN_REFLEN]; to_lc_buff[FN_REFLEN], buff[FN_REFLEN];
char *name_buffer_ptr; char *name_buffer_ptr;
const char *from_path; const char *from_path;
const char *to_path= NULL; const char *to_path= NULL;
...@@ -1950,24 +1950,28 @@ uint ha_partition::del_ren_cre_table(const char *from, ...@@ -1950,24 +1950,28 @@ uint ha_partition::del_ren_cre_table(const char *from,
if (create_info && create_info->options & HA_LEX_CREATE_TMP_TABLE) if (create_info && create_info->options & HA_LEX_CREATE_TMP_TABLE)
{ {
my_error(ER_PARTITION_NO_TEMPORARY, MYF(0)); my_error(ER_PARTITION_NO_TEMPORARY, MYF(0));
DBUG_RETURN(TRUE); DBUG_RETURN(error);
}
fn_format(buff,from, "", ha_par_ext, MY_APPEND_EXT);
/* Check if the par file exists */
if (my_access(buff,F_OK))
{
/*
If the .par file does not exist, return HA_ERR_NO_SUCH_TABLE,
This will signal to the caller that it can remove the .frm
file.
*/
error= HA_ERR_NO_SUCH_TABLE;
DBUG_RETURN(error);
} }
if (get_from_handler_file(from, ha_thd()->mem_root, false)) if (get_from_handler_file(from, ha_thd()->mem_root, false))
DBUG_RETURN(TRUE); DBUG_RETURN(error);
DBUG_ASSERT(m_file_buffer); DBUG_ASSERT(m_file_buffer);
DBUG_PRINT("enter", ("from: (%s) to: (%s)", from, to ? to : "(nil)")); DBUG_PRINT("enter", ("from: (%s) to: (%s)", from, to ? to : "(nil)"));
name_buffer_ptr= m_name_buffer_ptr; name_buffer_ptr= m_name_buffer_ptr;
file= m_file; file= m_file;
if (to == NULL && table_arg == NULL)
{
/*
Delete table, start by delete the .par file. If error, break, otherwise
delete as much as possible.
*/
if ((error= handler::delete_table(from)))
DBUG_RETURN(error);
}
/* /*
Since ha_partition has HA_FILE_BASED, it must alter underlying table names Since ha_partition has HA_FILE_BASED, it must alter underlying table names
if they do not have HA_FILE_BASED and lower_case_table_names == 2. if they do not have HA_FILE_BASED and lower_case_table_names == 2.
...@@ -2006,6 +2010,18 @@ uint ha_partition::del_ren_cre_table(const char *from, ...@@ -2006,6 +2010,18 @@ uint ha_partition::del_ren_cre_table(const char *from,
save_error= error; save_error= error;
i++; i++;
} while (*(++file)); } while (*(++file));
if (to == NULL && table_arg == NULL)
{
DBUG_EXECUTE_IF("crash_before_deleting_par_file", DBUG_SUICIDE(););
/* Delete the .par file. If error, break.*/
if ((error= handler::delete_table(from)))
DBUG_RETURN(error);
DBUG_EXECUTE_IF("crash_after_deleting_par_file", DBUG_SUICIDE(););
}
if (to != NULL) if (to != NULL)
{ {
if ((error= handler::rename_table(from, to))) if ((error= handler::rename_table(from, to)))
......
...@@ -275,7 +275,7 @@ private: ...@@ -275,7 +275,7 @@ private:
delete_table, rename_table and create uses very similar logic which delete_table, rename_table and create uses very similar logic which
is packed into this routine. is packed into this routine.
*/ */
uint del_ren_cre_table(const char *from, const char *to, int del_ren_cre_table(const char *from, const char *to,
TABLE *table_arg, HA_CREATE_INFO *create_info); TABLE *table_arg, HA_CREATE_INFO *create_info);
/* /*
One method to create the table_name.par file containing the names of the One method to create the table_name.par file containing the names of the
......
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