From 1c0d998a124265bdca1dfece48ab73205a4d9430 Mon Sep 17 00:00:00 2001 From: Mikael Ronstrom Date: Wed, 27 Oct 2010 20:29:09 +0200 Subject: [PATCH] Added more wait states for THD wait service --- include/mysql/plugin_audit.h.pp | 12 +++++++++--- include/mysql/plugin_ftparser.h.pp | 12 +++++++++--- include/mysql/service_thd_wait.h | 12 +++++++++--- sql/item_func.cc | 6 ++++++ sql/lock.cc | 12 ++++++++++++ sql/mdl.cc | 6 ++++++ sql/scheduler.cc | 2 +- storage/innobase/srv/srv0srv.c | 4 ++-- 8 files changed, 54 insertions(+), 12 deletions(-) diff --git a/include/mysql/plugin_audit.h.pp b/include/mysql/plugin_audit.h.pp index b48cbca2e87..0011dd8c41c 100644 --- a/include/mysql/plugin_audit.h.pp +++ b/include/mysql/plugin_audit.h.pp @@ -33,10 +33,16 @@ MYSQL_LEX_STRING *thd_make_lex_string(void* thd, MYSQL_LEX_STRING *lex_str, int allocate_lex_string); #include typedef enum _thd_wait_type_e { - THD_WAIT_MUTEX= 1, + THD_WAIT_SLEEP= 1, THD_WAIT_DISKIO= 2, - THD_WAIT_ROW_TABLE_LOCK= 3, - THD_WAIT_GLOBAL_LOCK= 4 + THD_WAIT_ROW_LOCK= 3, + THD_WAIT_GLOBAL_LOCK= 4, + THD_WAIT_META_DATA_LOCK= 5, + THD_WAIT_TABLE_LOCK= 6, + THD_WAIT_USER_LOCK= 7, + THD_WAIT_BINLOG= 8, + THD_WAIT_GROUP_COMMIT= 9, + THD_WAIT_LAST= 10 } thd_wait_type; extern struct thd_wait_service_st { void (*thd_wait_begin_func)(void*, thd_wait_type); diff --git a/include/mysql/plugin_ftparser.h.pp b/include/mysql/plugin_ftparser.h.pp index 2c2c1adbf88..003449ecf1c 100644 --- a/include/mysql/plugin_ftparser.h.pp +++ b/include/mysql/plugin_ftparser.h.pp @@ -33,10 +33,16 @@ MYSQL_LEX_STRING *thd_make_lex_string(void* thd, MYSQL_LEX_STRING *lex_str, int allocate_lex_string); #include typedef enum _thd_wait_type_e { - THD_WAIT_MUTEX= 1, + THD_WAIT_SLEEP= 1, THD_WAIT_DISKIO= 2, - THD_WAIT_ROW_TABLE_LOCK= 3, - THD_WAIT_GLOBAL_LOCK= 4 + THD_WAIT_ROW_LOCK= 3, + THD_WAIT_GLOBAL_LOCK= 4, + THD_WAIT_META_DATA_LOCK= 5, + THD_WAIT_TABLE_LOCK= 6, + THD_WAIT_USER_LOCK= 7, + THD_WAIT_BINLOG= 8, + THD_WAIT_GROUP_COMMIT= 9, + THD_WAIT_LAST= 10 } thd_wait_type; extern struct thd_wait_service_st { void (*thd_wait_begin_func)(void*, thd_wait_type); diff --git a/include/mysql/service_thd_wait.h b/include/mysql/service_thd_wait.h index 2a8f5e610a3..188aa0ab126 100644 --- a/include/mysql/service_thd_wait.h +++ b/include/mysql/service_thd_wait.h @@ -51,10 +51,16 @@ extern "C" { #endif typedef enum _thd_wait_type_e { - THD_WAIT_MUTEX= 1, + THD_WAIT_SLEEP= 1, THD_WAIT_DISKIO= 2, - THD_WAIT_ROW_TABLE_LOCK= 3, - THD_WAIT_GLOBAL_LOCK= 4 + THD_WAIT_ROW_LOCK= 3, + THD_WAIT_GLOBAL_LOCK= 4, + THD_WAIT_META_DATA_LOCK= 5, + THD_WAIT_TABLE_LOCK= 6, + THD_WAIT_USER_LOCK= 7, + THD_WAIT_BINLOG= 8, + THD_WAIT_GROUP_COMMIT= 9, + THD_WAIT_LAST= 10 } thd_wait_type; extern struct thd_wait_service_st { diff --git a/sql/item_func.cc b/sql/item_func.cc index 6699b2820e6..e20cae16094 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -52,6 +52,8 @@ #include "sp.h" #include "set_var.h" #include "debug_sync.h" +#include +#include #ifdef NO_EMBEDDED_ACCESS_CHECKS #define sp_restore_security_context(A,B) while (0) {} @@ -3802,7 +3804,9 @@ longlong Item_func_get_lock::val_int() while (ull->locked && !thd->killed) { DBUG_PRINT("info", ("waiting on lock")); + thd_wait_begin(thd, THD_WAIT_USER_LOCK); error= interruptible_wait(thd, &ull->cond, &LOCK_user_locks, timeout); + thd_wait_end(thd); if (error == ETIMEDOUT || error == ETIME) { DBUG_PRINT("info", ("lock wait timeout")); @@ -4026,7 +4030,9 @@ longlong Item_func_sleep::val_int() error= 0; while (!thd->killed) { + thd_wait_begin(thd, THD_WAIT_SLEEP); error= interruptible_wait(thd, &cond, &LOCK_user_locks, timeout); + thd_wait_end(thd); if (error == ETIMEDOUT || error == ETIME) break; error= 0; diff --git a/sql/lock.cc b/sql/lock.cc index 0181a544824..5abf90b0047 100644 --- a/sql/lock.cc +++ b/sql/lock.cc @@ -82,6 +82,8 @@ #include "sql_acl.h" // SUPER_ACL #include #include +#include +#include /** @defgroup Locking Locking @@ -1019,7 +1021,11 @@ bool Global_read_lock::lock_global_read_lock(THD *thd) waiting_for_read_lock++; while (protect_against_global_read_lock && !thd->killed) + { + thd_wait_begin(thd, THD_WAIT_GLOBAL_LOCK); mysql_cond_wait(&COND_global_read_lock, &LOCK_global_read_lock); + thd_wait_end(thd); + } waiting_for_read_lock--; if (thd->killed) { @@ -1187,7 +1193,9 @@ wait_if_global_read_lock(THD *thd, bool abort_on_refresh, thd->open_tables->s->version == refresh_version)) { DBUG_PRINT("signal", ("Waiting for COND_global_read_lock")); + thd_wait_begin(thd, THD_WAIT_GLOBAL_LOCK); mysql_cond_wait(&COND_global_read_lock, &LOCK_global_read_lock); + thd_wait_end(thd); DBUG_PRINT("signal", ("Got COND_global_read_lock")); } if (thd->killed) @@ -1285,7 +1293,11 @@ bool Global_read_lock::make_global_read_lock_block_commit(THD *thd) old_message= thd->enter_cond(&COND_global_read_lock, &LOCK_global_read_lock, "Waiting for all running commits to finish"); while (protect_against_global_read_lock && !thd->killed) + { + thd_wait_begin(thd, THD_WAIT_GLOBAL_LOCK); mysql_cond_wait(&COND_global_read_lock, &LOCK_global_read_lock); + thd_wait_end(thd); + } DBUG_EXECUTE_IF("make_global_read_lock_block_commit_loop", protect_against_global_read_lock--;); if ((error= test(thd->killed))) diff --git a/sql/mdl.cc b/sql/mdl.cc index aa7c2a4b7f2..924a005eec7 100644 --- a/sql/mdl.cc +++ b/sql/mdl.cc @@ -18,6 +18,8 @@ #include "debug_sync.h" #include #include +#include +#include #ifdef HAVE_PSI_INTERFACE static PSI_mutex_key key_MDL_map_mutex; @@ -991,8 +993,12 @@ MDL_wait::timed_wait(THD *thd, struct timespec *abs_timeout, while (!m_wait_status && !thd_killed(thd) && wait_result != ETIMEDOUT && wait_result != ETIME) + { + thd_wait_begin(thd, THD_WAIT_META_DATA_LOCK); wait_result= mysql_cond_timedwait(&m_COND_wait_status, &m_LOCK_wait_status, abs_timeout); + thd_wait_end(thd); + } if (m_wait_status == EMPTY) { diff --git a/sql/scheduler.cc b/sql/scheduler.cc index d61a452b99e..57e0f86f158 100644 --- a/sql/scheduler.cc +++ b/sql/scheduler.cc @@ -82,7 +82,7 @@ scheduler_functions *thread_scheduler= NULL; /**@{*/ static void scheduler_wait_begin(void) { MYSQL_CALLBACK(thread_scheduler, - thd_wait_begin, (current_thd, THD_WAIT_ROW_TABLE_LOCK)); + thd_wait_begin, (current_thd, THD_WAIT_TABLE_LOCK)); } static void scheduler_wait_end(void) { diff --git a/storage/innobase/srv/srv0srv.c b/storage/innobase/srv/srv0srv.c index b2da43c188b..f86f31ddfb0 100644 --- a/storage/innobase/srv/srv0srv.c +++ b/storage/innobase/srv/srv0srv.c @@ -1234,7 +1234,7 @@ retry: trx->op_info = "waiting in InnoDB queue"; - thd_wait_begin(trx->mysql_thd, THD_WAIT_ROW_TABLE_LOCK); + thd_wait_begin(trx->mysql_thd, THD_WAIT_USER_LOCK); os_event_wait(slot->event); thd_wait_end(trx->mysql_thd); @@ -1601,7 +1601,7 @@ srv_suspend_mysql_thread( /* Suspend this thread and wait for the event. */ - thd_wait_begin(trx->mysql_thd, THD_WAIT_ROW_TABLE_LOCK); + thd_wait_begin(trx->mysql_thd, THD_WAIT_ROW_LOCK); os_event_wait(event); thd_wait_end(trx->mysql_thd);