[Commits] 4668cbd6c09: MDEV-24351: S3, same-backend replication: Dropping a table on master...
revision-id: 4668cbd6c09a70c0793bd2495ce782bfc76a1038 (mariadb-10.5.4-375-g4668cbd6c09) parent(s): aa0e3805681552cff5dced141f695c96a4da872f author: Sergei Petrunia committer: Sergei Petrunia timestamp: 2020-12-08 16:51:14 +0300 message: MDEV-24351: S3, same-backend replication: Dropping a table on master... ..causes error on slave. Cause: if the master doesn't have the frm file for the table, DROP TABLE code will call ha_delete_table_force() to drop the table in all available storage engines. The issue was that this code path didn't check for HTON_TABLE_MAY_NOT_EXIST_ON_SLAVE flag for the storage engine, and so did not add "... IF EXISTS" to the statement that's written to the binary log. This can cause error on the slave when it tries to drop a table that's already gone. --- mysql-test/suite/s3/replication.inc | 20 ++++++++++++++++++++ mysql-test/suite/s3/replication_mixed.result | 20 ++++++++++++++++++++ mysql-test/suite/s3/replication_stmt.result | 20 ++++++++++++++++++++ sql/handler.cc | 2 ++ sql/sql_table.cc | 15 +++++++++++---- 5 files changed, 73 insertions(+), 4 deletions(-) diff --git a/mysql-test/suite/s3/replication.inc b/mysql-test/suite/s3/replication.inc index d790c70f221..d30733a4396 100644 --- a/mysql-test/suite/s3/replication.inc +++ b/mysql-test/suite/s3/replication.inc @@ -179,6 +179,26 @@ sync_slave_with_master; --source include/show_binlog_events.inc connection master; +--echo # +--echo # MDEV-24351: S3, same-backend replication: Dropping a table on master +--echo # causes error on slave +--echo # +show variables like 's3_replicate_alter_as_create_select'; + +connection slave; +create table t3 (a int, b int) engine=aria; +insert into t3 values (1,1),(2,2),(3,3); +alter table t3 engine=s3; + +connection master; +let $binlog_start= query_get_value("SHOW MASTER STATUS", Position, 1); +drop table t3; +--echo # Must show "DROP TABLE IF EXISTS t3", not just "DROP TABLE t3" +--source include/show_binlog_events.inc + +sync_slave_with_master; +connection master; + --echo # --echo # clean up --echo # diff --git a/mysql-test/suite/s3/replication_mixed.result b/mysql-test/suite/s3/replication_mixed.result index 077ae2bf1f9..66ed24d2626 100644 --- a/mysql-test/suite/s3/replication_mixed.result +++ b/mysql-test/suite/s3/replication_mixed.result @@ -272,6 +272,26 @@ slave-bin.000001 # Gtid # # GTID #-#-# slave-bin.000001 # Query # # use `database`; DROP TABLE IF EXISTS `t1`,`t2` /* generated by server */ connection master; # +# MDEV-24351: S3, same-backend replication: Dropping a table on master +# causes error on slave +# +show variables like 's3_replicate_alter_as_create_select'; +Variable_name Value +s3_replicate_alter_as_create_select ON +connection slave; +create table t3 (a int, b int) engine=aria; +insert into t3 values (1,1),(2,2),(3,3); +alter table t3 engine=s3; +connection master; +drop table t3; +# Must show "DROP TABLE IF EXISTS t3", not just "DROP TABLE t3" +include/show_binlog_events.inc +Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `database`; DROP TABLE IF EXISTS `t3` /* generated by server */ +connection slave; +connection master; +# # clean up # connection slave; diff --git a/mysql-test/suite/s3/replication_stmt.result b/mysql-test/suite/s3/replication_stmt.result index 8284c053cac..077029e2d7d 100644 --- a/mysql-test/suite/s3/replication_stmt.result +++ b/mysql-test/suite/s3/replication_stmt.result @@ -272,6 +272,26 @@ slave-bin.000001 # Gtid # # GTID #-#-# slave-bin.000001 # Query # # use `database`; DROP TABLE IF EXISTS `t1`,`t2` /* generated by server */ connection master; # +# MDEV-24351: S3, same-backend replication: Dropping a table on master +# causes error on slave +# +show variables like 's3_replicate_alter_as_create_select'; +Variable_name Value +s3_replicate_alter_as_create_select ON +connection slave; +create table t3 (a int, b int) engine=aria; +insert into t3 values (1,1),(2,2),(3,3); +alter table t3 engine=s3; +connection master; +drop table t3; +# Must show "DROP TABLE IF EXISTS t3", not just "DROP TABLE t3" +include/show_binlog_events.inc +Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `database`; DROP TABLE IF EXISTS `t3` /* generated by server */ +connection slave; +connection master; +# # clean up # connection slave; diff --git a/sql/handler.cc b/sql/handler.cc index 314fe7acb8c..bdf6011c364 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -5020,6 +5020,8 @@ static my_bool delete_table_force(THD *thd, plugin_ref plugin, void *arg) param->error= error; if (error == 0) { + if (hton && hton->flags & HTON_TABLE_MAY_NOT_EXIST_ON_SLAVE) + thd->replication_flags |= OPTION_IF_EXISTS; param->error= 0; return TRUE; // Table was deleted } diff --git a/sql/sql_table.cc b/sql/sql_table.cc index b8c51f05f77..318c01bb1dc 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -2424,6 +2424,7 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists, // note that for TABLE_TYPE_VIEW and TABLE_TYPE_UNKNOWN hton == NULL } + thd->replication_flags= 0; was_view= table_type == TABLE_TYPE_VIEW; if ((table_type == TABLE_TYPE_UNKNOWN) || (was_view && !drop_view) || (table_type != TABLE_TYPE_SEQUENCE && drop_sequence)) @@ -2473,7 +2474,6 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists, if (hton && hton->flags & HTON_TABLE_MAY_NOT_EXIST_ON_SLAVE) log_if_exists= 1; - thd->replication_flags= 0; bool enoent_warning= !dont_log_query && !(hton && hton->discover_table); error= ha_delete_table(thd, hton, path, &db, &table_name, enoent_warning); @@ -2489,9 +2489,6 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists, goto err; } } - /* This may be set by the storage engine in handler::delete_table() */ - if (thd->replication_flags & OPTION_IF_EXISTS) - log_if_exists= 1; /* Delete the .frm file if we managed to delete the table from the @@ -2569,6 +2566,16 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists, error= ferror; } + /* + This may be set + - by the storage engine in handler::delete_table() + - when deleting a table without .frm file: delete_table_force() will + check if the storage engine that had the table had + HTON_TABLE_MAY_NOT_EXIST_ON_SLAVE flag + */ + if (thd->replication_flags & OPTION_IF_EXISTS) + log_if_exists= 1; + if (likely(!error) || non_existing_table_error(error)) { if (Table_triggers_list::drop_all_triggers(thd, &db, &table_name,
participants (1)
-
psergey