mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
Bug #10600
remove_table_from_cache fails to signal other thread and gets blocked when other thread also gets blocked include/thr_lock.h: Report if any threads was signalled mysys/thr_lock.c: Report if any threads was signalled sql/lock.cc: Report if any threads was signalled Use new interface for remove_table_from_cache sql/mysql_priv.h: New interface for remove_table_from_cache + mysql_lock_abort_for_thread sql/sql_base.cc: Use new interface of remove_table_cache Rewrote remove_table_from_cache to fix bug sql/sql_table.cc: Use new interface of remove_table_from_cache
This commit is contained in:
132
sql/sql_base.cc
132
sql/sql_base.cc
@ -370,7 +370,9 @@ bool close_cached_tables(THD *thd, bool if_wait_for_refresh,
|
||||
bool found=0;
|
||||
for (TABLE_LIST *table=tables ; table ; table=table->next)
|
||||
{
|
||||
if (remove_table_from_cache(thd, table->db, table->real_name, 1))
|
||||
uint flags= OWNED_BY_THD_FLAG;
|
||||
if (remove_table_from_cache(thd, table->db, table->real_name,
|
||||
flags))
|
||||
found=1;
|
||||
}
|
||||
if (!found)
|
||||
@ -2407,62 +2409,106 @@ void flush_tables()
|
||||
*/
|
||||
|
||||
bool remove_table_from_cache(THD *thd, const char *db, const char *table_name,
|
||||
bool return_if_owned_by_thd)
|
||||
uint flags)
|
||||
{
|
||||
char key[MAX_DBKEY_LENGTH];
|
||||
uint key_length;
|
||||
TABLE *table;
|
||||
bool result=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");
|
||||
|
||||
key_length=(uint) (strmov(strmov(key,db)+1,table_name)-key)+1;
|
||||
for (table=(TABLE*) hash_search(&open_cache,(byte*) key,key_length) ;
|
||||
table;
|
||||
table = (TABLE*) hash_next(&open_cache,(byte*) key,key_length))
|
||||
do
|
||||
{
|
||||
THD *in_use;
|
||||
table->version=0L; /* Free when thread is ready */
|
||||
if (!(in_use=table->in_use))
|
||||
result= signalled= 0;
|
||||
|
||||
for (table=(TABLE*) hash_search(&open_cache,(byte*) key,key_length) ;
|
||||
table;
|
||||
table = (TABLE*) hash_next(&open_cache,(byte*) key,key_length))
|
||||
{
|
||||
DBUG_PRINT("info",("Table was not in use"));
|
||||
relink_unused(table);
|
||||
}
|
||||
else if (in_use != thd)
|
||||
{
|
||||
in_use->some_tables_deleted=1;
|
||||
if (table->db_stat)
|
||||
result=1;
|
||||
/* Kill delayed insert threads */
|
||||
if ((in_use->system_thread & SYSTEM_THREAD_DELAYED_INSERT) &&
|
||||
! in_use->killed)
|
||||
THD *in_use;
|
||||
table->version=0L; /* Free when thread is ready */
|
||||
if (!(in_use=table->in_use))
|
||||
{
|
||||
in_use->killed=1;
|
||||
pthread_mutex_lock(&in_use->mysys_var->mutex);
|
||||
if (in_use->mysys_var->current_cond)
|
||||
{
|
||||
pthread_mutex_lock(in_use->mysys_var->current_mutex);
|
||||
pthread_cond_broadcast(in_use->mysys_var->current_cond);
|
||||
pthread_mutex_unlock(in_use->mysys_var->current_mutex);
|
||||
}
|
||||
pthread_mutex_unlock(&in_use->mysys_var->mutex);
|
||||
DBUG_PRINT("info",("Table was not in use"));
|
||||
relink_unused(table);
|
||||
}
|
||||
/*
|
||||
Now we must abort all tables locks used by this thread
|
||||
as the thread may be waiting to get a lock for another table
|
||||
*/
|
||||
for (TABLE *thd_table= in_use->open_tables;
|
||||
thd_table ;
|
||||
thd_table= thd_table->next)
|
||||
else if (in_use != thd)
|
||||
{
|
||||
if (thd_table->db_stat) // If table is open
|
||||
mysql_lock_abort_for_thread(thd, thd_table);
|
||||
in_use->some_tables_deleted=1;
|
||||
if (table->db_stat)
|
||||
result=1;
|
||||
/* Kill delayed insert threads */
|
||||
if ((in_use->system_thread & SYSTEM_THREAD_DELAYED_INSERT) &&
|
||||
! in_use->killed)
|
||||
{
|
||||
in_use->killed=1;
|
||||
pthread_mutex_lock(&in_use->mysys_var->mutex);
|
||||
if (in_use->mysys_var->current_cond)
|
||||
{
|
||||
pthread_mutex_lock(in_use->mysys_var->current_mutex);
|
||||
signalled= 1;
|
||||
pthread_cond_broadcast(in_use->mysys_var->current_cond);
|
||||
pthread_mutex_unlock(in_use->mysys_var->current_mutex);
|
||||
}
|
||||
pthread_mutex_unlock(&in_use->mysys_var->mutex);
|
||||
}
|
||||
/*
|
||||
Now we must abort all tables locks used by this thread
|
||||
as the thread may be waiting to get a lock for another table
|
||||
*/
|
||||
for (TABLE *thd_table= in_use->open_tables;
|
||||
thd_table ;
|
||||
thd_table= thd_table->next)
|
||||
{
|
||||
if (thd_table->db_stat) // If table is open
|
||||
{
|
||||
bool found;
|
||||
found= mysql_lock_abort_for_thread(thd, thd_table);
|
||||
signalled|= found;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
result= result || return_if_owned_by_thd;
|
||||
}
|
||||
while (unused_tables && !unused_tables->version)
|
||||
VOID(hash_delete(&open_cache,(byte*) unused_tables));
|
||||
if (result && wait_for_other_thread)
|
||||
{
|
||||
if (!check_killed_flag || !thd->killed)
|
||||
{
|
||||
if (likely(signalled))
|
||||
{
|
||||
dropping_tables++;
|
||||
(void) pthread_cond_wait(&COND_refresh, &LOCK_open);
|
||||
dropping_tables--;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
It can happen that another thread has opened the
|
||||
table but has not yet locked any table at all. Since
|
||||
it can be locked waiting for a table that our thread
|
||||
has done LOCK TABLE x WRITE on previously, we need to
|
||||
ensure that the thread actually hears our signal
|
||||
before we go to sleep. Thus we wait for a short time
|
||||
and then we retry another loop in the
|
||||
remove_table_from_cache routine.
|
||||
*/
|
||||
pthread_mutex_unlock(&LOCK_open);
|
||||
my_sleep(10);
|
||||
pthread_mutex_lock(&LOCK_open);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
result= result || return_if_owned_by_thd;
|
||||
}
|
||||
while (unused_tables && !unused_tables->version)
|
||||
VOID(hash_delete(&open_cache,(byte*) unused_tables));
|
||||
break;
|
||||
} while (1);
|
||||
DBUG_RETURN(result);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user