1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

Merge next-mr -> next-4284

This commit is contained in:
Konstantin Osipov
2009-12-03 14:37:42 +03:00
251 changed files with 6942 additions and 3254 deletions

View File

@ -3994,15 +3994,43 @@ bool mysql_create_table_no_lock(THD *thd,
create_info->table_existed= 0; // Mark that table is created
#ifdef HAVE_READLINK
if (test_if_data_home_dir(create_info->data_file_name))
{
my_error(ER_WRONG_ARGUMENTS, MYF(0), "DATA DIRECTORY");
goto unlock_and_end;
}
if (test_if_data_home_dir(create_info->index_file_name))
{
my_error(ER_WRONG_ARGUMENTS, MYF(0), "INDEX DIRECTORY");
goto unlock_and_end;
size_t dirlen;
char dirpath[FN_REFLEN];
/*
data_file_name and index_file_name include the table name without
extension. Mostly this does not refer to an existing file. When
comparing data_file_name or index_file_name against the data
directory, we try to resolve all symbolic links. On some systems,
we use realpath(3) for the resolution. This returns ENOENT if the
resolved path does not refer to an existing file. my_realpath()
does then copy the requested path verbatim, without symlink
resolution. Thereafter the comparison can fail even if the
requested path is within the data directory. E.g. if symlinks to
another file system are used. To make realpath(3) return the
resolved path, we strip the table name and compare the directory
path only. If the directory doesn't exist either, table creation
will fail anyway.
*/
if (create_info->data_file_name)
{
dirname_part(dirpath, create_info->data_file_name, &dirlen);
if (test_if_data_home_dir(dirpath))
{
my_error(ER_WRONG_ARGUMENTS, MYF(0), "DATA DIRECTORY");
goto unlock_and_end;
}
}
if (create_info->index_file_name)
{
dirname_part(dirpath, create_info->index_file_name, &dirlen);
if (test_if_data_home_dir(dirpath))
{
my_error(ER_WRONG_ARGUMENTS, MYF(0), "INDEX DIRECTORY");
goto unlock_and_end;
}
}
}
#ifdef WITH_PARTITION_STORAGE_ENGINE
@ -4330,78 +4358,6 @@ static int send_check_errmsg(THD *thd, TABLE_LIST* table,
}
static int prepare_for_restore(THD* thd, TABLE_LIST* table,
HA_CHECK_OPT *check_opt)
{
MDL_LOCK_DATA *mdl_lock_data= 0;
enum enum_open_table_action ot_action_unused;
DBUG_ENTER("prepare_for_restore");
if (table->table) // do not overwrite existing tables on restore
{
DBUG_RETURN(send_check_errmsg(thd, table, "restore",
"table exists, will not overwrite on restore"
));
}
else
{
char* backup_dir= thd->lex->backup_dir;
char src_path[FN_REFLEN], dst_path[FN_REFLEN + 1], uname[FN_REFLEN];
char* table_name= table->table_name;
char* db= table->db;
tablename_to_filename(table->table_name, uname, sizeof(uname) - 1);
if (fn_format_relative_to_data_home(src_path, uname, backup_dir, reg_ext))
DBUG_RETURN(-1); // protect buffer overflow
build_table_filename(dst_path, sizeof(dst_path) - 1,
db, table_name, reg_ext, 0);
mdl_lock_data= mdl_alloc_lock(0, table->db, table->table_name,
thd->mem_root);
mdl_set_lock_type(mdl_lock_data, MDL_EXCLUSIVE);
mdl_add_lock(&thd->mdl_context, mdl_lock_data);
if (mdl_acquire_exclusive_locks(&thd->mdl_context))
DBUG_RETURN(TRUE);
pthread_mutex_lock(&LOCK_open);
tdc_remove_table(0, TDC_RT_REMOVE_UNUSED, table->db, table->table_name);
pthread_mutex_unlock(&LOCK_open);
if (my_copy(src_path, dst_path, MYF(MY_WME)))
{
mdl_release_lock(&thd->mdl_context, mdl_lock_data);
DBUG_RETURN(send_check_errmsg(thd, table, "restore",
"Failed copying .frm file"));
}
if (mysql_truncate(thd, table, 1))
{
mdl_release_lock(&thd->mdl_context, mdl_lock_data);
DBUG_RETURN(send_check_errmsg(thd, table, "restore",
"Failed generating table from .frm file"));
}
table->mdl_lock_data= mdl_lock_data;
}
/*
Now we should be able to open the partially restored table
to finish the restore in the handler later on
*/
if (open_table(thd, table, thd->mem_root,
&ot_action_unused, MYSQL_OPEN_REOPEN))
{
if (mdl_lock_data)
mdl_release_lock(&thd->mdl_context, mdl_lock_data);
DBUG_RETURN(send_check_errmsg(thd, table, "restore",
"Failed to open partially restored table"));
}
/* A MERGE table must not come here. */
DBUG_ASSERT(!table->table ||
table->table->file->ht->db_type != DB_TYPE_MRG_MYISAM);
DBUG_RETURN(0);
}
static int prepare_for_repair(THD *thd, TABLE_LIST *table_list,
HA_CHECK_OPT *check_opt)
{
@ -5089,29 +5045,6 @@ err:
}
bool mysql_backup_table(THD* thd, TABLE_LIST* table_list)
{
DBUG_ENTER("mysql_backup_table");
WARN_DEPRECATED(thd, "6.0", "BACKUP TABLE",
"MySQL Administrator (mysqldump, mysql)");
DBUG_RETURN(mysql_admin_table(thd, table_list, 0,
"backup", TL_READ, 0, 0, 0, 0,
&handler::ha_backup, 0));
}
bool mysql_restore_table(THD* thd, TABLE_LIST* table_list)
{
DBUG_ENTER("mysql_restore_table");
WARN_DEPRECATED(thd, "6.0", "RESTORE TABLE",
"MySQL Administrator (mysqldump, mysql)");
DBUG_RETURN(mysql_admin_table(thd, table_list, 0,
"restore", TL_WRITE, 1, 1, 0,
&prepare_for_restore,
&handler::ha_restore, 0));
}
bool mysql_repair_table(THD* thd, TABLE_LIST* tables, HA_CHECK_OPT* check_opt)
{
DBUG_ENTER("mysql_repair_table");