diff options
Diffstat (limited to 'sql')
-rw-r--r-- | sql/lock.cc | 20 | ||||
-rw-r--r-- | sql/mysql_priv.h | 3 | ||||
-rw-r--r-- | sql/slave.cc | 2 | ||||
-rw-r--r-- | sql/sql_base.cc | 19 |
4 files changed, 29 insertions, 15 deletions
diff --git a/sql/lock.cc b/sql/lock.cc index c198ff1e7d4..944c36d4d1e 100644 --- a/sql/lock.cc +++ b/sql/lock.cc @@ -335,7 +335,18 @@ void mysql_lock_abort(THD *thd, TABLE *table) } -/* Abort one thread / table combination */ +/* + Abort one thread / table combination + + SYNOPSIS + mysql_lock_abort_for_thread() + thd Thread handler + table Table that should be removed from lock queue + + RETURN + 0 Table was not locked by another thread + 1 Table was locked by at least one other thread +*/ bool mysql_lock_abort_for_thread(THD *thd, TABLE *table) { @@ -348,10 +359,9 @@ bool mysql_lock_abort_for_thread(THD *thd, TABLE *table) { for (uint i=0; i < locked->lock_count; i++) { - bool found; - found= thr_abort_locks_for_thread(locked->locks[i]->lock, - table->in_use->real_id); - result|= found; + if (thr_abort_locks_for_thread(locked->locks[i]->lock, + table->in_use->real_id)) + result= TRUE; } my_free((gptr) locked,MYF(0)); } diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index 53a2273eb6e..6969433649f 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -763,12 +763,15 @@ bool rename_temporary_table(THD* thd, TABLE *table, const char *new_db, const char *table_name); void remove_db_from_cache(const char *db); void flush_tables(); + +/* bits for last argument to remove_table_from_cache() */ #define RTFC_NO_FLAG 0x0000 #define RTFC_OWNED_BY_THD_FLAG 0x0001 #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, uint flags); + bool close_cached_tables(THD *thd, bool wait_for_refresh, TABLE_LIST *tables); void copy_field_from_tmp_record(Field *field,int offset); int fill_record(List<Item> &fields,List<Item> &values, bool ignore_errors); diff --git a/sql/slave.cc b/sql/slave.cc index b0d219e5dd5..f25ad90487a 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -3331,9 +3331,9 @@ err: mi->abort_slave = 0; // TODO: check if this is needed DBUG_ASSERT(thd->net.buff != 0); net_end(&thd->net); // destructor will not free it, because net.vio is 0 + close_thread_tables(thd, 0); pthread_mutex_lock(&LOCK_thread_count); THD_CHECK_SENTRY(thd); - close_thread_tables(thd); delete thd; pthread_mutex_unlock(&LOCK_thread_count); pthread_cond_broadcast(&mi->stop_cond); // tell the world we are done diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 720ce733ee1..ed09af5e070 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -2927,6 +2927,9 @@ void flush_tables() The table will be closed (not stored in cache) by the current thread when close_thread_tables() is called. + PREREQUISITES + Lock on LOCK_open() + RETURN 0 This thread now have exclusive access to this table and no other thread can access the table until close_thread_tables() is called. @@ -2942,6 +2945,7 @@ bool remove_table_from_cache(THD *thd, const char *db, const char *table_name, bool result=0, signalled= 0; DBUG_ENTER("remove_table_from_cache"); + key_length=(uint) (strmov(strmov(key,db)+1,table_name)-key)+1; for (;;) { @@ -2999,15 +3003,12 @@ bool remove_table_from_cache(THD *thd, const char *db, const char *table_name, { if (!(flags & RTFC_CHECK_KILLED_FLAG) || !thd->killed) { + dropping_tables++; if (likely(signalled)) - { - dropping_tables++; (void) pthread_cond_wait(&COND_refresh, &LOCK_open); - dropping_tables--; - continue; - } else { + struct timespec abstime; /* It can happen that another thread has opened the table but has not yet locked any table at all. Since @@ -3018,11 +3019,11 @@ bool remove_table_from_cache(THD *thd, const char *db, const char *table_name, 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; + set_timespec(abstime, 10); + pthread_cond_timedwait(&COND_refresh, &LOCK_open, &abstime); } + dropping_tables--; + continue; } } break; |