MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:hezx Date:December 3 2007 4:48am
Subject:bk commit into 5.0 tree (hezx:1.2557)
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of hezx. When hezx 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-12-03 12:47:28+08:00, hezx@hezx.(none) +3 -0
  #Bug30998 Drop View breaks replication if view does not exist
  
  When executing drop view statement on the master, the statement is written 
  into bin-log without checking for possible errors, so the statement would 
  always be bin-logged with error code 0 even if some error might occur, 
  for example, some of the views being dropped does not exist. This would cause 
  failure on the slave.
  
  Writing bin-log after check for errors, if at least one view has been dropped
  the query is bin-logged possible with an error.

  mysql-test/r/rpl_drop_view.result@stripped, 2007-12-03 12:47:24+08:00, hezx@hezx.(none) +27 -0
    Add test result for bug#30998

  mysql-test/r/rpl_drop_view.result@stripped, 2007-12-03 12:47:24+08:00, hezx@hezx.(none) +0 -0

  mysql-test/t/rpl_drop_view.test@stripped, 2007-12-03 12:47:24+08:00, hezx@hezx.(none) +31 -0
    Add test for bug#30998

  mysql-test/t/rpl_drop_view.test@stripped, 2007-12-03 12:47:24+08:00, hezx@hezx.(none) +0 -0

  sql/sql_view.cc@stripped, 2007-12-03 12:47:23+08:00, hezx@hezx.(none) +19 -13
    Writing bin-log after check for errors, if at least one view has been dropped the query is bin-logged possible with an error.

diff -Nrup a/mysql-test/r/rpl_drop_view.result b/mysql-test/r/rpl_drop_view.result
--- /dev/null	Wed Dec 31 16:00:00 196900
+++ b/mysql-test/r/rpl_drop_view.result	2007-12-03 12:47:24 +08:00
@@ -0,0 +1,27 @@
+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 table if exists t1, t2;
+drop view if exists v1, v2, v3, not_exist_view;
+create table t1 (a int);
+create table t2 (b int);
+create table t3 (c int);
+create view v1 as select * from t1;
+create view v2 as select * from t2;
+create view v3 as select * from t3;
+drop view not_exist_view;
+ERROR 42S02: Unknown table 'not_exist_view'
+drop view v1, not_exist_view;
+ERROR 42S02: Unknown table 'not_exist_view'
+select * from v1;
+ERROR 42S02: Table 'test.v1' doesn't exist
+drop view v2, v3;
+select * from v1;
+ERROR 42S02: Table 'test.v1' doesn't exist
+select * from v2;
+ERROR 42S02: Table 'test.v2' doesn't exist
+select * from v3;
+ERROR 42S02: Table 'test.v3' doesn't exist
diff -Nrup a/mysql-test/t/rpl_drop_view.test b/mysql-test/t/rpl_drop_view.test
--- /dev/null	Wed Dec 31 16:00:00 196900
+++ b/mysql-test/t/rpl_drop_view.test	2007-12-03 12:47:24 +08:00
@@ -0,0 +1,31 @@
+# test case for bug#30998
+# Drop View breaks replication if view does not exist
+#
+
+source include/master-slave.inc;
+--disable_warnings
+drop table if exists t1, t2;
+drop view if exists v1, v2, v3, not_exist_view;
+--enable_warnings
+create table t1 (a int);
+create table t2 (b int);
+create table t3 (c int);
+create view v1 as select * from t1;
+create view v2 as select * from t2;
+create view v3 as select * from t3;
+--error 1051
+drop view not_exist_view;
+--error 1051
+drop view v1, not_exist_view;
+--error 1146
+select * from v1;
+drop view v2, v3;
+save_master_pos;
+connection slave;
+sync_with_master;
+--error 1146
+select * from v1;
+--error 1146
+select * from v2;
+--error 1146
+select * from v3;
diff -Nrup a/sql/sql_view.cc b/sql/sql_view.cc
--- a/sql/sql_view.cc	2007-09-28 03:45:36 +08:00
+++ b/sql/sql_view.cc	2007-12-03 12:47:23 +08:00
@@ -1424,6 +1424,8 @@ bool mysql_drop_view(THD *thd, TABLE_LIS
   String non_existant_views;
   char *wrong_object_db= NULL, *wrong_object_name= NULL;
   bool error= FALSE;
+  bool some_views_deleted= FALSE;
+  bool something_wrong= FALSE;
 
   VOID(pthread_mutex_lock(&LOCK_open));
   for (view= views; view; view= view->next_local)
@@ -1462,33 +1464,37 @@ bool mysql_drop_view(THD *thd, TABLE_LIS
     }
     if (my_delete(path, MYF(MY_WME)))
       error= TRUE;
+    some_views_deleted= TRUE;
     query_cache_invalidate3(thd, view, 0);
     sp_cache_invalidate();
   }
-  if (mysql_bin_log.is_open())
-  {
-    thd->clear_error();
-    Query_log_event qinfo(thd, thd->query, thd->query_length, 0, FALSE);
-    mysql_bin_log.write(&qinfo);
-  }
-
-  VOID(pthread_mutex_unlock(&LOCK_open));
 
-  if (error)
-  {
-    DBUG_RETURN(TRUE);
-  }
   if (wrong_object_name)
   {
     my_error(ER_WRONG_OBJECT, MYF(0), wrong_object_db, wrong_object_name, 
              "VIEW");
-    DBUG_RETURN(TRUE);
   }
   if (non_existant_views.length())
   {
     my_error(ER_BAD_TABLE_ERROR, MYF(0), non_existant_views.c_ptr());
+  }
+
+  something_wrong= error || wrong_object_name || non_existant_views.length();
+  if (some_views_deleted || !something_wrong)
+  {
+    if (!something_wrong)
+      thd->clear_error();
+    Query_log_event qinfo(thd, thd->query, thd->query_length, 0, FALSE);
+    mysql_bin_log.write(&qinfo);
+  }
+
+  VOID(pthread_mutex_unlock(&LOCK_open));
+
+  if (something_wrong)
+  {
     DBUG_RETURN(TRUE);
   }
+
   send_ok(thd);
   DBUG_RETURN(FALSE);
 }
Thread
bk commit into 5.0 tree (hezx:1.2557)hezx3 Dec