#At file:///home/dlenev/src/bzr/mysql-6.1-mil14/ based on
revid:dlenev@stripped
2724 Dmitry Lenev 2009-05-13
WL#148 "Foreign keys".
Milestone 14 "DDL checks and changes: DROP, TRUNCATE, RENAME".
Work in progress. "Solve" remaining problems with auto-discovery
and LOCK_open handling.
modified:
sql/mysql_priv.h
sql/sql_base.cc
sql/sql_table.cc
=== modified file 'sql/mysql_priv.h'
--- a/sql/mysql_priv.h 2009-05-07 05:16:19 +0000
+++ b/sql/mysql_priv.h 2009-05-13 05:28:49 +0000
@@ -1311,6 +1311,9 @@ uint create_table_def_key(THD *thd, char
bool tmp_table);
TABLE_SHARE *get_table_share(THD *thd, TABLE_LIST *table_list, char *key,
uint key_length, uint db_flags, int *error);
+TABLE_SHARE *get_table_share_with_create(THD *thd, TABLE_LIST *table_list,
+ char *key, uint key_length,
+ uint db_flags, int *error);
void release_table_share(TABLE_SHARE *share);
TABLE_SHARE *get_cached_table_share(const char *db, const char *table_name);
TABLE *open_ltable(THD *thd, TABLE_LIST *table_list, thr_lock_type update,
=== modified file 'sql/sql_base.cc'
--- a/sql/sql_base.cc 2009-05-09 19:19:11 +0000
+++ b/sql/sql_base.cc 2009-05-13 05:28:49 +0000
@@ -536,7 +536,7 @@ found:
For arguments and return values, see get_table_from_share()
*/
-static TABLE_SHARE
+TABLE_SHARE
*get_table_share_with_create(THD *thd, TABLE_LIST *table_list,
char *key, uint key_length,
uint db_flags, int *error)
=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc 2009-05-09 19:19:11 +0000
+++ b/sql/sql_table.cc 2009-05-13 05:28:49 +0000
@@ -2340,13 +2340,11 @@ fk_check_tables_before_drop(THD *thd, TA
data-dictionary as result. We accept this as a trade-off.
ER_CANT_OPEN_FILE is transient so it makes sense to abort statement
to allow it to be executed normally later.
-
- TODO/QQ: Should we perform auto-discovery here ? Probably yes...
- But what about opt_fk_all_engines = 0 mode ?
*/
thd->push_internal_handler(&non_fatal_error_silencer);
pthread_mutex_lock(&LOCK_open);
- share= get_table_share(thd, table, key, key_length, OPEN_VIEW, &error);
+ share= get_table_share_with_create(thd, table, key, key_length, OPEN_VIEW,
+ &error);
pthread_mutex_unlock(&LOCK_open);
thd->pop_internal_handler();
@@ -2691,9 +2689,6 @@ retry_lock:
parents_locked= parents_to_lock;
fk_names_locked= fk_names_to_lock;
- // TODO/FIXME: Move auto-discovery here?
-
-
if (opt_fk_all_engines)
{
if (fk_check_tables_before_drop(thd, tables,
@@ -2849,11 +2844,22 @@ retry_lock:
/*
TODO: Investigate what should be done to remove this lock completely.
Is exclusive meta-data lock enough ?
+
+ TODO: We can move auto-discovery of table in --foreign-key-all-engines=0
+ mode to the same place as it happens in --foreign-key-all-engines=1
+ once WL#3983 "LOCK_open: no longer necessary for disk I/O (to read/
+ write .frm files)" is done so there will be no chance that other
+ thread will ignore metadata lock and create or drop table between
+ the moment when we perform auto-discovery and when the table is
+ finally dropped. To be efficient after this change we also will
+ have to introduce per-table runtime context to be able to cache
+ information about table type, existence and etc.
*/
pthread_mutex_lock(&LOCK_open);
if (drop_temporary ||
(table_type == NULL &&
(access(path, F_OK) &&
+ ! opt_fk_all_engines &&
ha_create_table_from_engine(thd, db, alias)) ||
(!drop_view &&
mysql_frm_type(thd, path, &frm_db_type) != FRMTYPE_TABLE)))
@@ -2869,18 +2875,22 @@ retry_lock:
else
{
char *end;
- /*
- FIXME: - Get rid of this ugly LOCK_open handling,
- - Ensure that FK operation is atomic with .FRM deletion.
- */
- pthread_mutex_unlock(&LOCK_open);
- if (opt_fk_all_engines &&
- fk_ctx.install_new_frms())
+
+ if (opt_fk_all_engines)
{
- error= 1;
- goto err_table;
+ /*
+ TODO: Once WL#3983 "LOCK_open: no longer necessary for disk I/O
+ (to read/write .frm files)" is done this ugly handling of
+ LOCK_open will go away.
+ */
+ pthread_mutex_unlock(&LOCK_open);
+ if (fk_ctx.install_new_frms())
+ {
+ error= 1;
+ goto err_table;
+ }
+ pthread_mutex_lock(&LOCK_open);
}
- pthread_mutex_lock(&LOCK_open);
if (table_type == NULL)
@@ -2932,8 +2942,15 @@ retry_lock:
}
}
- if (thd->locked_tables_mode)
+ if (opt_fk_all_engines && thd->locked_tables_mode)
{
+ /*
+ Re-open tables related to table being dropped (tables which
+ participate in a foreign key relationship with this table)
+ after updating their .FRMs.
+
+ See comment about the fate of LOCK_open above.
+ */
pthread_mutex_unlock(&LOCK_open);
if (thd->locked_tables_list.reopen_tables(thd))
{
Attachment: [text/bzr-bundle] bzr/dlenev@mysql.com-20090513052849-agtwm2qi5vg0c27s.bundle
| Thread |
|---|
| • bzr commit into mysql-6.1-fk branch (dlenev:2724) WL#148 | Dmitry Lenev | 13 May 2009 |