List:Commits« Previous MessageNext Message »
From:Dmitry Lenev Date:May 16 2012 8:04am
Subject:bzr push into mysql-trunk branch (Dmitry.Lenev:3896 to 3897) WL#5772
View as plain text  
 3897 Dmitry Lenev	2012-05-16
      WL#5772 "Add partitioned Table Definition Cache to avoid
      using LOCK_open and its derivatives in DML queries".
      
      Review change #9:
      - Move Table_cache::print_tables/print_tables_all() into sql_base.cc
      - Make Table_cache_element auxiliary struct private to the same file.

    modified:
      sql/sql_base.cc
      sql/sql_base.h
      sql/sql_test.cc
      sql/sql_test.h
 3896 Dmitry Lenev	2012-05-15
      WL#5772 "Add partitioned Table Definition Cache to avoid
      using LOCK_open and its derivatives in DML queries".
      
      Review change #8:
      - Improved comments.
      - Renamed Table_cache::rename_table_all() to free_table_all().
      - Changed size of TABLE_SHARE::cache_element array from 
        MAX_TABLE_CACHES to table_cache_instances.

    modified:
      sql/sql_base.cc
      sql/sql_base.h
      sql/sql_const.h
      sql/sys_vars.cc
      sql/table.cc
      sql/table.h
=== modified file 'sql/sql_base.cc'
--- a/sql/sql_base.cc	2012-05-15 19:36:12 +0000
+++ b/sql/sql_base.cc	2012-05-16 07:52:08 +0000
@@ -57,6 +57,7 @@
 #ifdef  __WIN__
 #include <io.h>
 #endif
+#include "sql_test.h" // lock_descriptions[]
 
 
 bool
@@ -241,6 +242,34 @@ Table_cache* Table_cache::get_cache(THD
 }
 
 
+/**
+  Element that represents the table in the specific table cache.
+  Plays for table cache instance role similar to role of TABLE_SHARE
+  for table definition cache.
+*/
+
+struct Table_cache_element
+{
+  /*
+    Doubly-linked (back-linked) lists of used and unused TABLE objects
+    for this table in this table cache (one such list per table cache).
+  */
+  typedef I_P_List <TABLE,
+                    I_P_List_adapter<TABLE,
+                                     &TABLE::cache_next,
+                                     &TABLE::cache_prev> > TABLE_list;
+
+  TABLE_list used_tables;
+  TABLE_list free_tables;
+  TABLE_SHARE *share;
+
+  Table_cache_element(TABLE_SHARE *share_arg)
+    : share(share_arg)
+  {
+  }
+};
+
+
 extern "C" uchar *table_cache_key(const uchar *record,
                                   size_t *length,
                                   my_bool not_used __attribute__((unused)))
@@ -594,6 +623,79 @@ void Table_cache::check_unused()
 #endif
 
 
+#ifndef DBUG_OFF
+
+/**
+  Print debug information for the contents of all table cache instances.
+*/
+
+void Table_cache::print_tables_all()
+{
+  puts("DB             Table                            Version  Thread  Open  Lock");
+
+  for (uint i= 0; i < table_cache_instances; i++)
+    m_table_cache[i].print_tables();
+}
+
+
+/**
+  Print debug information for the contents of the table cache.
+*/
+
+void Table_cache::print_tables()
+{
+  uint idx,count,unused;
+  TABLE *start_link, *lnk, *entry;
+  Table_cache_element *el;
+  unused= 0;
+  count=0;
+
+  compile_time_assert(TL_WRITE_ONLY+1 == array_elements(lock_descriptions));
+
+  for (idx= 0; idx < m_cache.records; idx++)
+  {
+    el= (Table_cache_element*) my_hash_element(&m_cache, idx);
+    Table_cache_element::TABLE_list::Iterator it(el->used_tables);
+
+    while ((entry= it++))
+    {
+      printf("%-14.14s %-32s%6ld%8ld%6d  %s\n",
+             entry->s->db.str, entry->s->table_name.str, entry->s->version,
+             entry->in_use->thread_id, entry->db_stat ? 1 : 0,
+             lock_descriptions[(int)entry->reginfo.lock_type]);
+    }
+    it.init(el->free_tables);
+    while ((entry= it++))
+    {
+      unused++;
+      printf("%-14.14s %-32s%6ld%8ld%6d  %s\n",
+             entry->s->db.str, entry->s->table_name.str, entry->s->version,
+             0L, entry->db_stat ? 1 : 0, "Not in use");
+    }
+  }
+  if ((start_link= lnk= m_unused_tables))
+  {
+    do
+    {
+      if (lnk != lnk->next->prev || lnk != lnk->prev->next)
+      {
+	printf("unused_links isn't linked properly\n");
+	return;
+      }
+    } while (count++ < m_table_count && (lnk=lnk->next) != start_link);
+    if (lnk != start_link)
+    {
+      printf("Unused_links aren't connected\n");
+    }
+  }
+  if (count != unused)
+    printf("Unused_links (%d) doesn't match table_def_cache: %d\n", count,
+           unused);
+}
+
+#endif
+
+
 /**
   Create a table cache/table definition cache key
 

=== modified file 'sql/sql_base.h'
--- a/sql/sql_base.h	2012-05-15 19:36:12 +0000
+++ b/sql/sql_base.h	2012-05-16 07:52:08 +0000
@@ -611,34 +611,6 @@ private:
 
 
 /**
-  Element that represents the table in the specific table cache.
-  Plays for table cache instance role similar to role of TABLE_SHARE
-  for table definition cache.
-*/
-
-struct Table_cache_element
-{
-  /*
-    Doubly-linked (back-linked) lists of used and unused TABLE objects
-    for this table in this table cache (one such list per table cache).
-  */
-  typedef I_P_List <TABLE,
-                    I_P_List_adapter<TABLE,
-                                     &TABLE::cache_next,
-                                     &TABLE::cache_prev> > TABLE_list;
-
-  TABLE_list used_tables;
-  TABLE_list free_tables;
-  TABLE_SHARE *share;
-
-  Table_cache_element(TABLE_SHARE *share_arg)
-    : share(share_arg)
-  {
-  }
-};
-
-
-/**
   Cache for open TABLE objects.
 
   The idea behind this cache is that most statements don't need to

=== modified file 'sql/sql_test.cc'
--- a/sql/sql_test.cc	2012-05-15 15:10:59 +0000
+++ b/sql/sql_test.cc	2012-05-16 07:52:08 +0000
@@ -41,7 +41,7 @@
 
 #include "global_threads.h"
 
-static const char *lock_descriptions[] =
+const char *lock_descriptions[TL_WRITE_ONLY + 1] =
 {
   /* TL_UNLOCK                  */  "No lock",
   /* TL_READ_DEFAULT            */  NULL,
@@ -82,9 +82,6 @@ print_where(Item *cond,const char *info,
 
 static void print_cached_tables(void)
 {
-
-  compile_time_assert(TL_WRITE_ONLY+1 == array_elements(lock_descriptions));
-
   /* purecov: begin tested */
   Table_cache::lock_all_and_tdc();
 
@@ -100,65 +97,6 @@ static void print_cached_tables(void)
 }
 
 
-void Table_cache::print_tables_all()
-{
-  puts("DB             Table                            Version  Thread  Open  Lock");
-
-  for (uint i= 0; i < table_cache_instances; i++)
-    m_table_cache[i].print_tables();
-}
-
-
-void Table_cache::print_tables()
-{
-  uint idx,count,unused;
-  TABLE *start_link, *lnk, *entry;
-  Table_cache_element *el;
-  unused= 0;
-  count=0;
-
-  for (idx= 0; idx < m_cache.records; idx++)
-  {
-    el= (Table_cache_element*) my_hash_element(&m_cache, idx);
-    Table_cache_element::TABLE_list::Iterator it(el->used_tables);
-
-    while ((entry= it++))
-    {
-      printf("%-14.14s %-32s%6ld%8ld%6d  %s\n",
-             entry->s->db.str, entry->s->table_name.str, entry->s->version,
-             entry->in_use->thread_id, entry->db_stat ? 1 : 0,
-             lock_descriptions[(int)entry->reginfo.lock_type]);
-    }
-    it.init(el->free_tables);
-    while ((entry= it++))
-    {
-      unused++;
-      printf("%-14.14s %-32s%6ld%8ld%6d  %s\n",
-             entry->s->db.str, entry->s->table_name.str, entry->s->version,
-             0L, entry->db_stat ? 1 : 0, "Not in use");
-    }
-  }
-  if ((start_link= lnk= m_unused_tables))
-  {
-    do
-    {
-      if (lnk != lnk->next->prev || lnk != lnk->prev->next)
-      {
-	printf("unused_links isn't linked properly\n");
-	return;
-      }
-    } while (count++ < m_table_count && (lnk=lnk->next) != start_link);
-    if (lnk != start_link)
-    {
-      printf("Unused_links aren't connected\n");
-    }
-  }
-  if (count != unused)
-    printf("Unused_links (%d) doesn't match table_def_cache: %d\n", count,
-           unused);
-}
-
-
 void
 TEST_join(JOIN *join)
 {

=== modified file 'sql/sql_test.h'
--- a/sql/sql_test.h	2011-09-19 11:29:21 +0000
+++ b/sql/sql_test.h	2012-05-16 07:52:08 +0000
@@ -24,6 +24,8 @@ struct TABLE_LIST;
 typedef class st_select_lex SELECT_LEX;
 typedef struct st_sort_field SORT_FIELD;
 
+extern const char *lock_descriptions[TL_WRITE_ONLY + 1];
+
 #ifndef DBUG_OFF
 void print_where(Item *cond,const char *info, enum_query_type query_type);
 void TEST_join(JOIN *join);

No bundle (reason: useless for push emails).
Thread
bzr push into mysql-trunk branch (Dmitry.Lenev:3896 to 3897) WL#5772Dmitry Lenev16 May