Bug #40303 Backup: Wrong error send to client if several errors reported.
Submitted: 24 Oct 2008 12:58 Modified: 13 Dec 2008 17:39
Reporter: Rafal Somla Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Backup Severity:S3 (Non-critical)
Version:6.0-backup OS:Any
Assigned to: Rafal Somla CPU Architecture:Any

[24 Oct 2008 12:58] Rafal Somla
Description:
If several errors are reported during BACKUP/RESTORE operation, then the last one is send to the client. This is usually not appropriate. For other statements, always the first error is reported.

Note. Fixing this is needed for BUG#35079 (providing correct feedback in case of an interruption).

How to repeat:
Apply the following patch:

=== modified file 'sql/backup/kernel.cc'
--- sql/backup/kernel.cc        2008-10-21 16:35:31 +0000
+++ sql/backup/kernel.cc        2008-10-24 12:43:52 +0000
@@ -181,6 +181,8 @@ execute_backup_command(THD *thd, LEX *le
 
     info->close(); // close catalogue after filling it with objects to backup
 
+    context.report_error(ER_UNKNOWN_ERROR);
+
     if (res || !info->is_valid())
       DBUG_RETURN(send_error(context, ER_BACKUP_BACKUP_PREPARE));

Then run these commands:

sql> backup database foo to 'foo.bkp';
ERROR HY000: Unknown error

sql> show warnings;
Level   Code    Message
Warning 1049    Unknown database 'foo'
Warning 1105    Unknown error

The last "Unknown error" error is returned from BACKUP statement but it should rather be the "Unknown database" error.

Suggested fix:
Change the logic of sending error reply from BACKUP/RESTORE command.
[5 Nov 2008 12:41] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/57880

2721 Rafal Somla	2008-11-05
      BUG#40303 (Backup: Wrong error send to client if several errors reported)
      BUG#40304 (Backup: Errors reported during BACKUP show as warnings on the 
                 error stack)
      
      Before: Errors reported using backup::Logger class could be saved and in 
      case several errors are reported, the last one was sent to client as an
      error reply from BACKUP/RESTORE command.
      
      After: Errors reported with backup::Logger are reported to the server 
      using my_printf_error(..) function. This function pushes error on the 
      error stack (unles told otherwise) and stores the first reported error
      so that it is send to the client.
      
      Additionally.
      
      - Function log_error(..) is moved to the Logger class.
      
      - Code is changed do consistently use Logger::report/log_error() for error 
      reporting.
      
      - Semantics of Backup_restore_ctx::fatal_error() has been changed to 
      discourage its use as an error reporting facility. Now it is an internal helper 
      method which moves the context object into error state. It is used only by the 
      class methods and it is made private. The idea is that context object should 
      move into error state only as a result of executing one of its methods (not 
      externally).
      
      - Improved error reporting in few places.
[12 Nov 2008 11:21] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/58536

2731 Rafal Somla	2008-11-12
      BUG#40303 (Backup: Wrong error send to client if several errors reported)
      BUG#40304 (Backup: Errors reported during BACKUP show as warnings on the 
                 error stack)
      
      Before: Errors reported using backup::Logger class could be saved and in 
      case several errors are reported, the last one was sent to client as an
      error reply from BACKUP/RESTORE command.
      
      After: Errors reported with backup::Logger are reported to the server 
      using my_printf_error(..) function. This function pushes error on the 
      error stack (unles told otherwise) and stores the first reported error
      so that it is send to the client.
      
      Additionally.
      
      - Function log_error(..) is moved to the Logger class.
      
      - Code is changed do consistently use Logger::report/log_error() for error 
      reporting.
      
      - Semantics of Backup_restore_ctx::fatal_error() has been changed to 
      discourage its use as an error reporting facility. Now it is an internal helper 
      method which moves the context object into error state. It is used only by the 
      class methods and it is made private. The idea is that context object should 
      move into error state only as a result of executing one of its methods (not 
      externally).
      
      - Improved error reporting in few places.
[12 Nov 2008 11:23] Rafal Somla
The new patch adapts changes from the current team tree.
[19 Nov 2008 10:19] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/59184

2731 Rafal Somla	2008-11-19
      BUG#40303 (Backup: Wrong error send to client if several errors reported)
      BUG#40304 (Backup: Errors reported during BACKUP show as warnings on the 
                 error stack)
      
      Before: Errors reported using backup::Logger class could be saved and in 
      case several errors are reported, the last one was sent to client as an
      error reply from BACKUP/RESTORE command.
      
      After: Errors reported with backup::Logger are reported to the server 
      using my_printf_error(..) function. This function pushes error on the 
      error stack (unles told otherwise) and stores the first reported error
      so that it is send to the client.
      
      Additionally.
      
      - Function log_error(..) is moved to the Logger class.
      
      - Code is changed to consistently use Logger::report/log_error() for error 
      reporting.
      
      - Semantics of Backup_restore_ctx::fatal_error() has been changed to 
      discourage its use as an error reporting facility. Now it is an internal helper 
      method which moves the context object into error state. It is used only by the 
      class methods and it is made private. The idea is that context object should 
      move into error state only as a result of executing one of its methods (not 
      externally).
      
      - Improved error reporting in few places.
[19 Nov 2008 13:08] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/59221

2736 Rafal Somla	2008-11-19
      BUG#40303 (Backup: Wrong error send to client if several errors reported)
      BUG#40304 (Backup: Errors reported during BACKUP show as warnings on the 
                 error stack)
      
      Before: Errors reported using backup::Logger class could be saved and in 
      case several errors are reported, the last one was sent to client as an
      error reply from BACKUP/RESTORE command.
      
      After: Errors reported with backup::Logger are reported to the server 
      using my_printf_error(..) function. This function pushes error on the 
      error stack (unles told otherwise) and stores the first reported error
      so that it is send to the client.
      
      Additionally.
      
      - Function log_error(..) is moved to the Logger class.
      
      - Code is changed to consistently use Logger::report/log_error() for error 
      reporting.
      
      - Semantics of Backup_restore_ctx::fatal_error() has been changed to 
      discourage its use as an error reporting facility. Now it is an internal helper 
      method which moves the context object into error state. It is used only by the 
      class methods and it is made private. The idea is that context object should 
      move into error state only as a result of executing one of its methods (not 
      externally).
      
      - Improved error reporting in few places.
[20 Nov 2008 12:42] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/59364

2738 Rafal Somla	2008-11-20
      BUG#40303 (Backup: Wrong error send to client if several errors reported)
      BUG#40304 (Backup: Errors reported during BACKUP show as warnings on the 
                 error stack)
      
      Before: Errors reported using backup::Logger class could be saved and in 
      case several errors are reported, the last one was sent to client as an
      error reply from BACKUP/RESTORE command.
      
      After: Errors reported with backup::Logger are reported to the server 
      using my_printf_error(..) function. This function pushes error on the 
      error stack (unles told otherwise) and stores the first reported error
      so that it is send to the client.
      
      Additionally.
      
      - Function log_error(..) is moved to the Logger class.
      
      - Code is changed to consistently use Logger::report/log_error() for error 
      reporting.
      
      - Semantics of Backup_restore_ctx::fatal_error() has been changed to 
      discourage its use as an error reporting facility. Now it is an internal helper 
      method which moves the context object into error state. It is used only by the 
      class methods and it is made private. The idea is that context object should 
      move into error state only as a result of executing one of its methods (not 
      externally).
      
      - Improved error reporting in few places.
[20 Nov 2008 14:40] Øystein Grøvlen
Patch approved.
[24 Nov 2008 9:10] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/59661

2745 Rafal Somla	2008-11-24
      BUG#40303 (Backup: Wrong error send to client if several errors reported)
      BUG#40304 (Backup: Errors reported during BACKUP show as warnings on the 
                 error stack)
      
      Before: Errors reported using backup::Logger class could be saved and in 
      case several errors are reported, the last one was sent to client as an
      error reply from BACKUP/RESTORE command.
      
      After: Errors reported with backup::Logger are reported to the server 
      using my_printf_error(..) function. This function pushes error on the 
      error stack (unles told otherwise) and stores the first reported error
      so that it is send to the client.
      
      Additionally.
      
      - Function log_error(..) is moved to the Logger class.
      
      - Code is changed to consistently use Logger::report/log_error() for error 
      reporting.
      
      - Semantics of Backup_restore_ctx::fatal_error() has been changed to 
      discourage its use as an error reporting facility. Now it is an internal helper 
      method which moves the context object into error state. It is used only by the 
      class methods and it is made private. The idea is that context object should 
      move into error state only as a result of executing one of its methods (not 
      externally).
      
      - Improved error reporting in few places.
[24 Nov 2008 20:40] Chuck Bell
Patch approved.
[25 Nov 2008 17:45] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/59832

2746 Rafal Somla	2008-11-25
      BUG#40303 (Backup: Wrong error send to client if several errors reported)
      BUG#40304 (Backup: Errors reported during BACKUP show as warnings on the 
                 error stack)
      
      Before: Errors reported using backup::Logger class could be saved and in 
      case several errors are reported, the last one was sent to client as an
      error reply from BACKUP/RESTORE command.
      
      After: Errors reported with backup::Logger are reported to the server 
      using my_printf_error(..) function. This function pushes error on the 
      error stack (unles told otherwise) and stores the first reported error
      so that it is send to the client.
      
      Additionally.
      
      - Function log_error(..) is moved to the Logger class.
      
      - Code is changed to consistently use Logger::report/log_error() for error 
      reporting.
      
      - Semantics of Backup_restore_ctx::fatal_error() has been changed to 
      discourage its use as an error reporting facility. Now it is an internal helper 
      method which moves the context object into error state. It is used only by the 
      class methods and it is made private. The idea is that context object should 
      move into error state only as a result of executing one of its methods (not 
      externally).
      
      - Improved error reporting in few places.
[26 Nov 2008 8:24] Rafal Somla
Pushed into 6.0-backup tree (Tue Nov 25 20:44:28 2008).
[12 Dec 2008 6:25] Bugs System
Pushed into 6.0.9-alpha  (revid:rafal.somla@sun.com-20081125174419-gy7zbs1otdbtylz1) (version source revid:jorgen.loland@sun.com-20081128091358-4518qjv1cnz0f8vb) (pib:5)
[13 Dec 2008 17:39] Paul DuBois
Noted in 6.0.9 changelog.

If several errors occurred during a BACKUP DATABASE or RESTORE
operation, the final error was returned to the client, even though
the first error is usually more pertinent.