MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:Davi Arnaut Date:September 30 2010 4:46pm
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 there was no obvious way to detect query
      cache contention as a thread waiting on the query cache lock
      didn't update its thread state.
      
      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.
     @ 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 16:46:08 +0000
@@ -371,6 +371,30 @@ 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 *proc_info;
+
+  Query_cache_wait_state(THD *thd)
+  : m_thd(thd)
+  {
+    if (m_thd)
+      proc_info= thd_proc_info(m_thd, "Waiting for query cache lock");
+  }
+
+  ~Query_cache_wait_state()
+  {
+    if (m_thd)
+      thd_proc_info(m_thd, proc_info);
+  }
+};
+
 
 /**
   Causes the thread to wait in a spin lock for a query kill signal.
@@ -428,6 +452,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);
   DBUG_ENTER("Query_cache::try_lock");
 
   mysql_mutex_lock(&structure_guard_mutex);
@@ -437,7 +463,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 +521,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);
   DBUG_ENTER("Query_cache::lock_and_suspend");
 
   mysql_mutex_lock(&structure_guard_mutex);
@@ -503,7 +530,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 +550,8 @@ void Query_cache::lock_and_suspend(void)
 
 void Query_cache::lock(void)
 {
+  THD *thd= current_thd;
+  Query_cache_wait_state wait_state(thd);
   DBUG_ENTER("Query_cache::lock");
 
   mysql_mutex_lock(&structure_guard_mutex);
@@ -531,7 +559,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-20100930164608-oisyj8ivo381ih6q.bundle
Thread
bzr commit into mysql-5.5-bugteam branch (davi:3211) Bug#56822Davi Arnaut30 Sep