Commit cd653ed9 authored by unknown's avatar unknown

WL 2826: Error handling of ALTER TABLE for partitioning

A number of fixes


sql/handler.h:
  A numbre of fixes
sql/mysql_priv.h:
  A numbre of fixes
sql/share/errmsg.txt:
  A numbre of fixes
sql/sql_partition.cc:
  A numbre of fixes
sql/sql_table.cc:
  A numbre of fixes
parent b037a7ca
......@@ -799,7 +799,7 @@ typedef int (*get_partitions_in_range_iter)(partition_info *part_info,
PARTITION_ITERATOR *part_iter);
struct TABLE_LOG_MEMORY_ENTRY;
struct st_table_log_memory_entry;
class partition_info : public Sql_alloc
{
......@@ -848,8 +848,8 @@ class partition_info : public Sql_alloc
Item *item_free_list;
TABLE_LOG_MEMORY_ENTRY *first_log_entry;
TABLE_LOG_MEMORY_ENTRY *exec_log_entry;
st_table_log_memory_entry *first_log_entry;
st_table_log_memory_entry *exec_log_entry;
/*
A bitmap of partitions used by the current query.
Usage pattern:
......@@ -961,6 +961,7 @@ class partition_info : public Sql_alloc
part_field_array(NULL), subpart_field_array(NULL),
full_part_field_array(NULL),
part_expr(NULL), subpart_expr(NULL), item_free_list(NULL),
first_log_entry(NULL), exec_log_entry(NULL),
list_array(NULL),
part_info_string(NULL),
part_func_string(NULL), subpart_func_string(NULL),
......
......@@ -1164,6 +1164,7 @@ typedef struct st_lock_param_type
uint key_count;
uint db_options;
uint pack_frm_len;
partition_info *part_info;
} ALTER_PARTITION_PARAM_TYPE;
void mem_alloc_error(size_t size);
......
......@@ -5798,3 +5798,5 @@ ER_CANT_WRITE_LOCK_LOG_TABLE
eng "You can't write-lock a log table. Only read access is possible."
ER_CANT_READ_LOCK_LOG_TABLE
eng "You can't use usual read lock with log tables. Try READ LOCAL instead."
ER_TABLE_LOG_ERROR
eng "Error in table log"
......@@ -5102,7 +5102,6 @@ release_part_info_log_entries(TABLE_LOG_MEMORY_ENTRY *log_entry)
release_table_log_memory_entry(log_entry);
log_entry= log_entry->next_log_entry;
}
part_info->first_log_entry= NULL;
DBUG_VOID_RETURN;
}
......@@ -5129,6 +5128,7 @@ write_log_shadow_frm(ALTER_PARTITION_PARAM_TYPE *lpt, bool install_frm)
TABLE_LOG_ENTRY table_log_entry;
partition_info *part_info= lpt->part_info;
TABLE_LOG_MEMORY_ENTRY *log_entry;
TABLE_LOG_MEMORY_ENTRY *exec_log_entry= NULL;
char shadow_path[FN_LEN];
DBUG_ENTER("write_log_shadow_frm");
......@@ -5145,14 +5145,16 @@ write_log_shadow_frm(ALTER_PARTITION_PARAM_TYPE *lpt, bool install_frm)
if (write_table_log_entry(&table_log_entry, &log_entry))
break;
insert_part_info_log_entry_list(part_info, log_entry);
if (write_execute_table_log_entry(log_entry->entry_pos, &log_entry))
if (write_execute_table_log_entry(log_entry->entry_pos, &exec_log_entry))
break;
part_info->exec_log_entry= log_entry;
part_info->exec_log_entry= exec_log_entry;
unlock_global_table_log();
DBUG_RETURN(FALSE);
} while (TRUE);
release_part_info_log_entries(part_info->first_log_entry);
part_info->first_log_entry= NULL;
unlock_global_table_log();
my_error(ER_TABLE_LOG_ERROR, MYF(0));
DBUG_RETURN(TRUE);
}
......@@ -5179,12 +5181,13 @@ write_log_dropped_partitions(ALTER_PARTITION_PARAM_TYPE *lpt,
char tmp_path[FN_LEN];
List_iterator<partition_element> part_it(part_info->partitions);
uint no_elements= part_info->partitions.elements;
uint i;
DBUG_ENTER("write_log_dropped_partitions");
table_log_entry.action_type= 'd';
do
{
partition_element part_elem= part_it++;
partition_element *part_elem= part_it++;
if (part_elem->part_state == PART_TO_BE_DROPPED ||
part_elem->part_state == PART_TO_BE_ADDED)
{
......@@ -5230,7 +5233,6 @@ write_log_dropped_partitions(ALTER_PARTITION_PARAM_TYPE *lpt,
}
} while (++i < no_elements);
DBUG_RETURN(FALSE);
error:
}
......@@ -5255,10 +5257,11 @@ write_log_drop_partition(ALTER_PARTITION_PARAM_TYPE *lpt)
TABLE_LOG_ENTRY table_log_entry;
partition_info *part_info= lpt->part_info;
TABLE_LOG_MEMORY_ENTRY *log_entry;
TABLE_LOG_MEMORY_ENTRY *exec_log_entry= part_info->exec_log_entry;
char tmp_path[FN_LEN];
char path[FN_LEN];
uint next_entry= 0;
TABLE_LOG_MEMORY_ENTRY *old_log_entry= part_info->first_log_entry;
TABLE_LOG_MEMORY_ENTRY *old_first_log_entry= part_info->first_log_entry;
DBUG_ENTER("write_log_drop_partition");
part_info->first_log_entry= NULL;
......@@ -5282,16 +5285,16 @@ write_log_drop_partition(ALTER_PARTITION_PARAM_TYPE *lpt)
if (write_table_log_entry(&table_log_entry, &log_entry))
break;
insert_part_info_log_entry_list(part_info, log_entry);
log_entry= part_info->exec_log_entry;
if (write_execute_table_log_entry(log_entry->entry_pos, NULL))
if (write_execute_table_log_entry(log_entry->entry_pos, &exec_log_entry))
break;
release_part_info_log_entries(old_first_log_entry);
unlock_global_table_log();
DBUG_RETURN(FALSE);
} while (TRUE);
release_part_info_log_entries(part_info->first_log_entry);
part_info->first_log_entry= old_log_entry;
part_info->first_log_entry= old_first_log_entry;
unlock_global_table_log();
my_error(ER_TABLE_LOG_ERROR, MYF(0));
DBUG_RETURN(TRUE);
}
......@@ -5320,14 +5323,14 @@ write_log_drop_partition(ALTER_PARTITION_PARAM_TYPE *lpt)
bool
write_log_add_partition(ALTER_PARTITION_PARAM_TYPE *lpt)
{
DBUG_ENTER("write_log_add_partition");
TABLE_LOG_ENTRY table_log_entry;
partition_info *part_info= lpt->part_info;
TABLE_LOG_MEMORY_ENTRY *log_entry;
char tmp_path[FN_LEN];
char path[FN_LEN];
TABLE_LOG_MEMORY_ENTRY *old_log_entry= part_info->first_log_entry;
uint next_entry= old_log_entry->entry_pos;
TABLE_LOG_MEMORY_ENTRY *exec_log_entry= part_info->exec_log_entry;
TABLE_LOG_MEMORY_ENTRY *old_first_log_entry= part_info->first_log_entry;
uint next_entry= old_first_log_entry->entry_pos;
/* Ensure we linked the existing entries at the back */
DBUG_ENTER("write_log_add_partition");
......@@ -5341,15 +5344,16 @@ write_log_add_partition(ALTER_PARTITION_PARAM_TYPE *lpt)
break;
log_entry= part_info->first_log_entry;
/* Ensure first entry is the last dropped partition */
if (write_execute_table_log_entry(log_entry->entry_pos, NULL))
if (write_execute_table_log_entry(log_entry->entry_pos, &exec_log_entry))
break;
release_part_info_log_entries(old_first_log_entry);
unlock_global_table_log();
DBUG_RETURN(FALSE);
} while (TRUE);
release_part_info_log_entries(part_info->first_log_entry);
part_info->first_log_entry= old_log_entry;
part_info->first_log_entry= old_first_log_entry;
unlock_global_table_log();
my_error(ER_TABLE_LOG_ERROR, MYF(0));
DBUG_RETURN(TRUE);
}
......@@ -5473,6 +5477,7 @@ uint fast_alter_partition_table(THD *thd, TABLE *table,
DBUG_ENTER("fast_alter_partition_table");
lpt->thd= thd;
lpt->part_info= part_info;
lpt->create_info= create_info;
lpt->create_list= create_list;
lpt->key_list= key_list;
......
......@@ -334,7 +334,8 @@ write_table_log_file_entry(uint entry_no)
char *file_entry= (char*)global_table_log.file_entry;
DBUG_ENTER("write_table_log_file_entry");
if (my_pwrite(file_id, file_entry, IO_SIZE, IO_SIZE * entry_no, MYF(0)))
if (my_pwrite(file_id, file_entry,
IO_SIZE, IO_SIZE * entry_no, MYF(0)) != IO_SIZE)
error= TRUE;
DBUG_RETURN(error);
}
......@@ -640,10 +641,10 @@ write_table_log_entry(TABLE_LOG_ENTRY *table_log_entry,
table_log_entry->next_entry);
strcpy(&global_table_log.file_entry[6], table_log_entry->name);
if (table_log_entry->action_type == 'r')
global_table_log.file_entry[6 + FN_LEN]= 0;
else
strcpy(&global_table_log.file_entry[6 + FN_LEN],
table_log_entry->from_name);
else
global_table_log.file_entry[6 + FN_LEN]= 0;
strcpy(&global_table_log.file_entry[6 + (2*FN_LEN)],
table_log_entry->handler_type);
if (get_free_table_log_entry(active_entry, &write_header))
......@@ -700,10 +701,13 @@ write_execute_table_log_entry(uint first_entry,
file_entry[6]= 0;
file_entry[6 + FN_LEN]= 0;
file_entry[6 + 2*FN_LEN]= 0;
if (!(*active_entry))
{
if (get_free_table_log_entry(active_entry, &write_header))
{
DBUG_RETURN(TRUE);
}
}
if (write_table_log_file_entry((*active_entry)->entry_pos))
{
release_table_log_memory_entry(*active_entry);
......
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