summaryrefslogtreecommitdiff
path: root/sql/sql_view.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/sql_view.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/sql_view.cc')
-rw-r--r--sql/sql_view.cc7
1 files changed, 2 insertions, 5 deletions
diff --git a/sql/sql_view.cc b/sql/sql_view.cc
index 59b8962a84a..c72d31d7472 100644
--- a/sql/sql_view.cc
+++ b/sql/sql_view.cc
@@ -1178,11 +1178,8 @@ loop_out:
if (old_view_exists)
{
- /* Make a backup that we can restore in case of crash */
- memcpy(backup_file_name, path.str, path.length);
- backup_file_name[path.length]='-';
- backup_file_name[path.length+1]= 0;
- if (my_copy(path.str, backup_file_name, MYF(MY_WME)))
+ LEX_CSTRING backup_name= { backup_file_name, 0 };
+ if (sql_backup_definition_file(&path, &backup_name))
{
error= 1;
goto err;