Bug #41012 Error checks when reading backup image not covered by tests.
Submitted: 25 Nov 2008 13:23 Modified: 26 Mar 2009 23:39
Reporter: Rafal Somla Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Backup Severity:S3 (Non-critical)
Version:6.0 source OS:Any
Assigned to: Jørgen Løland CPU Architecture:Any

[25 Nov 2008 13:23] Rafal Somla
Description:
When reading backup image, we check for errors and do other sanity checks. For example like here (Backup_restore_ctx::do_restore() in sql/backup/kernel.cc):

  if (read_meta_data(info, s))
  {
    m_thd->main_da.reset_diagnostics_area();    // Never errors

    fatal_error(ER_BACKUP_READ_META);
    DBUG_RETURN(m_error);
  }

  if (s.next_chunk() == BSTREAM_ERROR)
  {
    DBUG_RETURN(fatal_error(ER_BACKUP_NEXT_CHUNK));
  }

But there are no test cases checking these error branches of the code. This is because testing it is difficult, as it would require reading an inconsistent backup image which would have to be created somehow.

How to repeat:
Code inspection.
[1 Dec 2008 10:47] Jørgen Løland
We can test all these in two ways:

1: Inject errors by corrupting backup images
2: Inject errors by adding debug_execute_if

Strategy 1 gives more realistic tests than strategy 2. However, there are numerous problems with this strategy: 
 - We'll need to corrupt images in many different ways. This will be very hard and probably be trial and error.
 - If the backup image format changes, we'll need to do the trial and error work of corrupting an image all over again.
 - Once we have checksums on the backup images, this strategy will fail because all corrupted images will fail the checksum test. Thus, these tests will have a very limited lifetime.
[16 Dec 2008 9:30] 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/61735

2739 Jorgen Loland	2008-12-16
      Bug#41012 - Error checks when reading backup image not covered by tests.
      
      Previously, there were no tests of RESTORE when errors occured. This patch adds debug hooks that can be used to inject error into the RESTORE code.
[23 Jan 2009 13:55] Jørgen Løland
The following analysis was done to add tests for error handling in do_restore. All places where do_restore calls a method that can fail, error is injected at the lowest feasible place. The rationale for this is to make error injection test as much error handling code as possible.

METHOD CALL                        EXECUTE_IF KEYWORD      
-----------------------------------------------------
read_meta_data                     restore_read_meta_data
s.next_chunk                       restore_stream_next_chunk
lock_tables_for_restore            restore_lock_tables_for_restore
restore_table_data                 
 '-> in the main data reading loop restore_tbl_data_read
 '-> in default driver send_data   restore_default_send_data
restore_triggers_and_events
 '-> in trigger code only          restore_trigger
read_summary                       restore_read_summary

Remains untested - cannot fail if properly initialized:
-------------------------------------------------------
report_vp_time
report_binlog_pos
and method calls tagged "Never errors"
[23 Jan 2009 14:09] 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/63901

2754 Jorgen Loland	2009-01-23
      Bug#41012 - Error checks when reading backup image not covered by tests.
            
      Previously, there were no tests of RESTORE when errors occured. This patch adds debug hooks that can be used to inject error into the RESTORE code.
[26 Jan 2009 8:57] 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/64018

2754 Jorgen Loland	2009-01-26
      Bug#41012 - Error checks when reading backup image not covered by tests.
                  
      Previously, there were no tests of RESTORE when errors occured. This patch adds debug hooks that can be used to inject error into the RESTORE code.
[26 Jan 2009 8:58] Jørgen Løland
Added test for more error scenarios:

METHOD CALL                             EXECUTE_IF KEYWORD      
----------------------------------------------------------
prepare_for_restore                     
 |-> read_header                        restore_read_header 
 |-> s.next_chunk                       restore_prepare_next_chunk_1
 |-> read_catalog                       restore_read_catalog
 '-> s.next_chunk                       restore_prepare_next_chunk_1

do_restore
 |-> read_meta_data                     restore_read_meta_data
 |-> s.next_chunk                       restore_stream_next_chunk
 |-> lock_tables_for_restore            restore_lock_tables_for_restore
 |-> restore_table_data                 
 |    |-> in the main data reading loop restore_tbl_data_read
 |    '-> in default driver send_data   restore_default_send_data
 |-> restore_triggers_and_events
 |    '-> in trigger code only          restore_trigger
 '->  read_summary                      restore_read_summary
[27 Jan 2009 12:57] 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/64124

2754 Jorgen Loland	2009-01-27
      Bug#41012 - Error checks when reading backup image not covered by tests.
                        
      Previously, there were no tests of RESTORE when errors occured. This patch adds debug hooks that can be used to inject error into the RESTORE code.
[27 Jan 2009 13:21] Rafal Somla
Good to push.
[30 Jan 2009 15:53] Chuck Bell
Patch approved.
[3 Feb 2009 7:48] 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/64969

2756 Jorgen Loland	2009-02-03
      Bug#41012 - Error checks when reading backup image not covered by tests.
                              
      Previously, there were no tests of RESTORE when errors occured. This patch adds debug hooks that can be used to inject error into the RESTORE code.
[26 Mar 2009 12:34] Bugs System
Pushed into 6.0.11-alpha (revid:alik@sun.com-20090326121822-pt84kzxxayzho4mn) (version source revid:jorgen.loland@sun.com-20090203074809-1l4sh01tklb3cxfm) (merge vers: 6.0.10-alpha) (pib:6)
[26 Mar 2009 23:39] Paul DuBois
These changes are to facilitate testing. No changelog entry needed.