List:Commits« Previous MessageNext Message »
From:Davi Arnaut Date:September 30 2010 9:23pm
Subject:bzr commit into mysql-5.5-bugteam branch (davi:3211) Bug#56822
View as plain text  
# At a local mysql-5.5-bugteam repository of davi

 3211 Davi Arnaut	2010-09-30
      Bug#56822: Add a thread state for sessions waiting on the query cache lock
      
      The problem was that threads waiting on the query cache lock
      are not easily seen due to the lack of a state indicating that
      the thread is waiting on the said lock. This made it difficult
      for users to quickly spot (for example, via SHOW PROCESSLIST)
      a query cache contention problem.
      
      The solution is to update the thread state when the query cache
      lock needs to be acquired. Whenever the lock is to be acquired,
      the thread state is updated to "Waiting for query cache lock"
      and is reset once the lock is granted or the wait is interrupted.
      The intention is to make query cache related hangs more evident.
      
      To further investigate query cache related locking problems, one
      may use PERFORMANCE_SCHEMA to track the overhead associated with
      the locking bits and determine which particular lock is being a
      contention point.
     @ sql/sql_cache.cc
        Set and reset the thread state whenever a attempt to lock the
        query cache is made.

    modified:
      sql/sql_cache.cc
=== modified file 'sql/sql_cache.cc'
--- a/sql/sql_cache.cc	2010-09-24 12:12:09 +0000
+++ b/sql/sql_cache.cc	2010-09-30 21:23:51 +0000
@@ -371,6 +371,33 @@ TODO list:
 #define DUMP(C) DBUG_EXECUTE("qcache", {\
   (C)->cache_dump(); (C)->queries_dump();(C)->tables_dump();})
 
+/**
+  Thread state to be used when the query cache lock needs to be acquired.
+  Sets the thread state name in the constructor, resets on destructor.
+*/
+
+struct Query_cache_wait_state
+{
+  THD *m_thd;
+  const char *m_proc_info;
+
+  Query_cache_wait_state(THD *thd, const char *func,
+                         const char *file, unsigned int line)
+  : m_thd(thd)
+  {
+    if (m_thd)
+      m_proc_info= set_thd_proc_info(m_thd,
+                                     "Waiting for query cache lock",
+                                     func, file, line);
+  }
+
+  ~Query_cache_wait_state()
+  {
+    if (m_thd)
+      set_thd_proc_info(m_thd, m_proc_info, NULL, NULL, 0);
+  }
+};
+
 
 /**
   Causes the thread to wait in a spin lock for a query kill signal.
@@ -428,6 +455,8 @@ static void debug_wait_for_kill(const ch
 bool Query_cache::try_lock(bool use_timeout)
 {
   bool interrupt= FALSE;
+  THD *thd= current_thd;
+  Query_cache_wait_state wait_state(thd, __func__, __FILE__, __LINE__);
   DBUG_ENTER("Query_cache::try_lock");
 
   mysql_mutex_lock(&structure_guard_mutex);
@@ -437,7 +466,6 @@ bool Query_cache::try_lock(bool use_time
     {
       m_cache_lock_status= Query_cache::LOCKED;
 #ifndef DBUG_OFF
-      THD *thd= current_thd;
       if (thd)
         m_cache_lock_thread_id= thd->thread_id;
 #endif
@@ -496,6 +524,8 @@ bool Query_cache::try_lock(bool use_time
 
 void Query_cache::lock_and_suspend(void)
 {
+  THD *thd= current_thd;
+  Query_cache_wait_state wait_state(thd, __func__, __FILE__, __LINE__);
   DBUG_ENTER("Query_cache::lock_and_suspend");
 
   mysql_mutex_lock(&structure_guard_mutex);
@@ -503,7 +533,6 @@ void Query_cache::lock_and_suspend(void)
     mysql_cond_wait(&COND_cache_status_changed, &structure_guard_mutex);
   m_cache_lock_status= Query_cache::LOCKED_NO_WAIT;
 #ifndef DBUG_OFF
-  THD *thd= current_thd;
   if (thd)
     m_cache_lock_thread_id= thd->thread_id;
 #endif
@@ -524,6 +553,8 @@ void Query_cache::lock_and_suspend(void)
 
 void Query_cache::lock(void)
 {
+  THD *thd= current_thd;
+  Query_cache_wait_state wait_state(thd, __func__, __FILE__, __LINE__);
   DBUG_ENTER("Query_cache::lock");
 
   mysql_mutex_lock(&structure_guard_mutex);
@@ -531,7 +562,6 @@ void Query_cache::lock(void)
     mysql_cond_wait(&COND_cache_status_changed, &structure_guard_mutex);
   m_cache_lock_status= Query_cache::LOCKED;
 #ifndef DBUG_OFF
-  THD *thd= current_thd;
   if (thd)
     m_cache_lock_thread_id= thd->thread_id;
 #endif


Attachment: [text/bzr-bundle] bzr/davi.arnaut@oracle.com-20100930212351-zllnk9b2u1zj0b1d.bundle
Thread
bzr commit into mysql-5.5-bugteam branch (davi:3211) Bug#56822Davi Arnaut30 Sep
Re: bzr commit into mysql-5.5-bugteam branch (davi:3211) Bug#56822Konstantin Osipov6 Oct
  • Re: bzr commit into mysql-5.5-bugteam branch (davi:3211) Bug#56822Davi Arnaut8 Oct