List:Commits« Previous MessageNext Message »
From:Jorgen Loland Date:February 16 2009 12:20pm
Subject:bzr commit into mysql-6.0-backup branch (jorgen.loland:2772) Bug#39109
View as plain text  
#At file:///localhome/jl208045/mysql/mysql-6.0-backup-39109/

 2772 Jorgen Loland	2009-02-16
      Bug#39109 - Mysql Online Backup table doesn't show correct num_object count
                  
      Previously, the num_objects column in the backup_history table showed the number of
      tables in the backup image. It now shows the number of objects with names (i.e,
      tablespace, database, table, view, routine)
added:
  mysql-test/suite/backup/r/backup_object_count.result
  mysql-test/suite/backup/t/backup_object_count.test
modified:
  mysql-test/suite/backup/r/backup_logs.result
  mysql-test/suite/backup/r/backup_pipe.result
  mysql-test/suite/backup/t/backup_logs.test
  sql/backup/image_info.cc
  sql/backup/image_info.h
  sql/backup/logger.cc

per-file messages:
  mysql-test/suite/backup/r/backup_logs.result
    Updated object counts
  mysql-test/suite/backup/r/backup_object_count.result
    Added test for object count displayed in backup_history
  mysql-test/suite/backup/r/backup_pipe.result
    Updated object counts
  mysql-test/suite/backup/t/backup_logs.test
    Updated object counts
  mysql-test/suite/backup/t/backup_object_count.test
    Added test for object count displayed in backup_history
  sql/backup/image_info.cc
    Added counting of views, routines and privileges in the backup image
  sql/backup/image_info.h
    Added counting of views, routines and privileges in the backup image
  sql/backup/logger.cc
    Changed logging to backup_history to show number of objects instead of number of tables in the "num_objects" column
=== modified file 'mysql-test/suite/backup/r/backup_logs.result'
--- a/mysql-test/suite/backup/r/backup_logs.result	2009-02-06 08:28:24 +0000
+++ b/mysql-test/suite/backup/r/backup_logs.result	2009-02-16 12:20:31 +0000
@@ -78,7 +78,7 @@ WHERE command LIKE "BACKUP DATABASE back
 SELECT operation,num_objects, username, command FROM mysql.backup_history
 WHERE backup_id=@bup_id;
 operation	num_objects	username	command
-backup	0	tom	BACKUP DATABASE backup_logs TO 'backup_logs1.bak'
+backup	1	tom	BACKUP DATABASE backup_logs TO 'backup_logs1.bak'
 SELECT CURRENT_USER();
 CURRENT_USER()
 root@localhost
@@ -92,11 +92,7 @@ WHERE command LIKE "BACKUP DATABASE back
 SELECT operation,num_objects, username, command FROM mysql.backup_history
 WHERE backup_id=@bup_id;
 operation	num_objects	username	command
-backup	0	root	BACKUP DATABASE backup_logs TO 'backup_logs1.bak'
-
-From the above tables we can notice that num_objects shows '0' if only DB
-is included in backup image(BUG#39109)
-
+backup	1	root	BACKUP DATABASE backup_logs TO 'backup_logs1.bak'
 Include all objects in database(Databases, tables, procedures and
 functions, views, triggers and events) and perform backup operation.
 con1: Create tables
@@ -241,7 +237,7 @@ timediff(validity_point_time, start_time
 From backup_history log we will notice that "drivers" column will show
 Myisam, snapshot, default and no-data drivers
 "error_num" will be '0' as both backup and restore was successful
-"num_objects" count is always 5(as there are 5 tables in database).
+"num_objects" count is 11: (1 db, 4 routines, 2 views, 3 tables, 1 db)
 It does not list other objects from the backup image(BUG#39109)
 SHOW VARIABLES LIKE 'log_backup_output';
 Variable_name	Value
@@ -254,7 +250,7 @@ binlog_file	#
 backup_state	complete
 operation	backup
 error_num	0
-num_objects	4
+num_objects	11
 total_bytes	5215
 validity_point_time	#
 start_time	#
@@ -323,7 +319,7 @@ binlog_file	#
 backup_state	complete
 operation	restore
 error_num	0
-num_objects	4
+num_objects	11
 total_bytes	1483
 validity_point_time	#
 start_time	#

=== added file 'mysql-test/suite/backup/r/backup_object_count.result'
--- a/mysql-test/suite/backup/r/backup_object_count.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/backup/r/backup_object_count.result	2009-02-16 12:20:31 +0000
@@ -0,0 +1,80 @@
+#
+# Test 1 - Count database, table and view
+#
+CREATE DATABASE objectcount;
+USE objectcount;
+CREATE TABLE t1(id int);
+CREATE TABLE t2(id int);
+Creating view
+CREATE VIEW v1 AS SELECT * FROM t1;
+CREATE VIEW v2 AS SELECT * FROM t2;
+# Perform backup
+BACKUP DATABASE objectcount to 'objectcount.bak';
+backup_id
+#
+
+# num_objects should be 5: 1 db, 2 tables, 2 views
+SELECT num_objects FROM mysql.backup_history ORDER BY backup_id DESC LIMIT 1;
+num_objects
+5
+
+#
+# Test 2 - Count routines
+#
+CREATE TRIGGER trg BEFORE INSERT ON t1 FOR EACH ROW SET @a:=1;
+CREATE PROCEDURE foo() INSERT INTO t2 VALUES (42);
+CREATE FUNCTION bar(a int) RETURNS INTEGER
+BEGIN
+RETURN a;
+END;
+||
+# Perform backup
+BACKUP DATABASE objectcount to 'objectcount.bak';
+backup_id
+#
+
+# num_objects should be 8: 5 in test 1 + 1 trigger, 1 proc, 1 func
+SELECT num_objects FROM mysql.backup_history ORDER BY backup_id DESC LIMIT 1;
+num_objects
+8
+
+#
+# Test 3 - Count tablespace
+#
+CREATE TABLESPACE ts ADD DATAFILE 'afile' ENGINE=FALCON;
+CREATE TABLE t3 (i INT) ENGINE=FALCON TABLESPACE ts;
+# Perform backup
+BACKUP DATABASE objectcount to 'objectcount.bak';
+backup_id
+#
+
+# num_objects should be 10: 8 in test 2 + 1 ts, 1 table
+SELECT num_objects FROM mysql.backup_history ORDER BY backup_id DESC LIMIT 1;
+num_objects
+10
+
+#
+# Test 4 - Grants and users are *not* counted
+#
+CREATE USER 'bup_user1'@'%';
+GRANT ALL ON objectcount.* TO 'bup_user1'@'%';
+FLUSH PRIVILEGES;
+SHOW GRANTS FOR 'bup_user1'@'%';
+Grants for bup_user1@%
+GRANT USAGE ON *.* TO 'bup_user1'@'%'
+GRANT ALL PRIVILEGES ON `objectcount`.* TO 'bup_user1'@'%'
+# Perform backup
+BACKUP DATABASE objectcount to 'objectcount.bak';
+backup_id
+#
+
+# num_objects should be 10: 10 in test 3 + 0
+SELECT num_objects FROM mysql.backup_history ORDER BY backup_id DESC LIMIT 1;
+num_objects
+10
+
+#
+# Cleanup
+#
+DROP USER bup_user1;
+DROP DATABASE objectcount;

=== modified file 'mysql-test/suite/backup/r/backup_pipe.result'
--- a/mysql-test/suite/backup/r/backup_pipe.result	2009-02-13 01:00:22 +0000
+++ b/mysql-test/suite/backup/r/backup_pipe.result	2009-02-16 12:20:31 +0000
@@ -35,7 +35,7 @@ backup_id
 verify backup history log:
 SELECT backup_state, command, operation, num_objects FROM mysql.backup_history;
 backup_state	command	operation	num_objects
-complete	BACKUP DATABASE db1 TO 'db1_pipe'	backup	1
+complete	BACKUP DATABASE db1 TO 'db1_pipe'	backup	2
 Drop database and perform restore from a pipe.
 DROP DATABASE db1;
 PURGE BACKUP LOGS;
@@ -60,7 +60,7 @@ COUNT(*)
 64
 SELECT backup_state, command, operation, num_objects FROM mysql.backup_history;
 backup_state	command	operation	num_objects
-complete	RESTORE FROM 'db1_pipe'	restore	1
+complete	RESTORE FROM 'db1_pipe'	restore	2
 DROP DATABASE db1;
 verify that restore can be performed from output file that reads from
 pipe
@@ -77,7 +77,7 @@ COUNT(*)
 144
 SELECT backup_state, command, operation,  num_objects FROM mysql.backup_history;
 backup_state	command	operation	num_objects
-complete	RESTORE FROM 'db1_file'	restore	1
+complete	RESTORE FROM 'db1_file'	restore	2
 con1:
 Start backup to pipe:
 SET DEBUG_SYNC= 'before_backup_open_stream SIGNAL running WAIT_FOR backup';

=== modified file 'mysql-test/suite/backup/t/backup_logs.test'
--- a/mysql-test/suite/backup/t/backup_logs.test	2009-02-06 08:28:24 +0000
+++ b/mysql-test/suite/backup/t/backup_logs.test	2009-02-16 12:20:31 +0000
@@ -143,15 +143,6 @@ SELECT operation,num_objects, username, 
      WHERE backup_id=@bup_id;
 --remove_file $MYSQLD_DATADIR/backup_logs1.bak
 
---echo
---echo From the above tables we can notice that num_objects shows '0' if only DB
---echo is included in backup image(BUG#39109)
---echo
-
-# BUG#39109: Mysql Online Backup table doesn't show correct num_object count
-# Once BUG#39109 is fixed, all the objects should be listed in the num_object
-# count of backup_history log
-
 --echo Include all objects in database(Databases, tables, procedures and
 --echo functions, views, triggers and events) and perform backup operation.
 
@@ -330,7 +321,7 @@ from mysql.backup_history WHERE backup_i
 --echo From backup_history log we will notice that "drivers" column will show
 --echo Myisam, snapshot, default and no-data drivers
 --echo "error_num" will be '0' as both backup and restore was successful
---echo "num_objects" count is always 5(as there are 5 tables in database).
+--echo "num_objects" count is 11: (1 db, 4 routines, 2 views, 3 tables, 1 db)
 --echo It does not list other objects from the backup image(BUG#39109)
 
 #Show results

=== added file 'mysql-test/suite/backup/t/backup_object_count.test'
--- a/mysql-test/suite/backup/t/backup_object_count.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/backup/t/backup_object_count.test	2009-02-16 12:20:31 +0000
@@ -0,0 +1,113 @@
+#
+# This file tests that the backup_history table shows the correct
+# object count after performing a backup
+#
+# The following object types should be counted:
+#  - Tablespaces
+#  - Databases
+#  - Tables
+#  - Views
+#  - Routines (procedures, triggers etc)
+#
+# Privileges should not be counted.
+#
+
+--source include/not_embedded.inc
+--source include/have_falcon.inc
+
+let $MYSQLD_BACKUPDIR = `select @@backupdir`;
+
+--echo #
+--echo # Test 1 - Count database, table and view
+--echo #
+
+CREATE DATABASE objectcount;
+USE objectcount;
+
+CREATE TABLE t1(id int);
+CREATE TABLE t2(id int);
+
+--echo Creating view
+CREATE VIEW v1 AS SELECT * FROM t1;
+CREATE VIEW v2 AS SELECT * FROM t2;
+
+--echo # Perform backup
+--replace_column 1 #
+BACKUP DATABASE objectcount to 'objectcount.bak';
+
+--echo
+--echo # num_objects should be 5: 1 db, 2 tables, 2 views
+SELECT num_objects FROM mysql.backup_history ORDER BY backup_id DESC LIMIT 1;
+--echo
+
+--remove_file $MYSQLD_BACKUPDIR/objectcount.bak
+
+--echo #
+--echo # Test 2 - Count routines
+--echo #
+
+CREATE TRIGGER trg BEFORE INSERT ON t1 FOR EACH ROW SET @a:=1;
+CREATE PROCEDURE foo() INSERT INTO t2 VALUES (42);
+
+DELIMITER ||;
+CREATE FUNCTION bar(a int) RETURNS INTEGER
+BEGIN
+  RETURN a;
+END;
+||
+DELIMITER ;||
+
+--echo # Perform backup
+--replace_column 1 #
+BACKUP DATABASE objectcount to 'objectcount.bak';
+
+--echo
+--echo # num_objects should be 8: 5 in test 1 + 1 trigger, 1 proc, 1 func
+SELECT num_objects FROM mysql.backup_history ORDER BY backup_id DESC LIMIT 1;
+--echo
+
+--remove_file $MYSQLD_BACKUPDIR/objectcount.bak
+
+--echo #
+--echo # Test 3 - Count tablespace
+--echo #
+
+CREATE TABLESPACE ts ADD DATAFILE 'afile' ENGINE=FALCON;
+CREATE TABLE t3 (i INT) ENGINE=FALCON TABLESPACE ts;
+
+--echo # Perform backup
+--replace_column 1 #
+BACKUP DATABASE objectcount to 'objectcount.bak';
+
+--echo
+--echo # num_objects should be 10: 8 in test 2 + 1 ts, 1 table
+SELECT num_objects FROM mysql.backup_history ORDER BY backup_id DESC LIMIT 1;
+--echo
+
+--remove_file $MYSQLD_BACKUPDIR/objectcount.bak
+
+--echo #
+--echo # Test 4 - Grants and users are *not* counted
+--echo #
+
+CREATE USER 'bup_user1'@'%';
+GRANT ALL ON objectcount.* TO 'bup_user1'@'%';
+FLUSH PRIVILEGES;
+SHOW GRANTS FOR 'bup_user1'@'%';
+
+--echo # Perform backup
+--replace_column 1 #
+BACKUP DATABASE objectcount to 'objectcount.bak';
+
+--echo
+--echo # num_objects should be 10: 10 in test 3 + 0
+SELECT num_objects FROM mysql.backup_history ORDER BY backup_id DESC LIMIT 1;
+--echo
+
+--echo #
+--echo # Cleanup
+--echo #
+
+DROP USER bup_user1;
+DROP DATABASE objectcount;
+--remove_file $MYSQLD_BACKUPDIR/objectcount.bak

=== modified file 'sql/backup/image_info.cc'
--- a/sql/backup/image_info.cc	2008-12-18 21:46:36 +0000
+++ b/sql/backup/image_info.cc	2009-02-16 12:20:31 +0000
@@ -13,8 +13,14 @@
 
 namespace backup {
 
-Image_info::Image_info()
-  :data_size(0), m_table_count(0), m_dbs(16, 16), m_ts_map(16,16)
+Image_info::Image_info() :
+  data_size(0),
+  m_table_count(0),
+  m_view_count(0),
+  m_routine_count(0),
+  m_priv_count(0),
+  m_dbs(16, 16),
+  m_ts_map(16,16)
 {
   init_alloc_root(&mem_root, 4 * 1024, 0);      // Never errors
 
@@ -246,6 +252,7 @@ Image_info::Dbobj* Image_info::add_db_ob
     return NULL;
     
   o->base.pos= pos;
+  count_object(type);
 
   return o;
 }
@@ -310,7 +317,7 @@ Image_info::add_table(Db &db, const ::St
   t->snap_num= snap.m_num - 1;
   t->base.base.pos= pos;
 
-  m_table_count++;
+  count_object(BSTREAM_IT_TABLE);
 
   return t;  
 }

=== modified file 'sql/backup/image_info.h'
--- a/sql/backup/image_info.h	2009-01-08 14:57:41 +0000
+++ b/sql/backup/image_info.h	2009-02-16 12:20:31 +0000
@@ -90,9 +90,13 @@ public: // public interface
   size_t     data_size;      ///< How much of table data is saved in the image.
   st_bstream_binlog_pos  master_pos; ///< To store master position info.
 
+  ulong      object_count() const;
   ulong      table_count() const;
-  uint       db_count() const;
-  uint       ts_count() const;
+  ulong      view_count() const;
+  ulong      routine_count() const;
+  ulong      priv_count() const;
+  ulong      db_count() const;
+  ulong      ts_count() const;
   ushort     snap_count() const;
 
   // Examine contents of the catalogue.
@@ -148,11 +152,18 @@ protected: // internal interface
 protected:
 
   Image_info();
-  uint m_table_count;    ///< Number of tables in the image.
+  ulong m_table_count;    ///< Number of tables in the image.
+  ulong m_view_count;     ///< Number of views in the image
+  ulong m_routine_count;  ///< Number of stored routines in the image
+  ulong m_priv_count;     ///< Number of privileges in the image
+
   MEM_ROOT  mem_root;    ///< Memory root for storage of catalogue items.
 
   class Tables; ///< Implementation of Table_list interface. 
 
+  /// Increase counter for this object type
+  void count_object(const enum_bstream_item_type type);
+
 private:
 
   Map<uint, Db>   m_dbs; ///< Pointers to Db instances.
@@ -721,16 +732,77 @@ Image_info::Dbobj_iterator::Dbobj_iterat
  
  ********************************************************************/ 
 
+/**
+   Increase counter for this type of object. This is displayed as info
+   in the backup_history table.
+
+   @param[in] type type of the object
+*/
+inline
+void Image_info::count_object(const enum_bstream_item_type type)
+{
+
+  switch (type) {
+
+    case BSTREAM_IT_TABLE: 
+      m_table_count++;
+      break;
+    case BSTREAM_IT_VIEW: 
+      m_view_count++; 
+      break;
+    case BSTREAM_IT_SPROC: 
+    case BSTREAM_IT_SFUNC: 
+    case BSTREAM_IT_EVENT: 
+    case BSTREAM_IT_TRIGGER:
+      m_routine_count++;
+      break;
+    case BSTREAM_IT_PRIVILEGE: 
+      m_priv_count++;
+      break;
+                                  // ITEMS THAT ARE NOT COUNTED
+    case BSTREAM_IT_DB:           // counted via m_dbs.count()
+    case BSTREAM_IT_TABLESPACE:   // counted via m_ts_map.count()
+    case BSTREAM_IT_CHARSET:      // not counted yet
+    case BSTREAM_IT_USER:         // not counted yet
+      break;
+    default: 
+      // Fail if an item type is is not counted or ignored above. All
+      // item types should be explicitly handled by the switch
+      DBUG_ASSERT(FALSE);  
+  }
+}
+
+/**
+   Get number of named objects (ts, db, table, view, routines) in the
+   image.
+*/
+inline
+ulong Image_info::object_count() const
+{ 
+  return (db_count() +
+	  ts_count() +
+	  table_count() +
+	  view_count() +
+	  routine_count());
+}
+
+/// Returns number of routines in the image.
+inline
+ulong Image_info::routine_count() const
+{ 
+  return m_routine_count;
+}
+
 /// Returns number of databases in the image.
 inline
-uint Image_info::db_count() const
+ulong Image_info::db_count() const
 { 
   return m_dbs.count();
 }
 
 /// Returns number of tablespaces in the image.
 inline
-uint Image_info::ts_count() const
+ulong Image_info::ts_count() const
 { 
   return m_ts_map.count();
 }
@@ -742,6 +814,20 @@ ulong Image_info::table_count() const
   return m_table_count;
 }
 
+/// Returns total number of views in the image.
+inline
+ulong Image_info::view_count() const
+{ 
+  return m_view_count;
+}
+
+/// Returns total number of privileges in the image.
+inline
+ulong Image_info::priv_count() const
+{ 
+  return m_priv_count;
+}
+
 /// Returns number of snapshots used by the image.
 inline
 ushort Image_info::snap_count() const

=== modified file 'sql/backup/logger.cc'
--- a/sql/backup/logger.cc	2009-02-04 10:49:16 +0000
+++ b/sql/backup/logger.cc	2009-02-16 12:20:31 +0000
@@ -155,7 +155,7 @@ int Logger::v_write_message(log_level::v
 void Logger::report_stats_pre(const Image_info &info)
 {
   DBUG_ASSERT(m_state == RUNNING);
-  backup_log->num_objects(info.table_count());
+  backup_log->num_objects(info.object_count());
   // Compose list of databases.
 
   Image_info::Db_iterator *it= info.get_dbs();

Thread
bzr commit into mysql-6.0-backup branch (jorgen.loland:2772) Bug#39109Jorgen Loland16 Feb