List:Commits« Previous MessageNext Message »
From:Li-Bing.Song Date:September 18 2009 1:20am
Subject:bzr commit into mysql-5.1-bugteam branch (Li-Bing.Song:3111) Bug#43579
View as plain text  
#At file:///home/anders/work/bzrwork/September/Bug43579/mysql-5.1-bugteam/ based on revid:joro@stripped

 3111 Li-Bing.Song@stripped	2009-09-18
      BUG#43579 mysql_upgrade tries to alter log tables on replicated database 
      
      All statements executed by mysql_upgrade are binlogged and then are replicated to slave.
      This will result in some errors. The report of this bug has demonstrated some examples.
      
      Master and slave should be upgraded separately. All statements executed by
      mysql_upgrade will not be binlogged. It can be done by that msql_upgrade
      assigns 0 to session.sql_log_bin before any statements are executed

    added:
      mysql-test/include/have_mysql_upgrade.inc
      mysql-test/suite/rpl/r/rpl_mysql_upgrade.result
      mysql-test/suite/rpl/t/rpl_mysql_upgrade.test
    modified:
      client/client_priv.h
      client/mysql_upgrade.c
      client/mysqlcheck.c
=== modified file 'client/client_priv.h'
--- a/client/client_priv.h	2008-01-31 16:46:50 +0000
+++ b/client/client_priv.h	2009-09-18 01:20:36 +0000
@@ -80,5 +80,6 @@ enum options_client
   OPT_FIX_TABLE_NAMES, OPT_FIX_DB_NAMES, OPT_SSL_VERIFY_SERVER_CERT,
   OPT_DEBUG_INFO, OPT_DEBUG_CHECK, OPT_COLUMN_TYPES, OPT_ERROR_LOG_FILE,
   OPT_WRITE_BINLOG, OPT_DUMP_DATE,
+  OPT_DISABLE_BINLOG,
   OPT_MAX_CLIENT_OPTION
 };

=== modified file 'client/mysql_upgrade.c'
--- a/client/mysql_upgrade.c	2009-08-28 16:21:54 +0000
+++ b/client/mysql_upgrade.c	2009-09-18 01:20:36 +0000
@@ -448,6 +448,8 @@ static int run_query(const char *query, 
   int ret;
   File fd;
   char query_file_path[FN_REFLEN];
+  const uchar * sql_log_bin= "SET SQL_LOG_BIN=0;";
+
   DBUG_ENTER("run_query");
   DBUG_PRINT("enter", ("query: %s", query));
   if ((fd= create_temp_file(query_file_path, opt_tmpdir,
@@ -455,6 +457,19 @@ static int run_query(const char *query, 
                             MYF(MY_WME))) < 0)
     die("Failed to create temporary file for defaults");
 
+  /*
+    Master and slave should be upgraded separately. All statements executed
+    by mysql_upgrade will not be binlogged.
+    'SET SQL_LOG_BIN=0' is executed before any other statements.
+   */
+  if (my_write(fd, sql_log_bin, strlen(sql_log_bin),
+               MYF(MY_FNABP | MY_WME)))
+  {
+    my_close(fd, MYF(0));
+    my_delete(query_file_path, MYF(0));
+    die("Failed to write to '%s'", query_file_path);
+  }
+
   if (my_write(fd, (uchar*) query, strlen(query),
                MYF(MY_FNABP | MY_WME)))
   {
@@ -648,6 +663,7 @@ static int run_mysqlcheck_upgrade(void)
                   "--check-upgrade",
                   "--all-databases",
                   "--auto-repair",
+                  "--disable-binlog",
                   NULL);
 }
 
@@ -662,6 +678,7 @@ static int run_mysqlcheck_fixnames(void)
                   "--all-databases",
                   "--fix-db-names",
                   "--fix-table-names",
+                  "--disable-binlog",
                   NULL);
 }
 

=== modified file 'client/mysqlcheck.c'
--- a/client/mysqlcheck.c	2009-07-14 17:08:38 +0000
+++ b/client/mysqlcheck.c	2009-09-18 01:20:36 +0000
@@ -35,6 +35,7 @@ static my_bool opt_alldbs = 0, opt_check
                opt_silent = 0, opt_auto_repair = 0, ignore_errors = 0,
                tty_password= 0, opt_frm= 0, debug_info_flag= 0, debug_check_flag= 0,
                opt_fix_table_names= 0, opt_fix_db_names= 0, opt_upgrade= 0,
+               opt_disable_binlog= 0,
                opt_write_binlog= 1;
 static uint verbose = 0, opt_mysql_port=0;
 static int my_end_arg;
@@ -131,6 +132,10 @@ static struct my_option my_long_options[
    "Log ANALYZE, OPTIMIZE and REPAIR TABLE commands. Enabled by default; use --skip-write-binlog when commands should not be sent to replication slaves.",
    (uchar**) &opt_write_binlog, (uchar**) &opt_write_binlog, 0, GET_BOOL, NO_ARG,
    1, 0, 0, 0, 0, 0},
+  {"disable-binlog", OPT_DISABLE_BINLOG,
+   "This option assigns 0 to session.sql_log_bin, All commands including ANALYZE, OPTIMIZE and REPAIR are not binlogged and write-binlog is always invalid when disable-binlog is set.",
+   (uchar**) &opt_disable_binlog, (uchar**) &opt_disable_binlog, 0, GET_BOOL, NO_ARG,
+   0, 0, 0, 0, 0, 0},
   {"optimize", 'o', "Optimize table.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0,
    0, 0},
   {"password", 'p',
@@ -652,6 +657,17 @@ static int use_db(char *database)
   return 0;
 } /* use_db */
 
+static int disable_binlog()
+{
+  const char *stmt= "SET SQL_LOG_BIN=0";
+  if (mysql_query(sock, stmt))
+  {
+    fprintf(stderr, "Failed to %s\n", stmt);
+    fprintf(stderr, "Error: %s\n", mysql_error(sock));
+    return 1;
+  }
+  return 0;
+}
 
 static int handle_request_for_tables(char *tables, uint length)
 {
@@ -844,6 +860,15 @@ int main(int argc, char **argv)
   if (dbConnect(current_host, current_user, opt_password))
     exit(EX_MYSQLERR);
 
+  if (opt_disable_binlog)
+  {
+    if (disable_binlog()) {
+      first_error= 1;
+      goto end;
+    }
+    opt_write_binlog= 0;
+  }
+
   if (opt_auto_repair &&
       my_init_dynamic_array(&tables4repair, sizeof(char)*(NAME_LEN*2+2),16,64))
   {

=== added file 'mysql-test/include/have_mysql_upgrade.inc'
--- a/mysql-test/include/have_mysql_upgrade.inc	1970-01-01 00:00:00 +0000
+++ b/mysql-test/include/have_mysql_upgrade.inc	2009-09-18 01:20:36 +0000
@@ -0,0 +1,4 @@
+--require r/have_mysql_upgrade.result
+--disable_query_log
+select LENGTH("$MYSQL_UPGRADE")>0 as have_mysql_upgrade;
+--enable_query_log

=== added file 'mysql-test/suite/rpl/r/rpl_mysql_upgrade.result'
--- a/mysql-test/suite/rpl/r/rpl_mysql_upgrade.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/rpl/r/rpl_mysql_upgrade.result	2009-09-18 01:20:36 +0000
@@ -0,0 +1,12 @@
+stop slave;
+drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
+reset master;
+reset slave;
+drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
+start slave;
+DROP DATABASE IF EXISTS `#mysql50#mysqltest-1`;
+CREATE DATABASE `#mysql50#mysqltest-1`;
+Master file is not changed
+Master position is not changed
+DROP DATABASE `mysqltest-1`;
+DROP DATABASE `#mysql50#mysqltest-1`;

=== added file 'mysql-test/suite/rpl/t/rpl_mysql_upgrade.test'
--- a/mysql-test/suite/rpl/t/rpl_mysql_upgrade.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/rpl/t/rpl_mysql_upgrade.test	2009-09-18 01:20:36 +0000
@@ -0,0 +1,43 @@
+#############################################################################
+# BUG#43579 mysql_upgrade tries to alter log tables on replicated database
+# Master and slave should be upgraded separately.  All statements executed by
+# mysql_upgrade will not be binlogged.  It can be done by that msql_upgrade
+# assigns 0 to session.sql_log_bin before any statements are executed.
+# ###########################################################################
+--source include/master-slave.inc
+
+# Only run test if "mysql_upgrade" is found
+--source include/have_mysql_upgrade.inc
+
+connection master;
+--disable_warnings
+DROP DATABASE IF EXISTS `#mysql50#mysqltest-1`;
+CREATE DATABASE `#mysql50#mysqltest-1`;
+--enable_warnings
+sync_slave_with_master;
+
+connection master;
+let $before_file= query_get_value(SHOW MASTER STATUS, File, 1);
+let $before_position= query_get_value(SHOW MASTER STATUS, Position, 1);
+
+#With '--force' option, mysql_upgrade always executes all sql statements for upgrading.
+--exec $MYSQL_UPGRADE --skip-verbose --force --user=root > $MYSQLTEST_VARDIR/log/mysql_upgrade.log 2>&1
+sync_slave_with_master;
+
+connection master;
+let $after_file= query_get_value(SHOW MASTER STATUS, File, 1);
+let $after_position= query_get_value(SHOW MASTER STATUS, Position, 1);
+
+if (`SELECT '$before_file'='$after_file'`) 
+{
+  echo Master file is not changed;
+}
+if (`SELECT '$before_position'='$after_position'`)
+{
+  echo Master position is not changed;
+}
+
+DROP DATABASE `mysqltest-1`;
+connection slave;
+DROP DATABASE `#mysql50#mysqltest-1`;
+--source include/master-slave-end.inc


Attachment: [text/bzr-bundle] bzr/li-bing.song@sun.com-20090918012036-frrc8bwxfutqu0b8.bundle
Thread
bzr commit into mysql-5.1-bugteam branch (Li-Bing.Song:3111) Bug#43579Li-Bing.Song18 Sep
  • Re: bzr commit into mysql-5.1-bugteam branch (Li-Bing.Song:3111)Bug#43579He Zhenxing18 Sep
    • Re: bzr commit into mysql-5.1-bugteam branch (Li-Bing.Song:3111)Bug#43579Andrei Elkin21 Sep