summaryrefslogtreecommitdiff
path: root/sql/parse_file.cc
diff options
context:
space:
mode:
authorMonty <monty@mariadb.org>2021-01-31 18:43:50 +0200
committerSergei Golubchik <serg@mariadb.org>2021-05-19 22:54:13 +0200
commitffe7f19fa6019c03f3ff190dc5c2d0e8de60bf14 (patch)
tree82d5167fae20dbbd32257204bb044217728e6707 /sql/parse_file.cc
parentd494abd175d45aa114efbe3c35e2e765441b65b5 (diff)
downloadmariadb-git-ffe7f19fa6019c03f3ff190dc5c2d0e8de60bf14.tar.gz
MDEV-24746 Atomic CREATE TRIGGER
The purpose of this task is to ensure that CREATE TRIGGER is atomic When a trigger is created, we first create a trigger_name.TRN file and then create or update the table_name.TRG files. This is done by creating .TRN~ and .TRG~ files and replacing (or creating) the result files. The new logic is - Log CREATE TRIGGER to DDL log, with a marker if old trigger existsted - If old .TRN or .TRG files exists, make backup copies of these - Create the new .TRN and .TRG files as before - Remove the backups Crash recovery - If query has been logged to binary log: - delete any left over backup files - else - Delete any old .TRN~ or .TRG~ files - If there was orignally some triggers (old .TRG file existed) - If we crashed before creating all backup files - Delete existing backup files - else - Restore backup files - end - Delete .TRN and .TRG file (as there was no triggers before One benefit of the new code is that CREATE OR REPLACE TRIGGER is now totally atomic even if there existed an old trigger: Either the old trigger will be replaced or the old one will be left untouched. Other things: - If sql_create_definition_file() would fail, there could be memory leaks in CREATE TRIGGER, DROP TRIGGER or CREATE OR REPLACE TRIGGER. This is now fixed.
Diffstat (limited to 'sql/parse_file.cc')
-rw-r--r--sql/parse_file.cc42
1 files changed, 42 insertions, 0 deletions
diff --git a/sql/parse_file.cc b/sql/parse_file.cc
index aaf36970702..8ea00e96f33 100644
--- a/sql/parse_file.cc
+++ b/sql/parse_file.cc
@@ -347,6 +347,48 @@ err_w_file:
DBUG_RETURN(TRUE);
}
+
+/*
+ Make a copy of a definition file with '-' added to the name
+
+ @param org_name Original file name
+ @param new_name Pointer to a buff of FN_REFLEN. Will be updated to name of
+ backup file
+ @return 0 ok
+ @return 1 error
+*/
+
+int sql_backup_definition_file(const LEX_CSTRING *org_name,
+ LEX_CSTRING *new_name)
+{
+ char *new_name_buff= (char*) new_name->str;
+ new_name->length= org_name->length+1;
+
+ memcpy(new_name_buff, org_name->str, org_name->length+1);
+ new_name_buff[org_name->length]= '-';
+ new_name_buff[org_name->length+1]= 0;
+ return my_copy(org_name->str, new_name->str, MYF(MY_WME));
+}
+
+/*
+ Restore copy of a definition file
+
+ @param org_name Name of backup file (ending with '-' or '~')
+
+ @return 0 ok
+ @return 1 error
+*/
+
+int sql_restore_definition_file(const LEX_CSTRING *name)
+{
+ char new_name[FN_REFLEN+1];
+ memcpy(new_name, name->str, name->length-1);
+ new_name[name->length-1]= 0;
+ return mysql_file_rename(key_file_fileparser, name->str, new_name,
+ MYF(MY_WME));
+}
+
+
/**
Renames a frm file (including backups) in same schema.