BUG#21350: No errors on using erroneus DATA DIRECTORY clause

set_up_table_before_create can fail due to erroneus path to
data directory or index directory
Added abort handling to ensure created partitions are dropped
if a failure occurs in the middle of the create process.
parent a4eb61b8
drop table if exists t1; drop table if exists t1;
create table t1 (a int) create table t1 (a int)
partition by key (a)
(partition p0 DATA DIRECTORY 'part-data' INDEX DIRECTORY 'part-data');
ERROR 42000: Incorrect table name 'part-data'
create table t1 (a int)
partition by key (a)
(partition p0,
partition p1 DATA DIRECTORY 'part-data' INDEX DIRECTORY 'part-data');
ERROR 42000: Incorrect table name 'part-data'
create table t1 (a int)
partition by list (a) partition by list (a)
(partition p0 values in (1)); (partition p0 values in (1));
create procedure pz() create procedure pz()
......
...@@ -9,6 +9,22 @@ ...@@ -9,6 +9,22 @@
drop table if exists t1; drop table if exists t1;
--enable_warnings --enable_warnings
#
# Bug 21350: Data Directory problems
#
-- error 1103
create table t1 (a int)
partition by key (a)
(partition p0 DATA DIRECTORY 'part-data' INDEX DIRECTORY 'part-data');
#
# Insert a test that manages to create the first partition and fails with
# the second, ensure that we clean up afterwards in a proper manner.
#
--error 1103
create table t1 (a int)
partition by key (a)
(partition p0,
partition p1 DATA DIRECTORY 'part-data' INDEX DIRECTORY 'part-data');
# #
# Bug 19309 Partitions: Crash if double procedural alter # Bug 19309 Partitions: Crash if double procedural alter
# #
......
...@@ -1134,7 +1134,9 @@ int ha_partition::prepare_new_partition(TABLE *table, ...@@ -1134,7 +1134,9 @@ int ha_partition::prepare_new_partition(TABLE *table,
bool open_flag= FALSE; bool open_flag= FALSE;
DBUG_ENTER("prepare_new_partition"); DBUG_ENTER("prepare_new_partition");
set_up_table_before_create(table, part_name, create_info, 0, p_elem); if ((error= set_up_table_before_create(table, part_name, create_info,
0, p_elem)))
goto error;
if ((error= file->create(part_name, table, create_info))) if ((error= file->create(part_name, table, create_info)))
goto error; goto error;
create_flag= TRUE; create_flag= TRUE;
...@@ -1633,7 +1635,7 @@ uint ha_partition::del_ren_cre_table(const char *from, ...@@ -1633,7 +1635,7 @@ uint ha_partition::del_ren_cre_table(const char *from,
char from_buff[FN_REFLEN], to_buff[FN_REFLEN]; char from_buff[FN_REFLEN], to_buff[FN_REFLEN];
char *name_buffer_ptr; char *name_buffer_ptr;
uint i; uint i;
handler **file; handler **file, **abort_file;
DBUG_ENTER("del_ren_cre_table()"); DBUG_ENTER("del_ren_cre_table()");
if (get_from_handler_file(from, current_thd->mem_root)) if (get_from_handler_file(from, current_thd->mem_root))
...@@ -1657,8 +1659,10 @@ uint ha_partition::del_ren_cre_table(const char *from, ...@@ -1657,8 +1659,10 @@ uint ha_partition::del_ren_cre_table(const char *from,
error= (*file)->delete_table((const char*) from_buff); error= (*file)->delete_table((const char*) from_buff);
else else
{ {
set_up_table_before_create(table_arg, from_buff, create_info, i, NULL); if ((error= set_up_table_before_create(table_arg, from_buff,
error= (*file)->create(from_buff, table_arg, create_info); create_info, i, NULL)) ||
((error= (*file)->create(from_buff, table_arg, create_info))))
goto create_error;
} }
name_buffer_ptr= strend(name_buffer_ptr) + 1; name_buffer_ptr= strend(name_buffer_ptr) + 1;
if (error) if (error)
...@@ -1666,6 +1670,16 @@ uint ha_partition::del_ren_cre_table(const char *from, ...@@ -1666,6 +1670,16 @@ uint ha_partition::del_ren_cre_table(const char *from,
i++; i++;
} while (*(++file)); } while (*(++file));
DBUG_RETURN(save_error); DBUG_RETURN(save_error);
create_error:
name_buffer_ptr= m_name_buffer_ptr;
for (abort_file= file, file= m_file; file < abort_file; file++)
{
create_partition_name(from_buff, from, name_buffer_ptr, NORMAL_PART_NAME,
FALSE);
VOID((*file)->delete_table((const char*) from_buff));
name_buffer_ptr= strend(name_buffer_ptr) + 1;
}
DBUG_RETURN(error);
} }
/* /*
...@@ -1720,7 +1734,8 @@ partition_element *ha_partition::find_partition_element(uint part_id) ...@@ -1720,7 +1734,8 @@ partition_element *ha_partition::find_partition_element(uint part_id)
part_id Partition id of partition to set-up part_id Partition id of partition to set-up
RETURN VALUE RETURN VALUE
NONE TRUE Error
FALSE Success
DESCRIPTION DESCRIPTION
Set up Set up
...@@ -1730,31 +1745,39 @@ partition_element *ha_partition::find_partition_element(uint part_id) ...@@ -1730,31 +1745,39 @@ partition_element *ha_partition::find_partition_element(uint part_id)
4) Data file name on partition 4) Data file name on partition
*/ */
void ha_partition::set_up_table_before_create(TABLE *table, int ha_partition::set_up_table_before_create(TABLE *table,
const char *partition_name_with_path, const char *partition_name_with_path,
HA_CREATE_INFO *info, HA_CREATE_INFO *info,
uint part_id, uint part_id,
partition_element *part_elem) partition_element *part_elem)
{ {
int error= 0;
DBUG_ENTER("set_up_table_before_create");
if (!part_elem) if (!part_elem)
{ {
part_elem= find_partition_element(part_id); part_elem= find_partition_element(part_id);
if (!part_elem) if (!part_elem)
return; // Fatal error DBUG_RETURN(1); // Fatal error
} }
table->s->max_rows= part_elem->part_max_rows; table->s->max_rows= part_elem->part_max_rows;
table->s->min_rows= part_elem->part_min_rows; table->s->min_rows= part_elem->part_min_rows;
const char *partition_name= strrchr(partition_name_with_path, FN_LIBCHAR); const char *partition_name= strrchr(partition_name_with_path, FN_LIBCHAR);
if (part_elem->index_file_name) if ((part_elem->index_file_name &&
append_file_to_dir(current_thd, (error= append_file_to_dir(current_thd,
(const char**)&part_elem->index_file_name, (const char**)&part_elem->index_file_name,
partition_name+1); partition_name+1))) ||
if (part_elem->data_file_name) (part_elem->data_file_name &&
append_file_to_dir(current_thd, (error= append_file_to_dir(current_thd,
(const char**)&part_elem->data_file_name, (const char**)&part_elem->data_file_name,
partition_name+1); partition_name+1))))
{
DBUG_ASSERT(error);
DBUG_RETURN(error);
}
info->index_file_name= part_elem->index_file_name; info->index_file_name= part_elem->index_file_name;
info->data_file_name= part_elem->data_file_name; info->data_file_name= part_elem->data_file_name;
DBUG_RETURN(0);
} }
......
...@@ -222,11 +222,11 @@ class ha_partition :public handler ...@@ -222,11 +222,11 @@ class ha_partition :public handler
bool new_handlers_from_part_info(MEM_ROOT *mem_root); bool new_handlers_from_part_info(MEM_ROOT *mem_root);
bool create_handlers(MEM_ROOT *mem_root); bool create_handlers(MEM_ROOT *mem_root);
void clear_handler_file(); void clear_handler_file();
void set_up_table_before_create(TABLE *table_arg, int set_up_table_before_create(TABLE *table_arg,
const char *partition_name_with_path, const char *partition_name_with_path,
HA_CREATE_INFO *info, HA_CREATE_INFO *info,
uint part_id, uint part_id,
partition_element *p_elem); partition_element *p_elem);
partition_element *find_partition_element(uint part_id); partition_element *find_partition_element(uint part_id);
public: public:
......
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