List:Commits« Previous MessageNext Message »
From:Ingo Struewing Date:December 31 2009 7:09pm
Subject:bzr commit into mysql-backup-backport branch (ingo.struewing:3020)
Bug#44068 WL#5101
View as plain text  
#At file:///home2/mydev/bzrroot/mysql-5.6-backup-backport-ms09-2/ based on revid:ingo.struewing@stripped

 3020 Ingo Struewing	2009-12-31
      WL#5101 - MySQL Backup back port - MS09
      Merged revid:ingo.struewing@stripped
        Bug#44068 - RESTORE can disable the MyISAM Key Cache
        
        The test case myisam_keycache_coverage used to fail if it ran
        after backup_myisam_sync.
        
        The reason was that the latter test case disabled the key cache
        during RESTORE. The error injection in myisam_keycache_coverage
        became void as the key cache wasn't used any more. Reads of the
        index file bypassed the cache, and the statements succeeded.
        
        Fixed by moving initialization and de-initialization of the key
        cache from mi_examine_log() to myisamlog. In the server, the
        initialization is already done.
        
        Additional change: To make the state of the key cache visible,
        I added cleanup for the status variables blocks_used and
        blocks_unused. This improves the testability.
      
       @ mysql-test/r/myisam_keycache_coverage.result
          Bug#44068 - RESTORE can disable the MyISAM Key Cache
          Updated test result.
      
       @ mysql-test/suite/backup/r/backup_myisam_sync.result
          Bug#44068 - RESTORE can disable the MyISAM Key Cache
          Updated test result.
      
       @ mysql-test/suite/backup/t/backup_myisam_sync.test
          Bug#44068 - RESTORE can disable the MyISAM Key Cache
          Added checks for the state of the key cache.
      
       @ mysql-test/t/myisam_keycache_coverage.test
          Bug#44068 - RESTORE can disable the MyISAM Key Cache
          Added FORCE INDEX to the tested statement.
          Removed old attempts to stabilize the test case.
          Added proper resetting of the debug variable
          to disturb debugging as little as possible.
          Removed clearing of the debug variable.
      
       @ mysys/mf_keycache.c
          Bug#44068 - RESTORE can disable the MyISAM Key Cache
          Added cleanup for blocks_used and blocks_unused.
          Added DBUG.
      
       @ storage/myisam/myisamlog.c
          Bug#44068 - RESTORE can disable the MyISAM Key Cache
          Moved calls to init_key_cache() and end_key_cache()
          from mi_examine_log.c to here.
      
      original changeset: 2599.130.19
     @ mysql-test/r/backup_myisam2.result
        WL#5101 - MySQL Backup back port - MS09
            Bug#44068 - RESTORE can disable the MyISAM Key Cache
            Updated test result.
     @ mysql-test/r/myisam_keycache_coverage.result
        WL#5101 - MySQL Backup back port - MS09
            Bug#44068 - RESTORE can disable the MyISAM Key Cache
            Updated test result.
     @ mysql-test/t/backup_myisam2.test
        WL#5101 - MySQL Backup back port - MS09
            Bug#44068 - RESTORE can disable the MyISAM Key Cache
            Added checks for the state of the key cache.
     @ mysql-test/t/myisam_keycache_coverage.test
        WL#5101 - MySQL Backup back port - MS09
            Bug#44068 - RESTORE can disable the MyISAM Key Cache
            Added FORCE INDEX to the tested statement.
            Removed old attempts to stabilize the test case.
            Added proper resetting of the debug variable
            to disturb debugging as little as possible.
            Removed clearing of the debug variable.
     @ storage/myisam/mi_examine_log.c
        WL#5101 - MySQL Backup back port - MS09
            Bug#44068 - RESTORE can disable the MyISAM Key Cache
            Moved calls to init_key_cache() and end_key_cache()
            from here to myisamlog.c
     @ storage/myisam/myisamlog.c
        WL#5101 - MySQL Backup back port - MS09
            Bug#44068 - RESTORE can disable the MyISAM Key Cache
            Moved calls to init_key_cache() and end_key_cache()
            from mi_examine_log.c to here.

    added:
      mysql-test/r/myisam_keycache_coverage.result
      mysql-test/t/myisam_keycache_coverage.test
    modified:
      mysql-test/r/backup_myisam2.result
      mysql-test/t/backup_myisam2.test
      storage/myisam/mi_examine_log.c
      storage/myisam/myisamlog.c
=== modified file 'mysql-test/r/backup_myisam2.result'
--- a/mysql-test/r/backup_myisam2.result	2009-12-30 20:58:50 +0000
+++ b/mysql-test/r/backup_myisam2.result	2009-12-31 19:09:18 +0000
@@ -37,6 +37,15 @@ length(a)
 checksum table t1;
 Table	Checksum
 mysqltest.t1	1728069308
+
+# Verify that the MyISAM Key Cache is enabled.
+# See Bug#44068 (RESTORE can disable the MyISAM Key Cache).
+SELECT SUM(VARIABLE_VALUE) > 0 AS key_cache_is_enabled
+FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE
+VARIABLE_NAME LIKE 'Key_blocks_%used';
+key_cache_is_enabled
+1
+
 Signal BACKUP to finish
 SET DEBUG_SYNC= 'now SIGNAL bup_finish';
 
@@ -61,3 +70,12 @@ mysqltest.t1	1728069308
 connection default: cleanup
 SET DEBUG_SYNC= 'RESET';
 drop database mysqltest;
+
+# Verify that the MyISAM Key Cache is still enabled.
+# See Bug#44068 (RESTORE can disable the MyISAM Key Cache).
+SELECT SUM(VARIABLE_VALUE) > 0 AS key_cache_is_enabled
+FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE
+VARIABLE_NAME LIKE 'Key_blocks_%used';
+key_cache_is_enabled
+1
+

=== added file 'mysql-test/r/myisam_keycache_coverage.result'
--- a/mysql-test/r/myisam_keycache_coverage.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/myisam_keycache_coverage.result	2009-12-31 19:09:18 +0000
@@ -0,0 +1,57 @@
+call mtr.add_suppression("Incorrect key file for table './test/t1.MYI'");
+call mtr.add_suppression("Got an error from thread_id=.*, mi_update.c");
+call mtr.add_suppression("MySQL thread id .*, query id .* localhost root Updating");
+#
+# MyISAM keycache coverage tests.
+#
+DROP TABLE IF EXISTS t1;
+CREATE TABLE t1 (c1 VARCHAR(5), c2 int) ENGINE=MyISAM;
+CREATE INDEX i1 ON t1 (c1, c2);
+INSERT INTO t1 VALUES ('A',1);
+INSERT INTO t1 SELECT * FROM t1;
+INSERT INTO t1 SELECT * FROM t1;
+INSERT INTO t1 SELECT * FROM t1;
+#
+# Positive tests.
+#
+SELECT COUNT(*) FROM t1 FORCE INDEX(i1) WHERE c2 < 5;
+COUNT(*)
+8
+LOAD INDEX INTO CACHE t1;
+Table	Op	Msg_type	Msg_text
+test.t1	preload_keys	status	OK
+UPDATE t1 SET c2=2;
+#
+# Close table and clear cache.
+#
+FLUSH TABLE t1;
+#
+# Inject error key_cache_read_block_error
+#
+SET debug='+d,key_cache_read_block_error';
+SELECT COUNT(*) FROM t1 FORCE INDEX(i1) WHERE c2 < 5;
+ERROR HY000: Incorrect key file for table 't1.MYI'; try to repair it
+# Reset debug variable to its original value.
+FLUSH TABLE t1;
+#
+# Inject error key_cache_insert_block_error
+#
+SET debug='+d,key_cache_insert_block_error';
+LOAD INDEX INTO CACHE t1;
+Table	Op	Msg_type	Msg_text
+test.t1	preload_keys	error	Failed to read from index file (errno: 5)
+test.t1	preload_keys	status	Operation failed
+# Reset debug variable to its original value.
+FLUSH TABLE t1;
+#
+# Inject error key_cache_write_block_error
+#
+SET debug='+d,key_cache_write_block_error';
+UPDATE t1 SET c2=1;
+ERROR HY000: Incorrect key file for table 't1.MYI'; try to repair it
+# Reset debug variable to its original value.
+FLUSH TABLE t1;
+#
+# Cleanup
+#
+DROP TABLE t1;

=== modified file 'mysql-test/t/backup_myisam2.test'
--- a/mysql-test/t/backup_myisam2.test	2009-12-30 20:58:50 +0000
+++ b/mysql-test/t/backup_myisam2.test	2009-12-31 19:09:18 +0000
@@ -53,6 +53,14 @@ while ($1)
 select length(a) from t1;
 checksum table t1;
 
+--echo
+--echo # Verify that the MyISAM Key Cache is enabled.
+--echo # See Bug#44068 (RESTORE can disable the MyISAM Key Cache).
+SELECT SUM(VARIABLE_VALUE) > 0 AS key_cache_is_enabled
+  FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE
+  VARIABLE_NAME LIKE 'Key_blocks_%used';
+--echo
+
 --echo Signal BACKUP to finish
 SET DEBUG_SYNC= 'now SIGNAL bup_finish';
 
@@ -80,3 +88,11 @@ SET DEBUG_SYNC= 'RESET';
 drop database mysqltest;
 --remove_file $MYSQLD_BACKUPDIR/test.ba
 
+--echo
+--echo # Verify that the MyISAM Key Cache is still enabled.
+--echo # See Bug#44068 (RESTORE can disable the MyISAM Key Cache).
+SELECT SUM(VARIABLE_VALUE) > 0 AS key_cache_is_enabled
+  FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE
+  VARIABLE_NAME LIKE 'Key_blocks_%used';
+--echo
+

=== added file 'mysql-test/t/myisam_keycache_coverage.test'
--- a/mysql-test/t/myisam_keycache_coverage.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/myisam_keycache_coverage.test	2009-12-31 19:09:18 +0000
@@ -0,0 +1,76 @@
+call mtr.add_suppression("Incorrect key file for table './test/t1.MYI'");
+call mtr.add_suppression("Got an error from thread_id=.*, mi_update.c");
+call mtr.add_suppression("MySQL thread id .*, query id .* localhost root Updating");
+
+--echo #
+--echo # MyISAM keycache coverage tests.
+--echo #
+
+--source include/have_debug.inc
+let $debug= `SELECT @@debug`;
+
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+--enable_warnings
+
+CREATE TABLE t1 (c1 VARCHAR(5), c2 int) ENGINE=MyISAM;
+CREATE INDEX i1 ON t1 (c1, c2);
+INSERT INTO t1 VALUES ('A',1);
+INSERT INTO t1 SELECT * FROM t1;
+INSERT INTO t1 SELECT * FROM t1;
+INSERT INTO t1 SELECT * FROM t1;
+
+--echo #
+--echo # Positive tests.
+--echo #
+SELECT COUNT(*) FROM t1 FORCE INDEX(i1) WHERE c2 < 5;
+LOAD INDEX INTO CACHE t1;
+UPDATE t1 SET c2=2;
+
+--echo #
+--echo # Close table and clear cache.
+--echo #
+FLUSH TABLE t1;
+
+--echo #
+--echo # Inject error key_cache_read_block_error
+--echo #
+SET debug='+d,key_cache_read_block_error';
+--replace_regex /'.*[\/\\]/'/
+--error 126
+SELECT COUNT(*) FROM t1 FORCE INDEX(i1) WHERE c2 < 5;
+--echo # Reset debug variable to its original value.
+--disable_query_log
+eval SET debug= '$debug';
+--enable_query_log
+FLUSH TABLE t1;
+
+--echo #
+--echo # Inject error key_cache_insert_block_error
+--echo #
+SET debug='+d,key_cache_insert_block_error';
+LOAD INDEX INTO CACHE t1;
+--echo # Reset debug variable to its original value.
+--disable_query_log
+eval SET debug= '$debug';
+--enable_query_log
+FLUSH TABLE t1;
+
+--echo #
+--echo # Inject error key_cache_write_block_error
+--echo #
+SET debug='+d,key_cache_write_block_error';
+--replace_regex /'.*[\/\\]/'/
+--error 126
+UPDATE t1 SET c2=1;
+--echo # Reset debug variable to its original value.
+--disable_query_log
+eval SET debug= '$debug';
+--enable_query_log
+FLUSH TABLE t1;
+
+--echo #
+--echo # Cleanup
+--echo #
+DROP TABLE t1;
+

=== modified file 'storage/myisam/mi_examine_log.c'
--- a/storage/myisam/mi_examine_log.c	2009-12-31 16:09:59 +0000
+++ b/storage/myisam/mi_examine_log.c	2009-12-31 19:09:18 +0000
@@ -145,6 +145,9 @@ void mi_examine_log_param_init(MI_EXAMIN
   them.
   Is used both by the standalone program myisamlog and by the restore
   code of the MyISAM online backup driver.
+  An initialized key cache may accelerate this function. The MySQL server
+  has a key cache initialized anyway. For other programs it is recommended
+  to set up a key cache before calling this function.
 
   @param  mi_exl           Parameters of the applying
 
@@ -208,8 +211,6 @@ int mi_examine_log(MI_EXAMINE_LOG_PARAM 
   bzero(mi_exl->com_count,sizeof(mi_exl->com_count));
   init_tree(&tree,0,0,sizeof(file_info),(qsort_cmp2) file_info_compare,1,
 	    (tree_element_free) file_info_free, NULL);
-  (void) init_key_cache(dflt_key_cache,KEY_CACHE_BLOCK_SIZE,KEY_CACHE_SIZE,
-                        0, 0);
 
   /*
     Initialize members of file_info that are used for pointing to
@@ -778,7 +779,6 @@ int mi_examine_log(MI_EXAMINE_LOG_PARAM 
   }
   DBUG_PRINT("myisamlog", ("end loop access_time: %lu  cmd_cnt: %lu",
                            access_time, mi_exl->number_of_commands));
-  end_key_cache(dflt_key_cache,1);
   delete_tree(&tree);
   (void) end_io_cache(&cache);
   (void) mysql_file_close(log_file,MYF(0));
@@ -803,7 +803,6 @@ int mi_examine_log(MI_EXAMINE_LOG_PARAM 
   fflush(stderr);
  end:
   DBUG_PRINT("myisamlog", ("end label"));
-  end_key_cache(dflt_key_cache, 1);
   delete_tree(&tree);
   (void) end_io_cache(&cache);
   (void) mysql_file_close(log_file,MYF(0));

=== modified file 'storage/myisam/myisamlog.c'
--- a/storage/myisam/myisamlog.c	2009-12-31 16:09:59 +0000
+++ b/storage/myisam/myisamlog.c	2009-12-31 19:09:18 +0000
@@ -80,9 +80,19 @@ int main(int argc, char **argv)
     printf("Trying to %s MyISAM files according to log '%s'\n",
 	   (mi_exl.recover ? "recover" : "update"),mi_exl.log_filename);
 
+  /*
+    mi_examine_log() may work faster with an initialized key cache.
+    But it works also if the initialization fails.
+  */
+  (void) init_key_cache(dflt_key_cache, KEY_CACHE_BLOCK_SIZE,
+                        KEY_CACHE_SIZE, 0, 0);
+
   error= mi_examine_log(&mi_exl);
   DBUG_PRINT("myisamlog", ("error from mi_examine_log: %d", error));
 
+  /* Free resources that might be used by the key cache. */
+  end_key_cache(dflt_key_cache, 1);
+
   if (mi_exl.update && ! error)
     puts("Tables updated successfully");
   total_count=total_error=total_recover=0;


Attachment: [text/bzr-bundle] bzr/ingo.struewing@sun.com-20091231190918-udxpg1ylezde0ayo.bundle
Thread
bzr commit into mysql-backup-backport branch (ingo.struewing:3020)Bug#44068 WL#5101Ingo Struewing31 Dec