From f924523f26b8935665819c0d048a90a14d0e4c53 Mon Sep 17 00:00:00 2001 From: Davi Arnaut Date: Tue, 10 Nov 2009 12:21:50 -0200 Subject: [PATCH] Backport of Bug#41971 to mysql-next-mr ------------------------------------------------------------ revno: 2617.31.21 revision-id: davi.arnaut@sun.com-20090402193933-2zbhg15kd0z3xh8r parent: alik@sun.com-20090402081500-78l1hpkx03twe4bf committer: Davi Arnaut branch nick: 41971-6.0 timestamp: Thu 2009-04-02 16:39:33 -0300 message: Bug#41971: Thread state on embedded server is always "Writing to net" The problem is that the state of a thread on a embedded server is always displayed as "Writing to net", which is wrong as there is no "network" in the embedded server. The solution is only exclude, on a embedded server, the thread state conditions that are related to network operations. Other thread states related to waiting on conditions or other operations are preserved. --- sql/sql_show.cc | 57 ++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 76037792e94..5997ceaa941 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -1697,6 +1697,32 @@ public: template class I_List; #endif +static const char *thread_state_info(THD *tmp) +{ + if (tmp->locked) + return "Locked"; +#ifndef EMBEDDED_LIBRARY + if (tmp->net.reading_or_writing) + { + if (tmp->net.reading_or_writing == 2) + return "Writing to net"; + else if (tmp->command == COM_SLEEP) + return ""; + else + return "Reading from net"; + } + else +#endif + { + if (tmp->proc_info) + return tmp->proc_info; + else if (tmp->mysys_var && tmp->mysys_var->current_cond) + return "Waiting on cond"; + else + return NULL; + } +} + void mysqld_list_processes(THD *thd,const char *user, bool verbose) { Item *field; @@ -1758,20 +1784,7 @@ void mysqld_list_processes(THD *thd,const char *user, bool verbose) if ((mysys_var= tmp->mysys_var)) pthread_mutex_lock(&mysys_var->mutex); thd_info->proc_info= (char*) (tmp->killed == THD::KILL_CONNECTION? "Killed" : 0); -#ifndef EMBEDDED_LIBRARY - thd_info->state_info= (char*) (tmp->locked ? "Locked" : - tmp->net.reading_or_writing ? - (tmp->net.reading_or_writing == 2 ? - "Writing to net" : - thd_info->command == COM_SLEEP ? "" : - "Reading from net") : - tmp->proc_info ? tmp->proc_info : - tmp->mysys_var && - tmp->mysys_var->current_cond ? - "Waiting on cond" : NullS); -#else - thd_info->state_info= (char*)"Writing to net"; -#endif + thd_info->state_info= thread_state_info(tmp); if (mysys_var) pthread_mutex_unlock(&mysys_var->mutex); @@ -1883,21 +1896,7 @@ int fill_schema_processlist(THD* thd, TABLE_LIST* tables, COND* cond) table->field[5]->store((longlong)(tmp->start_time ? now - tmp->start_time : 0), FALSE); /* STATE */ -#ifndef EMBEDDED_LIBRARY - val= (char*) (tmp->locked ? "Locked" : - tmp->net.reading_or_writing ? - (tmp->net.reading_or_writing == 2 ? - "Writing to net" : - tmp->command == COM_SLEEP ? "" : - "Reading from net") : - tmp->proc_info ? tmp->proc_info : - tmp->mysys_var && - tmp->mysys_var->current_cond ? - "Waiting on cond" : NullS); -#else - val= (char *) (tmp->proc_info ? tmp->proc_info : NullS); -#endif - if (val) + if ((val= thread_state_info(tmp))) { table->field[6]->store(val, strlen(val), cs); table->field[6]->set_notnull();