List:Commits« Previous MessageNext Message »
From:cbell Date:June 29 2007 4:11am
Subject:bk commit into 5.2 tree (cbell:1.2542)
View as plain text  
Below is the list of changes that have just been committed into a local
5.2 repository of cbell. When cbell 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@stripped, 2007-06-29 00:11:05-04:00, cbell@mysql_cab_desk. +15 -0
  WL#3776 : Consistent snapshot backup for MVCC
  
  This patch adds consistent snapshot algorithm for online backup. The
  consistent snapshot algorithm is designed to work with any storage engine
  that supports a consistent read operation (transaction). Currently, this
  is limited to InnoDB but the code was written to allow the use of any
  storage engine that supposts consistent read via the consistent shapshot
  method in the handler.

  mysql-test/r/backup.result@stripped, 2007-06-29 00:10:56-04:00, cbell@mysql_cab_desk. +6 -6
    WL#3776 : Consistent snapshot backup for MVCC
    
    This patch adds the changes to the result file for the backup test.

  mysql-test/r/backup_snapshot.result@stripped, 2007-06-29 00:11:02-04:00, cbell@mysql_cab_desk. +58 -0
    WL#3776 : Consistent snapshot backup for MVCC
    
    This patch adds the changes to the result file for the backup_snapshot
    test.
    

  mysql-test/r/backup_snapshot.result@stripped, 2007-06-29 00:11:02-04:00, cbell@mysql_cab_desk. +0 -0

  mysql-test/t/backup.test@stripped, 2007-06-29 00:10:57-04:00, cbell@mysql_cab_desk. +6 -6
    WL#3776 : Consistent snapshot backup for MVCC
    
    This patch alters the base test file changing two of the tables to use
    innodb instead of myisam. This will require the backup kernel to use
    both the default and snapshot drivers.

  mysql-test/t/backup_snapshot.opt@stripped, 2007-06-29 00:11:01-04:00, cbell@mysql_cab_desk. +1 -0
    WL#3776 : Consistent snapshot backup for MVCC
    
    This patch adds the option file for the backup_snapshot test.
    

  mysql-test/t/backup_snapshot.opt@stripped, 2007-06-29 00:11:01-04:00, cbell@mysql_cab_desk. +0 -0

  mysql-test/t/backup_snapshot.test@stripped, 2007-06-29 00:11:02-04:00, cbell@mysql_cab_desk. +83 -0
    WL#3776 : Consistent snapshot backup for MVCC
    
    This patch adds a test file for the consistent snapshot algorithm. The test uses
    control insertion to ensure there are simultaneous inserts and deletes occuring at the
    same time as the backup.
    

  mysql-test/t/backup_snapshot.test@stripped, 2007-06-29 00:11:02-04:00, cbell@mysql_cab_desk. +0 -0

  sql/CMakeLists.txt@stripped, 2007-06-29 00:10:57-04:00, cbell@mysql_cab_desk. +1 -0
    WL#3776 : Consistent snapshot backup for MVCC
    
    This patch adds the consistent snapshot files to the CMakeLists.txt file.

  sql/backup/Makefile.am@stripped, 2007-06-29 00:10:57-04:00, cbell@mysql_cab_desk. +2 -0
    WL#3776 : Consistent snapshot backup for MVCC
    
    This patch adds the consistent snapshot files to the CMakeLists.txt file.

  sql/backup/archive.cc@stripped, 2007-06-29 00:10:58-04:00, cbell@mysql_cab_desk. +4 -0
    WL#3776 : Consistent snapshot backup for MVCC
    
    This patch adds the consistent snapshot class to the Image_info struct.

  sql/backup/archive.h@stripped, 2007-06-29 00:10:58-04:00, cbell@mysql_cab_desk. +1 -1
    WL#3776 : Consistent snapshot backup for MVCC
    
    This patch adds the consistent snapshot class to the image types for
    the Image_info struct.

  sql/backup/backup_kernel.h@stripped, 2007-06-29 00:10:59-04:00, cbell@mysql_cab_desk. +1 -0
    WL#3776 : Consistent snapshot backup for MVCC
    
    This patch adds a variable to store the index for the consistent snapshot
    driver in the images array.
    

  sql/backup/be_default.h@stripped, 2007-06-29 00:10:59-04:00, cbell@mysql_cab_desk. +1 -1
    WL#3776 : Consistent snapshot backup for MVCC
    
    This patch moves the variable tables_in_backup to the protected section
    so that they can be accessed by the snapshot code in the constructor.
    

  sql/backup/be_snapshot.cc@stripped, 2007-06-29 00:11:00-04:00, cbell@mysql_cab_desk. +159 -0
    WL#3776 : Consistent snapshot backup for MVCC
    
    This patch adds the consistent snapshot source file. This file contains 
    the consistent snapshot algorithm.
    

  sql/backup/be_snapshot.cc@stripped, 2007-06-29 00:11:00-04:00, cbell@mysql_cab_desk. +0 -0

  sql/backup/be_snapshot.h@stripped, 2007-06-29 00:11:01-04:00, cbell@mysql_cab_desk. +143 -0
    WL#3776 : Consistent snapshot backup for MVCC
    
    This patch adds the buffer_iterator class for buffering the blob fields for the 
    consistent snapshot and default drivers. This file contains the source code for the
    buffer iterator class.
    

  sql/backup/be_snapshot.h@stripped, 2007-06-29 00:11:01-04:00, cbell@mysql_cab_desk. +0 -0

  sql/backup/data_backup.cc@stripped, 2007-06-29 00:11:00-04:00, cbell@mysql_cab_desk. +6 -2
    WL#3776 : Consistent snapshot backup for MVCC
    
    This patch adds the consistent snapshot driver to the code to gather
    the tables for open in backup and restore.
    

  sql/backup/sql_backup.cc@stripped, 2007-06-29 00:11:00-04:00, cbell@mysql_cab_desk. +25 -4
    WL#3776 : Consistent snapshot backup for MVCC
    
    This patch adds the consistent snapshot option to the kernel backup image 
    generator.

# 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:	cbell
# Host:	mysql_cab_desk.
# Root:	C:/source/c++/mysql-5.2_WL_3776

--- 1.1/mysql-test/r/backup.result	2007-06-29 00:11:13 -04:00
+++ 1.2/mysql-test/r/backup.result	2007-06-29 00:11:13 -04:00
@@ -137,9 +137,9 @@
 `q` TEXT,
 PRIMARY KEY (`a`)
 ) ENGINE=myisam DEFAULT CHARSET=latin1;
-CREATE TABLE bup_default.t1 (a int) engine=myisam;
+CREATE TABLE bup_default.t1 (a int) engine=innodb;
 CREATE TABLE bup_default.t2 (a int) engine=myisam;
-CREATE TABLE bup_default.t1_blob (a int, b text);
+CREATE TABLE bup_default.t1_blob (a int, b text) engine=innodb;
 INSERT INTO bup_default.wide VALUES (
 NULL,
 "This is column b pass 01",
@@ -319,19 +319,19 @@
 Enter password:
 BACKUP DATABASE bup_default TO "bup_default.bak";
 Backup Summary
- header     =       40 bytes
+ header     =       43 bytes
  meta-data  =      890 bytes
  data       =     7425 bytes
               --------------
- total            8355 bytes
+ total            8358 bytes
 DROP DATABASE bup_default;
 RESTORE FROM "bup_default.bak";
 Restore Summary
- header     =       40 bytes
+ header     =       43 bytes
  meta-data  =      890 bytes
  data       =     7425 bytes
               --------------
- total            8355 bytes
+ total            8358 bytes
 SELECT * FROM bup_default.t1;
 a
 1

--- 1.1/mysql-test/t/backup.test	2007-06-29 00:11:13 -04:00
+++ 1.2/mysql-test/t/backup.test	2007-06-29 00:11:13 -04:00
@@ -1,3 +1,5 @@
+--source include/have_innodb.inc
+
 connect (backup,localhost,root,,);
 connect (restore,localhost,root,,);
 
@@ -124,10 +126,8 @@
 DROP DATABASE IF EXISTS db1;
 DROP DATABASE IF EXISTS db2;
 
-
-# This test is for the default online backup driver
-# The test is designed to show that a consistent snapshot
-# backup can be taken while data is being inserted and deleted.
+#
+# This test is for the default and snapshot online backup drivers
 #
 
 connection backup;
@@ -161,9 +161,9 @@
   PRIMARY KEY (`a`)
 ) ENGINE=myisam DEFAULT CHARSET=latin1;
 
-CREATE TABLE bup_default.t1 (a int) engine=myisam;
+CREATE TABLE bup_default.t1 (a int) engine=innodb;
 CREATE TABLE bup_default.t2 (a int) engine=myisam;
-CREATE TABLE bup_default.t1_blob (a int, b text);
+CREATE TABLE bup_default.t1_blob (a int, b text) engine=innodb;
 
 # Insert some data.
 

--- 1.1/sql/backup/be_default.h	2007-06-29 00:11:13 -04:00
+++ 1.2/sql/backup/be_default.h	2007-06-29 00:11:13 -04:00
@@ -103,6 +103,7 @@
  protected:
     THD *m_thd;                    ///< Pointer to current thread struct.
     TABLE_LIST *all_tables;        ///< Reference to list of tables used.
+    TABLE_LIST *tables_in_backup;  ///< List of tables used in backup.
     my_bool lock_called;           ///< Checks to see if locks have been reached.
 
   private:
@@ -134,7 +135,6 @@
     Buffer_iterator rec_buffer;    ///< Buffer iterator for windowing records
     Buffer_iterator blob_buffer;   ///< Buffer iterator for windowing BLOB fields
     byte *ptr;                     ///< Pointer to blob data from record.
-    TABLE_LIST *tables_in_backup;  ///< List of tables used in backup.
 };
 
 /**
--- New file ---
+++ mysql-test/r/backup_snapshot.result	07/06/29 00:11:02
DROP DATABASE IF EXISTS bup_snapshot;
CREATE DATABASE bup_snapshot;
CREATE TABLE bup_snapshot.t1 (word CHAR(20)) ENGINE=INNODB;
INSERT INTO bup_snapshot.t1 VALUES ("01 Some data to test");
INSERT INTO bup_snapshot.t1 VALUES ("02 Some data to test");
INSERT INTO bup_snapshot.t1 VALUES ("03 Some data to test");
INSERT INTO bup_snapshot.t1 VALUES ("04 Some data to test");
INSERT INTO bup_snapshot.t1 VALUES ("05 Some data to test");
INSERT INTO bup_snapshot.t1 VALUES ("06 Some data to test");
INSERT INTO bup_snapshot.t1 VALUES ("07 Some data to test");
INSERT INTO bup_snapshot.t1 VALUES ("08 Some data to test");
INSERT INTO bup_snapshot.t1 VALUES ("09 Some data to test");
INSERT INTO bup_snapshot.t1 VALUES ("10 Some data to test");
con1: Show that the new data doesn't exist before backup.
SELECT * FROM bup_snapshot.t1 WHERE word LIKE '-%';
word
SELECT COUNT(*) FROM bup_snapshot.t1;
COUNT(*)
10
con1: Backing up database.
BACKUP DATABASE bup_snapshot TO "bup_snapshot.bak";
Backup Summary
 header     =       22 bytes
 meta-data  =       95 bytes
 data       =      260 bytes
              --------------
 total             377 bytes
con2: Inserting new data.
INSERT INTO bup_snapshot.t1 VALUES("- Dave Mathews");
INSERT INTO bup_snapshot.t1 VALUES("- Yes");
INSERT INTO bup_snapshot.t1 VALUES("- Jethro Tull");
DELETE FROM bup_snapshot.t1 WHERE word LIKE '10%';
con2: Showing the data after inserts.
SELECT * FROM bup_snapshot.t1 WHERE word LIKE '-%';
word
- Dave Mathews
- Yes
- Jethro Tull
SELECT COUNT(*) FROM bup_snapshot.t1;
COUNT(*)
12
con1: Dropping the database
DROP TABLE bup_snapshot.t1;
con1: Restoring the database
RESTORE FROM "bup_snapshot.bak";
Restore Summary
 header     =       22 bytes
 meta-data  =       95 bytes
 data       =      260 bytes
              --------------
 total             377 bytes
con1: Showing the data (no new data should be here).
SELECT * FROM bup_snapshot.t1 WHERE word LIKE '-%';
word
SELECT COUNT(*) FROM bup_snapshot.t1;
COUNT(*)
10
DROP DATABASE IF EXISTS bup_snapshot;

--- New file ---
+++ mysql-test/t/backup_snapshot.opt	07/06/29 00:11:01
--loose-debug=d,SLEEP_SNAPSHOT

--- New file ---
+++ mysql-test/t/backup_snapshot.test	07/06/29 00:11:02
#
# This test is for the consistent snapshot online backup driver
# The test is designed to show that a consistent snapshot
# backup can be taken while data is being inserted and deleted.
#
# TODO
#  - Make the test run the insert statements in parallel with the backup
#    command using --send and --reap and signals from backup code.
#

--source include/have_innodb.inc
--source include/have_debug.inc

--disable_warnings
DROP DATABASE IF EXISTS bup_snapshot;
--enable_warnings

CREATE DATABASE bup_snapshot;

connect (con1,localhost,root,,);
connect (con2,localhost,root,,);

connection con1;

# Create a table and load it with lots of data.

CREATE TABLE bup_snapshot.t1 (word CHAR(20)) ENGINE=INNODB;

INSERT INTO bup_snapshot.t1 VALUES ("01 Some data to test");
INSERT INTO bup_snapshot.t1 VALUES ("02 Some data to test");
INSERT INTO bup_snapshot.t1 VALUES ("03 Some data to test");
INSERT INTO bup_snapshot.t1 VALUES ("04 Some data to test");
INSERT INTO bup_snapshot.t1 VALUES ("05 Some data to test");
INSERT INTO bup_snapshot.t1 VALUES ("06 Some data to test");
INSERT INTO bup_snapshot.t1 VALUES ("07 Some data to test");
INSERT INTO bup_snapshot.t1 VALUES ("08 Some data to test");
INSERT INTO bup_snapshot.t1 VALUES ("09 Some data to test");
INSERT INTO bup_snapshot.t1 VALUES ("10 Some data to test");

--echo con1: Show that the new data doesn't exist before backup.
SELECT * FROM bup_snapshot.t1 WHERE word LIKE '-%';
SELECT COUNT(*) FROM bup_snapshot.t1;

# While a consistent snapshot backup is executed,
# no external inserts should be visible to the transaction.

--echo con1: Backing up database.
BACKUP DATABASE bup_snapshot TO "bup_snapshot.bak";

connection con2;

--echo con2: Inserting new data.
INSERT INTO bup_snapshot.t1 VALUES("- Dave Mathews");
INSERT INTO bup_snapshot.t1 VALUES("- Yes");
INSERT INTO bup_snapshot.t1 VALUES("- Jethro Tull");
DELETE FROM bup_snapshot.t1 WHERE word LIKE '10%';

--echo con2: Showing the data after inserts.
SELECT * FROM bup_snapshot.t1 WHERE word LIKE '-%';
SELECT COUNT(*) FROM bup_snapshot.t1;

connection con1;

# Now restore the database and then check to make sure the new rows
# were not backed up.

--echo con1: Dropping the database
DROP TABLE bup_snapshot.t1;

--echo con1: Restoring the database
RESTORE FROM "bup_snapshot.bak";

--echo con1: Showing the data (no new data should be here).
SELECT * FROM bup_snapshot.t1 WHERE word LIKE '-%';
SELECT COUNT(*) FROM bup_snapshot.t1;

--disable_warnings
DROP DATABASE IF EXISTS bup_snapshot;
--enable_warnings

--exec rm $MYSQLTEST_VARDIR/master-data/bup_snapshot.bak



--- New file ---
+++ sql/backup/be_snapshot.cc	07/06/29 00:11:00
/* Copyright (C) 2004-2007 MySQL AB

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; version 2 of the License.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
*/

/**
 * @file
 *
 * @brief Contains the snapshot backup algorithm driver.
 *
 * This file contains the snapshot backup algorithm (also called a "driver"
 * in the online backup terminology. The snapshot backup algorithm may be
 * used in place of an engine-specific driver if one does not exist or if
 * chosen by the user.
 *
 * The snapshot backup algorithm is a non-blocking algorithm that enables a
 * consistent read of the tables given at the start of the backup/restore 
 * process. This is accomplished by using a consistent snapshot transaction
 * and table locks. Once all of the data is backed up or restored, the locks 
 * are removed. The snapshot backup is a row-level backup and therefore does 
 * not backup the indexes or any of the engine-specific files.
 *
 * The classes in this file use the namespace "snapshot_backup" to distinguish
 * these classes from other backup drivers. The backup functionality is
 * contained in the backup class shown below. Similarly, the restore
 * functionality is contained in the restore class below.
 *
 * The format of the backup is the same as the default backup driver.
 * Please see <code> be_default.cc </code> for a complete description.
 */

#include "mysql_priv.h"
#include "backup_engine.h"
#include "be_snapshot.h"
#include "backup_aux.h"

namespace snapshot_backup {

using backup::byte;
using backup::result_t;
using backup::version_t;
using backup::Table_list;
using backup::Table_ref;
using backup::Buffer;
using namespace backup;

/**
 * Create a snapshot backup backup driver.
 *
 * Given a list of tables to be backed-up, create instance of backup
 * driver which will create backup image of these tables.
 *
 * @param  tables (in) list of tables to be backed-up.
 * @param  eng    (out) pointer to backup driver instance.
 *
 * @retval Error code or backup::OK on success.
 */
result_t Engine::get_backup(const uint32, const Table_list &tables, Backup_driver*
&drv)
{
  DBUG_ENTER("Engine::get_backup");
  Backup *ptr= new snapshot_backup::Backup(tables, m_thd);
  if (!ptr)
    DBUG_RETURN(ERROR);
  drv= (backup::Backup_driver *)ptr;
  DBUG_RETURN(OK);
}

Backup::Backup(const Table_list &tables, THD *t_thd): 
  default_backup::Backup(tables, t_thd)
{
  DBUG_PRINT("default_backup",("Creating backup driver"));
  lock_called= FALSE;   /* lock has not been called */

  /*
     Create a TABLE_LIST * list for iterating through the tables.
     Initialize the list for opening the tables in read mode.
  */
  tables_in_backup= build_table_list(tables, TL_READ);
  all_tables= tables_in_backup;
  if (all_tables)
    for (TABLE_LIST *tbl= all_tables; tbl != NULL; tbl= tbl->next_global)
      tbl->lock_type= TL_READ;
}

/**
 * @brief End backup process.
 *
 * This method unlocks all of the tables.
 *
 * @retval backup::OK    all tables unlocked.
 */
result_t Backup::end()
{
  DBUG_ENTER("Snapshot_backup::end");
  end_active_trans(m_thd);
  DBUG_RETURN(OK);
}

result_t Backup::lock()
{
  DBUG_ENTER("Snapshot_backup::lock()");
  /*
    We must fool the locking code to think this is a select because
    any other command type places the engine in a non-consistent read
    state. 
  */
  m_thd->lex->sql_command= SQLCOM_SELECT; 
  m_thd->lex->start_transaction_opt|= MYSQL_START_TRANS_OPT_WITH_CONS_SNAPSHOT;
  int res= begin_trans(m_thd);
  if (res)
    DBUG_RETURN(ERROR);
  lock_called= TRUE;
  DBUG_RETURN(OK);
}

result_t Backup::unlock()
{
  DBUG_ENTER("Snapshot_backup::unlock()");
  DBUG_RETURN(OK);
}

/**
 * Create a snapshot backup restore driver.
 *
 * Given a list of tables to be restored, create instance of restore
 * driver which will restore these tables from a backup image.
 *
 * @param  version  (in) version of the backup image.
 * @param  tables   (in) list of tables to be restored.
 * @param  eng      (out) pointer to restore driver instance.
 *
 * @retval Error code or backup::OK on success.
 */
result_t Engine::get_restore(version_t ver, const uint32, const Table_list &tables,
Restore_driver* &drv)
{
  DBUG_ENTER("Engine::get_restore");
  Restore *ptr= new snapshot_backup::Restore(tables, m_thd);
  if (!ptr)
    DBUG_RETURN(ERROR);
  drv= ptr;
  DBUG_RETURN(OK);
}

} /* snapshot_backup namespace */



--- New file ---
+++ sql/backup/be_snapshot.h	07/06/29 00:11:01
#ifndef _SNAPSHOT_BACKUP_H
#define _SNAPSHOT_BACKUP_H

#include "archive.h"        
#include "buffer_iterator.h"
#include "be_default.h"

namespace snapshot_backup {

using backup::byte;
using backup::result_t;
using backup::version_t;
using backup::Table_list;
using backup::Table_ref;
using backup::Buffer;

/**
 * @class Engine
 *
 * @brief Encapsulates snapshot online backup/restore functionality.
 *
 * This class is used to initiate the snapshot backup algorithm, which is used
 * by the backup kernel to create a backup image of data stored in any
 * engine that does not have a native backup driver but supports consisten reads.
 * It may also be used as an option by the user.
 *
 * Using this class, the caller can create an instance of the snapshot backup
 * backup and restore class. The backup class is used to backup data for a
 * list of tables. The restore class is used to restore data from a
 * previously created snapshot backup image.
 */
class Engine: public Backup_engine
{
  public:
    Engine(THD *t_thd) { m_thd= t_thd; }

    /// Return version of backup images created by this engine.
    const version_t version() const { return 0; };
    result_t get_backup(const uint32, const Table_list &tables, Backup_driver*
&drv);
    result_t get_restore(version_t ver, const uint32, const Table_list &tables,
                         Restore_driver* &drv);
  private:
    THD *m_thd;     ///< Pointer to the current thread.
};

/**
 * @class Backup
 *
 * @brief Contains the snapshot backup algorithm backup functionality.
 *
 * The backup class is a row-level backup mechanism designed to perform
 * a table scan on each table reading the rows and saving the data to the
 * buffer from the backup algorithm using a consistent read transaction.
 *
 * @see <backup driver>
 */
class Backup: public default_backup::Backup
{
  public:
    Backup(const Table_list &tables, THD *t_thd);
    virtual ~Backup(){};
    result_t begin(const size_t) { return backup::OK; };
    result_t end();
    result_t prelock() { return backup::READY; }
    result_t lock();
    result_t unlock();
};

/**
 * @class Restore
 *
 * @brief Contains the snapshot backup algorithm restore functionality.
 *
 * The restore class is a row-level backup mechanism designed to restore
 * data for each table by writing the data for the rows from the
 * buffer given by the backup algorithm.
 *
 * @see <restore driver>
 */
class Restore: public default_backup::Restore
{
  public:
    Restore(const Table_list &tables, THD *t_thd):
      default_backup::Restore(tables, t_thd){};
    virtual ~Restore(){};
    void free() { delete this; };
};
} // snapshot_backup namespace


/*********************************************************************

  Snapshot image class

 *********************************************************************/

namespace backup {


class Snapshot_image: public Image_info
{
 public:

  Snapshot_image(Archive_info &info): Image_info(info)
  { ver= 1; }

  image_type type() const
  { return SNAPSHOT_IMAGE; }

  const char* name() const
  { return "Snapshot"; }

  bool accept(const Table_ref&, const ::handlerton* h)
  { 
    return (h->start_consistent_snapshot != NULL); 
  }; // accept all tables that support consistent read

  result_t get_backup_driver(Backup_driver* &ptr)
  { return (ptr= new snapshot_backup::Backup(tables,::current_thd)) ? OK : ERROR; }

  result_t get_restore_driver(Restore_driver* &ptr)
  { return (ptr= new snapshot_backup::Restore(tables,::current_thd)) ? OK : ERROR; }

  result_t do_write_description(OStream&)
  { return OK; } // nothing to write

  static result_t
  create_from_stream(version_t, Archive_info &info, IStream&,
                     Image_info* &ptr)
  {
    return (ptr= new Snapshot_image(info)) ? OK : ERROR;
  }

  bool is_valid(){ return TRUE; };

};

} // backup namespace


#endif



--- 1.7/sql/backup/Makefile.am	2007-06-29 00:11:13 -04:00
+++ 1.8/sql/backup/Makefile.am	2007-06-29 00:11:13 -04:00
@@ -32,6 +32,7 @@
 	data_backup.cc \
 	sql_backup.cc \
       be_default.cc \
+      be_snapshot.cc \
       buffer_iterator.cc
 
 noinst_HEADERS = \
@@ -48,6 +49,7 @@
     archive.h \
     meta_backup.h \
       be_default.h \
+      be_snapshot.h \
       buffer_iterator.h
 
 DEFS = \

--- 1.4/sql/backup/archive.cc	2007-06-29 00:11:13 -04:00
+++ 1.5/sql/backup/archive.cc	2007-06-29 00:11:13 -04:00
@@ -25,6 +25,7 @@
 #include "backup_aux.h"
 #include "archive.h"
 #include "be_default.h"
+#include "be_snapshot.h"
 
 /***************************************
 
@@ -354,6 +355,9 @@
 
   case DEFAULT_IMAGE:
     return Default_image::create_from_stream(ver,info,s,ptr);
+
+  case SNAPSHOT_IMAGE:
+    return Snapshot_image::create_from_stream(ver,info,s,ptr);
 
   default:
     DBUG_PRINT("restore",("Unknown image type %d",t));

--- 1.3/sql/backup/archive.h	2007-06-29 00:11:13 -04:00
+++ 1.4/sql/backup/archive.h	2007-06-29 00:11:13 -04:00
@@ -116,7 +116,7 @@
 {
  public:
  
-  enum image_type {NATIVE_IMAGE, DEFAULT_IMAGE};
+  enum image_type {NATIVE_IMAGE, DEFAULT_IMAGE, SNAPSHOT_IMAGE};
 
   virtual image_type type() const =0; ///< Return type of the image.
   version_t ver;  ///< Image format version.

--- 1.2/sql/backup/backup_kernel.h	2007-06-29 00:11:13 -04:00
+++ 1.3/sql/backup/backup_kernel.h	2007-06-29 00:11:13 -04:00
@@ -150,6 +150,7 @@
   int find_image(const Table_ref&);
 
   int default_image_no; ///< Position of the default image in @c images list, -1 if not used.
+  int snapshot_image_no; ///< Position of the snapshot image in @c images list, -1 if not used.
 
   Db_item*    add_db(const backup::Db_ref&);
   Table_item* add_table(Db_item&, const Table_ref&);

--- 1.6/sql/backup/data_backup.cc	2007-06-29 00:11:13 -04:00
+++ 1.7/sql/backup/data_backup.cc	2007-06-29 00:11:13 -04:00
@@ -44,6 +44,7 @@
 #include "backup_kernel.h"
 #include "debug.h"
 #include "be_default.h"
+#include "be_snapshot.h"
 
 /***********************************************
 
@@ -343,6 +344,7 @@
     table_list_last= table_list;
     while (table_list_last->next_global != NULL)
       table_list_last= table_list_last->next_global;
+    *tables_last= table_list_last;
   }
   else
     if (backup_drv)
@@ -416,7 +418,8 @@
       inactive.push_back(p);
     }
     if (!def_or_snap_used)
-      def_or_snap_used=  (i->type() == Image_info::DEFAULT_IMAGE);
+      def_or_snap_used=  ((i->type() == Image_info::DEFAULT_IMAGE) ||
+                          (i->type() == Image_info::SNAPSHOT_IMAGE));
     if (def_or_snap_used)
       get_default_snapshot_tables(&p->drv(), NULL, 
                                   &table_list, &table_list_last);
@@ -1293,7 +1296,8 @@
       Collect tables from default and snapshot for open and lock tables.
       There should be at most only 1 of each driver.
     */
-    if (img->type() == Image_info::DEFAULT_IMAGE)
+    if ((img->type() == Image_info::DEFAULT_IMAGE) ||
+        (img->type() == Image_info::SNAPSHOT_IMAGE))
       get_default_snapshot_tables(NULL, (default_backup::Restore *)drv[no], 
                                   &table_list, &table_list_last);
   }

--- 1.9/sql/backup/sql_backup.cc	2007-06-29 00:11:13 -04:00
+++ 1.10/sql/backup/sql_backup.cc	2007-06-29 00:11:13 -04:00
@@ -29,6 +29,7 @@
 #include "archive.h"
 #include "debug.h"
 #include "be_default.h"
+#include "be_snapshot.h"
 
 namespace backup {
 
@@ -352,7 +353,9 @@
    3. Otherwise check if one of the existing sub-images would accept table from
       this location.
 
-   4. When everything else fails, use default (blocking) backup driver.
+   4. If table has no native backup engine, try a consistent snapshot one.
+
+   5. When everything else fails, use default (blocking) backup driver.
 
    Note: 1 is not implemented yet and hence we start with 3.
  */
@@ -380,6 +383,9 @@
      if (default_image_no >= 0 && no == (uint)default_image_no)
        continue;
 
+     if (snapshot_image_no >= 0 && no == (uint)snapshot_image_no)
+       continue;
+
      img= images[no];
 
      // An image object decides if it can handle given table or not
@@ -419,9 +425,23 @@
      DBUG_RETURN(no);
    }
 
-   // Points 4: try default driver...
+   // Points 4 & 5: try consistent snapshot and default drivers..
 
-   int ino= default_image_no; //now try default driver
+   // try snapshot driver first
+   int ino= snapshot_image_no;
+   if (hton->start_consistent_snapshot != NULL)
+   {
+     if (snapshot_image_no < 0) //image doesn't exist
+     {
+       ino= img_count;
+       snapshot_image_no= img_count;
+       images[snapshot_image_no]= new Snapshot_image(*this);
+       img_count++;
+       DBUG_PRINT("backup",("Snapshot image added to archive"));
+     }
+   }
+   else
+     ino= default_image_no; //now try default driver
 
    if (ino < 0) //image doesn't exist
    {
@@ -466,7 +486,8 @@
   closed when the structure is closed with the @c close() method.
  */
 Backup_info::Backup_info(THD *thd):
-  m_state(INIT), default_image_no(-1), m_thd(thd), i_s_tables(NULL),
+  m_state(INIT), default_image_no(-1), snapshot_image_no(-2), 
+  m_thd(thd), i_s_tables(NULL),
   m_items(NULL), m_last_item(NULL), m_last_db(NULL)
 {
   i_s_tables= get_schema_table(m_thd, ::get_schema_table(SCH_TABLES));

--- 1.43/sql/CMakeLists.txt	2007-06-29 00:11:13 -04:00
+++ 1.44/sql/CMakeLists.txt	2007-06-29 00:11:13 -04:00
@@ -77,6 +77,7 @@
                backup/stream.cc backup/logger.cc backup/string_pool.cc
                backup/archive.cc backup/meta_backup.cc backup/data_backup.cc
                backup/sql_backup.cc backup/be_default.cc backup/buffer_iterator.cc
+               backup/be_snapshot.cc
                ${PROJECT_SOURCE_DIR}/sql/sql_yacc.cc
   			   ${PROJECT_SOURCE_DIR}/sql/sql_yacc.h
 			   ${PROJECT_SOURCE_DIR}/include/mysqld_error.h

Thread
bk commit into 5.2 tree (cbell:1.2542)cbell29 Jun