List:Commits« Previous MessageNext Message »
From:Jon Olav Hauglid Date:October 26 2011 8:08am
Subject:bzr push into mysql-trunk-wl5534 branch (jon.hauglid:3412 to 3413) WL#5534
View as plain text  
 3413 Jon Olav Hauglid	2011-10-26
      WL#5534 Online ALTER, Phase 1.
        
      Patch #39:
      Supply separate handler_add_index objects to different
      partitions so that each partition SE can maintain a
      separate context.

    modified:
      sql/ha_partition.cc
      sql/handler.h
 3412 Jon Olav Hauglid	2011-10-25
      WL#5534 Online ALTER, Phase 1.
        
      Patch #38:
      This patch adds MTR test coverage.
      Note that parts of the tests are disabled, awaiting
      WL#5526 InnoDB: Online ADD INDEX

    modified:
      mysql-test/r/alter_table.result
      mysql-test/r/innodb_mysql_sync.result
      mysql-test/t/alter_table.test
      mysql-test/t/innodb_mysql_sync.test
      sql/sql_table.cc
=== modified file 'sql/ha_partition.cc'
--- a/sql/ha_partition.cc	2011-10-21 18:00:03 +0000
+++ b/sql/ha_partition.cc	2011-10-26 08:08:16 +0000
@@ -6915,41 +6915,73 @@ ha_partition::check_if_supported_inplace
                                                HA_ALTER_FLAGS *alter_flags,
                                                uint table_changes)
 {
-  handler **file;
+  uint index= 0;
   enum_alter_inplace_result result= HA_ALTER_INPLACE_NO_LOCK;
 
   DBUG_ENTER("ha_partition::check_if_supported_inplace_alter");
 
-  for (file= m_file; *file; file++)
+  for (index= 0; index < m_tot_parts; index++)
   {
     enum_alter_inplace_result p_result=
-      (*file)->check_if_supported_inplace_alter(table, create_info, alter_info,
-                                                ha_alter_info, alter_flags,
-                                                table_changes);
+      m_file[index]->check_if_supported_inplace_alter(table, create_info, alter_info,
+                                                      ha_alter_info, alter_flags,
+                                                      table_changes);
     if (p_result < result)
       result= p_result;
     if (result == HA_ALTER_ERROR)
-      DBUG_RETURN(HA_ALTER_ERROR);
+      break;
   }
 
   DBUG_RETURN(result);
 }
 
 
+/**
+  Helper class for in-place alter, see handler.h
+*/
+
+class ha_partition_add_index : public handler_add_index
+{
+public:
+  handler_add_index **add_array;
+  ha_partition_add_index()
+    : handler_add_index(NULL, 0)
+  {}
+  ~ha_partition_add_index() {}
+};
+
+
 bool ha_partition::prepare_inplace_alter_table(HA_CREATE_INFO *create_info,
                                                Alter_inplace_information *ha_alter_info,
                                                HA_ALTER_FLAGS *alter_flags)
 {
-  handler **file;
+  uint index= 0;
+  bool error= false;
+  ha_partition_add_index *part_add_index;
+  THD *thd= ha_thd();
 
   DBUG_ENTER("ha_partition::prepare_inplace_alter_table");
 
-  for (file= m_file; *file; file++)
-    if ((*file)->prepare_inplace_alter_table(create_info, ha_alter_info,
-                                             alter_flags))
-      DBUG_RETURN(true);
+  part_add_index= new (thd->mem_root) ha_partition_add_index();
+  if (!part_add_index)
+    DBUG_RETURN(HA_ALTER_ERROR);
+
+  part_add_index->add_array= (handler_add_index **)
+                   thd->alloc(sizeof(void *) * m_tot_parts);
+  if (!part_add_index->add_array)
+    DBUG_RETURN(HA_ALTER_ERROR);
 
-  DBUG_RETURN(false);
+  for (index= 0; index < m_tot_parts && !error; index++)
+  {
+    ha_alter_info->handler_ctx= NULL;
+    if (m_file[index]->prepare_inplace_alter_table(create_info, ha_alter_info,
+                                                   alter_flags))
+      error= true;
+    part_add_index->add_array[index]= ha_alter_info->handler_ctx;
+  }
+  ha_alter_info->handler_ctx= part_add_index;
+
+  DBUG_RETURN(error);
 }
 
 
@@ -6957,16 +6989,26 @@ bool ha_partition::inplace_alter_table(H
                                        Alter_inplace_information *ha_alter_info,
                                        HA_ALTER_FLAGS *alter_flags)
 {
-  handler **file;
+  uint index= 0;
+  bool error= false;
+  ha_partition_add_index *part_add_index;
 
   DBUG_ENTER("ha_partition::inplace_alter_table");
 
-  for (file= m_file; *file; file++)
-    if ((*file)->inplace_alter_table(create_info, ha_alter_info,
-                                     alter_flags))
-      DBUG_RETURN(true);
+  part_add_index=
+    static_cast<class ha_partition_add_index*>(ha_alter_info->handler_ctx);
+
+  for (index= 0; index < m_tot_parts && !error; index++)
+  {
+    ha_alter_info->handler_ctx= part_add_index->add_array[index];
+    if (m_file[index]->inplace_alter_table(create_info, ha_alter_info,
+                                           alter_flags))
+      error= true;
+    part_add_index->add_array[index]= ha_alter_info->handler_ctx;
+  }
+  ha_alter_info->handler_ctx= part_add_index;
 
-  DBUG_RETURN(false);
+  DBUG_RETURN(error);
 }
 
 
@@ -6975,31 +7017,28 @@ bool ha_partition::commit_inplace_alter_
                                               HA_ALTER_FLAGS *alter_flags,
                                               bool commit)
 {
-  handler **file;
+  uint index= 0;
   bool error= false;
+  ha_partition_add_index *part_add_index;
 
   DBUG_ENTER("ha_partition::inplace_alter_table");
 
-  for (file= m_file; *file; file++)
+  part_add_index=
+    static_cast<class ha_partition_add_index*>(ha_alter_info->handler_ctx);
+
+  for (index= 0; index < m_tot_parts; index++)
   {
-    if ((*file)->commit_inplace_alter_table(create_info, ha_alter_info,
-                                            alter_flags, commit))
+    ha_alter_info->handler_ctx= part_add_index->add_array[index];
+    if (m_file[index]->commit_inplace_alter_table(create_info, ha_alter_info,
+                                                  alter_flags, commit))
     {
       error= true;
-      // If commit fails, stop and try rollback.
-      // If rollback fails, continue and rollback other paritions.
-      if (commit)
-        break;
+      // If commit fails, rollback remaining partitions.
+      // If rollback fails, continue and rollback other partitions.
+      commit= false;
     }
   }
-
-  // If error occured during commit, try rollback on all partitions.
-  if (error && !commit)
-  {
-    for (file= m_file; *file && !error; file++)
-      ((*file)->commit_inplace_alter_table(create_info, ha_alter_info,
-                                           alter_flags, false));
-  }
+  ha_alter_info->handler_ctx= part_add_index;
 
   DBUG_RETURN(error);
 }

=== modified file 'sql/handler.h'
--- a/sql/handler.h	2011-10-22 09:41:04 +0000
+++ b/sql/handler.h	2011-10-26 08:08:16 +0000
@@ -955,10 +955,12 @@ typedef struct st_ha_create_information
 
 /**
   Index creation context.
-  Created by handler::add_index() and freed by handler::final_add_index().
+  Created by handler::add_index() and destroyed by handler::final_add_index().
+  And finally freed at the end of the statement.
+  (Sql_alloc does not free in delete).
 */
 
-class handler_add_index
+class handler_add_index : public Sql_alloc
 {
 public:
   /* Indexes being created */

No bundle (reason: useless for push emails).
Thread
bzr push into mysql-trunk-wl5534 branch (jon.hauglid:3412 to 3413) WL#5534Jon Olav Hauglid26 Oct