Commit df35f2c3 authored by unknown's avatar unknown

Bug#30998 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 cleared 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.


sql/sql_view.cc:
  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:
  Add test result for bug#30998
mysql-test/t/rpl_drop_view.test:
  Add test for bug#30998
parent fff22e09
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
# 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;
...@@ -1424,6 +1424,8 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode) ...@@ -1424,6 +1424,8 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode)
String non_existant_views; String non_existant_views;
char *wrong_object_db= NULL, *wrong_object_name= NULL; char *wrong_object_db= NULL, *wrong_object_name= NULL;
bool error= FALSE; bool error= FALSE;
bool some_views_deleted= FALSE;
bool something_wrong= FALSE;
VOID(pthread_mutex_lock(&LOCK_open)); VOID(pthread_mutex_lock(&LOCK_open));
for (view= views; view; view= view->next_local) for (view= views; view; view= view->next_local)
...@@ -1462,33 +1464,37 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode) ...@@ -1462,33 +1464,37 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode)
} }
if (my_delete(path, MYF(MY_WME))) if (my_delete(path, MYF(MY_WME)))
error= TRUE; error= TRUE;
some_views_deleted= TRUE;
query_cache_invalidate3(thd, view, 0); query_cache_invalidate3(thd, view, 0);
sp_cache_invalidate(); 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) if (wrong_object_name)
{ {
my_error(ER_WRONG_OBJECT, MYF(0), wrong_object_db, wrong_object_name, my_error(ER_WRONG_OBJECT, MYF(0), wrong_object_db, wrong_object_name,
"VIEW"); "VIEW");
DBUG_RETURN(TRUE);
} }
if (non_existant_views.length()) if (non_existant_views.length())
{ {
my_error(ER_BAD_TABLE_ERROR, MYF(0), non_existant_views.c_ptr()); 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); DBUG_RETURN(TRUE);
} }
send_ok(thd); send_ok(thd);
DBUG_RETURN(FALSE); DBUG_RETURN(FALSE);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment