Commit de717a99 authored by unknown's avatar unknown
Browse files

WL 2826: Error handling of ALTER TABLE for partitioning

Fix compiler issues


sql/ha_heap.cc:
  Fix compiler warnings
sql/ha_myisammrg.cc:
  Fix compiler warnings
sql/log.cc:
  Fix compiler warnings
sql/sql_partition.cc:
  Fix compiler issues
sql/sql_table.cc:
  Fix compiler issues
parent f52e37ad
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -57,7 +57,9 @@ handlerton heap_hton= {
  NULL,    /* Partition flags */
  NULL,    /* Alter table flags */
  NULL,    /* Alter Tablespace */
  HTON_CAN_RECREATE
  HTON_CAN_RECREATE,
  NULL,    /* binlog func */
  NULL     /* binlog query */ 
};

static handler *heap_create_handler(TABLE_SHARE *table)
+3 −1
Original line number Diff line number Diff line
@@ -67,7 +67,9 @@ handlerton myisammrg_hton= {
  NULL,    /* Partition flags */
  NULL,    /* Alter table flags */
  NULL,    /* Alter Tablespace */
  HTON_CAN_RECREATE
  HTON_CAN_RECREATE,
  NULL,    /* binlog func */
  NULL     /* binlog query */
};

static handler *myisammrg_create_handler(TABLE_SHARE *table)
+3 −1
Original line number Diff line number Diff line
@@ -101,7 +101,9 @@ handlerton binlog_hton = {
  NULL,                         /* Partition flags */
  NULL,                         /* Alter table flags */
  NULL,                         /* Alter Tablespace */
  HTON_NOT_USER_SELECTABLE | HTON_HIDDEN
  HTON_NOT_USER_SELECTABLE | HTON_HIDDEN,
  NULL,                         /* binlog func */
  NULL                          /* binlog query */
};


+41 −26
Original line number Diff line number Diff line
@@ -5116,6 +5116,7 @@ release_part_info_log_entries(TABLE_LOG_MEMORY_ENTRY *log_entry)
    the partition info object
*/

static
bool
write_log_replace_delete_frm(ALTER_PARTITION_PARAM_TYPE *lpt,
                            uint next_entry,
@@ -5719,7 +5720,7 @@ write_log_completed(ALTER_PARTITION_PARAM_TYPE *lpt, bool dont_crash)

static
void
release_log_entries(partition *part_info)
release_log_entries(partition_info *part_info)
{
  lock_global_table_log();
  release_part_info_log_entries(part_info->first_log_entry);
@@ -5748,7 +5749,7 @@ handle_alter_part_error(ALTER_PARTITION_PARAM_TYPE *lpt, bool not_completed,
  DBUG_ENTER("handle_alter_part_error");

  if (!part_info->first_log_entry &&
      execute_table_log_entry(part_info->first_log_entry))
      execute_table_log_entry(part_info->first_log_entry->entry_pos))
  {
    /*
      We couldn't recover from error, most likely manual interaction is required.
@@ -5757,19 +5758,24 @@ handle_alter_part_error(ALTER_PARTITION_PARAM_TYPE *lpt, bool not_completed,
    release_log_entries(part_info);
    if (not_completed)
    {
      char *text1= "Operation was unsuccessful, table is still intact, ";
      char *text1= 
      (char*)"Operation was unsuccessful, table is still intact, ";
      if (drop_partition)
      {
        /* Table is still ok, but we left a shadow frm file behind. */
        char *text2= "but it is possible that a shadow frm file was left behind";
        char *text2=
      (char*)"but it is possible that a shadow frm file was left behind";
        push_warning_printf(lpt->thd, MYSQL_ERROR::WARN_LEVEL_WARN, 1,
                            "%s \n %s", text1, text2);
      }
      else
      {
        char *text2= "but it is possible that a shadow frm file was left behind.";
        char *text3= "It is also possible that temporary partitions are left behind, ";
        char *text4= "these could be empty or more or less filled with records";
        char *text2=
      (char*)"but it is possible that a shadow frm file was left behind.";
        char *text3=
      (char*)"It is also possible that temporary partitions are left behind, ";
        char *text4=
      (char*)"these could be empty or more or less filled with records";
        push_warning_printf(lpt->thd, MYSQL_ERROR::WARN_LEVEL_WARN, 1,
                            "%s \n %s \n %s \n %s", text1, text2, text3, text4);
      }
@@ -5782,10 +5788,13 @@ handle_alter_part_error(ALTER_PARTITION_PARAM_TYPE *lpt, bool not_completed,
           Failed during install of shadow frm file, table isn't intact
           and dropped partitions are still there
        */
        char *text1= "Failed during alter of partitions, table is no longer intact, ";
        char *text2= "The frm file is in an unknown state, and a backup";
        char *text3= " is required.
        push_warning_print(lpt->thd, MYSQL_ERROR::WARN_LEVEL_WARN, 1,
        char *text1=
      (char*)"Failed during alter of partitions, table is no longer intact, ";
        char *text2=
      (char*)"The frm file is in an unknown state, and a backup";
        char *text3=
      (char*)" is required.";
        push_warning_printf(lpt->thd, MYSQL_ERROR::WARN_LEVEL_WARN, 1,
                            "%s \n %s%s\n", text1, text2, text3);
      }
      else if (drop_partition)
@@ -5796,9 +5805,11 @@ handle_alter_part_error(ALTER_PARTITION_PARAM_TYPE *lpt, bool not_completed,
          perform the action manually. We remove the log records and ask the user
          to perform the action manually.
        */
        char *text1= "Failed during drop of partitions, table is intact, ";
        char *text2= "Manual drop of remaining partitions is required";
        push_warning_print(lpt->thd, MYSQL_ERROR::WARN_LEVEL_WARN, 1,
        char *text1=
      (char*)"Failed during drop of partitions, table is intact, ";
        char *text2=
      (char*)"Manual drop of remaining partitions is required";
        push_warning_printf(lpt->thd, MYSQL_ERROR::WARN_LEVEL_WARN, 1,
                            "%s\n%s", text1, text2);
      }
      else
@@ -5808,10 +5819,13 @@ handle_alter_part_error(ALTER_PARTITION_PARAM_TYPE *lpt, bool not_completed,
          a very bad state so we give user warning and disable the table by
          writing an ancient frm version into it.
        */
        char *text1= "Failed during renaming of partitions. We are now in a position"
        char *text2= " where table is not reusable";
        char *text3= "Table is disabled by writing ancient frm file version into it";
        push_warning_print(lpt->thd, MYSQL_ERROR::WARN_LEVEL_WARN, 1,
        char *text1=
      (char*)"Failed during renaming of partitions. We are now in a position";
        char *text2=
      (char*)" where table is not reusable";
        char *text3=
      (char*)"Table is disabled by writing ancient frm file version into it";
        push_warning_printf(lpt->thd, MYSQL_ERROR::WARN_LEVEL_WARN, 1,
                            "%s%s\n%s", text1, text2, text3);
      }
    }
@@ -5924,15 +5938,16 @@ uint fast_alter_partition_table(THD *thd, TABLE *table,
      In this case it is enough to call optimise_partitions, there is no
      need to change frm files or anything else.
    */
    int error;
    written_bin_log= FALSE;
    if (((alter_info->flags & ALTER_OPTIMIZE_PARTITION) &&
         (table->file->optimize_partitions(thd))) ||
         (error= table->file->optimize_partitions(thd))) ||
        ((alter_info->flags & ALTER_ANALYZE_PARTITION) &&
         (table->file->analyze_partitions(thd))) ||
         (error= table->file->analyze_partitions(thd))) ||
        ((alter_info->flags & ALTER_CHECK_PARTITION) &&
         (table->file->check_partitions(thd))) ||
         (error= table->file->check_partitions(thd))) ||
        ((alter_info->flags & ALTER_REPAIR_PARTITION) &&
         (table->file->repair_partitions(thd))))
         (error= table->file->repair_partitions(thd))))
    {
      table->file->print_error(error, MYF(0));
      DBUG_RETURN(TRUE);
+31 −17
Original line number Diff line number Diff line
@@ -321,7 +321,7 @@ read_table_log_file_entry(uint entry_no)
  DBUG_ENTER("read_table_log_file_entry");

  if (my_pread(file_id, file_entry, io_size, io_size * entry_no,
               MYF(MY_WME)))
               MYF(MY_WME)) != IO_SIZE)
    error= TRUE;
  DBUG_RETURN(error);
}
@@ -549,23 +549,24 @@ execute_table_log_action(TABLE_LOG_ENTRY *table_log_entry)
  bool frm_action= FALSE;
  LEX_STRING handler_name;
  handler *file;
  MEMROOT mem_root;
  bool= error= TRUE;
  MEM_ROOT mem_root;
  bool error= TRUE;
  char path[FN_REFLEN];
  char from_path[FN_REFLEN];
  char *par_ext= ".par";
  char *par_ext= (char*)".par";
  handlerton *hton;
  DBUG_ENTER("execute_table_log_action");

  if (table_log_entry->entry_type == TLOG_IGNORE_LOG_ENTRY_CODE)
  {
    DBUG_RETURN(FALSE);
  }
  handler_name.str= table_log_entry->handler_type;
  handler_name.str= (char*)table_log_entry->handler_type;
  handler_name.length= strlen(table_log_entry->handler_type);
  hton= ha_resolve_by_name(current_thd, handler_name);
  hton= ha_resolve_by_name(current_thd, &handler_name);
  if (!hton)
  {
    my_error(ER_ILLEGAL_HA, table_log_entry->handler_type);
    my_error(ER_ILLEGAL_HA, MYF(0), table_log_entry->handler_type);
    DBUG_RETURN(TRUE);
  }
  init_sql_alloc(&mem_root, TABLE_ALLOC_BLOCK_SIZE, 0); 
@@ -573,7 +574,9 @@ execute_table_log_action(TABLE_LOG_ENTRY *table_log_entry)
    frm_action= TRUE;
  else
  {
    file= get_new_handler(table_share, &mem_root, hton);
    TABLE_SHARE dummy;
    bzero(&dummy, sizeof(TABLE_SHARE));
    file= get_new_handler(&dummy, &mem_root, hton);
    if (!file)
    {
      mem_alloc_error(sizeof(handler));
@@ -581,10 +584,12 @@ execute_table_log_action(TABLE_LOG_ENTRY *table_log_entry)
    }
  }
  switch (table_log_entry->action_type)
    case TLOG_ACTION_DELETE_CODE:
    case TLOG_ACTION_REPLACE_CODE:
      if (table_log_entry->action_type == TLOG_ACTION_DELETE_CODE ||
          (table_log_entry->action_type == TLOG_ACTION_REPLACE_CODE &&
  {
    case TLOG_DELETE_ACTION_CODE:
    case TLOG_REPLACE_ACTION_CODE:
    {
      if (table_log_entry->action_type == TLOG_DELETE_ACTION_CODE ||
          (table_log_entry->action_type == TLOG_REPLACE_ACTION_CODE &&
           table_log_entry->phase == 0UL))
      {
        if (frm_action)
@@ -598,7 +603,7 @@ execute_table_log_action(TABLE_LOG_ENTRY *table_log_entry)
        }
        else
        {
          if (file->delete_table(table_name))
          if (file->delete_table(table_log_entry->name))
            break;
        }
        if ((!inactivate_table_log_entry(table_log_entry->entry_pos)))
@@ -610,9 +615,11 @@ execute_table_log_action(TABLE_LOG_ENTRY *table_log_entry)
        }
        break;
      }
      if (table_log_entry->action_type == TLOG_ACTION_DELETE_CODE)
      if (table_log_entry->action_type == TLOG_DELETE_ACTION_CODE)
        break;
    case TLOG_ACTION_RENAME_CODE:
    }
    case TLOG_RENAME_ACTION_CODE:
    {
      error= TRUE;
      if (frm_action)
      {
@@ -639,6 +646,7 @@ execute_table_log_action(TABLE_LOG_ENTRY *table_log_entry)
        }
      }
      break;
    }
    default:
      DBUG_ASSERT(0);
      break;
@@ -978,7 +986,7 @@ execute_table_log_entry(uint first_entry)
    DBUG_ASSERT(table_log_entry.entry_type == TLOG_LOG_ENTRY_CODE ||
                table_log_entry.entry_type == TLOG_IGNORE_LOG_ENTRY_CODE);

    if (execute_table_log_action(file, &table_log_entry))
    if (execute_table_log_action(&table_log_entry))
    {
      DBUG_ASSERT(0);
      /* Write to error log and continue with next log entry */
@@ -1028,7 +1036,6 @@ execute_table_log_recovery()
      }
    }
  }
  release_handler_objects();
  VOID(init_table_log());
  DBUG_VOID_RETURN;
}
@@ -1231,6 +1238,9 @@ bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags)
  }
  if (flags & WFRM_INSTALL_SHADOW)
  {
#ifdef WITH_PARTITION_STORAGE_ENGINE
    partition_info *part_info= lpt->part_info;
#endif
    /*
      Build frm file name
    */
@@ -1243,17 +1253,21 @@ bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags)
    */
    VOID(pthread_mutex_lock(&LOCK_open));
    if (my_delete(frm_name, MYF(MY_WME)) ||
#ifdef WITH_PARTITION_STORAGE_ENGINE
        inactivate_table_log_entry(part_info->frm_log_entry->entry_pos) ||
        (sync_table_log(), FALSE) ||
#endif
        my_rename(shadow_frm_name, frm_name, MYF(MY_WME)) ||
        lpt->table->file->create_handler_files(path, shadow_path, TRUE))
    {
      error= 1;
    }
    VOID(pthread_mutex_unlock(&LOCK_open));
#ifdef WITH_PARTITION_STORAGE_ENGINE
    inactivate_table_log_entry(part_info->frm_log_entry->entry_pos);
    part_info->frm_log_entry= NULL;
    VOID(sync_table_log());
#endif
  }

end: