List:Commits« Previous MessageNext Message »
From:rsomla Date:February 19 2008 11:15am
Subject:bk commit into 6.0 tree (rafal:1.2767) WL#4212
View as plain text  
Below is the list of changes that have just been committed into a local
6.0 repository of rafal. When rafal 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, 2008-02-19 12:15:21+01:00, rafal@quant.(none) +23 -0
  WL#4212 (Online Backup : Kernel updates for object metadata changes)
  
  This is third and last patch implementing this WL. It changes structure of the 
  backup source code as described in the WL. The main changes:
  
  a) Move definitions and implementations of classes Image_info, Backup_info and 
  Restore_info to separate files, respectively: image_info.{h,cc}, 
  backup_info.{h,cc} and restore_info.h. Note that there is no .cc file for 
  Restore_info structure as all its methods are inlined.
  
  b) Implement consistent policy for using #include directive, as detailed in the 
  WL.
  
  The patch mostly moves code around without changing it. However there are small 
  changes in kernel.cc fixing problems with error reporting, not captured in the 
  previous patch.

  BitKeeper/deleted/.del-catalog.cc@stripped, 2008-02-19 11:53:35+01:00, rafal@quant.(none) +0 -0
    Delete: sql/backup/catalog.cc

  BitKeeper/deleted/.del-catalog.h@stripped, 2008-02-19 11:53:36+01:00, rafal@quant.(none) +0 -0
    Delete: sql/backup/catalog.h

  sql/backup/CMakeLists.txt@stripped, 2008-02-19 12:15:10+01:00, rafal@quant.(none) +1 -1
    Added new files.

  sql/backup/Makefile.am@stripped, 2008-02-19 12:15:11+01:00, rafal@quant.(none) +5 -2
    Added new files.

  sql/backup/backup_kernel.h@stripped, 2008-02-19 12:15:11+01:00, rafal@quant.(none) +3 -157
    - Definitions of Backup/Restore_info classes moved to separate header files.

  sql/backup/backup_progress.cc@stripped, 2008-02-19 12:15:11+01:00, rafal@quant.(none) +1 -0
    Include mysql_priv.h here, not in the header..

  sql/backup/backup_progress.h@stripped, 2008-02-19 12:15:11+01:00, rafal@quant.(none) +0 -4
    Remove headers which are not needed.

  sql/backup/backup_stream.h@stripped, 2008-02-19 12:15:11+01:00, rafal@quant.(none) +1 -1
    Adapt guidelines for using #include directive.

  sql/backup/be_default.cc@stripped, 2008-02-19 12:15:11+01:00, rafal@quant.(none) +1 -0
    Add missing header file.

  sql/backup/be_default.h@stripped, 2008-02-19 12:15:11+01:00, rafal@quant.(none) +5 -6
    Adapt guidelines for using #include directive and remove not used headers.

  sql/backup/be_native.h@stripped, 2008-02-19 12:15:11+01:00, rafal@quant.(none) +2 -1
    Fix included headers.

  sql/backup/be_snapshot.cc@stripped, 2008-02-19 12:15:11+01:00, rafal@quant.(none) +2 -1
    Fix included headers.

  sql/backup/be_snapshot.h@stripped, 2008-02-19 12:15:11+01:00, rafal@quant.(none) +3 -3
    Adapt guidelines for using #include directive.

  sql/backup/be_thread.cc@stripped, 2008-02-19 12:15:11+01:00, rafal@quant.(none) +1 -0
    Fix included headers.

  sql/backup/be_thread.h@stripped, 2008-02-19 12:15:12+01:00, rafal@quant.(none) +2 -4
    Adapt guidelines for using #include directive and remove not used headers.

  sql/backup/buffer_iterator.cc@stripped, 2008-02-19 12:15:12+01:00, rafal@quant.(none) +1 -0
    Adapt guidelines for using #include directive.

  sql/backup/buffer_iterator.h@stripped, 2008-02-19 12:15:12+01:00, rafal@quant.(none) +0 -2
    Dont include mysql_priv.h from other header files.

  sql/backup/data_backup.cc@stripped, 2008-02-19 12:15:12+01:00, rafal@quant.(none) +4 -4
    Fix included headers.

  sql/backup/kernel.cc@stripped, 2008-02-19 12:15:12+01:00, rafal@quant.(none) +76 -516
    - Move helper functions send_error() and send_reply() closer to the place where they are used.
    - Fix problem with reporting ACCESS_DENIED error.
    - Enable saving errors in the logger - otherwise error reporting doesn't work as expected.
    - Implementation of Backup_info moved from here to backup_info.cc.

  sql/backup/logger.cc@stripped, 2008-02-19 12:15:12+01:00, rafal@quant.(none) +1 -1
    Fix included headers.

  sql/backup/stream.cc@stripped, 2008-02-19 12:15:12+01:00, rafal@quant.(none) +1 -1
    Adapt guidelines for using #include directive.

  sql/backup/stream.h@stripped, 2008-02-19 12:15:12+01:00, rafal@quant.(none) +56 -0
    Move wrappers around backup stream library functions here (previously in catalog.h).

  sql/backup/stream_services.h@stripped, 2008-02-19 12:15:12+01:00, rafal@quant.(none) +1 -1
    Adapt guidelines for using #include directive.

diff -Nrup a/sql/backup/CMakeLists.txt b/sql/backup/CMakeLists.txt
--- a/sql/backup/CMakeLists.txt	2008-01-31 05:40:29 +01:00
+++ b/sql/backup/CMakeLists.txt	2008-02-19 12:15:10 +01:00
@@ -23,7 +23,7 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/
                     ${CMAKE_SOURCE_DIR}/extra/yassl/include)
 
 SET(BACKUP_SOURCES stream.cc logger.cc kernel.cc
-               catalog.cc data_backup.cc
+               image_info.cc backup_info.cc data_backup.cc
                be_default.cc buffer_iterator.cc
                be_snapshot.cc be_thread.cc backup_progress.cc
                backup_test.cc)
diff -Nrup a/sql/backup/Makefile.am b/sql/backup/Makefile.am
--- a/sql/backup/Makefile.am	2008-01-15 01:26:32 +01:00
+++ b/sql/backup/Makefile.am	2008-02-19 12:15:11 +01:00
@@ -28,7 +28,8 @@ INCLUDES = \
 libbackup_la_SOURCES = \
   stream.cc \
   logger.cc \
-  catalog.cc \
+  image_info.cc \
+  backup_info.cc \
   kernel.cc \
   data_backup.cc \
   be_default.cc \
@@ -55,7 +56,9 @@ noinst_HEADERS = \
   stream.h \
   backup_aux.h \
   logger.h \
-  catalog.h \
+  image_info.h \
+  backup_info.h \
+  restore_info.h \
   be_native.h \
   be_default.h \
   be_snapshot.h \
diff -Nrup a/sql/backup/backup_kernel.h b/sql/backup/backup_kernel.h
--- a/sql/backup/backup_kernel.h	2008-02-18 13:04:23 +01:00
+++ b/sql/backup/backup_kernel.h	2008-02-19 12:15:11 +01:00
@@ -1,8 +1,8 @@
 #ifndef _BACKUP_KERNEL_API_H
 #define _BACKUP_KERNEL_API_H
 
-#include <backup/api_types.h>
-#include <backup/catalog.h>
+#include <backup/backup_info.h>
+#include <backup/restore_info.h>
 #include <backup/logger.h>
 #include <backup/stream_services.h>
 
@@ -36,14 +36,10 @@ int execute_backup_command(THD*, LEX*);
 
 // forward declarations
 
-class Backup_info;
-class Restore_info;
-
 namespace backup {
 
 class Mem_allocator;
-class OStream;
-class IStream;
+class Stream;
 class Native_snapshot;
 
 int write_table_data(THD*, Logger&, Backup_info&, OStream&);
@@ -163,156 +159,6 @@ int Backup_restore_ctx::fatal_error(int 
   va_end(args);
 
   return error_code;
-}
-
-/**
-  Specialization of @c Image_info which adds methods for selecting objects
-  to backup.
-
-  A pointer to empty @c Backup_info instance is returned by 
-  @c Backup_restore_ctx::prepare_for_backup() method.
-  Methods @c add_dbs() or @c add_all_dbs() can be used to select which databases
-  should be backed up. When this is done, the @c Backup_info object should be
-  "closed" with @c close() method. Only then it is ready to be used in a backup
-  operation.
-*/
-class Backup_info: public backup::Image_info
-{
- public:
-
-  Backup_restore_ctx &m_ctx;
-
-  Backup_info(Backup_restore_ctx&);
-  ~Backup_info();
-
-  bool is_valid();
-
-  int add_dbs(List< ::LEX_STRING >&);
-  int add_all_dbs();
-
-  int close();
-
- private:
-
-  /// State of the info structure.
-  enum {CREATED,
-        CLOSED,  
-        ERROR}   m_state;
-
-  backup::Snapshot_info* find_backup_engine(const backup::Table_ref&);
-
-  Db* add_db(obs::Obj*);
-  Table* add_table(Db&, obs::Obj*);
-
-  int add_db_items(Db&);
-  
-  /**
-    List of existing @c Snapshot_info objects.
-    
-    This list is used when selecting a backup engine for a given table. Order
-    of this list is important -- more preferred snapshots should come first. 
-   */ 
-  List<backup::Snapshot_info> snapshots;
-  
-  /**
-    Stores existing native snapshot objects.
-    
-    Given reference to a storage engine, a corresponding native snapshot object
-    can be quickly located if it was already created. 
-   */ 
-  Map<storage_engine_ref,backup::Native_snapshot > native_snapshots;
-
-  String serialization_buf; ///< Used to store serialization strings of backed-up objects.
-  
-  friend int backup::write_table_data(THD*, backup::Logger&, Backup_info&, 
-                                      backup::OStream&);
-  // Needs access to serialization_buf
-  friend int ::bcat_get_item_create_query(st_bstream_image_header *catalogue,
-                               struct st_bstream_item_info *item,
-                               bstream_blob *stmt);
-};
-
-/// Check if instance is correctly created.
-inline
-bool Backup_info::is_valid()
-{
-  return m_state != ERROR;
-}
-
-/**
-  Close @c Backup_info object after populating it with items.
-
-  After this call the @c Backup_info object is ready for use as a catalogue
-  for backup stream functions such as @c bstream_wr_preamble().
- */
-inline
-int Backup_info::close()
-{
-  if (!is_valid())
-    return ERROR;
-
-  if (m_state == CLOSED)
-    return 0;
-
-  // report backup drivers used in the image
-  
-  for (uint no=0; no < snap_count(); ++no)
-    m_ctx.report_driver(m_snap[no]->name());
-  
-  m_state= CLOSED;
-  return 0;
-}  
-
-
-/**
-  Specialization of @c Image_info which is in restore operation.
-
-  An instance of this class is created by 
-  @c Backup_restore_ctx::prepare_for_restore() method, which fills the catalogue
-  with data read from a backup image.
-  
-  Currently it is not possible to select objects which will be restored. Thus
-  this class can only be used to examine what is going to be restored.
- */
-
-class Restore_info: public backup::Image_info
-{
- public:
-
-  Backup_restore_ctx &m_ctx;
-
-  Restore_info(Backup_restore_ctx&);
-  ~Restore_info();
-
-  bool is_valid() const;
-
- private:
-
-  friend int backup::restore_table_data(THD*, backup::Logger&, Restore_info&, 
-                                        backup::IStream&);
-  friend int ::bcat_add_item(st_bstream_image_header*,
-                             struct st_bstream_item_info*);
-};
-
-inline
-Restore_info::Restore_info(Backup_restore_ctx &ctx):
-  m_ctx(ctx)
-{}
-
-inline
-Restore_info::~Restore_info()
-{
-  /*
-    Delete Snapshot_info instances - they are created in bcat_reset(). 
-   */
-  for (uint no=0; no < snap_count(); ++no)
-    delete m_snap[no];
-}
-
-inline
-bool Restore_info::is_valid() const
-{
-  return TRUE; 
 }
 
 #endif
diff -Nrup a/sql/backup/backup_progress.cc b/sql/backup/backup_progress.cc
--- a/sql/backup/backup_progress.cc	2008-01-31 18:26:20 +01:00
+++ b/sql/backup/backup_progress.cc	2008-02-19 12:15:11 +01:00
@@ -24,6 +24,7 @@
          of byte?
   */
 
+#include "../mysql_priv.h"
 #include "backup_progress.h"
 #include "be_thread.h"
 
diff -Nrup a/sql/backup/backup_progress.h b/sql/backup/backup_progress.h
--- a/sql/backup/backup_progress.h	2008-01-31 18:23:30 +01:00
+++ b/sql/backup/backup_progress.h	2008-02-19 12:15:11 +01:00
@@ -22,10 +22,6 @@
    Data Dictionary related operations of Online Backup.
 */
 
-#include "my_global.h"
-#include "my_time.h"
-#include "mysql_priv.h"
-
 /**
    List of fields for online backup table.
   */
diff -Nrup a/sql/backup/backup_stream.h b/sql/backup/backup_stream.h
--- a/sql/backup/backup_stream.h	2007-11-30 09:23:30 +01:00
+++ b/sql/backup/backup_stream.h	2008-02-19 12:15:11 +01:00
@@ -8,7 +8,7 @@ extern "C" {
 
 // We use version 1 of the stream format.
 
-#include "stream_v1.h"
+#include <backup/stream_v1.h>
 
 }
 
diff -Nrup a/sql/backup/be_default.cc b/sql/backup/be_default.cc
--- a/sql/backup/be_default.cc	2008-01-30 23:28:06 +01:00
+++ b/sql/backup/be_default.cc	2008-02-19 12:15:11 +01:00
@@ -68,6 +68,7 @@
 #include "be_default.h"
 #include "backup_aux.h"
 #include "rpl_record.h"
+#include "debug.h"
 
 namespace default_backup {
 
diff -Nrup a/sql/backup/be_default.h b/sql/backup/be_default.h
--- a/sql/backup/be_default.h	2008-02-12 18:17:50 +01:00
+++ b/sql/backup/be_default.h	2008-02-19 12:15:11 +01:00
@@ -1,12 +1,10 @@
 #ifndef _DEFAULT_BACKUP_H
 #define _DEFAULT_BACKUP_H
 
-#include <backup/backup_engine.h>
-#include "catalog.h"  // to define default backup image class
-#include "buffer_iterator.h"
-#include "backup_aux.h"
-#include "mysql_priv.h"
-#include "be_thread.h"
+#include <backup_engine.h>
+#include <backup/image_info.h>  // to define default backup image class
+#include <backup/buffer_iterator.h>
+#include <backup/be_thread.h>
 
 namespace default_backup {
 
@@ -207,6 +205,7 @@ class Restore: public Restore_driver
 
 namespace backup {
 
+class Logger;
 
 class Default_snapshot: public Snapshot_info
 {
diff -Nrup a/sql/backup/be_native.h b/sql/backup/be_native.h
--- a/sql/backup/be_native.h	2008-02-18 13:04:23 +01:00
+++ b/sql/backup/be_native.h	2008-02-19 12:15:11 +01:00
@@ -2,7 +2,8 @@
 #define BE_NATIVE_H_
 
 #include <backup_engine.h>
-#include "../sql_plugin.h"
+#include <backup/image_info.h>
+#include <backup/logger.h>
 
 namespace backup {
 
diff -Nrup a/sql/backup/be_snapshot.cc b/sql/backup/be_snapshot.cc
--- a/sql/backup/be_snapshot.cc	2007-11-30 05:22:05 +01:00
+++ b/sql/backup/be_snapshot.cc	2008-02-19 12:15:11 +01:00
@@ -40,10 +40,11 @@
  * Please see <code> be_default.cc </code> for a complete description.
  */
 
-#include "mysql_priv.h"
+#include "../mysql_priv.h"
 #include "backup_engine.h"
 #include "be_snapshot.h"
 #include "backup_aux.h"
+#include "debug.h"
 
 namespace snapshot_backup {
 
diff -Nrup a/sql/backup/be_snapshot.h b/sql/backup/be_snapshot.h
--- a/sql/backup/be_snapshot.h	2008-02-12 18:17:51 +01:00
+++ b/sql/backup/be_snapshot.h	2008-02-19 12:15:11 +01:00
@@ -1,9 +1,9 @@
 #ifndef _SNAPSHOT_BACKUP_H
 #define _SNAPSHOT_BACKUP_H
 
-#include "catalog.h"        
-#include "buffer_iterator.h"
-#include "be_default.h"
+#include <backup/image_info.h>        
+#include <backup/buffer_iterator.h>
+#include <backup/be_default.h>
 
 namespace snapshot_backup {
 
diff -Nrup a/sql/backup/be_thread.cc b/sql/backup/be_thread.cc
--- a/sql/backup/be_thread.cc	2008-01-30 23:28:06 +01:00
+++ b/sql/backup/be_thread.cc	2008-02-19 12:15:11 +01:00
@@ -24,6 +24,7 @@
   * calls easier for the driver code.
   */
 
+#include "../mysql_priv.h"
 #include "be_thread.h"
 
 /**
diff -Nrup a/sql/backup/be_thread.h b/sql/backup/be_thread.h
--- a/sql/backup/be_thread.h	2008-01-30 23:28:07 +01:00
+++ b/sql/backup/be_thread.h	2008-02-19 12:15:12 +01:00
@@ -1,10 +1,8 @@
 #ifndef _BACKUP_THREAD_H
 #define _BACKUP_THREAD_H
 
-#include "../mysql_priv.h"
-#include "catalog.h"
-#include "api_types.h"
-#include "backup_engine.h"
+#include <backup_engine.h>
+#include <backup/image_info.h>
 
 /**
    Macro for error handling.
diff -Nrup a/sql/backup/buffer_iterator.cc b/sql/backup/buffer_iterator.cc
--- a/sql/backup/buffer_iterator.cc	2007-11-06 19:32:12 +01:00
+++ b/sql/backup/buffer_iterator.cc	2008-02-19 12:15:12 +01:00
@@ -25,6 +25,7 @@
  * It can also be used to recombine the data from smaller windows.
   */
 
+#include "../mysql_priv.h"
 #include "buffer_iterator.h"
 
 /**
diff -Nrup a/sql/backup/buffer_iterator.h b/sql/backup/buffer_iterator.h
--- a/sql/backup/buffer_iterator.h	2007-11-06 19:32:13 +01:00
+++ b/sql/backup/buffer_iterator.h	2008-02-19 12:15:12 +01:00
@@ -1,8 +1,6 @@
 #ifndef _BUFFER_ITERATOR_H
 #define _BUFFER_ITERATOR_H
 
-#include "mysql_priv.h"
-
 using backup::byte;
 
 /**
diff -Nrup a/sql/backup/catalog.cc b/sql/backup/catalog.cc
--- a/sql/backup/catalog.cc	2008-02-18 13:04:23 +01:00
+++ /dev/null	Wed Dec 31 16:00:00 196900
@@ -1,240 +0,0 @@
-#include "../mysql_priv.h"
-
-#include "catalog.h"
-#include "be_native.h"
-
-/**
-  @file
-
-  @brief Implements @c Image_info class and friends.
-
-  @todo Error reporting
-  @todo Store endianess info in the image.
-*/
-
-namespace backup {
-
-Image_info::Image_info():
-  data_size(0), m_table_count(0), m_dbs(16,16)
-{
-  init_alloc_root(&mem_root, 4 * 1024, 0);
-
-  /* initialize st_bstream_image_header members */
-
-  bzero(static_cast<st_bstream_image_header*>(this),
-        sizeof(st_bstream_image_header));
-
-  version= 1;
-
-  /*
-    The arithmetic below assumes that MYSQL_VERSION_ID digits are arrenged
-    as follows: HLLRR where
-    H - major version number
-    L - minor version number
-    R - release
-
-    TODO: check if this is correct
-  */
-  DBUG_PRINT("backup",("version %d",MYSQL_VERSION_ID));
-  server_version.major= MYSQL_VERSION_ID / 10000;
-  server_version.minor= (MYSQL_VERSION_ID % 10000) / 100;
-  server_version.release= MYSQL_VERSION_ID % 100;
-  server_version.extra.begin= (byte*)MYSQL_SERVER_VERSION;
-  server_version.extra.end= server_version.extra.begin +
-                            strlen((const char*)server_version.extra.begin);
-
-  flags= 0;  // TODO: set BSTREAM_FLAG_BIG_ENDIAN flag accordingly
-
-  bzero(m_snap,sizeof(m_snap));
-}
-
-Image_info::~Image_info()
-{
-  // Delete server table objects 
-  
-  for (uint no=0; no<256; ++no)
-  {
-    Snapshot_info *snap= m_snap[no];
-    
-    if (!snap)
-      continue;
-    
-    for (uint i=0; i < snap->table_count(); ++i)
-    {
-      Table *t= snap->get_table(i);
-      
-      if (!t)
-        continue;
-        
-      delete t->m_obj_ptr;
-    }
-  }
-
-  // delete server database objects 
-
-  for (uint i=0; i < db_count(); ++i)
-  {
-    Db *db= get_db(i);
-    
-    if (db)
-      delete db->m_obj_ptr;
-  }
-
-  free_root(&mem_root, MYF(0));
-}
-
-
-Image_info::Db* 
-Image_info::add_db(const String &db_name, ulong pos)
-{
-  Db *db= new (&mem_root) Db(db_name);
-  
-  if (!db)
-    return NULL;
-  
-  if (m_dbs.insert(pos,db))
-    return NULL;
-  
-  db->base.pos= pos;
-  
-  return db;
-}
-
-Image_info::Db* 
-Image_info::get_db(uint pos) const
-{
-  return m_dbs[pos];
-}
-
-/**
-  Add snapshot to the catalogue.
-  
-  The snapshot should be non-empty, that is contain data of at least one table.
-  Snapshot is added to the list of snapshots used in the image and a number is
-  assigned to it. This number is stored in @c snap.m_no. If snapshot's number
-  is @c no then pointer to a corresponding @c Snapshot_info object is stored in 
-  @c m_snap[no-1].
-  
-  The @c Snapshot_info object is not owned by @c Image_info instance - it must
-  be deleted externally.
- */ 
-int Image_info::add_snapshot(Snapshot_info &snap)
-{
-  uint no= st_bstream_image_header::snap_count++;
-  
-  if (no > 256)
-    return -1;
-  
-  m_snap[no]= &snap;
-  snap.m_no= no+1;
-  
-  // Store information about snapshot in the snapshot[] table
-  
-  st_bstream_snapshot_info &info= snapshot[no];
-  
-  bzero(&info,sizeof(st_bstream_snapshot_info));
-  info.type= enum_bstream_snapshot_type(snap.type());
-  info.version= snap.version();
-  info.table_count= snap.table_count();
-  
-  if (snap.type() == Snapshot_info::NATIVE_SNAPSHOT)
-  {
-    Native_snapshot &ns= static_cast<Native_snapshot&>(snap);
-    uint se_ver= ns.se_ver();
-    const char *se_name= ns.se_name();
-    
-    info.engine.major= se_ver >> 8;
-    info.engine.minor= se_ver & 0xFF;
-    info.engine.name.begin= (byte*)se_name;
-    info.engine.name.end= info.engine.name.begin + strlen(se_name);    
-  }
-  
-  return no+1;
-}
-
-/**
-  Add table to the catalogue.
-  
-  Table's data snapshot is added to the catalogue if it was not there already.
-  
-  FIXME: add_table should generate error if table name starts with 'b' (?)
- */
-Image_info::Table* 
-Image_info::add_table(Db &db, const String &table_name, 
-                      Snapshot_info &snap, ulong pos)
-{
-  Table *t= new (&mem_root) Table(db, table_name);
-  
-  if (!t)
-    return NULL;
-
-  if (snap.add_table(*t, pos))
-    return NULL;
-  
-  if (db.add_table(*t))
-    return NULL;
-
-  if (!snap.m_no)
-    snap.m_no= add_snapshot(snap); // reports errors
-
-  if (!snap.m_no)
-   return NULL;
-
-  t->snap_no= snap.m_no - 1;
-  t->base.base.pos= pos;
-  t->base.db= &db;
-
-  m_table_count++;
-
-  return t;  
-}
-
-Image_info::Table* 
-Image_info::get_table(uint snap_no, ulong pos) const
-{
-  if (snap_no > snap_count() || m_snap[snap_no] == NULL)
-    return NULL;
-  
-  Table *t= m_snap[snap_no]->get_table(pos);
-  
-  if (!t)
-    return NULL;
-  
-  return t;
-}
-
-/**
-  Locate given item in a backup image catalogue.
-  
-  The positon of the item is stored in @c item structure in the format 
-  appropriate for the type of the object. Normally @c item is filled by 
-  backup stream library functions when reading backup image.
-  
-  @returns Pointer to the @c Image_info::Obj instance corresponding to the
-  object indicated by @c item or NULL if the object could not be found in
-  the catalogue.
-*/
-Image_info::Obj *find_obj(const Image_info &info, 
-                          const st_bstream_item_info &item)
-{
-  switch (item.type) {
-
-  case BSTREAM_IT_DB:
-    return info.get_db(item.pos);
-
-  case BSTREAM_IT_TABLE:
-  {
-    const st_bstream_table_info &ti= 
-                           reinterpret_cast<const st_bstream_table_info&>(item);
-
-    return info.get_table(ti.snap_no,item.pos);
-  }
-
-  default:
-    return NULL;
-  }
-}
-
-} // backup namespace
-
-template class Map<uint,backup::Image_info::Db>;
diff -Nrup a/sql/backup/catalog.h b/sql/backup/catalog.h
--- a/sql/backup/catalog.h	2008-02-18 13:04:23 +01:00
+++ /dev/null	Wed Dec 31 16:00:00 196900
@@ -1,901 +0,0 @@
-#ifndef CATALOG_H_
-#define CATALOG_H_
-
-#include <si_objects.h>
-#include <backup_stream.h> // for st_bstream_* types
-#include <backup/stream.h> // for I/OStream classes
-#include <backup/backup_aux.h>
-
-namespace backup {
-
-/********************************************************************
- 
-   Image_info and Snapshot_info classes.
- 
- ********************************************************************/ 
-
-
-class Snapshot_info;
-
-/**
-  Describes contents of a backup image.
-
-  This class stores a catalogue of a backup image, that is, description of
-  all objects stored in it (currently only databases and tables).
-
-  Only object names are stored in the catalogue. Other object data is stored
-  in the meta-data part of the image and in case of tables, their data is
-  stored in table data snapshots created by backup drivers.
-
-  For each snapshot present in the image there is a @c Snapshot_info object.
-  A pointer to n-th snapshot object is stored in @c m_snap[no]. This object 
-  contains list of tables whose data is stored in it. Note that each table must 
-  belong to exactly one snapshot.
-
-  Each object in the catalogue has its coordinates. The format of these 
-  coordinates depends on the object type. For databases, it is just its number. 
-  For tables, its coordinates are the number of the snapshot to which it belongs
-  and position within this snapshot. There are @c get_...() methods for getting
-  objects given their coordinates. Objects can be also browsed using one of
-  the iterator classes defined within @c Image_info.
-
-  For each type of objects stored in the catalogue, there is a class derived
-  from @c Image_info::Obj, whose instances are used to keep information about
-  such objects. These instances are owned by the @c Image_info object who is 
-  responsible for freeing memory used by them. Currently a memory root is used
-  for allocating this memory.
- */
-class Image_info: public st_bstream_image_header
-{
-public: // public interface
-
-   // datatypes
-   
-   typedef enum_bstream_item_type obj_type;
-
-   class Obj;   ///< Base for all object classes.
-   class Db;    ///< Class representing a database.
-   class Table; ///< Class representing a table.
-
-   class Iterator;      ///< Base for all iterators.
-   class Db_iterator;   ///< Iterates over all databases.
-   class DbObj_iterator;  ///< Iterates over tables in a database.
-
-   virtual ~Image_info();
- 
-   // info about image (most of it is in the st_bstream_image_header base
-
-   size_t     data_size;      ///< How much of table data is saved in the image.
-
-   uint       table_count() const;
-   uint       db_count() const;
-   uint       snap_count() const;
-
-   // Retrieve objects using their coordinates.
-
-   Db*    get_db(uint pos) const;
-   Table* get_table(uint snap_no, ulong pos) const;
-
-   // Iterators for enumerating the contents of the archive.
-
-   Db_iterator*    get_dbs();
-   DbObj_iterator* get_db_objects(const Db &db);
-
-   /**
-     Pointers to Snapshot_info objects corresponding to snapshots
-     present in the image. 
-    */ 
-   Snapshot_info *m_snap[256];
-   
-   // save timing & binlog info 
-   
-   void save_start_time(const time_t time);   
-   void save_end_time(const time_t time);
-   void save_vp_time(const time_t time);   
-
-   void save_binlog_pos(const ::LOG_INFO&);
-
- protected: // internal interface
-  
-  // Populate the catalogue
-  
-  int    add_snapshot(Snapshot_info&);
-  Db*    add_db(const String &db_name, ulong pos);
-  Table* add_table(Db &db, const String &table_name, 
-                   Snapshot_info &snap, ulong pos);
-
- // IMPLEMENTATION
-
- protected:
-
-  Image_info();
-  uint m_table_count;
-
- private:
-
-  class Tables; ///< Implementation of Table_list interface. 
-
-  // storage
-
-  MEM_ROOT  mem_root;    ///< Memory root used to allocate @c Obj instaces.
-  Map<uint,Db>   m_dbs;  ///< Pointers to Db instances.
-
-  // friends
-
-  friend class Snapshot_info;
-};
-
-/**
-  Find object in a catalogue.
-  
-  The object is identified by its coordinates stored in a 
-  @c st_bstream_item_info structure.
-  
-  @returns Pointer to the corresponding @c Obj instance or NULL if object
-  was not found.
- */ 
-Image_info::Obj* find_obj(const Image_info &info, 
-                          const st_bstream_item_info &item);
-
-
-/**
-  Implements Table_list interface.
-  
-  When list of tables is passed to a backup/restore driver, it is seen
-  by the driver as an object of abstract type Table_list. This class implements
-  that interface using a map, which for given table number returns a pointer
-  to corresponding @c Image_info::Table instance.
-  
-  This class is not a container - it only stores pointers to 
-  @c Image_info::Table objects which are owned by the @c Image_info instance.
- */ 
-class Image_info::Tables:
-  public Table_list,
-  public Map<uint,Image_info::Table>
-{
-  typedef Map<uint,Image_info::Table> Base;
- 
- public:
-
-  Tables(ulong, ulong);
-  ulong count() const;
-  Table_ref operator[](ulong) const;
-  Image_info::Table* get_table(ulong) const;
-};
-
-/**
-  Create instance of @c Image_info::Tables class.
-  
-  The parameters determine how memory is allocated.
-  
-  @param[in] init_size  the initial number of slots
-  @param[in] increase   the amount by which allocated memory is increased
-                        when the current capacity is exceeded
- */ 
-inline
-Image_info::Tables::Tables(ulong init_size, ulong increase): 
-  Base(init_size, increase) 
-{}
-
-
-/**
-  Describes table data snapshot stored inside backup image.
-
-  Such snapshot is created by a backup driver and read by a restore driver. For
-  each type of snapshot a separate class is derived from @c Snapshot_info.
-  Currently we support 
-  
-  - native snapshots (created by native backup engines),
-  - CS snapshot      (created by built-in backup engine using consistent read),
-  - default snapshot (created by built-in default backup engine).
-  
-  A @c Snapshot_info instance stores the list of tables whose data are stored
-  in the snapshot. It also has methods for determining whether a given table 
-  can be added to the snapshot or not, and for creating backup/restore drivers 
-  for processing the snapshot.
- */
-class Snapshot_info
-{
- public:
-
-  enum enum_snap_type {
-    NATIVE_SNAPSHOT= BI_NATIVE,   ///< snapshot created by native backup engine
-    DEFAULT_SNAPSHOT= BI_DEFAULT, ///< snapshot created by built-in, blocking backup engine
-    CS_SNAPSHOT= BI_CS            ///< snapshot created by built-in CS backup engine
-  };
-
-  virtual enum_snap_type type() const =0; 
-  version_t version() const; ///< Returns version of snapshot's format.
-  
-  /**
-    Position inside image's snapshot list.
-
-    Starts with 1. M_no == 0 means that this snapshot is not included in the
-    backup image (for example, no tables have been added to it yet).
-  */
-  ushort m_no;
-
-  /**
-    Size of the initial data transfer (estimate). This is
-    meaningful only after a call to get_backup_driver().
-  */
-  size_t init_size;
-
-  /**
-    Return name identifying the snapshot in debug messages.
-
-    The name should fit into "%s backup/restore driver" pattern.
-   */
-  virtual const char* name() const;
-
-  /// Check if instance was correctly constructed
-  virtual bool is_valid() =0;
-
-  ulong table_count() const;
-  
-  /// Determine if a table using given storage engine can be saved in this image.
-  virtual bool accept(const Table_ref&, const storage_engine_ref) =0;
-
-  /// Create backup driver for the image.
-  virtual result_t get_backup_driver(Backup_driver*&) =0;
-
-  /// Create restore driver for the image.
-  virtual result_t get_restore_driver(Restore_driver*&) =0;
-
-  virtual ~Snapshot_info();
-
- protected:
- 
-  version_t m_version; ///< to store version of the snapshot's format
-
-  Snapshot_info(const version_t);
-
-  // Methods for adding and accessing tables stored in the table list.
-
-  int add_table(Image_info::Table &t, ulong pos);
-  Image_info::Table* get_table(ulong pos);
- 
-  // IMPLEMENTATION
- 
-  Image_info::Tables m_tables; ///< List of tables stored in this image.
-
-  friend class Image_info;
-};
-
-
-inline
-Snapshot_info::Snapshot_info(const version_t version): 
-  m_no(0), init_size(0), m_version(version), m_tables(128,1024)
-{}
-
-inline
-Snapshot_info::~Snapshot_info()
-{}
-
-/********************************************************************
- 
-   Classes for representing various object types.
- 
- ********************************************************************/ 
-
-/**
-  Represents object stored in a backup image.
-
-  Instances of this class store name of the object and other relevant
-  information. For each type of objects a subclass of this class is derived
-  which is specialized in storing information about that kind of objects.
-
-  Method @c info() returns a pointer to @c st_bstream_item_info structure 
-  filled with data describing the corresponding object in the way required by
-  backup stream library.
-  
-  Method @c materialize() can be used to create a corresponding instance of
-  @c obs::Obj, to be used by server's objects services API. If @c m_obj_ptr is
-  not NULL then it contains a pointer to the corresponding @c obs:;Obj instance
-  which was obtained earlier (wither with @c materialize() or from server's 
-  object enumerators).
-*/
-class Image_info::Obj: public Sql_alloc
-{
- public:
- 
-  /* 
-    Note: Snice we are using Sql_alloc and allocate instances using MEM_ROOT,
-    destructors will not be called! This is also true for derived classes.
-   */
-  virtual ~Obj();
-
-  obj_type type() const;
-
-  /**
-    Returns pointer to @c st_bstream_item_info structure filled with data about
-    the object.
-   */ 
-  virtual const st_bstream_item_info* info() const =0;
-
-  /**
-    Pointer to the corresponding @c obs::Obj instance, if it is known.
-   */ 
-  obs::Obj  *m_obj_ptr;
-  
-  /**
-    Create corresponding @c obs::Obj instance from a serialization string.
-   */ 
-  virtual obs::Obj *materialize(uint ver, const String&) =0;
-
-  typedef Table_ref::describe_buf describe_buf;
-  virtual const char* describe(describe_buf&) const =0;
-
- protected:
-
-  String m_name;  ///< For storing object's name.
-
-  void store_name(const String&); 
-
-  Obj();
-
-  friend class Image_info;
-};
-
-inline
-Image_info::Obj::Obj(): m_obj_ptr(NULL)
-{}
-
-inline
-Image_info::Obj::~Obj()
-{}
-
-/**
-  Specialization of @c Image_info::Obj for storing info about a database.
-*/
-class Image_info::Db
- : public st_bstream_db_info,
-   public Image_info::Obj,
-   public Db_ref
-{
-  ulong m_table_count;  ///< Number of tables belonging to that database.
-
- public:
-
-  Db(const String&);
-
-  const st_bstream_item_info* info() const;
-  obs::Obj* materialize(uint ver, const String &sdata);
-  result_t add_table(Table&);
-  const char* describe(describe_buf&) const;
-
- private:
- 
-  Table *first_table; ///< Pointer to the first table in this database's table list. 
-  Table *last_table;  ///< Pointer to the last table in this database's table list.
-
-  friend class DbObj_iterator;
-};
-
-inline
-Image_info::Db::Db(const String &name):
- Db_ref(Image_info::Obj::m_name),
- m_table_count(0), first_table(NULL), last_table(NULL)
-{
-  bzero(&base,sizeof(base));
-  base.type= BSTREAM_IT_DB;
-  store_name(name);
-}
-
-
-/**
-  Specialization of @c Image_info::Obj for storing info about a table.
-*/
-class Image_info::Table
- : public st_bstream_table_info,
-   public Image_info::Obj,
-   public Table_ref
-{
-  const Db &m_db;     ///< The database to which this table belongs.
-  Table  *next_table; ///< Used to crate a linked list of tables in a database.
-
- public:
-
-  Table(const Db &db, const String &name);
-
-  const st_bstream_item_info* info() const;
-  obs::Obj* materialize(uint ver, const String &sdata);
-  const char* describe(Obj::describe_buf&) const;
-
-  friend class Db;
-  friend class DbObj_iterator;
-};
-
-inline
-Image_info::Table::Table(const Db &db, const String &name):
-  Table_ref(db.name(), Image_info::Obj::m_name), m_db(db), next_table(NULL)
-{
-  bzero(&base,sizeof(base));
-  base.base.type= BSTREAM_IT_TABLE;
-  store_name(name);
-}
-
-
-/********************************************************************
- 
-   Iterators
- 
- ********************************************************************/ 
-
-/**
-  Base class for all iterators.
-  
-  An iterator is used as follows
-  @code
-  Iterator_X      it;
-  Image_info::Obj *obj;
-  
-  while ((obj= it++))
-  {
-    <do something with obj>
-  }
-  @endcode
-
-  This is an abstract class. Derived iterators must define @c get_ptr() and
-  @c next() methods which are used to implement @c operator++().
- */ 
-class Image_info::Iterator
-{
- public:
-
-  Iterator(const Image_info &info);
-  virtual ~Iterator();
-
-  const Obj* operator++(int);
-
- protected:
-
-  const Image_info &m_info;
-
- private:
-
-  /** 
-    Return pointer to the current object of the iterator.
-   
-    Returns NULL if iterator is past the last object in the sequence.
-   */
-  virtual const Obj* get_ptr() const =0;
-  
-  /** 
-    Move iterator to next object.
-   
-    Returns FALSE if there are no more objects to enumerate.
-   */
-  virtual bool next() =0;
-};
-
-inline
-Image_info::Iterator::Iterator(const Image_info &info): 
- m_info(info) 
-{}
-
-inline
-Image_info::Iterator::~Iterator() 
-{}
-
-/**
-  Used to iterate over all databases stored in a backup image.
- */ 
-class Image_info::Db_iterator
- : public Image_info::Iterator
-{
- public:
-
-  Db_iterator(const Image_info&);
-
- protected:
-
-  uint pos;
-  const Obj* get_ptr() const;
-  bool next();
-};
-
-inline
-Image_info::Db_iterator::Db_iterator(const Image_info &info): 
-  Iterator(info), pos(0)
-{}
-
-/**
-  Used to iterate over all objects belonging to a given database.
-  
-  Currently only tables are enumerated.
- */ 
-class Image_info::DbObj_iterator
- : public Image_info::Db_iterator
-{
-  const Table *ptr;
-
- public:
-
-  DbObj_iterator(const Image_info&, const Db&);
-
- private:
-
-  const Obj* get_ptr() const;
-  bool next();
-};
-
-inline
-Image_info::DbObj_iterator::DbObj_iterator(const Image_info &info, const Db &db):
- Db_iterator(info), ptr(db.first_table)
-{}
-
-
-/********************************************************************
- 
-   Inline members of Image_info class 
- 
- ********************************************************************/ 
-
-/// Returns number of databases in the image.
-inline
-uint Image_info::db_count() const
-{ 
-  return m_dbs.count();
-}
-
-/// Returns total number of tables in the image.
-inline
-uint Image_info::table_count() const
-{ 
-  return m_table_count;
-}
-
-/// Returns number of snapshots used by the image.
-inline
-uint Image_info::snap_count() const
-{ 
-  return st_bstream_image_header::snap_count;
-}
-
-/**
-  Save time inside a @c bstream_time_t structure (helper function).
- */ 
-inline
-static
-void save_time(const time_t t, bstream_time_t &buf)
-{
-  struct tm time;
-  gmtime_r(&t,&time);
-  buf.year= time.tm_year;
-  buf.mon= time.tm_mon;
-  buf.mday= time.tm_mday;
-  buf.hour= time.tm_hour;
-  buf.min= time.tm_min;
-  buf.sec= time.tm_sec;  
-}
-
-/**
-  Store backup/restore start time inside image's header.
- */ 
-inline
-void Image_info::save_start_time(const time_t time)
-{
-  save_time(time, start_time);
-}
-
-/**
-  Store backup/restore end time inside image's header.
- */ 
-inline
-void Image_info::save_end_time(const time_t time)
-{
-  save_time(time, end_time);
-}
-
-/**
-  Store validity point time inside image's header.
- */ 
-inline
-void Image_info::save_vp_time(const time_t time)
-{
-  save_time(time, vp_time);
-}
-
-/**
-  Store validity point binlog position inside image's header.
- */ 
-inline
-void Image_info::save_binlog_pos(const ::LOG_INFO &li)
-{
-  binlog_pos.pos= (unsigned long int)li.pos;
-  binlog_pos.file= const_cast<char*>(li.log_file_name);
-}
-
-inline
-Image_info::Db_iterator* Image_info::get_dbs()
-{
-  return new Db_iterator(*this);
-}
-
-inline
-Image_info::DbObj_iterator* Image_info::get_db_objects(const Db &db)
-{
-  return new DbObj_iterator(*this,db);
-}
-
-/********************************************************************
- 
-   Inline members of Image_info::Tables class.
- 
- ********************************************************************/ 
-
-/// Return number of tables in the list.
-inline
-ulong Image_info::Tables::count() const
-{ return Base::count(); }
-
-/** 
-  Return table stored at a given position.
- 
-  @returns pointer to the @c Image_info::Table instance stored at
-  position @c pos or NULL if that position is empty.
- */
-inline
-Image_info::Table* Image_info::Tables::get_table(ulong pos) const
-{ 
-  return Base::operator[](pos);
-} 
-
-/// Implementation of @c Table_list virtual method.
-inline
-Table_ref Image_info::Tables::operator[](ulong pos) const
-{ 
-  Table *t= get_table(pos);
-  DBUG_ASSERT(t);
-  return *t; 
-}
-
-/********************************************************************
- 
-   Inline members of Snapshot_info::Obj and derived classes.
- 
- ********************************************************************/ 
-
-/**
-  Store objects name inside the object.
-  
-  The name is also stored inside the corresponding @c st_bstream_item_info
-  structure (just pointer).
- */ 
-inline
-void Image_info::Obj::store_name(const String &name)
-{
-  m_name.copy(name);
-  st_bstream_item_info *info= const_cast<st_bstream_item_info*>(this->info());
-  info->name.begin= (byte*)name.ptr();
-  info->name.end= info->name.begin + name.length();
-}
-
-inline
-Image_info::obj_type  Image_info::Obj::type() const
-{
-  return info()->type;
-}
-
-/// Implementation of @c Image_info::Obj virtual method.
-inline
-const st_bstream_item_info* Image_info::Db::info() const 
-{
-  return &base; 
-}
-
-/// Implementation of @c Image_info::Obj virtual method.
-inline
-const st_bstream_item_info* Image_info::Table::info() const 
-{
-  return &base.base; 
-}
-
-/// Implementation of @c Image_info::Obj virtual method.
-inline
-const char* Image_info::Db::describe(describe_buf &buf) const
-{
-  my_snprintf(buf, sizeof(buf), "`%s`", Obj::m_name.ptr());
-  return buf;
-}
-
-/// Implementation of @c Image_info::Obj virtual method.
-inline
-const char* Image_info::Table::describe(Obj::describe_buf &buf) const
-{
-  return Table_ref::describe(buf);
-}
-
-/// Implementation of @c Image_info::Obj virtual method.
-inline
-obs::Obj* Image_info::Db::materialize(uint ver, const String &sdata)
-{
-  return m_obj_ptr= obs::materialize_database(&name(), ver, &sdata); 
-}
-
-/// Implementation of @c Image_info::Obj virtual method.
-inline
-obs::Obj* Image_info::Table::materialize(uint ver, const String &sdata)
-{
-  return m_obj_ptr= obs::materialize_table(&db().name(), &name(), ver, &sdata);
-}
-
-/**
-  Add table to a database.
-  
-  The table is appended to database's table list.
- */
-inline
-result_t Image_info::Db::add_table(Table &tbl)
-{
-  tbl.next_table= NULL;
-  
-  if (!last_table)
-    first_table= last_table= &tbl;
-  else
-  {
-    last_table->next_table= &tbl;
-    last_table= &tbl;
-  }
-  
-  m_table_count++;
-    
-  return OK;
-}
-
-
-/********************************************************************
- 
-   Inline members of Snapshot_info class.
- 
- ********************************************************************/ 
-
-/// version of snapshot's format
-inline
-version_t Snapshot_info::version() const  
-{ return m_version; }
-
-/// Default implementation of the virtual method
-inline 
-const char* Snapshot_info::name() const
-{ return "<Unknown>"; }
-
-/// Add table at a given position.
-inline
-int Snapshot_info::add_table(Image_info::Table &t, ulong pos)
-{
-  return m_tables.insert(pos, &t);
-}
-
-/// Get table at a given position
-inline
-Image_info::Table* Snapshot_info::get_table(ulong pos)
-{
-  return m_tables.get_table(pos);
-}
-
-/// Return number of tables stored in this snapshot.
-inline
-ulong Snapshot_info::table_count() const
-{
-  return m_tables.count();
-}
-
-/********************************************************************
- 
-   Inline members of iterators.
- 
- ********************************************************************/ 
-
-inline
-const Image_info::Obj* Image_info::Iterator::operator++(int)
-{
-  const Obj *obj= get_ptr();
-  next();
-  return obj; 
-}
-
-/// Implementation of @c Image_info::Iterator virtual method.
-inline
-const Image_info::Obj* Image_info::Db_iterator::get_ptr() const
-{
-  /*
-    There should be no "holes" in the sequence of databases. That is,
-    if there are N databases in the catalogue then for i=0,1,..,N-1, 
-    m_info.m_dbs[i] should store pointer to the i-th database.
-   */ 
-  DBUG_ASSERT(pos >= m_info.db_count() || m_info.m_dbs[pos]);
-  return m_info.m_dbs[pos];
-}
-
-/// Implementation of @c Image_info::Iterator virtual method.
-inline
-bool Image_info::Db_iterator::next()
-{
-  if (pos < m_info.db_count())
-  {
-    pos++;
-    return TRUE;
-  }
-  else
-    return FALSE;
-}
-
-/// Implementation of @c Image_info::Iterator virtual method.
-inline
-const Image_info::Obj* Image_info::DbObj_iterator::get_ptr() const
-{
-  return ptr;
-}
-
-/// Implementation of @c Image_info::Iterator virtual method.
-inline
-bool Image_info::DbObj_iterator::next()
-{
-  if (ptr)
-    ptr= ptr->next_table;
-  return ptr != NULL;
-}
-
-} // backup namespace
-
-namespace backup {
-
-/*
- Wrappers around backup stream functions which perform necessary type conversions.
-*/
-
-inline
-result_t
-write_preamble(const Image_info &info, OStream &s)
-{
-  const st_bstream_image_header *hdr= static_cast<const st_bstream_image_header*>(&info);
-  int ret= bstream_wr_preamble(&s, const_cast<st_bstream_image_header*>(hdr));
-  return ret == BSTREAM_ERROR ? ERROR : OK;
-}
-
-inline
-result_t
-write_summary(const Image_info &info, OStream &s)
-{
-  const st_bstream_image_header *hdr= static_cast<const st_bstream_image_header*>(&info);
-  int ret= bstream_wr_summary(&s, const_cast<st_bstream_image_header*>(hdr));
-  return ret == BSTREAM_ERROR ? ERROR : OK;
-}
-
-inline
-result_t
-read_header(Image_info &info, IStream &s)
-{
-  int ret= bstream_rd_header(&s, static_cast<st_bstream_image_header*>(&info));
-  return ret == BSTREAM_ERROR ? ERROR : OK;
-}
-
-inline
-result_t
-read_catalog(Image_info &info, IStream &s)
-{
-  int ret= bstream_rd_catalogue(&s, static_cast<st_bstream_image_header*>(&info));
-  return ret == BSTREAM_ERROR ? ERROR : OK;
-}
-
-inline
-result_t
-read_meta_data(Image_info &info, IStream &s)
-{
-  int ret= bstream_rd_meta_data(&s, static_cast<st_bstream_image_header*>(&info));
-  return ret == BSTREAM_ERROR ? ERROR : OK;
-}
-
-inline
-result_t
-read_summary(Image_info &info, IStream &s)
-{
-  int ret= bstream_rd_summary(&s, static_cast<st_bstream_image_header*>(&info));
-  return ret == BSTREAM_ERROR ? ERROR : OK;
-}
-
-} // backup namespace
-
-#endif /*CATALOG_H_*/
diff -Nrup a/sql/backup/data_backup.cc b/sql/backup/data_backup.cc
--- a/sql/backup/data_backup.cc	2008-02-18 13:04:23 +01:00
+++ b/sql/backup/data_backup.cc	2008-02-19 12:15:12 +01:00
@@ -1,6 +1,3 @@
-#include "../mysql_priv.h"
-#include "backup_progress.h"
-
 /**
   @file
 
@@ -16,9 +13,12 @@
         of the error in the log.
  */
 
+#include "../mysql_priv.h"
+
+#include "backup_kernel.h"
 #include "backup_engine.h"
 #include "stream.h"
-#include "backup_kernel.h"
+#include "backup_progress.h"
 #include "debug.h"
 #include "be_default.h"  // needed for table locking code
 
diff -Nrup a/sql/backup/kernel.cc b/sql/backup/kernel.cc
--- a/sql/backup/kernel.cc	2008-02-18 13:04:23 +01:00
+++ b/sql/backup/kernel.cc	2008-02-19 12:15:12 +01:00
@@ -215,10 +215,77 @@ execute_backup_command(THD *thd, LEX *le
   DBUG_RETURN(send_reply(context));
 }
 
+/**
+  Report errors.
+
+  Current implementation reports the last error saved in the logger if it exist.
+  Otherwise it reports error given by @c error_code.
+ */
+int send_error(Backup_restore_ctx &log, int error_code, ...)
+{
+  MYSQL_ERROR *error= log.last_saved_error();
+
+  if (error && !util::report_mysql_error(log.m_thd,error,error_code))
+  {
+    if (error->code)
+      error_code= error->code;
+  }
+  else // there are no error information in the logger - report error_code
+  {
+    char buf[ERRMSGSIZE + 20];
+    va_list args;
+    va_start(args,error_code);
+
+    my_vsnprintf(buf,sizeof(buf),ER_SAFE(error_code),args);
+    my_printf_error(error_code,buf,MYF(0));
+
+    va_end(args);
+  }
+
+  if (log.backup::Logger::m_state == backup::Logger::RUNNING)
+    log.report_stop(my_time(0),FALSE); // FASLE = no success
+  return error_code;
+}
+
+
+/**
+  Send a summary of the backup/restore operation to the client.
+
+  The data about the operation is taken from filled @c Archive_info
+  structure. Parameter @c backup determines if this was backup or
+  restore operation.
+*/
+int send_reply(Backup_restore_ctx &context)
+{
+  Protocol *protocol= context.m_thd->protocol;    // client comms
+  List<Item> field_list;                // list of fields to send
+  char buf[255];                        // buffer for llstr
+
+  DBUG_ENTER("send_reply");
+
+  /*
+    Send field list.
+  */
+  field_list.push_back(new Item_empty_string(STRING_WITH_LEN("backup_id"))); //op_str.c_ptr(), op_str.length()));
+  protocol->send_fields(&field_list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF);
+
+  /*
+    Send field data.
+  */
+  protocol->prepare_for_resend();
+  llstr(context.op_id(),buf);
+  protocol->store(buf, system_charset_info);
+  protocol->write();
+
+  send_eof(context.m_thd);
+  DBUG_RETURN(0);
+}
+
+
 namespace backup {
 
 /**
-  This calss provides memory allocation services for backup stream library.
+  This class provides memory allocation services for backup stream library.
 
   An instance of this class is created during preparations for backup/restore
   operation. When it is deleted, all allocated memory is freed.
@@ -294,7 +361,10 @@ int Backup_restore_ctx::prepare(LEX_STRI
     Check access for SUPER rights. If user does not have SUPER, fail with error.
   */
   if (check_global_access(m_thd, SUPER_ACL))
+  {
     fatal_error(ER_SPECIFIC_ACCESS_DENIED_ERROR, "SUPER");
+    return m_error;
+  }
 
   /*
     Check if another BACKUP/RESTORE is running and if not, register 
@@ -381,7 +451,9 @@ Backup_info* Backup_restore_ctx::prepare
     fatal_error(ER_BACKUP_LOGGER_INIT);
     return NULL;
   }
-  
+
+  save_errors();  
+
   time_t when= my_time(0);
   report_start(when);
   
@@ -458,6 +530,8 @@ Restore_info* Backup_restore_ctx::prepar
     return NULL;
   }
 
+  save_errors();  
+
   time_t when= my_time(0);  
   report_start(when);
 
@@ -727,454 +801,6 @@ int Backup_restore_ctx::do_restore()
   DBUG_RETURN(0);
 }
 
-/*************************************************
-
-   Implementation of Backup_info class
-
- *************************************************/
-
-/**
-  Create @c Backup_info instance and prepare it for populating with objects.
- 
-  Snapshots created by the built-in backup engines are added to @c snapshots
-  list to be used in the backup engine selection algoritm in 
-  @c find_backup_engine().
- */
-Backup_info::Backup_info(Backup_restore_ctx &ctx):
-  m_state(ERROR), m_ctx(ctx), 
-  native_snapshots(8)
-{
-  using namespace backup;
-
-  Snapshot_info *snap;
-
-  bzero(m_snap, sizeof(m_snap));
-
-  // create default and CS snapshot objects - order is important!
-  
-  snap= new CS_snapshot(m_ctx); // reports errors
-
-  if (!snap || !snap->is_valid())
-    return;
-
-  snapshots.push_back(snap);
-
-  snap= new Default_snapshot(m_ctx);  // reports errors
-
-  if (!snap || !snap->is_valid())
-    return;
-
-  snapshots.push_back(snap);
-  
-  m_state= CREATED;
-}
-
-Backup_info::~Backup_info()
-{
-  using namespace backup;
-
-  close();
-
-  // delete Snapshot_info instances.
-
-  Snapshot_info *snap;
-  List_iterator<Snapshot_info> it(snapshots);
-
-  while ((snap= it++))
-    delete snap;
-}
-
-/**
-  Select database object for backup.
-  
-  The object is added to the backup image's catalogue. A pointer to the
-  servers obj::Obj instance is saved for later usage.
- */ 
-backup::Image_info::Db* Backup_info::add_db(obs::Obj *obj)
-{
-  ulong pos= db_count();
-  
-  DBUG_ASSERT(obj);
-  
-  Db *db= Image_info::add_db(*obj->get_name(), pos);  // reports errors
-  
-  if (db)
-    db->m_obj_ptr= obj;
-
-  return db;  
-}
-
-/**
-  Select given databases for restore.
-
-  For each database, all objects stored in that database are also added to
-  the image.
-
-  @todo Report errors.
- */
-int Backup_info::add_dbs(List< ::LEX_STRING > &dbs)
-{
-  using namespace obs;
-
-  List_iterator< ::LEX_STRING > it(dbs);
-  ::LEX_STRING *s;
-  String unknown_dbs; // comma separated list of databases which don't exist
-
-  while ((s= it++))
-  {
-    backup::String db_name(*s);
-    
-    if (is_internal_db_name(&db_name))
-    {
-      m_ctx.fatal_error(ER_BACKUP_CANNOT_INCLUDE_DB, db_name.c_ptr());
-      goto error;
-    }
-    
-    obs::Obj *obj= get_database(&db_name); // reports errors
-
-    if (obj && !check_db_existence(&db_name))
-    {    
-      if (!unknown_dbs.is_empty()) // we just compose unknown_dbs list
-      {
-        delete obj;
-        continue;
-      }
-      
-      Db *db= add_db(obj);  // reports errors
-
-      if (!db)
-      {
-        delete obj;
-        goto error;
-      }
-
-      if (add_db_items(*db))  // reports errors
-        goto error;
-    }
-    else if (obj)
-    {
-      if (!unknown_dbs.is_empty())
-        unknown_dbs.append(",");
-      unknown_dbs.append(*obj->get_name());
-      
-      delete obj;
-    }
-    else
-      goto error; // error was reported in get_database()
-  }
-
-  if (!unknown_dbs.is_empty())
-  {
-    m_ctx.fatal_error(ER_BAD_DB_ERROR,unknown_dbs.c_ptr());
-    goto error;
-  }
-
-  return 0;
-
- error:
-
-  m_state= ERROR;
-  return backup::ERROR;
-}
-
-/**
-  Select all existing databases for backup.
-
-  For each database, all objects stored in that database are also added to
-  the image. The internal databases are skipped.
-
-  @todo Report errors.
-*/
-int Backup_info::add_all_dbs()
-{
-  using namespace obs;
-
-  int res= 0;
-  ObjIterator *dbit= get_databases(m_ctx.m_thd);
-  
-  if (!dbit)
-  {
-    m_ctx.fatal_error(ER_BACKUP_LIST_DBS);
-    return ERROR;
-  }
-  
-  obs::Obj *obj;
-  
-  while ((obj= dbit->next()))
-  {
-    // skip internal databases
-    if (is_internal_db_name(obj->get_name()))
-    {
-      DBUG_PRINT("backup",(" Skipping internal database %s",obj->get_name()->ptr()));
-      delete obj;
-      continue;
-    }
-
-    DBUG_PRINT("backup", (" Found database %s", obj->get_name()->ptr()));
-
-    Db *db= add_db(obj);  // reports errors
-
-    if (!db)
-    {
-      res= ERROR;
-      delete obj;
-      goto finish;
-    }
-
-    if (add_db_items(*db))  // reports errors
-    {
-      res= ERROR;
-      goto finish;
-    }
-  }
-
-  DBUG_PRINT("backup", ("No more databases in I_S"));
-
- finish:
-
-  delete dbit;
-
-  if (res)
-    m_state= ERROR;
-
-  return res;
-}
-
-
-/**
-  Add to image all objects belonging to a given database.
- */
-int Backup_info::add_db_items(Db &db)
-{
-  using namespace obs;
-
-  ObjIterator *it= get_db_tables(m_ctx.m_thd,&db.name()); 
-
-  /*
-    If error debugging is switched on (see debug.h) then I_S.TABLES access
-    error will be triggered when backing up database whose name starts with 'a'.
-   */
-  TEST_ERROR_IF(db.name().ptr()[0]=='a');
-
-  if (!it || TEST_ERROR)
-  {
-    m_ctx.fatal_error(ER_BACKUP_LIST_DB_TABLES,db.name().ptr());
-    return ERROR;
-  }
-  
-  int res= 0;
-  obs::Obj *obj= NULL;
-
-  while ((obj= it->next()))
-  {
-    DBUG_PRINT("backup", ("Found table %s for database %s",
-                           obj->get_name()->ptr(), db.name().ptr()));
-
-    /*
-      add_table() method selects/creates a snapshot to which this table is added.
-      The backup engine is choosen in Backup_info::find_backup_engine() method.
-    */
-    Table *tbl= add_table(db,obj); // reports errors
-
-    if (!tbl)
-    {
-      delete obj;
-      goto error;
-    }
-
-    /*
-      TODO: When we handle per-table objects, don't forget to add them here
-      to the catalogue.
-     */ 
-  }
-
-  goto finish;
-
- error:
-
-  res= res ? res : ERROR;
-  m_state= ERROR;
-  
- finish:
-
-  delete it;
-  return res;
-}
-
-
-/// Return storage engine of a given table.
-inline
-static
-storage_engine_ref get_storage_engine(THD *thd, const backup::Table_ref &tbl)
-{
-  storage_engine_ref se= NULL;
-  char path[FN_REFLEN];
-
-  const char *db= tbl.db().name().ptr();
-  const char *name= tbl.name().ptr();
-
-  ::build_table_filename(path, sizeof(path), db, name, "", 0);
-
-  ::TABLE *table= ::open_temporary_table(thd, path, db, name,
-                    FALSE /* don't link to thd->temporary_tables */,
-                    OTM_OPEN);
-  if (table)
-  {
-    se= plugin_ref_to_se_ref(table->s->db_plugin);
-    ::intern_close_table(table);
-    my_free(table, MYF(0));
-  }
-  
-  return se;
-}
-
-/// Determine if a given storage engine has native backup engine.
-inline
-static
-bool has_native_backup(storage_engine_ref se)
-{
-  handlerton *hton= se_hton(se);
-
-  return hton && hton->get_backup_engine;
-}
-
-/**
-  Find backup engine which can backup data of a given table.
-
-  @param[in] tbl  Table_ref describing the table
-
-  @returns pointer to a Snapshot_info instance representing 
-  snapshot to which the given table can be added. 
-
-  @todo Add error messages.
- */
-backup::Snapshot_info* 
-Backup_info::find_backup_engine(const backup::Table_ref &tbl)
-{
-  using namespace backup;
-
-  Table_ref::describe_buf buf;
-  Snapshot_info *snap= NULL;
-  
-  DBUG_ENTER("Backup_info::find_backup_engine");
-
-  // See if table has native backup engine
-
-  storage_engine_ref se= get_storage_engine(m_ctx.m_thd, tbl);
-  
-  if (!se)
-  {
-    m_ctx.fatal_error(ER_NO_STORAGE_ENGINE,tbl.describe(buf));
-    DBUG_RETURN(NULL);
-  }
-  
-  snap= native_snapshots[se];
-  
-  if (!snap)
-    if (has_native_backup(se))
-    {
-      Native_snapshot *nsnap= new Native_snapshot(m_ctx,se);
-      DBUG_ASSERT(nsnap);
-      snapshots.push_front(nsnap);
-      native_snapshots.insert(se,nsnap);
-
-      /*
-        Question: Can native snapshot for a given storage engine not accept
-        a table using that engine? If yes, then what to do in that case - error 
-        or try other (default) snapshots?
-       */     
-      DBUG_ASSERT(nsnap->accept(tbl,se));
-      snap= nsnap;
-    }
-  
-  /* 
-    If we couldn't locate native snapshot for that table - iterate over
-    all existing snapshots and see if one of them can accept the table.
-    At the end, the snapshots using default backup engines will be tried.
-  */
-    
-  if (!snap)
-  {
-    List_iterator<Snapshot_info> it(snapshots);
-    
-    while ((snap= it++))
-      if (snap->accept(tbl,se))
-        break;
-  }
-
-  if (!snap)
-    m_ctx.fatal_error(ER_BACKUP_NO_BACKUP_DRIVER,tbl.describe(buf));
-  
-  DBUG_RETURN(snap);
-}
-
-namespace {
-
-/**
-  Implementation of @c Table_ref which gets table identity from a server
-  object instance - to be used in @c Backup_info::add_table().
- */ 
-class Tbl: public backup::Table_ref
-{
- public:
-
-   Tbl(obs::Obj *obj): backup::Table_ref(*obj->get_db_name(),*obj->get_name())
-   {}
-
-   ~Tbl()
-   {}
-};
-
-} // anonymous namespace
-
-/**
-  Select table object for backup.
-
-  The object is added to the backup image's catalogue. A pointer to the
-  servers obj::Obj instance is saved for later usage. This method picks 
-  the best available backup engine for the table using @c find_backup_engine() 
-  method.
-
-  @todo Correctly handle temporary tables.
-  @todo Implement error debug code.
-*/
-backup::Image_info::Table* Backup_info::add_table(Db &dbi, obs::Obj *obj)
-{
-  Table *tbl= NULL;
-  
-  DBUG_ASSERT(obj);
-
-  Tbl t(obj);
-  // TODO: skip table if it is a tmp one
-  
-  /*
-    TODO:
-    If error debugging is switched on (see debug.h) then any table whose
-    name starts with 'b' will trigger error when added to backup image.
-    TEST_ERROR_IF(t.name().ptr()[0]=='b');
-   */
-
-  backup::Snapshot_info *snap= find_backup_engine(t); // reports errors
-
-  if (!snap)
-    return NULL;
-
-  // add table to the catalogue
-
-  ulong pos= snap->table_count();
-  
-  tbl= Image_info::add_table(dbi, t.name(), *snap, pos);  // reports errors
-  
-  if (!tbl)
-    return NULL;
-
-  tbl->m_obj_ptr= obj;
-
-  DBUG_PRINT("backup",(" table %s backed-up with %s engine (snapshot %d)",
-                      t.name().ptr(), snap->name(), snap->m_no));
-  return tbl;
-}
-
 
 namespace backup {
 
@@ -1788,72 +1414,6 @@ int bcat_get_item_create_data(st_bstream
                  Helper functions
 
  *************************************************/
-
-/**
-  Report errors.
-
-  Current implementation reports the last error saved in the logger if it exist.
-  Otherwise it reports error given by @c error_code.
- */
-int send_error(Backup_restore_ctx &log, int error_code, ...)
-{
-  MYSQL_ERROR *error= log.last_saved_error();
-
-  if (error && !util::report_mysql_error(log.m_thd,error,error_code))
-  {
-    if (error->code)
-      error_code= error->code;
-  }
-  else // there are no error information in the logger - report error_code
-  {
-    char buf[ERRMSGSIZE + 20];
-    va_list args;
-    va_start(args,error_code);
-
-    my_vsnprintf(buf,sizeof(buf),ER_SAFE(error_code),args);
-    my_printf_error(error_code,buf,MYF(0));
-
-    va_end(args);
-  }
-
-  if (log.backup::Logger::m_state == backup::Logger::RUNNING)
-    log.report_stop(my_time(0),FALSE); // FASLE = no success
-  return error_code;
-}
-
-
-/**
-  Send a summary of the backup/restore operation to the client.
-
-  The data about the operation is taken from filled @c Archive_info
-  structure. Parameter @c backup determines if this was backup or
-  restore operation.
-*/
-int send_reply(Backup_restore_ctx &context)
-{
-  Protocol *protocol= context.m_thd->protocol;    // client comms
-  List<Item> field_list;                // list of fields to send
-  char buf[255];                        // buffer for llstr
-
-  DBUG_ENTER("send_reply");
-
-  /*
-    Send field list.
-  */
-  field_list.push_back(new Item_empty_string(STRING_WITH_LEN("backup_id"))); //op_str.c_ptr(), op_str.length()));
-  protocol->send_fields(&field_list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF);
-
-  /*
-    Send field data.
-  */
-  protocol->prepare_for_resend();
-  llstr(context.op_id(),buf);
-  protocol->store(buf, system_charset_info);
-  protocol->write();
-
-  send_eof(context.m_thd);
-  DBUG_RETURN(0);
-}
 
 namespace backup {
 
diff -Nrup a/sql/backup/logger.cc b/sql/backup/logger.cc
--- a/sql/backup/logger.cc	2008-02-18 13:04:24 +01:00
+++ b/sql/backup/logger.cc	2008-02-19 12:15:12 +01:00
@@ -1,7 +1,7 @@
 #include "../mysql_priv.h"
 
 #include "logger.h"
-#include "catalog.h"
+#include "image_info.h"
 
 /** @file
  
diff -Nrup a/sql/backup/stream.cc b/sql/backup/stream.cc
--- a/sql/backup/stream.cc	2008-02-18 13:04:24 +01:00
+++ b/sql/backup/stream.cc	2008-02-19 12:15:12 +01:00
@@ -1,6 +1,6 @@
 #include "../mysql_priv.h"
 
-#include <backup_stream.h>
+#include "backup_stream.h"
 #include "stream.h"
 
 const unsigned char backup_magic_bytes[8]=
diff -Nrup a/sql/backup/stream.h b/sql/backup/stream.h
--- a/sql/backup/stream.h	2008-02-18 13:04:24 +01:00
+++ b/sql/backup/stream.h	2008-02-19 12:15:12 +01:00
@@ -4,6 +4,7 @@
 #include <backup_stream.h>
 
 #include <backup/api_types.h>    // for Buffer definition
+#include <backup/image_info.h>
 #include <backup/debug.h>        // for definition of DBUG_BACKUP
 #include <backup/logger.h>
 
@@ -131,6 +132,61 @@ class IStream:
   int check_magic_and_version();
   bool init();
 };
+
+
+/*
+ Wrappers around backup stream functions which perform necessary type conversions.
+*/
+
+inline
+result_t
+write_preamble(const Image_info &info, OStream &s)
+{
+  const st_bstream_image_header *hdr= static_cast<const st_bstream_image_header*>(&info);
+  int ret= bstream_wr_preamble(&s, const_cast<st_bstream_image_header*>(hdr));
+  return ret == BSTREAM_ERROR ? ERROR : OK;
+}
+
+inline
+result_t
+write_summary(const Image_info &info, OStream &s)
+{
+  const st_bstream_image_header *hdr= static_cast<const st_bstream_image_header*>(&info);
+  int ret= bstream_wr_summary(&s, const_cast<st_bstream_image_header*>(hdr));
+  return ret == BSTREAM_ERROR ? ERROR : OK;
+}
+
+inline
+result_t
+read_header(Image_info &info, IStream &s)
+{
+  int ret= bstream_rd_header(&s, static_cast<st_bstream_image_header*>(&info));
+  return ret == BSTREAM_ERROR ? ERROR : OK;
+}
+
+inline
+result_t
+read_catalog(Image_info &info, IStream &s)
+{
+  int ret= bstream_rd_catalogue(&s, static_cast<st_bstream_image_header*>(&info));
+  return ret == BSTREAM_ERROR ? ERROR : OK;
+}
+
+inline
+result_t
+read_meta_data(Image_info &info, IStream &s)
+{
+  int ret= bstream_rd_meta_data(&s, static_cast<st_bstream_image_header*>(&info));
+  return ret == BSTREAM_ERROR ? ERROR : OK;
+}
+
+inline
+result_t
+read_summary(Image_info &info, IStream &s)
+{
+  int ret= bstream_rd_summary(&s, static_cast<st_bstream_image_header*>(&info));
+  return ret == BSTREAM_ERROR ? ERROR : OK;
+}
 
 } // backup namespace
 
diff -Nrup a/sql/backup/stream_services.h b/sql/backup/stream_services.h
--- a/sql/backup/stream_services.h	2007-11-30 09:23:30 +01:00
+++ b/sql/backup/stream_services.h	2008-02-19 12:15:12 +01:00
@@ -3,7 +3,7 @@
 
 extern "C" {
 
-#include "stream_v1_services.h"
+#include <backup/stream_v1_services.h>
 
 }
 
Thread
bk commit into 6.0 tree (rafal:1.2767) WL#4212rsomla19 Feb