mirror of
https://github.com/MariaDB/server.git
synced 2025-08-01 03:47:19 +03:00
Initial import of WL#3726 "DDL locking for all metadata objects".
Backport of: ------------------------------------------------------------ revno: 2630.4.1 committer: Dmitry Lenev <dlenev@mysql.com> branch nick: mysql-6.0-3726-w timestamp: Fri 2008-05-23 17:54:03 +0400 message: WL#3726 "DDL locking for all metadata objects". After review fixes in progress. ------------------------------------------------------------ This is the first patch in series. It transforms the metadata locking subsystem to use a dedicated module (mdl.h,cc). No significant changes in the locking protocol. The import passes the test suite with the exception of deprecated/removed 6.0 features, and MERGE tables. The latter are subject to a fix by WL#4144. Unfortunately, the original changeset comments got lost in a merge, thus this import has its own (largely insufficient) comments. This patch fixes Bug#25144 "replication / binlog with view breaks". Warning: this patch introduces an incompatible change: Under LOCK TABLES, it's no longer possible to FLUSH a table that was not locked for WRITE. Under LOCK TABLES, it's no longer possible to DROP a table or VIEW that was not locked for WRITE. ****** Backport of: ------------------------------------------------------------ revno: 2630.4.2 committer: Dmitry Lenev <dlenev@mysql.com> branch nick: mysql-6.0-3726-w timestamp: Sat 2008-05-24 14:03:45 +0400 message: WL#3726 "DDL locking for all metadata objects". After review fixes in progress. ****** Backport of: ------------------------------------------------------------ revno: 2630.4.3 committer: Dmitry Lenev <dlenev@mysql.com> branch nick: mysql-6.0-3726-w timestamp: Sat 2008-05-24 14:08:51 +0400 message: WL#3726 "DDL locking for all metadata objects" Fixed failing Windows builds by adding mdl.cc to the lists of files needed to build server/libmysqld on Windows. ****** Backport of: ------------------------------------------------------------ revno: 2630.4.4 committer: Dmitry Lenev <dlenev@mysql.com> branch nick: mysql-6.0-3726-w timestamp: Sat 2008-05-24 21:57:58 +0400 message: WL#3726 "DDL locking for all metadata objects". Fix for assert failures in kill.test which occured when one tried to kill ALTER TABLE statement on merge table while it was waiting in wait_while_table_is_used() for other connections to close this table. These assert failures stemmed from the fact that cleanup code in this case assumed that temporary table representing new version of table was open with adding to THD::temporary_tables list while code which were opening this temporary table wasn't always fulfilling this. This patch changes code that opens new version of table to always do this linking in. It also streamlines cleanup process for cases when error occurs while we have new version of table open. ****** WL#3726 "DDL locking for all metadata objects" Add libmysqld/mdl.cc to .bzrignore. ****** Backport of: ------------------------------------------------------------ revno: 2630.4.6 committer: Dmitry Lenev <dlenev@mysql.com> branch nick: mysql-6.0-3726-w timestamp: Sun 2008-05-25 00:33:22 +0400 message: WL#3726 "DDL locking for all metadata objects". Addition to the fix of assert failures in kill.test caused by changes for this worklog. Make sure we close the new table only once.
This commit is contained in:
@ -387,8 +387,6 @@ bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create)
|
||||
!(need_start_waiting= !wait_if_global_read_lock(thd, 0, 1)))
|
||||
DBUG_RETURN(TRUE);
|
||||
|
||||
pthread_mutex_lock(&LOCK_open);
|
||||
|
||||
if (!create)
|
||||
{
|
||||
bool if_exists= thd->lex->drop_if_exists;
|
||||
@ -444,26 +442,28 @@ bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create)
|
||||
tables->required_type= FRMTYPE_TABLE;
|
||||
|
||||
/* Keep consistent with respect to other DDL statements */
|
||||
mysql_ha_rm_tables(thd, tables, TRUE);
|
||||
mysql_ha_rm_tables(thd, tables);
|
||||
|
||||
if (thd->locked_tables)
|
||||
{
|
||||
/* Table must be write locked */
|
||||
if (name_lock_locked_table(thd, tables))
|
||||
goto end;
|
||||
pthread_mutex_lock(&LOCK_open);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Grab the name lock and insert the placeholder*/
|
||||
/*
|
||||
Obtain exlusive meta-data lock on the table and remove TABLE
|
||||
instances from cache.
|
||||
*/
|
||||
if (lock_table_names(thd, tables))
|
||||
goto end;
|
||||
|
||||
/* Convert the placeholder to a real table */
|
||||
if (reopen_name_locked_table(thd, tables, TRUE))
|
||||
{
|
||||
unlock_table_name(thd, tables);
|
||||
goto end;
|
||||
}
|
||||
pthread_mutex_lock(&LOCK_open);
|
||||
expel_table_from_cache(0, tables->db, tables->table_name);
|
||||
|
||||
if (reopen_name_locked_table(thd, tables))
|
||||
goto end_unlock;
|
||||
}
|
||||
table= tables->table;
|
||||
|
||||
@ -472,11 +472,11 @@ bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create)
|
||||
if (!create)
|
||||
{
|
||||
my_error(ER_TRG_DOES_NOT_EXIST, MYF(0));
|
||||
goto end;
|
||||
goto end_unlock;
|
||||
}
|
||||
|
||||
if (!(table->triggers= new (&table->mem_root) Table_triggers_list(table)))
|
||||
goto end;
|
||||
goto end_unlock;
|
||||
}
|
||||
|
||||
result= (create ?
|
||||
@ -489,7 +489,7 @@ bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create)
|
||||
/* Make table suitable for reopening */
|
||||
close_data_files_and_morph_locks(thd, tables->db, tables->table_name);
|
||||
thd->in_lock_tables= 1;
|
||||
if (reopen_tables(thd, 1, 1))
|
||||
if (reopen_tables(thd, 1))
|
||||
{
|
||||
/* To be safe remove this table from the set of LOCKED TABLES */
|
||||
unlink_open_table(thd, tables->table, FALSE);
|
||||
@ -503,14 +503,22 @@ bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create)
|
||||
thd->in_lock_tables= 0;
|
||||
}
|
||||
|
||||
end:
|
||||
end_unlock:
|
||||
pthread_mutex_unlock(&LOCK_open);
|
||||
|
||||
end:
|
||||
if (!result)
|
||||
{
|
||||
write_bin_log(thd, TRUE, stmt_query.ptr(), stmt_query.length());
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&LOCK_open);
|
||||
/*
|
||||
If we are under LOCK TABLES we should restore original state of meta-data
|
||||
locks. Otherwise call to close_thread_tables() will take care about both
|
||||
TABLE instance created by reopen_name_locked_table() and meta-data lock.
|
||||
*/
|
||||
if (thd->locked_tables)
|
||||
mdl_downgrade_exclusive_locks(&thd->mdl_context);
|
||||
|
||||
if (need_start_waiting)
|
||||
start_waiting_global_read_lock(thd);
|
||||
@ -1879,11 +1887,7 @@ bool Table_triggers_list::change_table_name(THD *thd, const char *db,
|
||||
In the future, only an exclusive table name lock will be enough.
|
||||
*/
|
||||
#ifndef DBUG_OFF
|
||||
uchar key[MAX_DBKEY_LENGTH];
|
||||
uint key_length= (uint) (strmov(strmov((char*)&key[0], db)+1,
|
||||
old_table)-(char*)&key[0])+1;
|
||||
|
||||
if (!is_table_name_exclusively_locked_by_this_thread(thd, key, key_length))
|
||||
if (mdl_is_exclusive_lock_owner(&thd->mdl_context, 0, db, old_table))
|
||||
safe_mutex_assert_owner(&LOCK_open);
|
||||
#endif
|
||||
|
||||
|
Reference in New Issue
Block a user