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.
This commit is contained in:
parent
6168d3e14f
commit
c267a923a3
27
mysql-test/r/rpl_drop_view.result
Normal file
27
mysql-test/r/rpl_drop_view.result
Normal file
@ -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
|
31
mysql-test/t/rpl_drop_view.test
Normal file
31
mysql-test/t/rpl_drop_view.test
Normal file
@ -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;
|
@ -1424,6 +1424,8 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode)
|
||||
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_LIST *views, enum_drop_mode drop_mode)
|
||||
}
|
||||
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())
|
||||
|
||||
if (wrong_object_name)
|
||||
{
|
||||
thd->clear_error();
|
||||
my_error(ER_WRONG_OBJECT, MYF(0), wrong_object_db, wrong_object_name,
|
||||
"VIEW");
|
||||
}
|
||||
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 (error)
|
||||
if (something_wrong)
|
||||
{
|
||||
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());
|
||||
DBUG_RETURN(TRUE);
|
||||
}
|
||||
|
||||
send_ok(thd);
|
||||
DBUG_RETURN(FALSE);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user