List:Commits« Previous MessageNext Message »
From:Davi Arnaut Date:October 2 2008 6:19pm
Subject:bzr commit into mysql-6.0 branch (davi:2718)
View as plain text  
# At a local mysql-6.0 repository of davi

 2718 Davi Arnaut	2008-10-02
      Rework the backup error handling to remove a dependency on the internals
      and lifetime of MYSQL_ERROR by relying on the diagnostics area.
removed:
  sql/backup/error.h
modified:
  mysql-test/r/backup_errors.result
  mysql-test/r/backup_views.result
  mysql-test/t/backup_views.test
  sql/backup/Makefile.am
  sql/backup/kernel.cc
  sql/backup/logger.cc
  sql/backup/logger.h

per-file messages:
  mysql-test/r/backup_errors.result
    Error message is not pushed anymore if one is already set.
  mysql-test/r/backup_views.result
    Report the missing table dependency when restoring views.
  mysql-test/t/backup_views.test
    Report the actual error that was encountered: missing table.
  sql/backup/Makefile.am
    Remove file made obsolete by this changes.
  sql/backup/error.h
    Remove file made obsolete by this changes.
  sql/backup/kernel.cc
    Iterate over the list of pushed errors and set the diagnostics
    area status if it's not already set. This is done this way because
    backup code works tries to delay the setting of errors until its
    time to send it to the client.
  sql/backup/logger.cc
    Only push a error into the stack if one is not already set.
  sql/backup/logger.h
    Remove functions used to save MYSQL_ERROR. Now they are kept
    in the diagnostics area.
=== modified file 'mysql-test/r/backup_errors.result'
--- a/mysql-test/r/backup_errors.result	2008-08-21 11:36:09 +0000
+++ b/mysql-test/r/backup_errors.result	2008-10-02 18:18:49 +0000
@@ -79,7 +79,6 @@ ERROR 42S02: Table 'mysql.online_backup'
 SHOW ERRORS;
 Level	Code	Message
 Error	#	Table 'mysql.online_backup' doesn't exist
-Error	#	Cannot create backup/restore execution context
 Restoring the table
 CREATE TABLE mysql.online_backup LIKE test.ob_copy;
 DROP TABLE test.ob_copy;
@@ -90,7 +89,6 @@ ERROR 42S02: Table 'mysql.online_backup_
 SHOW ERRORS;
 Level	Code	Message
 Error	#	Table 'mysql.online_backup_progress' doesn't exist
-Error	#	Cannot create backup/restore execution context
 Restoring the table
 CREATE TABLE mysql.online_backup_progress LIKE test.obp_copy;
 DROP TABLE test.obp_copy;

=== modified file 'mysql-test/r/backup_views.result'
--- a/mysql-test/r/backup_views.result	2008-08-20 13:23:10 +0000
+++ b/mysql-test/r/backup_views.result	2008-10-02 18:18:49 +0000
@@ -277,10 +277,10 @@ DROP DATABASE bup_db2;
 Restore database.
 restore database with view dependency to other, non-existing db
 RESTORE FROM 'bup_objectview1.bak';
-ERROR HY000: Could not restore view `bup_db1`.`v5`. Please check the view definition for possible missing dependencies.
+ERROR 42S02: Table 'bup_db2.t2' doesn't exist
 DROP DATABASE bup_db1;
 RESTORE FROM 'bup_objectview2.bak';
-ERROR HY000: Could not restore view `bup_db2`.`student_details`. Please check the view definition for possible missing dependencies.
+ERROR 42S02: Table 'bup_db1.t3' doesn't exist
 DROP DATABASE bup_db2;
 RESTORE FROM 'bup_objectview.bak';
 backup_id

=== modified file 'mysql-test/t/backup_views.test'
--- a/mysql-test/t/backup_views.test	2008-08-20 13:23:10 +0000
+++ b/mysql-test/t/backup_views.test	2008-10-02 18:18:49 +0000
@@ -205,14 +205,14 @@ DROP DATABASE bup_db2;
 
 --echo restore database with view dependency to other, non-existing db
 
---error ER_BACKUP_CANT_RESTORE_VIEW
+--error ER_NO_SUCH_TABLE
 RESTORE FROM 'bup_objectview1.bak';
 
 # An incomplete bup_db1 was created by the failing restore operation.
 # Remove it before trying restore of bup_db2.
 DROP DATABASE bup_db1;
 
---error ER_BACKUP_CANT_RESTORE_VIEW
+--error ER_NO_SUCH_TABLE
 RESTORE FROM 'bup_objectview2.bak';
 
 # An incomplete bup_db2 was created by the failing restore operation.

=== modified file 'sql/backup/Makefile.am'
--- a/sql/backup/Makefile.am	2008-07-07 12:51:56 +0000
+++ b/sql/backup/Makefile.am	2008-10-02 18:18:49 +0000
@@ -53,7 +53,6 @@ noinst_HEADERS = \
   backup_kernel.h \
   backup_stream.h \
   stream_services.h \
-  error.h \
   stream.h \
   backup_aux.h \
   logger.h \

=== removed file 'sql/backup/error.h'
--- a/sql/backup/error.h	2008-04-08 15:32:47 +0000
+++ b/sql/backup/error.h	1970-01-01 00:00:00 +0000
@@ -1,39 +0,0 @@
-#ifndef _BACKUP_ERROR_H
-#define _BACKUP_ERROR_H
-
-namespace util {
-
-/**
-  Report error stored in MYSQL_ERROR structure to a client.
-
-  If @c err doesn't contain any error code, the given error code is reported.
-
-  @returns 0 if error was reported, non-zero otherwise.
- */
-inline
-int report_mysql_error(THD* thd, MYSQL_ERROR *err, int code= 0)
-{
-  DBUG_ASSERT(err);
-
-  if (err->level == MYSQL_ERROR::WARN_LEVEL_END
-      && !err->msg && !err->code ) // err doesn't store any error
-    return -1;
-
-  switch (err->level) {
-
-  case MYSQL_ERROR::WARN_LEVEL_ERROR:
-  {
-    bool old_value= thd->no_warnings_for_error;
-    thd->no_warnings_for_error= TRUE;
-    my_printf_error(err->code ? err->code : code, err->msg, MYF(0));
-    thd->no_warnings_for_error= old_value;
-    return 0;
-  }
-  default: // Q: What to do with warnings and notes? push them... ?
-    return -1;
-  }
-}
-
-} // util namespace
-
-#endif

=== modified file 'sql/backup/kernel.cc'
--- a/sql/backup/kernel.cc	2008-10-01 10:14:28 +0000
+++ b/sql/backup/kernel.cc	2008-10-02 18:18:49 +0000
@@ -264,12 +264,25 @@ execute_backup_command(THD *thd, LEX *le
  */
 int send_error(Backup_restore_ctx &log, int error_code, ...)
 {
-  MYSQL_ERROR *error= log.last_saved_error();
+  THD *thd= log.thd();
+  MYSQL_ERROR *ptr, *err= NULL;
+  List_iterator_fast<MYSQL_ERROR> it(thd->warn_list);
 
-  if (error && !util::report_mysql_error(log.thd(), error, error_code))
+  // Too late, diagnostics area is already set
+  if (thd->main_da.is_set())
+    return error_code;
+
+  // look for the last error that was pushed
+  while ((ptr= it++))
+  {
+    if (ptr->level == MYSQL_ERROR::WARN_LEVEL_ERROR)
+      err= ptr;
+  }
+
+  // report the last error if one was found
+  if (err)
   {
-    if (error->code)
-      error_code= error->code;
+    thd->main_da.set_error_status(thd, err->code, err->msg);
   }
   else // there are no error information in the logger - report error_code
   {
@@ -416,12 +429,9 @@ int Backup_restore_ctx::prepare(LEX_STRI
   
   // FIXME: detect errors if  reported.
   // FIXME: error logging.
+  // FIXME: use a special diagnostics area if necessary.
   mysql_reset_errors(m_thd, 0);
   m_thd->no_warnings_for_error= FALSE;
-  // FIXME: detect errors if  reported.
-  // FIXME: error logging.
-  save_errors();  
-
 
   /*
     Check access for SUPER rights. If user does not have SUPER, fail with error.

=== modified file 'sql/backup/logger.cc'
--- a/sql/backup/logger.cc	2008-08-27 15:48:32 +0000
+++ b/sql/backup/logger.cc	2008-10-02 18:18:49 +0000
@@ -34,6 +34,7 @@ namespace backup {
 int Logger::write_message(log_level::value level, int error_code,
                           const char *msg)
 {
+   THD *thd= current_thd;
    char buf[ERRMSGSIZE + 30];
    const char *out= msg;
 
@@ -46,12 +47,10 @@ int Logger::write_message(log_level::val
    
    switch (level) {
    case log_level::ERROR:
-     if (m_save_errors)
-       errors.push_front(new MYSQL_ERROR(::current_thd, error_code,
-                                         MYSQL_ERROR::WARN_LEVEL_ERROR, msg));
      sql_print_error(out);
-     push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
-                         error_code, msg);
+     if (!thd->main_da.is_error())
+       push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
+                           error_code, msg);
      DBUG_PRINT("backup_log",("[ERROR] %s", out));
      
      if (m_state == READY || m_state == RUNNING)
@@ -61,7 +60,7 @@ int Logger::write_message(log_level::val
 
    case log_level::WARNING:
      sql_print_warning(out);
-     push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+     push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
                          error_code, msg);
      DBUG_PRINT("backup_log",("[Warning] %s", out));
      return 0;

=== modified file 'sql/backup/logger.h'
--- a/sql/backup/logger.h	2008-07-09 18:37:42 +0000
+++ b/sql/backup/logger.h	2008-10-02 18:18:49 +0000
@@ -3,7 +3,6 @@
 
 #include "mysql_priv.h"
 #include <backup_stream.h>
-#include <backup/error.h>
 #include <backup/backup_progress.h>
 
 
@@ -45,7 +44,7 @@ class Logger
    enum { CREATED, READY, RUNNING, DONE } m_state;
 
    Logger(THD*);
-   ~Logger();
+   ~Logger() {}
    int init(enum_type, const LEX_STRING, const char*);
 
    int report_error(int error_code, ...);
@@ -61,11 +60,6 @@ class Logger
    void report_driver(const char*);
    void report_stats_pre(const Image_info&);
    void report_stats_post(const Image_info&);
-   
-   void save_errors();
-   void stop_save_errors();
-   void clear_saved_errors();
-   MYSQL_ERROR *last_saved_error();
 
  protected:
 
@@ -84,25 +78,14 @@ class Logger
   int v_report_error(log_level::value, int, va_list);
   int v_write_message(log_level::value, int, const char*, va_list);
   int write_message(log_level::value level , int error_code, const char *msg);
-
- private:
-
-  List<MYSQL_ERROR> errors;  ///< Used to store saved errors.
-  bool m_save_errors;        ///< Flag telling if errors should be saved.
 };
 
 inline
 Logger::Logger(THD *thd) 
   :m_type(BACKUP), m_state(CREATED),
-   m_thd(thd), m_op_id(0), m_save_errors(FALSE)
+   m_thd(thd), m_op_id(0)
 {}
 
-inline
-Logger::~Logger()
-{
-  clear_saved_errors();
-}
-
 /**
   Initialize logger for backup or restore operation.
   
@@ -186,39 +169,6 @@ int Logger::report_error(const char *for
   return res;
 }
 
-///  Request that all reported errors are saved in the logger.
-inline
-void Logger::save_errors()
-{
-  if (m_save_errors)
-    return;
-  clear_saved_errors();
-  m_save_errors= TRUE;
-}
-
-/// Stop saving errors.
-inline
-void Logger::stop_save_errors()
-{
-  if (!m_save_errors)
-    return;
-  m_save_errors= FALSE;
-}
-
-/// Delete all saved errors to free resources.
-inline
-void Logger::clear_saved_errors()
-{ 
-  errors.delete_elements();
-}
-
-/// Return a pointer to most recent saved error.
-inline
-MYSQL_ERROR *Logger::last_saved_error()
-{ 
-  return errors.is_empty() ? NULL : errors.head();
-}
-
 /// Report start of an operation.
 inline
 void Logger::report_start(time_t when)

Thread
bzr commit into mysql-6.0 branch (davi:2718) Davi Arnaut2 Oct