List:Commits« Previous MessageNext Message »
From:Mikael Ronström Date:August 7 2006 1:08pm
Subject:bk commit - 5.1 tree (mikael:1.2265) BUG#21350
View as plain text  
# This is a BitKeeper generated diff -Nru style patch.
#
# ChangeSet
#   2006/08/07 06:22:08-04:00 mikael@dator5.(none)
#   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.
#
# mysql-test/r/partition.result
#   2006/08/07 06:22:05-04:00 mikael@dator5.(none) +9 -0
#   New test cases
#
# mysql-test/t/partition.test
#   2006/08/07 06:22:05-04:00 mikael@dator5.(none) +16 -0
#   New test cases
#
# sql/ha_partition.cc
#   2006/08/07 06:22:05-04:00 mikael@dator5.(none) +42 -19
#   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.
#
# sql/ha_partition.h
#   2006/08/07 06:22:05-04:00 mikael@dator5.(none) +5 -5
#   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.
#
diff -Nru a/mysql-test/r/partition.result 
b/mysql-test/r/partition.result
--- a/mysql-test/r/partition.result	2006-08-07 07:02:07 -04:00
+++ b/mysql-test/r/partition.result	2006-08-07 07:02:07 -04:00
@@ -1,5 +1,14 @@
  drop table if exists t1;
  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 p0 values in (1));
  create procedure pz()
diff -Nru a/mysql-test/t/partition.test b/mysql-test/t/partition.test
--- a/mysql-test/t/partition.test	2006-08-07 07:02:07 -04:00
+++ b/mysql-test/t/partition.test	2006-08-07 07:02:07 -04:00
@@ -10,6 +10,22 @@
  --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
  #
  create table t1 (a int)
diff -Nru a/sql/ha_partition.cc b/sql/ha_partition.cc
--- a/sql/ha_partition.cc	2006-08-07 07:02:07 -04:00
+++ b/sql/ha_partition.cc	2006-08-07 07:02:07 -04:00
@@ -1134,7 +1134,9 @@
    bool open_flag= FALSE;
    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)))
      goto error;
    create_flag= TRUE;
@@ -1633,7 +1635,7 @@
    char from_buff[FN_REFLEN], to_buff[FN_REFLEN];
    char *name_buffer_ptr;
    uint i;
-  handler **file;
+  handler **file, **abort_file;
    DBUG_ENTER("del_ren_cre_table()");

    if (get_from_handler_file(from, current_thd->mem_root))
@@ -1657,8 +1659,10 @@
        error= (*file)->delete_table((const char*) from_buff);
      else
      {
-      set_up_table_before_create(table_arg, from_buff, create_info, i, 
NULL);
-      error= (*file)->create(from_buff, table_arg, create_info);
+      if ((error= set_up_table_before_create(table_arg, from_buff,
+                                             create_info, i, NULL)) ||
+          ((error= (*file)->create(from_buff, table_arg, 
create_info))))
+        goto create_error;
      }
      name_buffer_ptr= strend(name_buffer_ptr) + 1;
      if (error)
@@ -1666,6 +1670,16 @@
      i++;
    } while (*(++file));
    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 @@
       part_id                     Partition id of partition to set-up

     RETURN VALUE
-     NONE
+     TRUE                        Error
+     FALSE                       Success

     DESCRIPTION
       Set up
@@ -1730,31 +1745,39 @@
       4) Data file name on partition
  */

-void ha_partition::set_up_table_before_create(TABLE *table,
-                   const char *partition_name_with_path,
-                   HA_CREATE_INFO *info,
-                   uint part_id,
-                   partition_element *part_elem)
+int ha_partition::set_up_table_before_create(TABLE *table,
+                    const char *partition_name_with_path,
+                    HA_CREATE_INFO *info,
+                    uint part_id,
+                    partition_element *part_elem)
  {
+  int error= 0;
+  DBUG_ENTER("set_up_table_before_create");
+
    if (!part_elem)
    {
      part_elem= find_partition_element(part_id);
      if (!part_elem)
-      return;                                   // Fatal error
+      DBUG_RETURN(1);                             // Fatal error
    }
    table->s->max_rows= part_elem->part_max_rows;
    table->s->min_rows= part_elem->part_min_rows;
    const char *partition_name= strrchr(partition_name_with_path, 
FN_LIBCHAR);
-  if (part_elem->index_file_name)
-    append_file_to_dir(current_thd,
-                       (const char**)&part_elem->index_file_name,
-                       partition_name+1);
-  if (part_elem->data_file_name)
-    append_file_to_dir(current_thd,
-                       (const char**)&part_elem->data_file_name,
-                       partition_name+1);
+  if ((part_elem->index_file_name &&
+      (error= append_file_to_dir(current_thd,
+                                 (const 
char**)&part_elem->index_file_name,
+                                 partition_name+1))) ||
+      (part_elem->data_file_name &&
+      (error= append_file_to_dir(current_thd,
+                                 (const 
char**)&part_elem->data_file_name,
+                                 partition_name+1))))
+  {
+    DBUG_ASSERT(error);
+    DBUG_RETURN(error);
+  }
    info->index_file_name= part_elem->index_file_name;
    info->data_file_name= part_elem->data_file_name;
+  DBUG_RETURN(0);
  }


diff -Nru a/sql/ha_partition.h b/sql/ha_partition.h
--- a/sql/ha_partition.h	2006-08-07 07:02:07 -04:00
+++ b/sql/ha_partition.h	2006-08-07 07:02:07 -04:00
@@ -222,11 +222,11 @@
    bool new_handlers_from_part_info(MEM_ROOT *mem_root);
    bool create_handlers(MEM_ROOT *mem_root);
    void clear_handler_file();
-  void set_up_table_before_create(TABLE *table_arg,
-                                  const char *partition_name_with_path,
-                                  HA_CREATE_INFO *info,
-                                  uint part_id,
-                                  partition_element *p_elem);
+  int set_up_table_before_create(TABLE *table_arg,
+                                 const char *partition_name_with_path,
+                                 HA_CREATE_INFO *info,
+                                 uint part_id,
+                                 partition_element *p_elem);
    partition_element *find_partition_element(uint part_id);

  public:

Mikael Ronstrom, Senior Software Architect
MySQL AB, www.mysql.com

Jumpstart your cluster:
http://www.mysql.com/consulting/packaged/cluster.html
My blog:
http://mikaelronstrom.blogspot.com

Thread
bk commit - 5.1 tree (mikael:1.2265) BUG#21350Mikael Ronström7 Aug