From 7180afa0943714942678d037d27fad072e3e98e9 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Sat, 7 Mar 2020 15:12:02 +0100 Subject: [PATCH] fix perfschema for pool-of-threads --- .../include/maybe_pool_of_threads.combinations | 5 +++++ mysql-test/include/maybe_pool_of_threads.inc | 1 + mysql-test/include/not_threadpool.inc | 3 +-- .../suite/perfschema/t/show_aggregate.test | 1 + .../suite/perfschema/t/thread_cache.test | 1 + .../t/transaction_nested_events.test | 2 ++ sql/scheduler.h | 11 ----------- sql/sql_class.cc | 1 - sql/threadpool_common.cc | 18 +++--------------- storage/perfschema/pfs.cc | 9 ++++++++- storage/perfschema/pfs_instr.cc | 2 +- 11 files changed, 23 insertions(+), 31 deletions(-) create mode 100644 mysql-test/include/maybe_pool_of_threads.combinations create mode 100644 mysql-test/include/maybe_pool_of_threads.inc diff --git a/mysql-test/include/maybe_pool_of_threads.combinations b/mysql-test/include/maybe_pool_of_threads.combinations new file mode 100644 index 00000000000..29d3d7f4871 --- /dev/null +++ b/mysql-test/include/maybe_pool_of_threads.combinations @@ -0,0 +1,5 @@ +[pot] +thread_handling=pool-of-threads + +[1tpc] +thread_handling=one-thread-per-connection diff --git a/mysql-test/include/maybe_pool_of_threads.inc b/mysql-test/include/maybe_pool_of_threads.inc new file mode 100644 index 00000000000..51a179b4426 --- /dev/null +++ b/mysql-test/include/maybe_pool_of_threads.inc @@ -0,0 +1 @@ +# run with and without threadpool diff --git a/mysql-test/include/not_threadpool.inc b/mysql-test/include/not_threadpool.inc index a49c8cfcc32..98e1f7d2535 100644 --- a/mysql-test/include/not_threadpool.inc +++ b/mysql-test/include/not_threadpool.inc @@ -1,5 +1,4 @@ if (`SELECT count(*) FROM information_schema.GLOBAL_VARIABLES WHERE - VARIABLE_NAME = 'THREAD_HANDLING' AND - VARIABLE_VALUE = 'loaded-dynamically'`){ + VARIABLE_NAME = 'THREAD_HANDLING' AND VARIABLE_VALUE = 'pool-of-threads'`){ skip Test requires: 'not_threadpool'; } diff --git a/mysql-test/suite/perfschema/t/show_aggregate.test b/mysql-test/suite/perfschema/t/show_aggregate.test index df5a6cdf036..788979dc0f0 100644 --- a/mysql-test/suite/perfschema/t/show_aggregate.test +++ b/mysql-test/suite/perfschema/t/show_aggregate.test @@ -12,6 +12,7 @@ --source include/have_innodb.inc --source include/not_embedded.inc --source include/no_protocol.inc +--source include/maybe_pool_of_threads.inc --enable_connect_log diff --git a/mysql-test/suite/perfschema/t/thread_cache.test b/mysql-test/suite/perfschema/t/thread_cache.test index 92309bb9ca1..90823988f8c 100644 --- a/mysql-test/suite/perfschema/t/thread_cache.test +++ b/mysql-test/suite/perfschema/t/thread_cache.test @@ -2,6 +2,7 @@ --source include/not_embedded.inc --source include/have_perfschema.inc +--source include/not_threadpool.inc # # Important note: diff --git a/mysql-test/suite/perfschema/t/transaction_nested_events.test b/mysql-test/suite/perfschema/t/transaction_nested_events.test index 4babe47bc77..9d441b5d2c3 100644 --- a/mysql-test/suite/perfschema/t/transaction_nested_events.test +++ b/mysql-test/suite/perfschema/t/transaction_nested_events.test @@ -11,6 +11,8 @@ --source include/not_embedded.inc --source include/have_innodb.inc --source include/no_protocol.inc +--source include/maybe_pool_of_threads.inc + --disable_query_log --source ../include/transaction_setup.inc --enable_query_log diff --git a/sql/scheduler.h b/sql/scheduler.h index 676262f6454..ebf8d6e9e64 100644 --- a/sql/scheduler.h +++ b/sql/scheduler.h @@ -82,17 +82,6 @@ extern void post_kill_notification(THD *); struct thd_scheduler { public: - /* - Thread instrumentation for the user job. - This member holds the instrumentation while the user job is not run - by a thread. - - Note that this member is not conditionally declared - (ifdef HAVE_PSI_INTERFACE), because doing so will change the binary - layout of THD, which is exposed to plugin code that may be compiled - differently. - */ - PSI_thread *m_psi; void *data; /* scheduler-specific data structure */ }; diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 0325ef5cc9c..2143a9d4008 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -758,7 +758,6 @@ THD::THD(my_thread_id id, bool is_wsrep_applier) thread_stack= 0; scheduler= thread_scheduler; // Will be fixed later event_scheduler.data= 0; - event_scheduler.m_psi= 0; skip_wait_timeout= false; catalog= (char*)"std"; // the only catalog we have for now main_security_ctx.init(); diff --git a/sql/threadpool_common.cc b/sql/threadpool_common.cc index 0588562ae61..40b230e5392 100644 --- a/sql/threadpool_common.cc +++ b/sql/threadpool_common.cc @@ -151,7 +151,7 @@ static void thread_attach(THD* thd) pthread_setspecific(THR_KEY_mysys,thd->mysys_var); thd->thread_stack=(char*)&thd; thd->store_globals(); - PSI_CALL_set_thread(thd->event_scheduler.m_psi); + PSI_CALL_set_thread(thd->get_psi()); mysql_socket_set_thread_owner(thd->net.vio->mysql_socket); } @@ -235,21 +235,13 @@ static THD* threadpool_add_connection(CONNECT *connect, void *scheduler_data) pthread_setspecific(THR_KEY_mysys, 0); my_thread_init(); st_my_thread_var* mysys_var= (st_my_thread_var *)pthread_getspecific(THR_KEY_mysys); + PSI_CALL_set_thread(PSI_CALL_new_thread(key_thread_one_connection, connect, 0)); if (!mysys_var ||!(thd= connect->create_thd(NULL))) { /* Out of memory? */ connect->close_and_delete(); if (mysys_var) - { -#ifdef HAVE_PSI_INTERFACE - /* - current PSI is still from worker thread. - Set to 0, to avoid premature cleanup by my_thread_end - */ - if (PSI_server) PSI_server->set_thread(0); -#endif my_thread_end(); - } return NULL; } delete connect; @@ -257,11 +249,6 @@ static THD* threadpool_add_connection(CONNECT *connect, void *scheduler_data) thd->set_mysys_var(mysys_var); thd->event_scheduler.data= scheduler_data; - /* Create new PSI thread for use with the THD. */ - thd->event_scheduler.m_psi= - PSI_CALL_new_thread(key_thread_one_connection, thd, thd->thread_id); - - /* Login. */ thread_attach(thd); re_init_net_server_extension(thd); @@ -301,6 +288,7 @@ static void threadpool_remove_connection(THD *thd) end_connection(thd); close_connection(thd, 0); unlink_thd(thd); + PSI_CALL_delete_current_thread(); // before THD is destroyed delete thd; /* diff --git a/storage/perfschema/pfs.cc b/storage/perfschema/pfs.cc index a5d5af03969..1bb712f64cc 100644 --- a/storage/perfschema/pfs.cc +++ b/storage/perfschema/pfs.cc @@ -2168,7 +2168,6 @@ extern "C" void* pfs_spawn_thread(void *arg) pfs= create_thread(klass, typed_arg->m_child_identity, 0); if (likely(pfs != NULL)) { - pfs->m_thread_os_id= my_thread_os_id(); clear_thread_account(pfs); pfs->m_parent_thread_internal_id= typed_arg->m_thread_internal_id; @@ -2267,7 +2266,15 @@ pfs_new_thread_v1(PSI_thread_key key, const void *identity, ulonglong processlis PFS_thread_class *klass= find_thread_class(key); if (likely(klass != NULL)) + { pfs= create_thread(klass, identity, processlist_id); + if (pfs != NULL) + { + PFS_thread *parent= my_thread_get_THR_PFS(); + if (parent != NULL) + pfs->m_parent_thread_internal_id= parent->m_parent_thread_internal_id; + } + } else pfs= NULL; diff --git a/storage/perfschema/pfs_instr.cc b/storage/perfschema/pfs_instr.cc index 335087443a5..f1064e2731c 100644 --- a/storage/perfschema/pfs_instr.cc +++ b/storage/perfschema/pfs_instr.cc @@ -529,7 +529,7 @@ PFS_thread* create_thread(PFS_thread_class *klass, const void *identity, PFS_atomic::add_u64(&thread_internal_id_counter.m_u64, 1); pfs->m_parent_thread_internal_id= 0; pfs->m_processlist_id= static_cast(processlist_id); - pfs->m_thread_os_id= 0; + pfs->m_thread_os_id= my_thread_os_id(); pfs->m_event_id= 1; pfs->m_stmt_lock.set_allocated(); pfs->m_session_lock.set_allocated();