List:Internals« Previous MessageNext Message »
From:Georg Richter Date:September 18 2005 9:43pm
Subject:bk commit into 5.0 tree (georg:1.1965)
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of georg. When georg does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet
  1.1965 05/09/18 21:43:28 georg@stripped +4 -0
  Changes after discussion/review with Sanja

  sql/sql_view.cc
    1.65 05/09/18 21:43:21 georg@stripped +18 -38
    moved rename_view_files to rename_in_schema_file (parse_file.cc)
    corrected MYF parameter from MY_WME to 0.

  sql/sql_rename.cc
    1.30 05/09/18 21:43:21 georg@stripped +25 -25
    simplified code (thanks to Sanja)

  sql/parse_file.h
    1.9 05/09/18 21:43:21 georg@stripped +3 -0
    added prototype for rename_in_schema_file

  sql/parse_file.cc
    1.15 05/09/18 21:43:21 georg@stripped +53 -0
    Fix after discussion/review with Sanja: removed rename_view from sql_view to general
function rename_in_schema_file
    (so it can be used for other .frm types like triggers too)

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	georg
# Host:	lmy002.wdf.sap.corp
# Root:	/home/georg/work/mysql/bugs/mysql-5.0-master

--- 1.14/sql/parse_file.cc	2005-07-28 21:39:07 +02:00
+++ 1.15/sql/parse_file.cc	2005-09-18 21:43:21 +02:00
@@ -333,6 +333,59 @@
   DBUG_RETURN(TRUE);
 }
 
+/*
+  Renames a frm file (including backups) in same schema
+
+  SYNOPSIS
+    rename_in_schema_file
+    schema            name of given schema           
+    old_name          original file name
+    new_name          new file name
+    revision          revision number
+    num_view_backups  number of backups
+
+  RETURN
+    0 - OK 
+    1 - Error (only if renaming of frm failed)
+
+*/
+my_bool rename_in_schema_file(const char *schema, const char *old_name, 
+                              const char *new_name, ulonglong revision, 
+                              uint num_view_backups)
+{
+  char old_path[FN_REFLEN], new_path[FN_REFLEN], arc_path[FN_REFLEN];
+
+  strxnmov(old_path, FN_REFLEN, mysql_data_home, "/", schema, "/",
+           old_name, reg_ext, NullS);
+  (void) unpack_filename(old_path, old_path);
+
+  strxnmov(new_path, FN_REFLEN, mysql_data_home, "/", schema, "/",
+           new_name, reg_ext, NullS);
+  (void) unpack_filename(new_path, new_path);
+
+  if (my_rename(old_path, new_path, MYF(MY_WME)))
+    return 1;
+
+  /* check if arc_dir exists */
+  strxnmov(arc_path, FN_REFLEN, mysql_data_home, "/", schema, "/arc", NullS);
+  (void) unpack_filename(arc_path, arc_path);
+  
+  if (revision > 0 && !access(arc_path, F_OK))
+  {
+    ulonglong limit= (revision > num_view_backups) ? revision - num_view_backups : 0;
+    while (revision > limit) {
+      my_snprintf(old_path, FN_REFLEN, "%s/%s%s-%04lu",
+		  arc_path, old_name, reg_ext, (ulong)revision);
+      (void) unpack_filename(old_path, old_path);
+      my_snprintf(new_path, FN_REFLEN, "%s/%s%s-%04lu",
+		  arc_path, new_name, reg_ext, (ulong)revision);
+      (void) unpack_filename(new_path, new_path);
+      my_rename(old_path, new_path, MYF(0));
+      revision--;
+    }
+  }
+  return 0;
+}
 
 /*
   Prepare frm to parse (read to memory)

--- 1.8/sql/parse_file.h	2005-07-28 21:39:07 +02:00
+++ 1.9/sql/parse_file.h	2005-09-18 21:43:21 +02:00
@@ -48,6 +48,9 @@
 sql_create_definition_file(const LEX_STRING *dir, const  LEX_STRING *file_name,
 			   const LEX_STRING *type,
 			   gptr base, File_option *parameters, uint versions);
+my_bool rename_in_schema_file(const char *schema, const char *old_name, 
+                              const char *new_name, ulonglong revision, 
+                              uint num_view_backups);
 
 class File_parser: public Sql_alloc
 {

--- 1.64/sql/sql_view.cc	2005-09-16 17:13:14 +02:00
+++ 1.65/sql/sql_view.cc	2005-09-18 21:43:21 +02:00
@@ -1167,7 +1167,7 @@
   int length;
   DBUG_ENTER("mysql_frm_type");
 
-  if ((file= my_open(path, O_RDONLY | O_SHARE, MYF(MY_WME))) < 0)
+  if ((file= my_open(path, O_RDONLY | O_SHARE, MYF(0))) < 0)
   {
     DBUG_RETURN(FRMTYPE_ERROR);
   }
@@ -1372,43 +1372,21 @@
           HA_ADMIN_OK);
 }
 
-bool rename_view_files(const char *schema, const char *old_name, 
-                       const char *new_name, ulonglong revision)
-{
-  char old_path[FN_REFLEN], new_path[FN_REFLEN], arc_path[FN_REFLEN];
+/*
+  rename view
 
-  strxnmov(old_path, FN_REFLEN, mysql_data_home, "/", schema, "/",
-           old_name, reg_ext, NullS);
-  (void) unpack_filename(old_path, old_path);
-
-  strxnmov(new_path, FN_REFLEN, mysql_data_home, "/", schema, "/",
-           new_name, reg_ext, NullS);
-  (void) unpack_filename(new_path, new_path);
-
-  if (my_rename(old_path, new_path, MYF(MY_WME)))
-    return 1;
-
-  /* check if arc_dir exists */
-  strxnmov(arc_path, FN_REFLEN, mysql_data_home, "/", schema, "/arc", NullS);
-  (void) unpack_filename(arc_path, arc_path);
-  
-  if (revision && !access(arc_path, F_OK))
-  {
-    while (revision) {
-      my_snprintf(old_path, FN_REFLEN, "%s/%s%s-%04lu",
-		  arc_path, old_name, reg_ext, (ulong)revision);
-      (void) unpack_filename(old_path, old_path);
-      my_snprintf(new_path, FN_REFLEN, "%s/%s%s-%04lu",
-		  arc_path, new_name, reg_ext, (ulong)revision);
-      (void) unpack_filename(new_path, new_path);
-      if (my_rename(old_path, new_path, MYF(0)))
-        return 0;
-      revision--;
-    }
-  }
-  return 0;
-}
+  Synopsis:
+    renames a view
 
+  Parameters:
+    thd        thread handler
+    new_name   new name of view
+    view       view
+
+  Return values:
+    FALSE      Ok 
+    TRUE       Error
+*/
 bool
 mysql_rename_view(THD *thd,
 		   const char *new_name,
@@ -1438,7 +1416,8 @@
       DBUG_RETURN(1);
 
     /* rename view and it's backups */
-    if (rename_view_files(view->db, view->table_name, new_name, view->revision -
1))
+    if (rename_in_schema_file(view->db, view->table_name, new_name, 
+                              view->revision - 1, num_view_backups))
       DBUG_RETURN(1);
 
     strxnmov(dir_buff, FN_REFLEN, mysql_data_home, "/", view->db, "/", NullS);
@@ -1454,7 +1433,8 @@
     if (sql_create_definition_file(&pathstr, &file, view_file_type,
       (gptr)view, view_parameters, num_view_backups)) {
       /* restore renamed view in case of error */
-      rename_view_files(view->db, new_name, view->table_name, view->revision -
1);
+      rename_in_schema_file(view->db, new_name, view->table_name, 
+                             view->revision - 1, num_view_backups);
       DBUG_RETURN(1);
     }
   } else

--- 1.29/sql/sql_rename.cc	2005-09-16 17:13:14 +02:00
+++ 1.30/sql/sql_rename.cc	2005-09-18 21:43:21 +02:00
@@ -138,7 +138,7 @@
 
   for (ren_table= table_list; ren_table; ren_table= new_table->next_local)
   {
-    db_type table_type;
+    int rc= 1;
     char name[FN_REFLEN];
     const char *new_alias, *old_alias;
 
@@ -165,36 +165,36 @@
 	    ren_table->db, old_alias,
 	    reg_ext);
     unpack_filename(name, name);
-    if ((frm_type= mysql_frm_type(name)) == FRMTYPE_TABLE &&
-        (table_type= get_table_type(thd, name)) == DB_TYPE_UNKNOWN)
+
+    frm_type= mysql_frm_type(name);
+    switch (frm_type)
     {
-      my_error(ER_FILE_NOT_FOUND, MYF(0), name, my_errno);
-      if (!skip_error)
-        DBUG_RETURN(ren_table);
-    }
-    else {
-      int rc= 1;
-      switch (frm_type)
+      case FRMTYPE_TABLE:
       {
-        case FRMTYPE_TABLE:
+        db_type table_type;
+        if ((table_type= get_table_type(thd, name)) == DB_TYPE_UNKNOWN) 
+          my_error(ER_FILE_NOT_FOUND, MYF(0), name, my_errno);
+        else
           rc= mysql_rename_table(table_type, ren_table->db, old_alias,
                                  new_table->db, new_alias);
-          break;
-        case FRMTYPE_VIEW:
-          /* change of schema is not allowed */
-          if (strcmp(ren_table->db, new_table->db))
-            my_error(ER_FORBID_SCHEMA_CHANGE, MYF(0), ren_table->db, 
-                     new_table->db);
-          else
-            rc= mysql_rename_view(thd, new_alias, ren_table);
-          break;
-        case FRMTYPE_ERROR:
-        default:
-          my_error(ER_FILE_NOT_FOUND, MYF(0), name, my_errno);
+        break;
       }
-      if (rc && !skip_error)
-	    DBUG_RETURN(ren_table);
+      case FRMTYPE_VIEW:
+        /* change of schema is not allowed */
+        if (strcmp(ren_table->db, new_table->db))
+          my_error(ER_FORBID_SCHEMA_CHANGE, MYF(0), ren_table->db, 
+                   new_table->db);
+        else
+          rc= mysql_rename_view(thd, new_alias, ren_table);
+        break;
+      default:
+        DBUG_ASSERT(0); // should never happen
+      case FRMTYPE_ERROR:
+        my_error(ER_FILE_NOT_FOUND, MYF(0), name, my_errno);
+        break;
     }
+    if (rc && !skip_error)
+      DBUG_RETURN(ren_table);
   }
   DBUG_RETURN(0);
 }
Thread
bk commit into 5.0 tree (georg:1.1965)Georg Richter18 Sep