summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Osipov <kostja@sun.com>2009-12-01 16:27:03 +0300
committerKonstantin Osipov <kostja@sun.com>2009-12-01 16:27:03 +0300
commit1ed585adff48bffbd5440eda246e1918d53ca7ac (patch)
treef22662f715c12704721d57ac2670684f125d9eba
parent379a441d9cc2c60585f96150bcacb41312c260f6 (diff)
downloadmariadb-git-1ed585adff48bffbd5440eda246e1918d53ca7ac.tar.gz
Backport of:
--------------------------------------------- 2630.7.3 Konstantin Osipov 2008-06-02 Various style changes preceding the removal of reopen_table(). (Post-review fixes for WL#3726). sql/event_db_repository.cc: Update to use the new signature of TABLE_LIST::init_one_table(). sql/mysql_priv.h: Move close_cached_table() and wait_while_table_is_used() to sql_base.cc. sql/sql_base.cc: Move close_cached_table() and wait_while_table_is_used() from sql_table.cc. sql/sql_table.cc: Move close_cached_table() and wait_while_table_is_used() to sql_base.cc. sql/table.h: Update the signature of TABLE_LIST::init_one_table().
-rw-r--r--sql/event_db_repository.cc8
-rw-r--r--sql/mysql_priv.h5
-rw-r--r--sql/sql_base.cc79
-rw-r--r--sql/sql_table.cc79
-rw-r--r--sql/table.h4
5 files changed, 89 insertions, 86 deletions
diff --git a/sql/event_db_repository.cc b/sql/event_db_repository.cc
index 0cf16e3a8a4..b17785a6be7 100644
--- a/sql/event_db_repository.cc
+++ b/sql/event_db_repository.cc
@@ -554,7 +554,7 @@ Event_db_repository::open_event_table(THD *thd, enum thr_lock_type lock_type,
TABLE_LIST tables;
DBUG_ENTER("Event_db_repository::open_event_table");
- tables.init_one_table("mysql", "event", lock_type);
+ tables.init_one_table("mysql", "event", "event", lock_type);
alloc_mdl_locks(&tables, thd->mem_root);
if (simple_open_n_lock_tables(thd, &tables))
@@ -1109,7 +1109,7 @@ Event_db_repository::check_system_tables(THD *thd)
/* Check mysql.db */
- tables.init_one_table("mysql", "db", TL_READ);
+ tables.init_one_table("mysql", "db", "db", TL_READ);
alloc_mdl_locks(&tables, thd->mem_root);
if (simple_open_n_lock_tables(thd, &tables))
@@ -1127,7 +1127,7 @@ Event_db_repository::check_system_tables(THD *thd)
close_thread_tables(thd);
}
/* Check mysql.user */
- tables.init_one_table("mysql", "user", TL_READ);
+ tables.init_one_table("mysql", "user", "user", TL_READ);
alloc_mdl_locks(&tables, thd->mem_root);
if (simple_open_n_lock_tables(thd, &tables))
@@ -1148,7 +1148,7 @@ Event_db_repository::check_system_tables(THD *thd)
close_thread_tables(thd);
}
/* Check mysql.event */
- tables.init_one_table("mysql", "event", TL_READ);
+ tables.init_one_table("mysql", "event", "event", TL_READ);
alloc_mdl_locks(&tables, thd->mem_root);
if (simple_open_n_lock_tables(thd, &tables))
diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h
index 3e3d3b6df24..a29e819f90b 100644
--- a/sql/mysql_priv.h
+++ b/sql/mysql_priv.h
@@ -1033,8 +1033,6 @@ bool check_dup(const char *db, const char *name, TABLE_LIST *tables);
bool compare_record(TABLE *table);
bool append_file_to_dir(THD *thd, const char **filename_ptr,
const char *table_name);
-bool wait_while_table_is_used(THD *thd, TABLE *table,
- enum ha_extra_function function);
bool table_def_init(void);
void table_def_free(void);
void assign_new_table_id(TABLE_SHARE *share);
@@ -1390,6 +1388,9 @@ void add_join_on(TABLE_LIST *b,Item *expr);
void add_join_natural(TABLE_LIST *a,TABLE_LIST *b,List<String> *using_fields,
SELECT_LEX *lex);
bool add_proc_to_list(THD *thd, Item *item);
+bool close_cached_table(THD *thd, TABLE *table);
+bool wait_while_table_is_used(THD *thd, TABLE *table,
+ enum ha_extra_function function);
void unlink_open_table(THD *thd, TABLE *find, bool unlock);
void drop_open_table(THD *thd, TABLE *table, const char *db_name,
const char *table_name);
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index 6dc9c67f348..237c4c8e771 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -2201,6 +2201,85 @@ static void unlink_open_merge(THD *thd, TABLE *table, TABLE ***prev_pp)
/**
+ Force all other threads to stop using the table by upgrading
+ metadata lock on it and remove unused TABLE instances from cache.
+
+ @param thd Thread handler
+ @param table Table to remove from cache
+ @param function HA_EXTRA_PREPARE_FOR_DROP if table is to be deleted
+ HA_EXTRA_FORCE_REOPEN if table is not be used
+ HA_EXTRA_PREPARE_FOR_RENAME if table is to be renamed
+
+ @note When returning, the table will be unusable for other threads
+ until metadata lock is downgraded.
+
+ @retval FALSE Success.
+ @retval TRUE Failure (e.g. because thread was killed).
+*/
+
+bool wait_while_table_is_used(THD *thd, TABLE *table,
+ enum ha_extra_function function)
+{
+ enum thr_lock_type old_lock_type;
+
+ DBUG_ENTER("wait_while_table_is_used");
+ DBUG_PRINT("enter", ("table: '%s' share: 0x%lx db_stat: %u version: %lu",
+ table->s->table_name.str, (ulong) table->s,
+ table->db_stat, table->s->version));
+
+ (void) table->file->extra(function);
+
+ old_lock_type= table->reginfo.lock_type;
+ mysql_lock_abort(thd, table, TRUE); /* end threads waiting on lock */
+
+ if (mdl_upgrade_shared_lock_to_exclusive(&thd->mdl_context,
+ table->mdl_lock_data))
+ {
+ mysql_lock_downgrade_write(thd, table, old_lock_type);
+ DBUG_RETURN(TRUE);
+ }
+
+ pthread_mutex_lock(&LOCK_open);
+ expel_table_from_cache(thd, table->s->db.str, table->s->table_name.str);
+ pthread_mutex_unlock(&LOCK_open);
+ DBUG_RETURN(FALSE);
+}
+
+
+/**
+ Upgrade metadata lock on the table and close all its instances.
+
+ @param thd Thread handler
+ @param table Table to remove from cache
+
+ @retval FALSE Success.
+ @retval TRUE Failure (e.g. because thread was killed).
+*/
+
+bool close_cached_table(THD *thd, TABLE *table)
+{
+ DBUG_ENTER("close_cached_table");
+
+ /* FIXME: check if we pass proper parameters everywhere. */
+ if (wait_while_table_is_used(thd, table, HA_EXTRA_FORCE_REOPEN))
+ DBUG_RETURN(TRUE);
+
+ /* Close lock if this is not got with LOCK TABLES */
+ if (thd->lock)
+ {
+ mysql_unlock_tables(thd, thd->lock);
+ thd->lock=0; // Start locked threads
+ }
+
+ pthread_mutex_lock(&LOCK_open);
+ /* Close all copies of 'table'. This also frees all LOCK TABLES lock */
+ unlink_open_table(thd, table, TRUE);
+ pthread_mutex_unlock(&LOCK_open);
+ DBUG_RETURN(FALSE);
+}
+
+
+/**
Remove all instances of table from thread's open list and
table cache.
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 6aa3566b8fa..f5c22d32e94 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -53,7 +53,6 @@ static bool
mysql_prepare_alter_table(THD *thd, TABLE *table,
HA_CREATE_INFO *create_info,
Alter_info *alter_info);
-static bool close_cached_table(THD *thd, TABLE *table);
#ifndef DBUG_OFF
@@ -4295,84 +4294,6 @@ mysql_rename_table(handlerton *base, const char *old_db,
}
-/**
- Force all other threads to stop using the table by upgrading
- metadata lock on it and remove unused TABLE instances from cache.
-
- @param thd Thread handler
- @param table Table to remove from cache
- @param function HA_EXTRA_PREPARE_FOR_DROP if table is to be deleted
- HA_EXTRA_FORCE_REOPEN if table is not be used
- HA_EXTRA_PREPARE_FOR_RENAME if table is to be renamed
-
- @note When returning, the table will be unusable for other threads
- until metadata lock is downgraded.
-
- @retval FALSE Success.
- @retval TRUE Failure (e.g. because thread was killed).
-*/
-
-bool wait_while_table_is_used(THD *thd, TABLE *table,
- enum ha_extra_function function)
-{
- enum thr_lock_type old_lock_type;
-
- DBUG_ENTER("wait_while_table_is_used");
- DBUG_PRINT("enter", ("table: '%s' share: 0x%lx db_stat: %u version: %lu",
- table->s->table_name.str, (ulong) table->s,
- table->db_stat, table->s->version));
-
- (void) table->file->extra(function);
-
- old_lock_type= table->reginfo.lock_type;
- mysql_lock_abort(thd, table, TRUE); /* end threads waiting on lock */
-
- if (mdl_upgrade_shared_lock_to_exclusive(&thd->mdl_context,
- table->mdl_lock_data))
- {
- mysql_lock_downgrade_write(thd, table, old_lock_type);
- DBUG_RETURN(TRUE);
- }
-
- pthread_mutex_lock(&LOCK_open);
- expel_table_from_cache(thd, table->s->db.str, table->s->table_name.str);
- pthread_mutex_unlock(&LOCK_open);
- DBUG_RETURN(FALSE);
-}
-
-
-/**
- Upgrade metadata lock on the table and close all its instances.
-
- @param thd Thread handler
- @param table Table to remove from cache
-
- @retval FALSE Success.
- @retval TRUE Failure (e.g. because thread was killed).
-*/
-
-static bool close_cached_table(THD *thd, TABLE *table)
-{
- DBUG_ENTER("close_cached_table");
-
- /* FIXME: check if we pass proper parameters everywhere. */
- if (wait_while_table_is_used(thd, table, HA_EXTRA_FORCE_REOPEN))
- DBUG_RETURN(TRUE);
-
- /* Close lock if this is not got with LOCK TABLES */
- if (thd->lock)
- {
- mysql_unlock_tables(thd, thd->lock);
- thd->lock=0; // Start locked threads
- }
-
- pthread_mutex_lock(&LOCK_open);
- /* Close all copies of 'table'. This also frees all LOCK TABLES lock */
- unlink_open_table(thd, table, TRUE);
- pthread_mutex_unlock(&LOCK_open);
- DBUG_RETURN(FALSE);
-}
-
static int send_check_errmsg(THD *thd, TABLE_LIST* table,
const char* operator_name, const char* errmsg)
diff --git a/sql/table.h b/sql/table.h
index 601f1e154c9..de1354e17e5 100644
--- a/sql/table.h
+++ b/sql/table.h
@@ -1121,11 +1121,13 @@ struct TABLE_LIST
*/
inline void init_one_table(const char *db_name_arg,
const char *table_name_arg,
+ const char *alias_arg,
enum thr_lock_type lock_type_arg)
{
bzero((char*) this, sizeof(*this));
db= (char*) db_name_arg;
- table_name= alias= (char*) table_name_arg;
+ table_name= (char*) table_name_arg;
+ alias= (char*) alias_arg;
lock_type= lock_type_arg;
}