← Back to team overview

maria-developers team mailing list archive

bzr commit into Mariadb 5.2, with Maria 2.0:maria/5.2 branch (igor:2750)

 

#At lp:maria/5.2 based on revid:igor@xxxxxxxxxxxx-20100405202809-beg2cwhelygpbl6i

 2750 Igor Babaev	2010-04-05
      Post review fixes.
      modified:
        include/keycache.h
        mysql-test/suite/funcs_1/r/is_columns_is.result
        mysql-test/suite/funcs_1/r/is_tables_is.result
        mysys/mf_keycache.c
        sql/sql_show.cc

=== modified file 'include/keycache.h'
--- a/include/keycache.h	2010-04-01 21:42:40 +0000
+++ b/include/keycache.h	2010-04-06 02:08:10 +0000
@@ -52,7 +52,7 @@ typedef struct st_key_cache_statistics
   ulonglong writes;       /* number of actual writes from buffers into files */
 } KEY_CACHE_STATISTICS;
 
-#define NO_LONG_KEY_CACHE_STAT_VARIABLES 3
+#define NUM_LONG_KEY_CACHE_STAT_VARIABLES 3
 
 /* The type of a key cache object */
 typedef enum key_cache_type

=== modified file 'mysql-test/suite/funcs_1/r/is_columns_is.result'
--- a/mysql-test/suite/funcs_1/r/is_columns_is.result	2010-04-02 10:03:39 +0000
+++ b/mysql-test/suite/funcs_1/r/is_columns_is.result	2010-04-06 02:08:10 +0000
@@ -230,6 +230,18 @@ NULL	information_schema	INNODB_TRX	trx_s
 NULL	information_schema	INNODB_TRX	trx_state	2		NO	varchar	13	39	NULL	NULL	utf8	utf8_general_ci	varchar(13)			select	
 NULL	information_schema	INNODB_TRX	trx_wait_started	5	NULL	YES	datetime	NULL	NULL	NULL	NULL	NULL	NULL	datetime			select	
 NULL	information_schema	INNODB_TRX	trx_weight	6	0	NO	bigint	NULL	NULL	19	0	NULL	NULL	bigint(21) unsigned			select	
+NULL	information_schema	KEY_CACHES	BLOCK_SIZE	5	0	NO	bigint	NULL	NULL	19	0	NULL	NULL	bigint(21) unsigned			select	
+NULL	information_schema	KEY_CACHES	DIRTY_BLOCKS	8	0	NO	bigint	NULL	NULL	19	0	NULL	NULL	bigint(21) unsigned			select	
+NULL	information_schema	KEY_CACHES	FULL_SIZE	4	0	NO	bigint	NULL	NULL	19	0	NULL	NULL	bigint(21) unsigned			select	
+NULL	information_schema	KEY_CACHES	KEY_CACHE_NAME	1		NO	varchar	192	576	NULL	NULL	utf8	utf8_general_ci	varchar(192)			select	
+NULL	information_schema	KEY_CACHES	PARTITIONS	2	NULL	YES	int	NULL	NULL	10	0	NULL	NULL	int(3) unsigned			select	
+NULL	information_schema	KEY_CACHES	PARTITION_NUMBER	3	NULL	YES	int	NULL	NULL	10	0	NULL	NULL	int(3) unsigned			select	
+NULL	information_schema	KEY_CACHES	READS	10	0	NO	bigint	NULL	NULL	19	0	NULL	NULL	bigint(21) unsigned			select	
+NULL	information_schema	KEY_CACHES	READ_REQUESTS	9	0	NO	bigint	NULL	NULL	19	0	NULL	NULL	bigint(21) unsigned			select	
+NULL	information_schema	KEY_CACHES	UNUSED_BLOCKS	7	0	NO	bigint	NULL	NULL	19	0	NULL	NULL	bigint(21) unsigned			select	
+NULL	information_schema	KEY_CACHES	USED_BLOCKS	6	0	NO	bigint	NULL	NULL	19	0	NULL	NULL	bigint(21) unsigned			select	
+NULL	information_schema	KEY_CACHES	WRITES	12	0	NO	bigint	NULL	NULL	19	0	NULL	NULL	bigint(21) unsigned			select	
+NULL	information_schema	KEY_CACHES	WRITE_REQUESTS	11	0	NO	bigint	NULL	NULL	19	0	NULL	NULL	bigint(21) unsigned			select	
 NULL	information_schema	KEY_COLUMN_USAGE	COLUMN_NAME	7		NO	varchar	64	192	NULL	NULL	utf8	utf8_general_ci	varchar(64)			select	
 NULL	information_schema	KEY_COLUMN_USAGE	CONSTRAINT_CATALOG	1	NULL	YES	varchar	512	1536	NULL	NULL	utf8	utf8_general_ci	varchar(512)			select	
 NULL	information_schema	KEY_COLUMN_USAGE	CONSTRAINT_NAME	3		NO	varchar	64	192	NULL	NULL	utf8	utf8_general_ci	varchar(64)			select	
@@ -743,6 +755,18 @@ NULL	information_schema	INNODB_TRX	trx_w
 NULL	information_schema	INNODB_TRX	trx_weight	bigint	NULL	NULL	NULL	NULL	bigint(21) unsigned
 NULL	information_schema	INNODB_TRX	trx_mysql_thread_id	bigint	NULL	NULL	NULL	NULL	bigint(21) unsigned
 3.0000	information_schema	INNODB_TRX	trx_query	varchar	1024	3072	utf8	utf8_general_ci	varchar(1024)
+3.0000	information_schema	KEY_CACHES	KEY_CACHE_NAME	varchar	192	576	utf8	utf8_general_ci	varchar(192)
+NULL	information_schema	KEY_CACHES	PARTITIONS	int	NULL	NULL	NULL	NULL	int(3) unsigned
+NULL	information_schema	KEY_CACHES	PARTITION_NUMBER	int	NULL	NULL	NULL	NULL	int(3) unsigned
+NULL	information_schema	KEY_CACHES	FULL_SIZE	bigint	NULL	NULL	NULL	NULL	bigint(21) unsigned
+NULL	information_schema	KEY_CACHES	BLOCK_SIZE	bigint	NULL	NULL	NULL	NULL	bigint(21) unsigned
+NULL	information_schema	KEY_CACHES	USED_BLOCKS	bigint	NULL	NULL	NULL	NULL	bigint(21) unsigned
+NULL	information_schema	KEY_CACHES	UNUSED_BLOCKS	bigint	NULL	NULL	NULL	NULL	bigint(21) unsigned
+NULL	information_schema	KEY_CACHES	DIRTY_BLOCKS	bigint	NULL	NULL	NULL	NULL	bigint(21) unsigned
+NULL	information_schema	KEY_CACHES	READ_REQUESTS	bigint	NULL	NULL	NULL	NULL	bigint(21) unsigned
+NULL	information_schema	KEY_CACHES	READS	bigint	NULL	NULL	NULL	NULL	bigint(21) unsigned
+NULL	information_schema	KEY_CACHES	WRITE_REQUESTS	bigint	NULL	NULL	NULL	NULL	bigint(21) unsigned
+NULL	information_schema	KEY_CACHES	WRITES	bigint	NULL	NULL	NULL	NULL	bigint(21) unsigned
 3.0000	information_schema	KEY_COLUMN_USAGE	CONSTRAINT_CATALOG	varchar	512	1536	utf8	utf8_general_ci	varchar(512)
 3.0000	information_schema	KEY_COLUMN_USAGE	CONSTRAINT_SCHEMA	varchar	64	192	utf8	utf8_general_ci	varchar(64)
 3.0000	information_schema	KEY_COLUMN_USAGE	CONSTRAINT_NAME	varchar	64	192	utf8	utf8_general_ci	varchar(64)

=== modified file 'mysql-test/suite/funcs_1/r/is_tables_is.result'
--- a/mysql-test/suite/funcs_1/r/is_tables_is.result	2010-02-01 06:14:12 +0000
+++ b/mysql-test/suite/funcs_1/r/is_tables_is.result	2010-04-06 02:08:10 +0000
@@ -590,6 +590,29 @@ user_comment	
 Separator	-----------------------------------------------------
 TABLE_CATALOG	NULL
 TABLE_SCHEMA	information_schema
+TABLE_NAME	KEY_CACHES
+TABLE_TYPE	SYSTEM VIEW
+ENGINE	MEMORY
+VERSION	10
+ROW_FORMAT	Fixed
+TABLE_ROWS	#TBLR#
+AVG_ROW_LENGTH	#ARL#
+DATA_LENGTH	#DL#
+MAX_DATA_LENGTH	#MDL#
+INDEX_LENGTH	#IL#
+DATA_FREE	#DF#
+AUTO_INCREMENT	NULL
+CREATE_TIME	#CRT#
+UPDATE_TIME	#UT#
+CHECK_TIME	#CT#
+TABLE_COLLATION	utf8_general_ci
+CHECKSUM	NULL
+CREATE_OPTIONS	#CO#
+TABLE_COMMENT	#TC#
+user_comment	
+Separator	-----------------------------------------------------
+TABLE_CATALOG	NULL
+TABLE_SCHEMA	information_schema
 TABLE_NAME	KEY_COLUMN_USAGE
 TABLE_TYPE	SYSTEM VIEW
 ENGINE	MEMORY
@@ -1688,6 +1711,29 @@ user_comment	
 Separator	-----------------------------------------------------
 TABLE_CATALOG	NULL
 TABLE_SCHEMA	information_schema
+TABLE_NAME	KEY_CACHES
+TABLE_TYPE	SYSTEM VIEW
+ENGINE	MEMORY
+VERSION	10
+ROW_FORMAT	Fixed
+TABLE_ROWS	#TBLR#
+AVG_ROW_LENGTH	#ARL#
+DATA_LENGTH	#DL#
+MAX_DATA_LENGTH	#MDL#
+INDEX_LENGTH	#IL#
+DATA_FREE	#DF#
+AUTO_INCREMENT	NULL
+CREATE_TIME	#CRT#
+UPDATE_TIME	#UT#
+CHECK_TIME	#CT#
+TABLE_COLLATION	utf8_general_ci
+CHECKSUM	NULL
+CREATE_OPTIONS	#CO#
+TABLE_COMMENT	#TC#
+user_comment	
+Separator	-----------------------------------------------------
+TABLE_CATALOG	NULL
+TABLE_SCHEMA	information_schema
 TABLE_NAME	KEY_COLUMN_USAGE
 TABLE_TYPE	SYSTEM VIEW
 ENGINE	MEMORY

=== modified file 'mysys/mf_keycache.c'
--- a/mysys/mf_keycache.c	2010-04-03 20:19:35 +0000
+++ b/mysys/mf_keycache.c	2010-04-06 02:08:10 +0000
@@ -5158,6 +5158,7 @@ int init_partitioned_key_cache(PARTITION
 {
   int i;
   size_t mem_per_cache;
+  size_t mem_decr;
   int cnt;
   SIMPLE_KEY_CACHE_CB *partition;
   SIMPLE_KEY_CACHE_CB **partition_ptr;
@@ -5175,9 +5176,11 @@ int init_partitioned_key_cache(PARTITION
        (SIMPLE_KEY_CACHE_CB **) my_malloc(sizeof(SIMPLE_KEY_CACHE_CB *) *
                                           partitions, MYF(MY_WME))))
       DBUG_RETURN(-1);
+    bzero(partition_ptr, sizeof(SIMPLE_KEY_CACHE_CB *) * partitions);
     keycache->partition_array= partition_ptr;
   }
 
+  mem_decr= mem_per_cache / 5;
   mem_per_cache = use_mem / partitions;
 
   for (i= 0; i < (int) partitions; i++)
@@ -5194,30 +5197,64 @@ int init_partitioned_key_cache(PARTITION
       partition->key_cache_inited= 0;
     }
 
-    if ((cnt= init_simple_key_cache(partition, 
-                                    key_cache_block_size, mem_per_cache, 
-                                    division_limit, age_threshold)) <= 0)
+    cnt= init_simple_key_cache(partition, key_cache_block_size, mem_per_cache, 
+			       division_limit, age_threshold);
+    if (cnt <= 0)
     {
       end_simple_key_cache(partition, 1);
-      my_free(partition,  MYF(0));
-      partition= 0;
-      if (key_cache_inited)
+      if (!key_cache_inited)
       {
-        memmove(partition_ptr, partition_ptr+1,
-                sizeof(partition_ptr)*(partitions-i-1));
+        my_free(partition,  MYF(0));
+        partition= 0;
       }
-      if (!--partitions)
-        break;
-      if (i == 0)
+      if (i == 0 && cnt < 0 || i > 0)
       {
-        i--;
-        mem_per_cache = use_mem / partitions;
-        continue;
+        /* 
+          Here we have two cases: 
+            1. i == 0 and cnt < 0
+            cnt < 0 => mem_per_cache is not big enough to allocate minimal
+            number of key blocks in the key cache of the partition.
+            Decrease the the number of the partitions by 1 and start again.
+            2. i > 0 
+            There is not enough memory for one of the succeeding partitions.
+            Just skip this partition decreasing the number of partitions in
+            the key cache by one.
+          Do not change the value of mem_per_cache in both cases.
+	*/
+        if (key_cache_inited)
+	{
+          my_free(partition,  MYF(0));
+          partition= 0;
+          if(key_cache_inited) 
+            memmove(partition_ptr, partition_ptr+1, 
+                    sizeof(partition_ptr)*(partitions-i-1));
+	}
+        if (!--partitions)
+          break;
+      }
+      else
+      {
+        /*
+          We come here when i == 0 && cnt == 0.
+          cnt == 0 => the memory allocator fails to allocate a block of
+          memory of the size mem_per_cache. Decrease the value of
+          mem_per_cache  without changing the current number of partitions
+          and start again. Make sure that such a decrease may happen not
+          more than 5 times in total.
+	*/
+        if (use_mem <= mem_decr)
+          break;
+        use_mem-= mem_decr;
       }
+      i--;
+      mem_per_cache= use_mem/partitions;
+      continue;
+    }
+    else
+    {
+      blocks+= cnt;
+      *partition_ptr++= partition;
     }
-
-    blocks+= cnt;
-    *partition_ptr++= partition;
   } 
 
   keycache->partitions= partitions= partition_ptr-keycache->partition_array;
@@ -5859,7 +5896,7 @@ get_partitioned_key_cache_stat_value(PAR
   ulonglong res= 0;
   DBUG_ENTER("get_partitioned_key_cache_stat_value");
 
-  if (var_no < NO_LONG_KEY_CACHE_STAT_VARIABLES)
+  if (var_no < NUM_LONG_KEY_CACHE_STAT_VARIABLES)
   {
     for (i = 0; i < partitions; i++)
     {

=== modified file 'sql/sql_show.cc'
--- a/sql/sql_show.cc	2010-04-03 20:19:35 +0000
+++ b/sql/sql_show.cc	2010-04-06 02:08:10 +0000
@@ -2265,7 +2265,7 @@ static void update_key_cache_stat_var(KE
   case offsetof(KEY_CACHE, global_cache_read):
   case offsetof(KEY_CACHE, global_cache_w_requests):
   case offsetof(KEY_CACHE, global_cache_write):
-    var_no= NO_LONG_KEY_CACHE_STAT_VARIABLES +
+    var_no= NUM_LONG_KEY_CACHE_STAT_VARIABLES +
             (ofs-offsetof(KEY_CACHE, global_cache_w_requests))/
              sizeof(ulonglong);
     *(ulonglong *)((char *) key_cache + ofs)=