diff options
author | Sergey Vojtovich <svoj@mariadb.org> | 2020-05-04 00:15:00 +0400 |
---|---|---|
committer | Sergey Vojtovich <svoj@mariadb.org> | 2020-05-06 13:53:07 +0400 |
commit | 725e43cefc422fe49fdbfe2f9252698b5c4a7175 (patch) | |
tree | 07ad77e09c91876409cdc2d06cfa7f7f4f6edec4 /sql/thread_cache.h | |
parent | 91734431bac4384c07beda60e0cb374c7720e5c6 (diff) | |
download | mariadb-git-bb-10.5-svoj.tar.gz |
Thread_cache::unregistred_connections()bb-10.5-svoj
There is a gap between connection spawn time and connection becoming
killable time (registration in server_threads). If shutdown is initiated
when such connection is being executed through this gap, connection may
access destroyed data or cause shutdown hang.
Fixed by adding a counter of connections going through this gap and
waiting until this counter drops down to 0 on shutdown.
Part of
MDEV-18353 - Shutdown may miss to wait for connection thread
Diffstat (limited to 'sql/thread_cache.h')
-rw-r--r-- | sql/thread_cache.h | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/sql/thread_cache.h b/sql/thread_cache.h index 5cb6c0fe85c..c9343587a9f 100644 --- a/sql/thread_cache.h +++ b/sql/thread_cache.h @@ -33,6 +33,8 @@ class Thread_cache ulong cached_thread_count; /** Number of active flush requests. */ uint32_t kill_cached_threads; + /** Number of connections that haven't registered in server_threads. */ + Atomic_counter<uint32_t> unregistered_connections; /** PFS stuff, only used during initialization. Unfortunately needs to survive till destruction. @@ -64,6 +66,7 @@ public: list.empty(); kill_cached_threads= 0; cached_thread_count= 0; + unregistered_connections= 0; } @@ -71,6 +74,7 @@ public: { DBUG_ASSERT(cached_thread_count == 0); DBUG_ASSERT(list.is_empty()); + DBUG_ASSERT(unregistered_connections == 0); mysql_cond_destroy(&COND_flush_thread_cache); mysql_cond_destroy(&COND_thread_cache); mysql_mutex_destroy(&LOCK_thread_cache); @@ -106,6 +110,8 @@ public: { kill_cached_threads++; flush(); + while (unregistered_connections) + my_sleep(1010); } @@ -118,6 +124,7 @@ public: */ bool enqueue(CONNECT *connect) { + unregistered_connections++; mysql_mutex_lock(&LOCK_thread_cache); if (cached_thread_count) { @@ -205,6 +212,14 @@ public: mysql_mutex_unlock(&LOCK_thread_cache); return r; } + + + /** + Informs thread cache that connection reached killable state. + + In other words THD was added to the server_threads list. + */ + void reset_unregistered() { unregistered_connections--; } }; extern Thread_cache thread_cache; |