Commit 4cb96343 authored by mronstrom@mysql.com's avatar mronstrom@mysql.com

Bug #10600 After review fixes

parent 2d23c691
...@@ -549,9 +549,8 @@ int lock_table_name(THD *thd, TABLE_LIST *table_list) ...@@ -549,9 +549,8 @@ int lock_table_name(THD *thd, TABLE_LIST *table_list)
} }
{ {
uint flags= 0;
if (remove_table_from_cache(thd, db, if (remove_table_from_cache(thd, db,
table_list->real_name, flags)) table_list->real_name, RTFC_NO_FLAG))
{ {
DBUG_RETURN(1); // Table is in use DBUG_RETURN(1); // Table is in use
} }
......
...@@ -606,9 +606,10 @@ bool rename_temporary_table(THD* thd, TABLE *table, const char *new_db, ...@@ -606,9 +606,10 @@ bool rename_temporary_table(THD* thd, TABLE *table, const char *new_db,
const char *table_name); const char *table_name);
void remove_db_from_cache(const my_string db); void remove_db_from_cache(const my_string db);
void flush_tables(); void flush_tables();
#define OWNED_BY_THD_FLAG 1 #define RTFC_NO_FLAG 0x0000
#define WAIT_OTHER_THREAD_FLAG 2 #define RTFC_OWNED_BY_THD_FLAG 0x0001
#define CHECK_KILLED_FLAG 4 #define RTFC_WAIT_OTHER_THREAD_FLAG 0x0002
#define RTFC_CHECK_KILLED_FLAG 0x0004
bool remove_table_from_cache(THD *thd, const char *db, const char *table, bool remove_table_from_cache(THD *thd, const char *db, const char *table,
uint flags); uint flags);
bool close_cached_tables(THD *thd, bool wait_for_refresh, TABLE_LIST *tables); bool close_cached_tables(THD *thd, bool wait_for_refresh, TABLE_LIST *tables);
......
...@@ -370,9 +370,8 @@ bool close_cached_tables(THD *thd, bool if_wait_for_refresh, ...@@ -370,9 +370,8 @@ bool close_cached_tables(THD *thd, bool if_wait_for_refresh,
bool found=0; bool found=0;
for (TABLE_LIST *table=tables ; table ; table=table->next) for (TABLE_LIST *table=tables ; table ; table=table->next)
{ {
uint flags= OWNED_BY_THD_FLAG;
if (remove_table_from_cache(thd, table->db, table->real_name, if (remove_table_from_cache(thd, table->db, table->real_name,
flags)) RTFC_OWNED_BY_THD_FLAG))
found=1; found=1;
} }
if (!found) if (!found)
...@@ -2415,13 +2414,10 @@ bool remove_table_from_cache(THD *thd, const char *db, const char *table_name, ...@@ -2415,13 +2414,10 @@ bool remove_table_from_cache(THD *thd, const char *db, const char *table_name,
uint key_length; uint key_length;
TABLE *table; TABLE *table;
bool result=0, signalled= 0; bool result=0, signalled= 0;
bool return_if_owned_by_thd= flags & OWNED_BY_THD_FLAG;
bool wait_for_other_thread= flags & WAIT_OTHER_THREAD_FLAG;
bool check_killed_flag= flags & CHECK_KILLED_FLAG;
DBUG_ENTER("remove_table_from_cache"); DBUG_ENTER("remove_table_from_cache");
key_length=(uint) (strmov(strmov(key,db)+1,table_name)-key)+1; key_length=(uint) (strmov(strmov(key,db)+1,table_name)-key)+1;
do for (;;)
{ {
result= signalled= 0; result= signalled= 0;
...@@ -2465,21 +2461,17 @@ bool remove_table_from_cache(THD *thd, const char *db, const char *table_name, ...@@ -2465,21 +2461,17 @@ bool remove_table_from_cache(THD *thd, const char *db, const char *table_name,
thd_table= thd_table->next) thd_table= thd_table->next)
{ {
if (thd_table->db_stat) // If table is open if (thd_table->db_stat) // If table is open
{ signalled|= mysql_lock_abort_for_thread(thd, thd_table);
bool found;
found= mysql_lock_abort_for_thread(thd, thd_table);
signalled|= found;
}
} }
} }
else else
result= result || return_if_owned_by_thd; result= result || (flags & RTFC_OWNED_BY_THD_FLAG);
} }
while (unused_tables && !unused_tables->version) while (unused_tables && !unused_tables->version)
VOID(hash_delete(&open_cache,(byte*) unused_tables)); VOID(hash_delete(&open_cache,(byte*) unused_tables));
if (result && wait_for_other_thread) if (result && (flags & RTFC_WAIT_OTHER_THREAD_FLAG))
{ {
if (!check_killed_flag || !thd->killed) if (!(flags & RTFC_CHECK_KILLED_FLAG) || !thd->killed)
{ {
if (likely(signalled)) if (likely(signalled))
{ {
...@@ -2508,7 +2500,7 @@ bool remove_table_from_cache(THD *thd, const char *db, const char *table_name, ...@@ -2508,7 +2500,7 @@ bool remove_table_from_cache(THD *thd, const char *db, const char *table_name,
} }
} }
break; break;
} while (1); }
DBUG_RETURN(result); DBUG_RETURN(result);
} }
......
...@@ -187,7 +187,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, ...@@ -187,7 +187,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
} }
abort_locked_tables(thd,db,table->real_name); abort_locked_tables(thd,db,table->real_name);
flags= WAIT_OTHER_THREAD_FLAG | CHECK_KILLED_FLAG; flags= RTFC_WAIT_OTHER_THREAD_FLAG | RTFC_CHECK_KILLED_FLAG;
remove_table_from_cache(thd,db,table->real_name,flags); remove_table_from_cache(thd,db,table->real_name,flags);
drop_locked_tables(thd,db,table->real_name); drop_locked_tables(thd,db,table->real_name);
if (thd->killed) if (thd->killed)
...@@ -976,7 +976,6 @@ mysql_rename_table(enum db_type base, ...@@ -976,7 +976,6 @@ mysql_rename_table(enum db_type base,
static void wait_while_table_is_used(THD *thd,TABLE *table, static void wait_while_table_is_used(THD *thd,TABLE *table,
enum ha_extra_function function) enum ha_extra_function function)
{ {
uint flags;
DBUG_PRINT("enter",("table: %s", table->real_name)); DBUG_PRINT("enter",("table: %s", table->real_name));
DBUG_ENTER("wait_while_table_is_used"); DBUG_ENTER("wait_while_table_is_used");
safe_mutex_assert_owner(&LOCK_open); safe_mutex_assert_owner(&LOCK_open);
...@@ -986,9 +985,8 @@ static void wait_while_table_is_used(THD *thd,TABLE *table, ...@@ -986,9 +985,8 @@ static void wait_while_table_is_used(THD *thd,TABLE *table,
mysql_lock_abort(thd, table); // end threads waiting on lock mysql_lock_abort(thd, table); // end threads waiting on lock
/* Wait until all there are no other threads that has this table open */ /* Wait until all there are no other threads that has this table open */
flags= WAIT_OTHER_THREAD_FLAG;
remove_table_from_cache(thd,table->table_cache_key, remove_table_from_cache(thd,table->table_cache_key,
table->real_name,flags); table->real_name, RTFC_WAIT_OTHER_THREAD_FLAG);
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
...@@ -1305,7 +1303,7 @@ static int mysql_admin_table(THD* thd, TABLE_LIST* tables, ...@@ -1305,7 +1303,7 @@ static int mysql_admin_table(THD* thd, TABLE_LIST* tables,
const char *old_message=thd->enter_cond(&COND_refresh, &LOCK_open, const char *old_message=thd->enter_cond(&COND_refresh, &LOCK_open,
"Waiting to get writelock"); "Waiting to get writelock");
mysql_lock_abort(thd,table->table); mysql_lock_abort(thd,table->table);
flags= WAIT_OTHER_THREAD_FLAG | CHECK_KILLED_FLAG; flags= RTFC_WAIT_OTHER_THREAD_FLAG | RTFC_CHECK_KILLED_FLAG;
remove_table_from_cache(thd, table->table->table_cache_key, remove_table_from_cache(thd, table->table->table_cache_key,
table->table->real_name, flags); table->table->real_name, flags);
thd->exit_cond(old_message); thd->exit_cond(old_message);
...@@ -1372,10 +1370,9 @@ static int mysql_admin_table(THD* thd, TABLE_LIST* tables, ...@@ -1372,10 +1370,9 @@ static int mysql_admin_table(THD* thd, TABLE_LIST* tables,
table->table->version=0; // Force close of table table->table->version=0; // Force close of table
else if (open_for_modify) else if (open_for_modify)
{ {
uint flags= 0;
pthread_mutex_lock(&LOCK_open); pthread_mutex_lock(&LOCK_open);
remove_table_from_cache(thd, table->table->table_cache_key, remove_table_from_cache(thd, table->table->table_cache_key,
table->table->real_name, flags); table->table->real_name, RTFC_NO_FLAG);
pthread_mutex_unlock(&LOCK_open); pthread_mutex_unlock(&LOCK_open);
/* May be something modified consequently we have to invalidate cache */ /* May be something modified consequently we have to invalidate cache */
query_cache_invalidate3(thd, table->table, 0); query_cache_invalidate3(thd, table->table, 0);
...@@ -2099,9 +2096,9 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name, ...@@ -2099,9 +2096,9 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
*/ */
if (table) if (table)
{ {
uint flags= 0;
VOID(table->file->extra(HA_EXTRA_FORCE_REOPEN)); // Use new file VOID(table->file->extra(HA_EXTRA_FORCE_REOPEN)); // Use new file
remove_table_from_cache(thd,db,table_name,flags);// Mark in-use copies old remove_table_from_cache(thd,db,table_name,RTFC_NO_FLAG);
// Mark in-use copies old
mysql_lock_abort(thd,table); // end threads waiting on lock mysql_lock_abort(thd,table); // end threads waiting on lock
} }
VOID(quick_rm_table(old_db_type,db,old_name)); VOID(quick_rm_table(old_db_type,db,old_name));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment