diff options
-rw-r--r-- | extra/mariabackup/xtrabackup.cc | 4 | ||||
-rw-r--r-- | sql/mysqld.cc | 15 | ||||
-rw-r--r-- | sql/mysqld.h | 1 | ||||
-rw-r--r-- | sql/signal_handler.cc | 2 | ||||
-rw-r--r-- | sql/sql_class.h | 33 | ||||
-rw-r--r-- | sql/sql_parse.cc | 8 | ||||
-rw-r--r-- | sql/wsrep_mysqld.cc | 8 | ||||
-rw-r--r-- | storage/innobase/handler/ha_innodb.cc | 2 |
8 files changed, 34 insertions, 39 deletions
diff --git a/extra/mariabackup/xtrabackup.cc b/extra/mariabackup/xtrabackup.cc index c2f76b50af4..db7f20d2fdd 100644 --- a/extra/mariabackup/xtrabackup.cc +++ b/extra/mariabackup/xtrabackup.cc @@ -51,7 +51,7 @@ Street, Fifth Floor, Boston, MA 02110-1335 USA #include <my_getopt.h> #include <mysql_com.h> #include <my_default.h> -#include <mysqld.h> +#include <sql_class.h> #include <fcntl.h> #include <string.h> @@ -6199,7 +6199,7 @@ static bool xtrabackup_prepare_func(char** argv) // See innobase_end() and thd_destructor_proxy() while (srv_fast_shutdown == 0 && (trx_sys.any_active_transactions() || - static_cast<uint>(thread_count) > srv_n_purge_threads + 1)) + THD_count::value() > srv_n_purge_threads + 1)) os_thread_sleep(1000); srv_shutdown_bg_undo_sources(); diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 23ec3592073..1f3cecd4b94 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -456,7 +456,7 @@ ulong delay_key_write_options; uint protocol_version; uint lower_case_table_names; ulong tc_heuristic_recover= 0; -Atomic_counter<uint32_t> thread_count; +Atomic_counter<uint32_t> THD_count::count; bool shutdown_wait_for_slaves; Atomic_counter<uint32_t> slave_open_temp_tables; ulong thread_created; @@ -1745,9 +1745,9 @@ static void close_connections(void) much smaller than even 2 seconds, this is only a safety fallback against stuck threads so server shutdown is not held up forever. */ - DBUG_PRINT("info", ("thread_count: %u", uint32_t(thread_count))); + DBUG_PRINT("info", ("THD_count: %u", THD_count::value())); - for (int i= 0; (thread_count - binlog_dump_thread_count) && i < 1000; i++) + for (int i= 0; (THD_count::value() - binlog_dump_thread_count) && i < 1000; i++) my_sleep(20000); if (global_system_variables.log_warnings) @@ -1760,15 +1760,14 @@ static void close_connections(void) } #endif /* All threads has now been aborted */ - DBUG_PRINT("quit", ("Waiting for threads to die (count=%u)", - uint32_t(thread_count))); + DBUG_PRINT("quit", ("Waiting for threads to die (count=%u)", THD_count::value())); - while (thread_count - binlog_dump_thread_count) + while (THD_count::value() - binlog_dump_thread_count) my_sleep(1000); /* Kill phase 2 */ server_threads.iterate(kill_thread_phase_2); - for (uint64 i= 0; thread_count; i++) + for (uint64 i= 0; THD_count::value(); i++) { /* This time the warnings are emitted within the loop to provide a @@ -8037,7 +8036,7 @@ static int mysql_init_variables(void) mqh_used= 0; cleanup_done= 0; select_errors= dropping_tables= ha_open_options=0; - thread_count= kill_cached_threads= wake_thread= 0; + THD_count::count= kill_cached_threads= wake_thread= 0; slave_open_temp_tables= 0; cached_thread_count= 0; opt_endinfo= using_udf_functions= 0; diff --git a/sql/mysqld.h b/sql/mysqld.h index 6a462d25abb..37269125dc6 100644 --- a/sql/mysqld.h +++ b/sql/mysqld.h @@ -630,7 +630,6 @@ extern mysql_rwlock_t LOCK_ssl_refresh; extern mysql_prlock_t LOCK_system_variables_hash; extern mysql_cond_t COND_start_thread; extern mysql_cond_t COND_manager; -extern Atomic_counter<uint32_t> thread_count; extern char *opt_ssl_ca, *opt_ssl_capath, *opt_ssl_cert, *opt_ssl_cipher, *opt_ssl_key, *opt_ssl_crl, *opt_ssl_crlpath; diff --git a/sql/signal_handler.cc b/sql/signal_handler.cc index f27676bee19..098d881eca8 100644 --- a/sql/signal_handler.cc +++ b/sql/signal_handler.cc @@ -185,7 +185,7 @@ extern "C" sig_handler handle_fatal_signal(int sig) (uint) thread_scheduler->max_threads + (uint) extra_max_connections); - my_safe_printf_stderr("thread_count=%u\n", (uint) thread_count); + my_safe_printf_stderr("thread_count=%u\n", THD_count::value()); if (dflt_key_cache && thread_scheduler) { diff --git a/sql/sql_class.h b/sql/sql_class.h index 6d6d15fba5e..a439da53a7d 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -993,6 +993,23 @@ static inline bool is_supported_parser_charset(CHARSET_INFO *cs) return MY_TEST(cs->mbminlen == 1 && cs->number != 17 /* filename */); } +/** + A counter of THDs + + It must be specified as a first base class of THD, so that increment is + done before any other THD constructors and decrement - after any other THD + destructors. + + Destructor unblocks close_conneciton() if there are no more THD's left. +*/ +struct THD_count +{ + static Atomic_counter<uint32_t> count; + static uint value() { return static_cast<uint>(count); } + THD_count() { count++; } + ~THD_count() { count--; } +}; + #ifdef MYSQL_SERVER void free_tmp_table(THD *thd, TABLE *entry); @@ -2156,22 +2173,6 @@ extern "C" void my_message_sql(uint error, const char *str, myf MyFlags); /** - A wrapper around thread_count. - - It must be specified as a first base class of THD, so that increment is - done before any other THD constructors and decrement - after any other THD - destructors. - - Destructor unblocks close_conneciton() if there are no more THD's left. -*/ -struct THD_count -{ - THD_count() { thread_count++; } - ~THD_count() { thread_count--; } -}; - - -/** @class THD For each client connection we create a separate thread with THD serving as a thread/connection descriptor diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index e12817d231c..3cccca9b786 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -2232,15 +2232,13 @@ bool dispatch_command(enum enum_server_command command, THD *thd, size_t length= #endif my_snprintf(buff, buff_len - 1, - "Uptime: %lu Threads: %d Questions: %lu " + "Uptime: %lu Threads: %u Questions: %lu " "Slow queries: %lu Opens: %lu Flush tables: %lld " "Open tables: %u Queries per second avg: %u.%03u", - uptime, - (int) thread_count, (ulong) thd->query_id, + uptime, THD_count::value(), (ulong) thd->query_id, current_global_status_var->long_query_count, current_global_status_var->opened_tables, - tdc_refresh_version(), - tc_records(), + tdc_refresh_version(), tc_records(), (uint) (queries_per_second1000 / 1000), (uint) (queries_per_second1000 % 1000)); #ifdef EMBEDDED_LIBRARY diff --git a/sql/wsrep_mysqld.cc b/sql/wsrep_mysqld.cc index 195b882a3fb..193c06725cf 100644 --- a/sql/wsrep_mysqld.cc +++ b/sql/wsrep_mysqld.cc @@ -2511,15 +2511,13 @@ void wsrep_close_client_connections(my_bool wait_to_end, THD* except_caller_thd) */ server_threads.iterate(kill_remaining_threads, except_caller_thd); - DBUG_PRINT("quit", ("Waiting for threads to die (count=%u)", - uint32_t(thread_count))); - WSREP_DEBUG("waiting for client connections to close: %u", - uint32_t(thread_count)); + DBUG_PRINT("quit", ("Waiting for threads to die (count=%u)", THD_count::value())); + WSREP_DEBUG("waiting for client connections to close: %u", THD_count::value()); while (wait_to_end && server_threads.iterate(have_client_connections)) { sleep(1); - DBUG_PRINT("quit",("One thread died (count=%u)", uint32_t(thread_count))); + DBUG_PRINT("quit",("One thread died (count=%u)", THD_count::value())); } /* All client connection threads have now been aborted */ diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index ce2e4b6990f..25e2468770e 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -314,7 +314,7 @@ thd_destructor_proxy(void *) while (srv_fast_shutdown == 0 && (trx_sys.any_active_transactions() || - (uint)thread_count > srv_n_purge_threads + 1)) { + THD_count::value() > srv_n_purge_threads + 1)) { thd_proc_info(thd, "InnoDB slow shutdown wait"); os_thread_sleep(1000); } |