MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:ingo Date:May 31 2007 6:05pm
Subject:bk commit into 5.0 tree (istruewing:1.2466) BUG#28478
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of istruewing. When istruewing does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet@stripped, 2007-05-31 20:04:54+02:00, istruewing@stripped +4 -0
  Bug#28478 - Improper key_cache_block_size corrupts MyISAM tables
  
  Setting a key_cache_block_size which is not a power of 2
  could corrupt MyISAM tables.
  
  A couple of computations in the key cache code use bit
  operations which do only work if key_cache_block_size
  is a power of 2.
  
  Replaced bit operations by arithmetic operations
  to make key cache able to handle block sizes that are
  not a power of 2.

  include/keycache.h@stripped, 2007-05-31 20:04:51+02:00, istruewing@stripped +0 -1
    Bug#28478 - Improper key_cache_block_size corrupts MyISAM tables
    Removed element 'key_cache_shift' from KEY_CACHE after
    the changes in mf_keycache.c made it unused.

  mysql-test/r/key_cache.result@stripped, 2007-05-31 20:04:51+02:00, istruewing@stripped +27 -0
    Bug#28478 - Improper key_cache_block_size corrupts MyISAM tables
    Added test result

  mysql-test/t/key_cache.test@stripped, 2007-05-31 20:04:51+02:00, istruewing@stripped +27 -0
    Bug#28478 - Improper key_cache_block_size corrupts MyISAM tables
    Added test

  mysys/mf_keycache.c@stripped, 2007-05-31 20:04:51+02:00, istruewing@stripped +5 -6
    Bug#28478 - Improper key_cache_block_size corrupts MyISAM tables
    Replaced bit operations by arithmetic operations
    to make key cache able to handle block sizes that are
    not a power of 2.

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	istruewing
# Host:	chilla.local
# Root:	/home/mydev/mysql-5.0-bug23068

--- 1.62/mysys/mf_keycache.c	2007-05-31 20:05:01 +02:00
+++ 1.63/mysys/mf_keycache.c	2007-05-31 20:05:01 +02:00
@@ -173,7 +173,7 @@ static void test_key_cache(KEY_CACHE *ke
 #endif
 
 #define KEYCACHE_HASH(f, pos)                                                 \
-(((ulong) ((pos) >> keycache->key_cache_shift)+                               \
+(((ulong) ((pos) / keycache->key_cache_block_size) +                          \
                                      (ulong) (f)) & (keycache->hash_entries-1))
 #define FILE_HASH(f)                 ((uint) (f) & (CHANGED_BLOCKS_HASH-1))
 
@@ -329,7 +329,6 @@ int init_key_cache(KEY_CACHE *keycache, 
 
   keycache->key_cache_mem_size= use_mem;
   keycache->key_cache_block_size= key_cache_block_size;
-  keycache->key_cache_shift= my_bit_log2(key_cache_block_size);
   DBUG_PRINT("info", ("key_cache_block_size: %u",
 		      key_cache_block_size));
 
@@ -352,7 +351,7 @@ int init_key_cache(KEY_CACHE *keycache, 
 		       ALIGN_SIZE(hash_links * sizeof(HASH_LINK)) +
 		       ALIGN_SIZE(sizeof(HASH_LINK*) *
                                   keycache->hash_entries))) +
-	     ((ulong) blocks << keycache->key_cache_shift) > use_mem)
+	     ((ulong) blocks * keycache->key_cache_block_size) > use_mem)
         blocks--;
       /* Allocate memory for cache page buffers */
       if ((keycache->block_mem=
@@ -1807,7 +1806,7 @@ byte *key_cache_read(KEY_CACHE *keycache
     uint status;
     int page_st;
 
-    offset= (uint) (filepos & (keycache->key_cache_block_size-1));
+    offset= (uint) (filepos % keycache->key_cache_block_size);
     /* Read data in key_cache_block_size increments */
     do
     {
@@ -1946,7 +1945,7 @@ int key_cache_insert(KEY_CACHE *keycache
     int error;
     uint offset;
 
-    offset= (uint) (filepos & (keycache->key_cache_block_size-1));
+    offset= (uint) (filepos % keycache->key_cache_block_size);
     do
     {
       keycache_pthread_mutex_lock(&keycache->cache_lock);
@@ -2081,7 +2080,7 @@ int key_cache_write(KEY_CACHE *keycache,
     int page_st;
     uint offset;
 
-    offset= (uint) (filepos & (keycache->key_cache_block_size-1));
+    offset= (uint) (filepos % keycache->key_cache_block_size);
     do
     {
       keycache_pthread_mutex_lock(&keycache->cache_lock);

--- 1.20/mysql-test/r/key_cache.result	2007-05-31 20:05:01 +02:00
+++ 1.21/mysql-test/r/key_cache.result	2007-05-31 20:05:01 +02:00
@@ -341,3 +341,30 @@ Warning	1438	Cannot drop default keycach
 select @@global.key_buffer_size;
 @@global.key_buffer_size
 2097152
+SET @bug28478_key_cache_block_size= @@global.key_cache_block_size;
+SET GLOBAL key_cache_block_size= 1536;
+CREATE TABLE t1 (
+id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+c1 CHAR(150),
+c2 CHAR(150),
+c3 CHAR(150),
+KEY(c1, c2, c3)
+) ENGINE= MyISAM;
+INSERT INTO t1 (c1, c2, c3) VALUES
+('a', 'b', 'c'), ('b', 'c', 'd'), ('c', 'd', 'e'), ('d', 'e', 'f'),
+('e', 'f', 'g'), ('f', 'g', 'h'), ('g', 'h', 'i'), ('h', 'i', 'j'),
+('i', 'j', 'k'), ('j', 'k', 'l'), ('k', 'l', 'm'), ('l', 'm', 'n'),
+('m', 'n', 'o'), ('n', 'o', 'p'), ('o', 'p', 'q'), ('p', 'q', 'r'),
+('q', 'r', 's'), ('r', 's', 't'), ('s', 't', 'u'), ('t', 'u', 'v'),
+('u', 'v', 'w'), ('v', 'w', 'x'), ('w', 'x', 'y'), ('x', 'y', 'z');
+INSERT INTO t1 (c1, c2, c3) SELECT c1, c2, c3 from t1;
+INSERT INTO t1 (c1, c2, c3) SELECT c1, c2, c3 from t1;
+INSERT INTO t1 (c1, c2, c3) SELECT c1, c2, c3 from t1;
+CHECK TABLE t1;
+Table	Op	Msg_type	Msg_text
+test.t1	check	status	OK
+SHOW VARIABLES LIKE 'key_cache_block_size';
+Variable_name	Value
+key_cache_block_size	1536
+SET GLOBAL key_cache_block_size= @bug28478_key_cache_block_size;
+DROP TABLE t1;

--- 1.19/mysql-test/t/key_cache.test	2007-05-31 20:05:01 +02:00
+++ 1.20/mysql-test/t/key_cache.test	2007-05-31 20:05:01 +02:00
@@ -219,4 +219,31 @@ set global key_cache_block_size= @my_key
 set @@global.key_buffer_size=0;
 select @@global.key_buffer_size;
 
+#
+# Bug#28478 - Improper key_cache_block_size corrupts MyISAM tables
+#
+SET @bug28478_key_cache_block_size= @@global.key_cache_block_size;
+SET GLOBAL key_cache_block_size= 1536;
+CREATE TABLE t1 (
+  id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+  c1 CHAR(150),
+  c2 CHAR(150),
+  c3 CHAR(150),
+  KEY(c1, c2, c3)
+  ) ENGINE= MyISAM;
+INSERT INTO t1 (c1, c2, c3) VALUES
+  ('a', 'b', 'c'), ('b', 'c', 'd'), ('c', 'd', 'e'), ('d', 'e', 'f'),
+  ('e', 'f', 'g'), ('f', 'g', 'h'), ('g', 'h', 'i'), ('h', 'i', 'j'),
+  ('i', 'j', 'k'), ('j', 'k', 'l'), ('k', 'l', 'm'), ('l', 'm', 'n'),
+  ('m', 'n', 'o'), ('n', 'o', 'p'), ('o', 'p', 'q'), ('p', 'q', 'r'),
+  ('q', 'r', 's'), ('r', 's', 't'), ('s', 't', 'u'), ('t', 'u', 'v'),
+  ('u', 'v', 'w'), ('v', 'w', 'x'), ('w', 'x', 'y'), ('x', 'y', 'z');
+INSERT INTO t1 (c1, c2, c3) SELECT c1, c2, c3 from t1;
+INSERT INTO t1 (c1, c2, c3) SELECT c1, c2, c3 from t1;
+INSERT INTO t1 (c1, c2, c3) SELECT c1, c2, c3 from t1;
+CHECK TABLE t1;
+SHOW VARIABLES LIKE 'key_cache_block_size';
+SET GLOBAL key_cache_block_size= @bug28478_key_cache_block_size;
+DROP TABLE t1;
+
 # End of 4.1 tests

--- 1.7/include/keycache.h	2007-05-31 20:05:01 +02:00
+++ 1.8/include/keycache.h	2007-05-31 20:05:01 +02:00
@@ -46,7 +46,6 @@ typedef struct st_key_cache
   my_bool key_cache_inited;
   my_bool resize_in_flush;       /* true during flush of resize operation    */
   my_bool can_be_used;           /* usage of cache for read/write is allowed */
-  uint key_cache_shift;
   ulong key_cache_mem_size;      /* specified size of the cache memory       */
   uint key_cache_block_size;     /* size of the page buffer of a cache block */
   ulong min_warm_blocks;         /* min number of warm blocks;               */
Thread
bk commit into 5.0 tree (istruewing:1.2466) BUG#28478ingo31 May