Bug #46574 Backup fails to return error ER_BACKUP_BINLOG
Submitted: 5 Aug 2009 20:11 Modified: 28 Oct 2009 22:20
Reporter: Chuck Bell Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Backup Severity:S3 (Non-critical)
Version:5.4.4 OS:Any
Assigned to: Chuck Bell CPU Architecture:Any

[5 Aug 2009 20:11] Chuck Bell
Description:
The code in data_backup.cc is designed to return an error if the binary log is open and the binary log is unreadable raw_get_current_log() returns non-zero (get_current_log() in log.cc #4551).

Once you activate a debug insertion test (see below), the server crashes instead of handling the error. The crash occurs on the DBUG_RETURN() call after the debug insertion error is processed.

    Backup_info *info= context.prepare_for_backup(backupdir, lex->backup_dir, 
                                                  thd->query,
                                                  lex->backup_compression);
                                                              // reports errors

    if (!info || !info->is_valid())
-->>   DBUG_RETURN(send_error(context, ER_BACKUP_BACKUP_PREPARE));

How to repeat:
Using debug insertion, one can simulate the error by using this patch:

=== modified file 'sql/backup/data_backup.cc'
--- sql/backup/data_backup.cc   2009-05-21 13:17:37 +0000
+++ sql/backup/data_backup.cc   2009-08-05 19:34:40 +0000
@@ -470,6 +470,10 @@ int save_vp_info(Backup_info &info)
   */
   if (mysql_bin_log.is_open())
   {
+    DBUG_EXECUTE_IF("ER_BACKUP_BINLOG",
+      info.m_log.report_error(ER_BACKUP_BINLOG);
+      return TRUE;);
+
     if (mysql_bin_log.get_current_log(&binlog_start_pos))
     {
       info.m_log.report_error(ER_BACKUP_BINLOG);

The problem can be tested using this test:

Note: start with --mysqld=--log-bin=mysql-bin 

--echo #
--echo # Create database and data to test.
--echo #
CREATE DATABASE backup_test;
CREATE TABLE backup_test.t1 (a char(30)) ENGINE=MEMORY;
INSERT INTO backup_test.t1 VALUES ("01 Test Basic database example"); 
INSERT INTO backup_test.t1 VALUES ("02 Test Basic database example"); 
INSERT INTO backup_test.t1 VALUES ("03 Test Basic database example"); 
INSERT INTO backup_test.t1 VALUES ("04 Test Basic database example"); 
INSERT INTO backup_test.t1 VALUES ("05 Test Basic database example"); 
INSERT INTO backup_test.t1 VALUES ("06 Test Basic database example"); 
INSERT INTO backup_test.t1 VALUES ("07 Test Basic database example"); 

CREATE TABLE backup_test.t2 (a char(30)) ENGINE=MEMORY;
INSERT INTO backup_test.t2 VALUES ("11 Test Basic database example"); 
INSERT INTO backup_test.t2 VALUES ("12 Test Basic database example"); 
INSERT INTO backup_test.t2 VALUES ("13 Test Basic database example"); 

--echo #
--echo # Now create more database objects for test.
--echo #
CREATE PROCEDURE backup_test.p1(p1 CHAR(20))
  INSERT INTO backup_test.t1 VALUES ("50");

CREATE TRIGGER backup_test.trg AFTER INSERT ON backup_test.t1 FOR EACH ROW
 INSERT INTO backup_test.t1 VALUES('Test objects count');

CREATE FUNCTION backup_test.f1() RETURNS INT RETURN (SELECT 1);

CREATE VIEW backup_test.v1 as SELECT * FROM backup_test.t1;

CREATE EVENT backup_test.e1 ON SCHEDULE EVERY 1 YEAR DO
  DELETE FROM backup_test.t1 WHERE a = "not there";

--echo #
--echo # Now we need some privileges
--echo #
GRANT ALL ON backup_test.* TO 'joe'@'user';

BACKUP DATABASE backup_test TO 'orig.bak';

SET SESSION debug="+d,ER_BACKUP_BINLOG";
--replace_column 1 #
BACKUP DATABASE backup_test TO '1.bak';
SET SESSION debug="-d";

RESTORE FROM 'orig.bak';

Suggested fix:
Change code to allow successful return of the ER_BACKUP_BINLOG error.
[5 Aug 2009 20:14] Chuck Bell
Once fixed, and WL#4722 has been pushed, the test case can be activated in backup_errors_debug_1.test using this test case:

# Test for error ER_BACKUP_BINLOG.
LET $caseno = 1;
LET $errno = $ER_BACKUP_BINLOG;
LET $errname = ER_BACKUP_BINLOG;
LET $operation = BACKUP;
--source suite/backup/include/test_for_error.inc
[7 Aug 2009 14:58] Chuck Bell
Note: The code and test case are part of the patch for WL#4722. Once that is pushed, or made available, the test case can be enabled in backup_errors_debug_1.test and the code for the error condition insertion is active.
[27 Aug 2009 0:56] Chuck Bell
Chuck steals another bug.
[27 Aug 2009 1:02] Chuck Bell
The problem is the code does not detect when an error is returned from save_vp_info() in data_backup.cc. The following patch corrects the problem.

This patch can be applied and the test case enabled once WL#4722 is pushed. Also, there are two test cases -- one with a database that has objects and another that does not have objects. Both test cases must be added to the tests in WL#4722.

=== modified file 'sql/backup/data_backup.cc'
--- sql/backup/data_backup.cc	2009-05-21 13:17:37 +0000
+++ sql/backup/data_backup.cc	2009-08-27 01:01:31 +0000
@@ -470,7 +470,11 @@
   */
   if (mysql_bin_log.is_open())
   {
-    if (mysql_bin_log.get_current_log(&binlog_start_pos))
+    ret= mysql_bin_log.get_current_log(&binlog_start_pos);
+
+    DBUG_EXECUTE_IF("ER_BACKUP_BINLOG", ret= TRUE;);
+
+    if (ret)
     {
       info.m_log.report_error(ER_BACKUP_BINLOG);
       ret= TRUE;
@@ -735,7 +739,8 @@
     if (sch.lock())    // logs errors
       goto error;
 
-    save_vp_info(info);
+    if (save_vp_info(info))
+      goto error;
 
     DEBUG_SYNC(thd, "before_backup_data_unlock");
     if (sch.unlock() || log.report_killed())    // logs errors
[10 Sep 2009 16:04] 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/82963

2867 Chuck Bell	2009-09-10
      BUG#46574 : Backup fails to return error ER_BACKUP_BINLOG
      
      The ER_BACKUP_BINLOG error is not detected in the current
      code. The WL#4722 patch provided a debug insertion test
      that revealed the error was not being handled correctly.
      
      This patch corrects the problem by detecting the error
      returned by the save_vp_info() method.
     @ mysql-test/suite/backup/r/backup_errors_debug_1.result
        Corrected result file that includes enabled test case.
     @ mysql-test/suite/backup/t/backup_errors_debug_1-master.opt
        Added option file to turn on binlog for test case.
     @ mysql-test/suite/backup/t/backup_errors_debug_1.test
        Enabled test case.
     @ sql/backup/data_backup.cc
        Add error detection for return of save_vp_info().
        Corrected debug insertion code for ER_BACKUP_BINLOG.
[10 Sep 2009 17:58] Ingo Strüwing
Approved.
[14 Sep 2009 18:15] Jørgen Løland
Good to push
[14 Sep 2009 20:15] 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/83219

2868 Chuck Bell	2009-09-14 [merge]
      Local merge before push of BUG#46574.
[25 Oct 2009 13:38] Bugs System
Pushed into 6.0.14-alpha (revid:alik@sun.com-20091025133616-ca4inerav4vpdnaz) (version source revid:ingo.struewing@sun.com-20090921175031-i1ubh1ln575lh1di) (merge vers: 6.0.14-alpha) (pib:13)
[28 Oct 2009 22:20] Paul DuBois
Noted in 6.0.14 changelog.

If the binary log was open and unreadable, BACKUP DATABASE crashed
rather than handling the error.