From acf282c36b9edad67846675ba36665ab8e25a41f Mon Sep 17 00:00:00 2001 From: Monty Date: Mon, 10 May 2021 18:36:13 +0300 Subject: [PATCH] MDEV-25606: Concurrent CREATE TRIGGER statements mix up in binlog and break replication The bug is that we don't have a a lock on the trigger name, so it is possible for two threads to try to create the same trigger at the same time and both thinks that they have succeed. Same thing can happen with drop trigger or a combinations of create and drop trigger. Fixed by adding a mdl lock for the trigger name for the duration of the create/drop. --- sql/sql_trigger.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/sql_trigger.cc b/sql/sql_trigger.cc index 4f6d5c6a1dd..957fe44d621 100644 --- a/sql/sql_trigger.cc +++ b/sql/sql_trigger.cc @@ -475,7 +475,7 @@ bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create) } /* Protect against concurrent create/drop */ - MDL_REQUEST_INIT(&mdl_request_for_trn, MDL_key::TABLE, + MDL_REQUEST_INIT(&mdl_request_for_trn, MDL_key::TRIGGER, create ? tables->db.str : thd->lex->spname->m_db.str, thd->lex->spname->m_name.str, MDL_EXCLUSIVE, MDL_EXPLICIT);