mirror of
https://github.com/MariaDB/server.git
synced 2025-07-27 18:02:13 +03:00
WL 2826: First step in error handling of ALTER TABLE for partitioning
This commit is contained in:

parent
86a15e5e86
commit
08e12cada9
167
sql/sql_table.cc
167
sql/sql_table.cc
@ -245,6 +245,28 @@ static int mysql_copy_key_list(List<Key> *orig_key,
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
SYNOPSIS
|
||||
write_table_log()
|
||||
lpt Struct carrying parameters to the function
|
||||
|
||||
RETURN VALUES
|
||||
TRUE Failure in writing the log
|
||||
FALSE Success
|
||||
|
||||
DESCRIPTION
|
||||
A careful write of the table log is performed to ensure that we can
|
||||
handle crashes occurring during CREATE and ALTER TABLE processing.
|
||||
*/
|
||||
|
||||
bool
|
||||
write_table_log(ALTER_PARTITION_PARAM_TYPE *lpt)
|
||||
{
|
||||
DBUG_ENTER("write_table_log");
|
||||
DBUG_RETURN(FALSE);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
SYNOPSIS
|
||||
mysql_write_frm()
|
||||
@ -277,83 +299,66 @@ bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags)
|
||||
*/
|
||||
int error= 0;
|
||||
char path[FN_REFLEN+1];
|
||||
char shadow_path[FN_REFLEN+1];
|
||||
char shadow_frm_name[FN_REFLEN+1];
|
||||
char frm_name[FN_REFLEN+1];
|
||||
DBUG_ENTER("mysql_write_frm");
|
||||
|
||||
if (flags & WFRM_INITIAL_WRITE)
|
||||
/*
|
||||
Build shadow frm file name
|
||||
*/
|
||||
build_table_filename(shadow_path, sizeof(path), lpt->db,
|
||||
lpt->table_name, "#");
|
||||
strxmov(shadow_frm_name, path, reg_ext, NullS);
|
||||
if (flags & WFRM_WRITE_SHADOW)
|
||||
{
|
||||
error= mysql_copy_create_list(lpt->create_list,
|
||||
&lpt->new_create_list);
|
||||
error+= mysql_copy_key_list(lpt->key_list,
|
||||
&lpt->new_key_list);
|
||||
if (error)
|
||||
if (mysql_copy_create_list(lpt->create_list,
|
||||
&lpt->new_create_list) ||
|
||||
mysql_copy_key_list(lpt->key_list,
|
||||
&lpt->new_key_list) ||
|
||||
mysql_prepare_table(lpt->thd, lpt->create_info,
|
||||
&lpt->new_create_list,
|
||||
&lpt->new_key_list,
|
||||
/*tmp_table*/ 1,
|
||||
&lpt->db_options,
|
||||
lpt->table->file,
|
||||
&lpt->key_info_buffer,
|
||||
&lpt->key_count,
|
||||
/*select_field_count*/ 0)))
|
||||
{
|
||||
DBUG_RETURN(TRUE);
|
||||
}
|
||||
}
|
||||
build_table_filename(path, sizeof(path), lpt->db, lpt->table_name, "");
|
||||
strxmov(frm_name, path, reg_ext, NullS);
|
||||
if ((flags & WFRM_INITIAL_WRITE) &&
|
||||
(mysql_prepare_table(lpt->thd, lpt->create_info, &lpt->new_create_list,
|
||||
&lpt->new_key_list,/*tmp_table*/ 1, &lpt->db_options,
|
||||
lpt->table->file, &lpt->key_info_buffer,
|
||||
&lpt->key_count, /*select_field_count*/ 0)))
|
||||
{
|
||||
DBUG_RETURN(TRUE);
|
||||
}
|
||||
#ifdef WITH_PARTITION_STORAGE_ENGINE
|
||||
{
|
||||
partition_info *part_info= lpt->table->part_info;
|
||||
char *part_syntax_buf;
|
||||
uint syntax_len, i;
|
||||
bool any_unnormal_state= FALSE;
|
||||
|
||||
if (part_info)
|
||||
{
|
||||
uint max_part_state_len= part_info->partitions.elements +
|
||||
part_info->temp_partitions.elements;
|
||||
if (!(part_info->part_state= (uchar*)sql_alloc(max_part_state_len)))
|
||||
partition_info *part_info= lpt->table->part_info;
|
||||
char *part_syntax_buf;
|
||||
uint syntax_len;
|
||||
|
||||
if (part_info)
|
||||
{
|
||||
DBUG_RETURN(TRUE);
|
||||
if (!(part_syntax_buf= generate_partition_syntax(part_info,
|
||||
&syntax_len,
|
||||
TRUE, FALSE)))
|
||||
{
|
||||
DBUG_RETURN(TRUE);
|
||||
}
|
||||
part_info->part_info_string= part_syntax_buf;
|
||||
part_info->part_info_len= syntax_len;
|
||||
}
|
||||
part_info->part_state_len= 0;
|
||||
if (!(part_syntax_buf= generate_partition_syntax(part_info,
|
||||
&syntax_len,
|
||||
TRUE, FALSE)))
|
||||
{
|
||||
DBUG_RETURN(TRUE);
|
||||
}
|
||||
for (i= 0; i < part_info->part_state_len; i++)
|
||||
{
|
||||
enum partition_state part_state=
|
||||
(enum partition_state)part_info->part_state[i];
|
||||
if (part_state != PART_NORMAL && part_state != PART_IS_ADDED)
|
||||
any_unnormal_state= TRUE;
|
||||
}
|
||||
if (!any_unnormal_state)
|
||||
{
|
||||
part_info->part_state= NULL;
|
||||
part_info->part_state_len= 0;
|
||||
}
|
||||
part_info->part_info_string= part_syntax_buf;
|
||||
part_info->part_info_len= syntax_len;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
We write the frm file with the LOCK_open mutex since otherwise we could
|
||||
overwrite the frm file as another is reading it in open_table.
|
||||
*/
|
||||
lpt->create_info->table_options= lpt->db_options;
|
||||
VOID(pthread_mutex_lock(&LOCK_open));
|
||||
if ((mysql_create_frm(lpt->thd, frm_name, lpt->db, lpt->table_name,
|
||||
lpt->create_info, lpt->new_create_list, lpt->key_count,
|
||||
lpt->key_info_buffer, lpt->table->file)) ||
|
||||
((flags & WFRM_CREATE_HANDLER_FILES) &&
|
||||
lpt->table->file->create_handler_files(path)))
|
||||
{
|
||||
error= 1;
|
||||
goto end;
|
||||
/* Write shadow frm file */
|
||||
lpt->create_info->table_options= lpt->db_options;
|
||||
if ((mysql_create_frm(lpt->thd, shadow_frm_name, lpt->db,
|
||||
lpt->table_name, lpt->create_info,
|
||||
lpt->new_create_list, lpt->key_count,
|
||||
lpt->key_info_buffer, lpt->table->file)) ||
|
||||
lpt->table->file->create_handler_files(shadow_path, NULL, FALSE))
|
||||
{
|
||||
my_delete(shadow_frm_name, MYF(0));
|
||||
error= 1;
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
if (flags & WFRM_PACK_FRM)
|
||||
{
|
||||
@ -365,7 +370,7 @@ bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags)
|
||||
*/
|
||||
const void *data= 0;
|
||||
uint length= 0;
|
||||
if (readfrm(path, &data, &length) ||
|
||||
if (readfrm(shadow_path, &data, &length) ||
|
||||
packfrm(data, length, &lpt->pack_frm_data, &lpt->pack_frm_len))
|
||||
{
|
||||
my_free((char*)data, MYF(MY_ALLOW_ZERO_PTR));
|
||||
@ -374,11 +379,31 @@ bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags)
|
||||
error= 1;
|
||||
goto end;
|
||||
}
|
||||
error= my_delete(frm_name, MYF(MY_WME));
|
||||
error= my_delete(shadow_frm_name, MYF(MY_WME));
|
||||
}
|
||||
/* Frm file have been updated to reflect the change about to happen. */
|
||||
if (flags & WFRM_INSTALL_SHADOW)
|
||||
{
|
||||
/*
|
||||
Build frm file name
|
||||
*/
|
||||
build_table_filename(path, sizeof(path), lpt->db,
|
||||
lpt->table_name, "");
|
||||
strxmov(frm_name, path, reg_ext, NullS);
|
||||
/*
|
||||
When we are changing to use new frm file we need to ensure that we
|
||||
don't collide with another thread in process to open the frm file.
|
||||
*/
|
||||
VOID(pthread_mutex_lock(&LOCK_open));
|
||||
if (my_delete(frm_name, MYF(MY_WME)) ||
|
||||
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));
|
||||
}
|
||||
|
||||
end:
|
||||
VOID(pthread_mutex_unlock(&LOCK_open));
|
||||
DBUG_RETURN(error);
|
||||
}
|
||||
|
||||
@ -4631,7 +4656,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
|
||||
error= (mysql_create_frm(thd, reg_path, db, table_name,
|
||||
create_info, prepared_create_list, key_count,
|
||||
key_info_buffer, table->file) ||
|
||||
table->file->create_handler_files(reg_path));
|
||||
table->file->create_handler_files(reg_path, NULL, FALSE));
|
||||
VOID(pthread_mutex_unlock(&LOCK_open));
|
||||
if (error)
|
||||
goto err;
|
||||
@ -4677,7 +4702,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
|
||||
error= (mysql_create_frm(thd, reg_path, db, table_name,
|
||||
create_info, prepared_create_list, key_count,
|
||||
key_info_buffer, table->file) ||
|
||||
table->file->create_handler_files(reg_path));
|
||||
table->file->create_handler_files(reg_path, NULL, FALSE));
|
||||
VOID(pthread_mutex_unlock(&LOCK_open));
|
||||
if (error)
|
||||
goto err;
|
||||
@ -4900,7 +4925,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
|
||||
VOID(pthread_mutex_lock(&LOCK_open));
|
||||
}
|
||||
/* Tell the handler that a new frm file is in place. */
|
||||
if (table->file->create_handler_files(reg_path))
|
||||
if (table->file->create_handler_files(reg_path, NULL, FALSE))
|
||||
{
|
||||
VOID(pthread_mutex_unlock(&LOCK_open));
|
||||
goto err;
|
||||
|
Reference in New Issue
Block a user