Commit e8b9d8d3 authored by Sergei Golubchik's avatar Sergei Golubchik

MDEV-25530 Error 1451 on slave: Cannot delete or update a parent row: a...

MDEV-25530 Error 1451 on slave: Cannot delete or update a parent row: a foreign key constraint fails

after dfb41fdd tables that failed to drop are excluded from the
binlogged DROP TABLE statement. It means that the slave should not
expect any errors when executing DROP TABLE, and the binlog should
report that no error has happened, even if it was.

Do not write error code into the binlogged DROP TABLE,
and remove all code that was needed to compute it.
parent 65e73b56
...@@ -55,4 +55,21 @@ count(*) ...@@ -55,4 +55,21 @@ count(*)
0 0
connection master; connection master;
drop table t2,t1; drop table t2,t1;
set foreign_key_checks=1;
#
# MDEV-25530 Error 1451 on slave: Cannot delete or update a parent row: a foreign key constraint fails
#
create table t1 (id int primary key)engine=innodb;
create table t2 (id int not null primary key auto_increment,
id2 int default null, key f1 (id2),
constraint f1 foreign key (id2) references t1 (id) on delete cascade) engine=innodb;
drop table t1,t2;
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails
connection slave;
show tables;
Tables_in_test
t1
connection master;
drop table t1;
connection slave;
include/rpl_end.inc include/rpl_end.inc
...@@ -57,5 +57,22 @@ select count(*) from t1 /* must be zero */; ...@@ -57,5 +57,22 @@ select count(*) from t1 /* must be zero */;
connection master; connection master;
drop table t2,t1; drop table t2,t1;
set foreign_key_checks=1;
--echo #
--echo # MDEV-25530 Error 1451 on slave: Cannot delete or update a parent row: a foreign key constraint fails
--echo #
create table t1 (id int primary key)engine=innodb;
create table t2 (id int not null primary key auto_increment,
id2 int default null, key f1 (id2),
constraint f1 foreign key (id2) references t1 (id) on delete cascade) engine=innodb;
error ER_ROW_IS_REFERENCED_2;
drop table t1,t2;
sync_slave_with_master;
show tables;
connection master;
drop table t1;
sync_slave_with_master;
--source include/rpl_end.inc --source include/rpl_end.inc
...@@ -2238,7 +2238,6 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists, ...@@ -2238,7 +2238,6 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists,
uint not_found_errors= 0; uint not_found_errors= 0;
int error= 0; int error= 0;
int non_temp_tables_count= 0; int non_temp_tables_count= 0;
bool non_tmp_error= 0;
bool trans_tmp_table_deleted= 0, non_trans_tmp_table_deleted= 0; bool trans_tmp_table_deleted= 0, non_trans_tmp_table_deleted= 0;
bool non_tmp_table_deleted= 0; bool non_tmp_table_deleted= 0;
bool is_drop_tmp_if_exists_added= 0; bool is_drop_tmp_if_exists_added= 0;
...@@ -2304,7 +2303,7 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists, ...@@ -2304,7 +2303,7 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists,
{ {
bool is_trans= 0, temporary_table_was_dropped= 0; bool is_trans= 0, temporary_table_was_dropped= 0;
bool table_creation_was_logged= 0; bool table_creation_was_logged= 0;
bool local_non_tmp_error= 0, wrong_drop_sequence= 0; bool wrong_drop_sequence= 0;
bool table_dropped= 0; bool table_dropped= 0;
const LEX_CSTRING db= table->db; const LEX_CSTRING db= table->db;
const LEX_CSTRING table_name= table->table_name; const LEX_CSTRING table_name= table->table_name;
...@@ -2469,7 +2468,6 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists, ...@@ -2469,7 +2468,6 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists,
*/ */
wrong_drop_sequence= drop_sequence && hton; wrong_drop_sequence= drop_sequence && hton;
was_table|= wrong_drop_sequence; was_table|= wrong_drop_sequence;
local_non_tmp_error= 1;
error= table_type == TABLE_TYPE_UNKNOWN ? ENOENT : -1; error= table_type == TABLE_TYPE_UNKNOWN ? ENOENT : -1;
tdc_remove_table(thd, db.str, table_name.str); tdc_remove_table(thd, db.str, table_name.str);
} }
...@@ -2562,7 +2560,6 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists, ...@@ -2562,7 +2560,6 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists,
table_dropped= 1; table_dropped= 1;
} }
} }
local_non_tmp_error|= MY_TEST(error);
} }
/* /*
...@@ -2580,8 +2577,6 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists, ...@@ -2580,8 +2577,6 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists,
ferror= ha_delete_table_force(thd, path, &db, &table_name); ferror= ha_delete_table_force(thd, path, &db, &table_name);
if (!ferror) if (!ferror)
{ {
/* Table existed and was deleted */
local_non_tmp_error= 0;
table_dropped= 1; table_dropped= 1;
error= 0; error= 0;
} }
...@@ -2655,12 +2650,7 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists, ...@@ -2655,12 +2650,7 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists,
didn't exists didn't exists
*/ */
if (if_exists && non_existing_table_error(error)) if (if_exists && non_existing_table_error(error))
{
error= 0; error= 0;
local_non_tmp_error= 0;
}
non_tmp_error|= local_non_tmp_error;
if (!error && table_dropped) if (!error && table_dropped)
{ {
...@@ -2774,12 +2764,10 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists, ...@@ -2774,12 +2764,10 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists,
normal_tables.chop(); normal_tables.chop();
built_query.append(normal_tables.ptr(), normal_tables.length()); built_query.append(normal_tables.ptr(), normal_tables.length());
built_query.append(" /* generated by server */"); built_query.append(" /* generated by server */");
int error_code = non_tmp_error ? thd->get_stmt_da()->sql_errno() : 0;
error |= (thd->binlog_query(THD::STMT_QUERY_TYPE, error |= (thd->binlog_query(THD::STMT_QUERY_TYPE,
built_query.ptr(), built_query.ptr(),
built_query.length(), built_query.length(),
TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, 0) > 0);
error_code) > 0);
} }
} }
} }
......
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