1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

MDEV-24395 Atomic DROP TRIGGER

The purpose of this task is to ensure that DROP TRIGGER is atomic.

Description of how atomic drop trigger works:

Logging of DROP TRIGGER
    Log the following information:
    db
    table name
    trigger name
    xid /* Used to check if query was already logged to binary log */
    initial length of the .TRG file
    query if there is space for it, if not log a zero length query.

Recovery operations:
- Delete if exists 'database/trigger_name.TRN~'
  - If this file existed, it means that we crashed before the trigger
    was deleted and there is nothing else to do.
- Get length of .TRG file
  - If file length is unchanged, trigger was not dropped. Nothing else to
    do.
- Log original query to binary, if it was stored in the ddl log. If it was
  not stored (long query string), log the following query to binary log:
  use `database` ; DROP TRIGGER IF EXISTS `trigger_name`
  /* generated by ddl log */;

Other things:
- Added trigger name and DDL_LOG_STATE to drop_trigger()
  Trigger name was added to make the interface more consistent and
  more general.
This commit is contained in:
Monty
2020-12-14 15:57:04 +02:00
committed by Sergei Golubchik
parent e3cfb7c803
commit 407e9b78cf
6 changed files with 378 additions and 27 deletions

View File

@ -28,6 +28,7 @@ class sp_name;
class Query_tables_list;
struct TABLE_LIST;
class Query_tables_list;
typedef struct st_ddl_log_state DDL_LOG_STATE;
/** Event on which trigger is invoked. */
enum trg_event_type
@ -220,7 +221,9 @@ public:
~Table_triggers_list();
bool create_trigger(THD *thd, TABLE_LIST *table, String *stmt_query);
bool drop_trigger(THD *thd, TABLE_LIST *table, String *stmt_query);
bool drop_trigger(THD *thd, TABLE_LIST *table,
LEX_CSTRING *sp_name,
String *stmt_query, DDL_LOG_STATE *ddl_log_state);
bool process_triggers(THD *thd, trg_event_type event,
trg_action_time_type time_type,
bool old_row_is_record1);
@ -324,6 +327,8 @@ bool load_table_name_for_trigger(THD *thd,
const LEX_CSTRING *trn_path,
LEX_CSTRING *tbl_name);
bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create);
bool rm_trigname_file(char *path, const LEX_CSTRING *db,
const LEX_CSTRING *trigger_name, myf MyFlags);
extern const char * const TRG_EXT;
extern const char * const TRN_EXT;