From 3c9d4ea8219469510999a89d6800e3d1786ec88c Mon Sep 17 00:00:00 2001 From: Gleb Shchepa Date: Tue, 30 Sep 2008 17:50:28 +0500 Subject: Fixed bug #17823: 'arc' directories inside database directories. Server created "arc" directories inside database directories and maintained there useless copies of .frm files. Creation and renaming procedures of those copies as well as creation of "arc" directories has been discontinued. Removal procedure has been kept untouched to be able to cleanup existent database directories by the DROP DATABASE query. Also view renaming procedure has been updated to remove these directories. sql/parse_file.cc: Fixed bug #17823: 'arc' directories inside database directories. View/table creation and renaming procedures maintained backup copies of .frm files. Those copies are unused yet, so this feature was incomplete and unnecessary. 1. Unwanted code has been hidden by FRM_ARCHIVE ifdefs (the FRM_ARCHIVE macro is not defined). 2. Renaming procedure has been modified to remove obsolete "arc" directories. sql/parse_file.h: Fixed bug #17823: 'arc' directories inside database directories. The "thd" parameter has been added to the rename_in_schema_file() function. sql/sql_db.cc: Fixed bug #17823: 'arc' directories inside database directories. Scope of the mysql_rm_arc_files() function has been changed to global for use from the parse_file.cc file. sql/sql_view.cc: Fixed bug #17823: 'arc' directories inside database directories. Added the "thd" argument to rename_in_schema_file() calls. --- sql/sql_db.cc | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'sql/sql_db.cc') diff --git a/sql/sql_db.cc b/sql/sql_db.cc index e25ede1be03..8fbb407555a 100644 --- a/sql/sql_db.cc +++ b/sql/sql_db.cc @@ -35,7 +35,7 @@ static long mysql_rm_known_files(THD *thd, MY_DIR *dirp, const char *db, const char *path, uint level, TABLE_LIST **dropped_tables); -static long mysql_rm_arc_files(THD *thd, MY_DIR *dirp, const char *org_path); +long mysql_rm_arc_files(THD *thd, MY_DIR *dirp, const char *org_path); static my_bool rm_dir_w_symlink(const char *org_path, my_bool send_error); /* Database options hash */ static HASH dboptions; @@ -906,7 +906,11 @@ static long mysql_rm_known_files(THD *thd, MY_DIR *dirp, const char *db, else if (file->name[0] == 'a' && file->name[1] == 'r' && file->name[2] == 'c' && file->name[3] == '\0') { - /* .frm archive */ + /* .frm archive: + Those archives are obsolete, but following code should + exist to remove existent "arc" directories. + See #ifdef FRM_ARCHIVE directives for obsolete code. + */ char newpath[FN_REFLEN]; MY_DIR *new_dirp; strxmov(newpath, org_path, "/", "arc", NullS); @@ -1061,9 +1065,13 @@ static my_bool rm_dir_w_symlink(const char *org_path, my_bool send_error) RETURN > 0 number of removed files -1 error + + NOTE + A support of "arc" directories is obsolete, however this + function should exist to remove existent "arc" directories. + See #ifdef FRM_ARCHIVE directives for obsolete code. */ -static long mysql_rm_arc_files(THD *thd, MY_DIR *dirp, - const char *org_path) +long mysql_rm_arc_files(THD *thd, MY_DIR *dirp, const char *org_path) { long deleted= 0; ulong found_other_files= 0; @@ -1105,6 +1113,7 @@ static long mysql_rm_arc_files(THD *thd, MY_DIR *dirp, { goto err; } + deleted++; } if (thd->killed) goto err; -- cgit v1.2.1 From 56b9586fd1d94ebd70662417a1d2ac1921da4ad2 Mon Sep 17 00:00:00 2001 From: Gleb Shchepa Date: Fri, 14 Nov 2008 21:25:57 +0400 Subject: Bug #40021: Renaming view fails, archived .frm for view is missing after downgrade Obsolete arc/ directory and view .frm file backup support has been removed by the patch for bug 17823. However, that bugfix caused a problem with "live downgrades" of the server: if we rename some view 4 times under 5.1.29/5.0.72 and then try to rename it under 5.1.28/5.0.70 on the same database, the server fails with a error: query 'RENAME TABLE ... TO ...' failed: 6: Error on delete of '....frm-0001' (Errcode: 2) Also .frm file of that view may be lost (renamed to .frm~). The server failed because it tried to rename latest 3 backup .frm files renaming the view: the server used an integer value of the "revision" field of .frm file to extract those file names. After the fix for bug 17823 those files were not created/maintained any more, however the "revision" field was incremented as usual. So, the server failed renaming non existent files. This fix solves the problem by removing the support for "revision" .frm file field: 1. New server silently ignores existent "revision" fields in old .frm files and never write it down; 2. Old server assumes, that missing "revision" field in new .frm files means default value of 0. 3. Accordingly to the fix for bug 17823 the new server drops arc/ directory on alter/rename view, so after "live downgrade" old server begins maintenance of the arc/ directory from scratch without conflicts with .frm files. sql/parse_file.cc: Bug #40021: Renaming view fails, archived .frm for view is missing after downgrade 1. static write_parameter(): the old_version parameter and the section for FILE_OPTIONS_REV have been re moved. 2. write_parameter(): the max_versions parameter has been removed; 3. sql_create_definition_file(): removal of dead code; 4. rename_in_schema_file(): revision and num_view_backups parameters and dead code have been removed; 5. File_parser::parse(): FILE_OPTIONS_REV section has been removed. sql/parse_file.h: Bug #40021: Renaming view fails, archived .frm for view is missing after downgrade 1. The FILE_OPTIONS_REV constant has been removed. 2. sql_create_definition_file and rename_in_schema_file functions: obsolete versions, revision and num_view_backups parameters have been removed. sql/sql_db.cc: Bug #40021: Renaming view fails, archived .frm for view is missing after downgrade Commentary update. sql/sql_trigger.cc: Bug #40021: Renaming view fails, archived .frm for view is missing after downgrade sql_create_definition_file() calls have been updates to new parameter lists. sql/sql_view.cc: Bug #40021: Renaming view fails, archived .frm for view is missing after downgrade 1. The mysql_create_view function code is used for both CREATE VIEW and ALTER queries, but query cache is necessary for ALTER command only. Check for a non first view revision has been replaced with a direct check for ALTER query. 2. The num_view_backups global constant has been removed. 3. view_parameters: the "revision" .frm field support has been removed. 4. sql_create_definition_file and rename_in_schema_file function calls have been updates to new parameter lists. sql/table.h: Bug #40021: Renaming view fails, archived .frm for view is missing after downgrade TABLE_LIST: the revision field has been removed. --- sql/sql_db.cc | 2 -- 1 file changed, 2 deletions(-) (limited to 'sql/sql_db.cc') diff --git a/sql/sql_db.cc b/sql/sql_db.cc index 8fbb407555a..c3cf7429222 100644 --- a/sql/sql_db.cc +++ b/sql/sql_db.cc @@ -909,7 +909,6 @@ static long mysql_rm_known_files(THD *thd, MY_DIR *dirp, const char *db, /* .frm archive: Those archives are obsolete, but following code should exist to remove existent "arc" directories. - See #ifdef FRM_ARCHIVE directives for obsolete code. */ char newpath[FN_REFLEN]; MY_DIR *new_dirp; @@ -1069,7 +1068,6 @@ static my_bool rm_dir_w_symlink(const char *org_path, my_bool send_error) NOTE A support of "arc" directories is obsolete, however this function should exist to remove existent "arc" directories. - See #ifdef FRM_ARCHIVE directives for obsolete code. */ long mysql_rm_arc_files(THD *thd, MY_DIR *dirp, const char *org_path) { -- cgit v1.2.1