summaryrefslogtreecommitdiff
path: root/sql/sql_alter.cc
diff options
context:
space:
mode:
authorsjaakola <seppo.jaakola@iki.fi>2020-10-27 12:45:42 +0200
committerJan Lindström <jan.lindstrom@mariadb.com>2020-11-03 19:40:06 +0200
commit4d6c6611443f1e0e1cdab34ac6e320031e7f980b (patch)
tree668ad8155d96f1cd151f729fac2fd2503083e4e3 /sql/sql_alter.cc
parent5739c7702d83e83ecff5cdd84e0fab899101f9f5 (diff)
downloadmariadb-git-4d6c6611443f1e0e1cdab34ac6e320031e7f980b.tar.gz
MDEV-21577 MDL BF-BF conflict
Some DDL statements appear to acquire MDL locks for a table referenced by foreign key constraint from the actual affected table of the DDL statement. OPTIMIZE, REPAIR and ALTER TABLE belong to this class of DDL statements. Earlier MariaDB version did not take this in consideration, and appended only affected table in the certification key list in write set. Because of missing certification information, it could happen that e.g. OPTIMIZE table for FK child table could be allowed to apply in parallel with DML operating on the foreign key parent table, and this could lead to unhandled MDL lock conflicts between two high priority appliers (BF). The fix in this patch, changes the TOI replication for OPTIMIZE, REPAIR and ALTER TABLE statements so that before the execution of respective DDL statement, there is foreign key parent search round. This FK parent search contains following steps: * open and lock the affected table (with permissive shared locks) * iterate over foreign key contstraints and collect and array of Fk parent table names * close all tables open for the THD and release MDL locks * do the actual TOI replication with the affected table and FK parent table names as key values The patch contains also new mtr test for verifying that the above mentioned DDL statements replicate without problems when operating on FK child table. The mtr test scenario #1, which can be used to check if some other DDL (on top of OPTIMIZE, REPAIR and ALTER) could cause similar excessive FK parent table locking. Reviewed-by: Aleksey Midenkov <aleksey.midenkov@mariadb.com> Reviewed-by: Jan Lindström <jan.lindstrom@mariadb.com>
Diffstat (limited to 'sql/sql_alter.cc')
-rw-r--r--sql/sql_alter.cc30
1 files changed, 16 insertions, 14 deletions
diff --git a/sql/sql_alter.cc b/sql/sql_alter.cc
index 21c79a046a5..cefd37811a2 100644
--- a/sql/sql_alter.cc
+++ b/sql/sql_alter.cc
@@ -470,6 +470,22 @@ bool Sql_cmd_alter_table::execute(THD *thd)
if (check_grant(thd, priv_needed, first_table, FALSE, UINT_MAX, FALSE))
DBUG_RETURN(TRUE); /* purecov: inspected */
+#ifdef WITH_WSREP
+ if (WSREP(thd) && WSREP_CLIENT(thd) &&
+ (!thd->is_current_stmt_binlog_format_row() ||
+ !thd->find_temporary_table(first_table)))
+ {
+ wsrep::key_array keys;
+ wsrep_append_fk_parent_table(thd, first_table, &keys);
+
+ WSREP_TO_ISOLATION_BEGIN_ALTER((lex->name.str ? select_lex->db.str : NULL),
+ (lex->name.str ? lex->name.str : NULL),
+ first_table, &alter_info, &keys);
+
+ thd->variables.auto_increment_offset = 1;
+ thd->variables.auto_increment_increment = 1;
+ }
+#endif
if (lex->name.str && !test_all_bits(priv, INSERT_ACL | CREATE_ACL))
{
@@ -497,20 +513,6 @@ bool Sql_cmd_alter_table::execute(THD *thd)
thd->work_part_info= 0;
#endif
-#ifdef WITH_WSREP
- if (WSREP(thd) &&
- (!thd->is_current_stmt_binlog_format_row() ||
- !thd->find_temporary_table(first_table)))
- {
- WSREP_TO_ISOLATION_BEGIN_ALTER((lex->name.str ? select_lex->db.str : NULL),
- (lex->name.str ? lex->name.str : NULL),
- first_table, &alter_info);
-
- thd->variables.auto_increment_offset = 1;
- thd->variables.auto_increment_increment = 1;
- }
-#endif
-
result= mysql_alter_table(thd, &select_lex->db, &lex->name,
&create_info,
first_table,