List:Commits« Previous MessageNext Message »
From:rsomla Date:December 13 2007 9:26am
Subject:bk commit into 6.0 tree (rafal:1.2748) BUG#32190
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, 2007-12-13 10:26:34+01:00, rafal@quant.(none) +8 -0
  BUG#32190 (Online backup does not save character set settings for databases).
  
  This patch redefines backup::meta::Db::get_create_stmt() method to return a
  correct CREATE DATABASE statement with all necessary clauses. This will make the 
  backup kernel to use this statement when creating a database during restore. 
  Thus the default character set and collation will be restored as needed.

  mysql-test/r/backup.result@stripped, 2007-12-13 10:26:30+01:00, rafal@quant.(none) +15 -19
    Results update.

  mysql-test/r/backup_ddl_blocker.result@stripped, 2007-12-13 10:26:31+01:00, rafal@quant.(none) +1 -1
    Results update.

  mysql-test/r/backup_errors.result@stripped, 2007-12-13 10:26:31+01:00, rafal@quant.(none) +2 -10
    Results update.

  mysql-test/t/backup.test@stripped, 2007-12-13 10:26:31+01:00, rafal@quant.(none) +12 -11
    Add CHARACTER SET and COLLATION clauses to CREATE DATABASE statements to test that these 
    settings are correctly restored. Disable warnings during cleanup so that test will not
    fail when it deletes objects left-over from previous tests. Removed spurious DROP TABLES 
    for the tables created in empty database db1.

  mysql-test/t/backup_ddl_blocker.test@stripped, 2007-12-13 10:26:31+01:00, rafal@quant.(none) +0 -15
    Remove obsolete comments.

  mysql-test/t/backup_errors.test@stripped, 2007-12-13 10:26:31+01:00, rafal@quant.(none) +10 -6
    - Disable warnings during cleanup so that test will not
      fail when it deletes objects left-over from previous tests.
    - Use "--remove_file" to remove file.

  sql/backup/meta_data.cc@stripped, 2007-12-13 10:26:31+01:00, rafal@quant.(none) +81 -13
    Define store_db_create_info() function and use it to get a CREATE statement for a database.

  sql/backup/meta_data.h@stripped, 2007-12-13 10:26:31+01:00, rafal@quant.(none) +2 -1
    The meta::Db class uses now the standard create() method and doesn't redefine it.

diff -Nrup a/mysql-test/r/backup.result b/mysql-test/r/backup.result
--- a/mysql-test/r/backup.result	2007-12-03 21:28:01 +01:00
+++ b/mysql-test/r/backup.result	2007-12-13 10:26:30 +01:00
@@ -1,15 +1,10 @@
 DROP DATABASE IF EXISTS db1;
-Warnings:
-Note	1008	Can't drop database 'db1'; database doesn't exist
 DROP DATABASE IF EXISTS db2;
-Warnings:
-Note	1008	Can't drop database 'db2'; database doesn't exist
+DROP DATABASE IF EXISTS db3;
 CREATE DATABASE db1;
-CREATE DATABASE db2;
+CREATE DATABASE db2 CHARACTER SET=utf8;
+CREATE DATABASE db3 COLLATE latin1_bin;
 USE db1;
-DROP TABLE IF EXISTS `building`;
-Warnings:
-Note	1051	Unknown table 'building'
 CREATE TABLE `building` (
 `dir_code` char(4),
 `building` char(6)
@@ -17,9 +12,6 @@ CREATE TABLE `building` (
 LOCK TABLES `building` WRITE;
 INSERT INTO `building` VALUES ('N41','1300'),('N01','1453'),('M00','1000'),('N41','1301'),('N41','1305');
 UNLOCK TABLES;
-DROP TABLE IF EXISTS `directorate`;
-Warnings:
-Note	1051	Unknown table 'directorate'
 CREATE TABLE `directorate` (
 `dir_code` char(4),
 `dir_name` char(30),
@@ -29,9 +21,6 @@ LOCK TABLES `directorate` WRITE;
 INSERT INTO `directorate` VALUES ('N41','Development','333445555'),('N01','Human Resources','123654321'),('M00','Management','333444444');
 UNLOCK TABLES;
 USE db2;
-DROP TABLE IF EXISTS `staff`;
-Warnings:
-Note	1051	Unknown table 'staff'
 CREATE TABLE `staff` (
 `id` char(9),
 `first_name` char(20),
@@ -44,9 +33,6 @@ CREATE TABLE `staff` (
 LOCK TABLES `staff` WRITE;
 INSERT INTO `staff` VALUES ('333445555','John','Q','Smith','M',30000,'333444444'),('123763153','William','E','Walters','M',25000,'123654321'),('333444444','Alicia','F','St.Cruz','F',25000,NULL),('921312388','Goy','X','Hong','F',40000,'123654321'),('800122337','Rajesh','G','Kardakarna','M',38000,'333445555'),('820123637','Monty','C','Smythe','M',38000,'333445555'),('830132335','Richard','E','Jones','M',38000,'333445555'),('333445665','Edward','E','Engles','M',25000,'333445555'),('123654321','Beware','D','Borg','F',55000,'333444444'),('123456789','Wilma','N','Maxima','F',43000,'333445555');
 UNLOCK TABLES;
-DROP TABLE IF EXISTS `tasking`;
-Warnings:
-Note	1051	Unknown table 'tasking'
 CREATE TABLE `tasking` (
 `id` char(9),
 `project_number` char(9),
@@ -63,6 +49,15 @@ DROP DATABASE db2;
 USE mysql;
 RESTORE FROM 'test.ba';
 backup_id	#
+SHOW CREATE DATABASE db1;
+Database	Create Database
+db1	CREATE DATABASE `db1` /*!40100 DEFAULT CHARACTER SET latin1 */
+SHOW CREATE DATABASE db2;
+Database	Create Database
+db2	CREATE DATABASE `db2` /*!40100 DEFAULT CHARACTER SET utf8 */
+SHOW CREATE DATABASE db3;
+Database	Create Database
+db3	CREATE DATABASE `db3` /*!40100 DEFAULT CHARACTER SET latin1 COLLATE latin1_bin */
 USE db1;
 SHOW TABLES;
 Tables_in_db1
@@ -104,8 +99,9 @@ tasking	CREATE TABLE `tasking` (
   `project_number` char(9) DEFAULT NULL,
   `hours_worked` double(10,2) DEFAULT NULL
 ) ENGINE=BLACKHOLE DEFAULT CHARSET=latin1
-DROP DATABASE IF EXISTS db1;
-DROP DATABASE IF EXISTS db2;
+DROP DATABASE db1;
+DROP DATABASE db2;
+DROP DATABASE db3;
 DROP DATABASE IF EXISTS bup_default;
 CREATE DATABASE bup_default;
 CREATE TABLE bup_default.wide (
diff -Nrup a/mysql-test/r/backup_ddl_blocker.result b/mysql-test/r/backup_ddl_blocker.result
--- a/mysql-test/r/backup_ddl_blocker.result	2007-12-04 18:38:01 +01:00
+++ b/mysql-test/r/backup_ddl_blocker.result	2007-12-13 10:26:31 +01:00
@@ -933,7 +933,7 @@ bup_ddl_blocker_2
 bup_ddl_blocker_4
 SHOW CREATE DATABASE bup_ddl_blocker_2;
 Database	Create Database
-bup_ddl_blocker_2	CREATE DATABASE `bup_ddl_blocker_2` /*!40100 DEFAULT CHARACTER SET latin1 */
+bup_ddl_blocker_2	CREATE DATABASE `bup_ddl_blocker_2` /*!40100 DEFAULT CHARACTER SET latin2 */
 SHOW CREATE DATABASE bup_ddl_blocker_4;
 Database	Create Database
 bup_ddl_blocker_4	CREATE DATABASE `bup_ddl_blocker_4` /*!40100 DEFAULT CHARACTER SET latin1 */
diff -Nrup a/mysql-test/r/backup_errors.result b/mysql-test/r/backup_errors.result
--- a/mysql-test/r/backup_errors.result	2007-11-06 19:32:22 +01:00
+++ b/mysql-test/r/backup_errors.result	2007-12-13 10:26:31 +01:00
@@ -1,9 +1,5 @@
 DROP DATABASE IF EXISTS adb;
-Warnings:
-Note	1008	Can't drop database 'adb'; database doesn't exist
 DROP DATABASE IF EXISTS bdb;
-Warnings:
-Note	1008	Can't drop database 'bdb'; database doesn't exist
 RESTORE FROM 'test.bak';
 ERROR HY000: Can't read backup location 'test.bak'
 CREATE DATABASE adb;
@@ -11,14 +7,10 @@ CREATE DATABASE bdb;
 BACKUP DATABASE adb TO '';
 ERROR HY000: Invalid backup location ''
 DROP DATABASE IF EXISTS foo;
-Warnings:
-Note	1008	Can't drop database 'foo'; database doesn't exist
 DROP DATABASE IF EXISTS bar;
-Warnings:
-Note	1008	Can't drop database 'bar'; database doesn't exist
 BACKUP DATABASE foo TO 'test.bak';
 ERROR 42000: Unknown database 'foo'
 BACKUP DATABASE test,foo,bdb,bar TO 'test.bak';
 ERROR 42000: Unknown database 'foo,bar'
-DROP DATABASE IF EXISTS adb;
-DROP DATABASE IF EXISTS bdb;
+DROP DATABASE adb;
+DROP DATABASE bdb;
diff -Nrup a/mysql-test/t/backup.test b/mysql-test/t/backup.test
--- a/mysql-test/t/backup.test	2007-12-03 21:28:06 +01:00
+++ b/mysql-test/t/backup.test	2007-12-13 10:26:31 +01:00
@@ -5,19 +5,18 @@ connect (backup,localhost,root,,);
 
 connection backup;
 
+--disable_warnings
 DROP DATABASE IF EXISTS db1;
 DROP DATABASE IF EXISTS db2;
+DROP DATABASE IF EXISTS db3;
+--enable_warnings
 
 CREATE DATABASE db1;
-CREATE DATABASE db2;
+CREATE DATABASE db2 CHARACTER SET=utf8;
+CREATE DATABASE db3 COLLATE latin1_bin;
 
 USE db1;
 
-# SHOW ENGINES;
-
-#SET @@storage_engine = 'MEMORY';
-
-DROP TABLE IF EXISTS `building`;
 CREATE TABLE `building` (
   `dir_code` char(4),
   `building` char(6)
@@ -36,7 +35,6 @@ UNLOCK TABLES;
 # Table structure for table `directorate`
 #
 
-DROP TABLE IF EXISTS `directorate`;
 CREATE TABLE `directorate` (
   `dir_code` char(4),
   `dir_name` char(30),
@@ -57,7 +55,6 @@ USE db2;
 # Table structure for table `staff`
 #
 
-DROP TABLE IF EXISTS `staff`;
 CREATE TABLE `staff` (
   `id` char(9),
   `first_name` char(20),
@@ -80,7 +77,6 @@ UNLOCK TABLES;
 # Table structure for table `tasking`
 #
 
-DROP TABLE IF EXISTS `tasking`;
 CREATE TABLE `tasking` (
   `id` char(9),
   `project_number` char(9),
@@ -110,6 +106,10 @@ USE mysql;
 --replace_column 1 # 2 # 3 # 4 # 10 # 11 # 12 #
 --query_vertical RESTORE FROM 'test.ba'
 
+SHOW CREATE DATABASE db1;
+SHOW CREATE DATABASE db2;
+SHOW CREATE DATABASE db3;
+
 USE db1;
 SHOW TABLES;
 
@@ -123,8 +123,9 @@ SHOW TABLES;
 SELECT * FROM staff;
 SHOW CREATE TABLE tasking;
 
-DROP DATABASE IF EXISTS db1;
-DROP DATABASE IF EXISTS db2;
+DROP DATABASE db1;
+DROP DATABASE db2;
+DROP DATABASE db3;
 
 #
 # This test is for the default and snapshot online backup drivers
diff -Nrup a/mysql-test/t/backup_ddl_blocker.test b/mysql-test/t/backup_ddl_blocker.test
--- a/mysql-test/t/backup_ddl_blocker.test	2007-12-06 19:05:56 +01:00
+++ b/mysql-test/t/backup_ddl_blocker.test	2007-12-13 10:26:31 +01:00
@@ -1583,14 +1583,6 @@ RESTORE FROM "bup_ddl_blocker.bak";
 
 --echo con1: Showing databases that were backed up
 --echo con1: bup_ddl_blocker_1 has been renamed and
-
-#
-# NOTE: The online backup does not preserve character set information as 
-# it should. Thus, the results of this test will not show the changes
-# made with the alter database command to bup_ddl_blocker_2. This has
-# been reported as BUG#32190. 
-#
-
 --echo con1: bup_ddl_blocker_2.t1 has been truncated.
 --echo con1: bup_ddl_blocker_4 has not had its character set changed. 
 --echo con1: bup_ddl_blocker_4.t1 has not been truncated.
@@ -1772,13 +1764,6 @@ reap;
 --echo Verifying Test 5 results for restore.
 --echo
 ##############################################################
-
-#
-# NOTE: The online backup does not preserve character set information as 
-# it should. Thus, the results of this test will not show the changes
-# made with the alter database command to bup_ddl_blocker_2. This has
-# been reported as BUG#32190. 
-#
 
 --echo con1: bup_ddl_blocker_4 has had its character set changed. 
 --echo con1: bup_ddl_blocker_2.t1 has not been truncated.
diff -Nrup a/mysql-test/t/backup_errors.test b/mysql-test/t/backup_errors.test
--- a/mysql-test/t/backup_errors.test	2007-11-30 05:22:00 +01:00
+++ b/mysql-test/t/backup_errors.test	2007-12-13 10:26:31 +01:00
@@ -1,11 +1,14 @@
 --source include/not_embedded.inc
 
+--disable_warnings
 DROP DATABASE IF EXISTS adb;
 DROP DATABASE IF EXISTS bdb;
+--enable_warnings
 
 # non-existent backup archive
--- exec rm -f $MYSQLTEST_VARDIR/master-data/test.bak
--- error ER_BACKUP_READ_LOC
+--error 0,1
+--remove_file $MYSQLTEST_VARDIR/master-data/test.bak
+--error ER_BACKUP_READ_LOC
 RESTORE FROM 'test.bak';
 
 CREATE DATABASE adb;
@@ -16,8 +19,11 @@ CREATE DATABASE bdb;
 BACKUP DATABASE adb TO '';
 
 # non-existent database
+--disable_warnings
 DROP DATABASE IF EXISTS foo;
 DROP DATABASE IF EXISTS bar;
+--enable_warnings
+
 -- error ER_BAD_DB_ERROR
 BACKUP DATABASE foo TO 'test.bak';
 -- error ER_BAD_DB_ERROR
@@ -25,7 +31,5 @@ BACKUP DATABASE test,foo,bdb,bar TO 'tes
 
 # TODO: fix error injection and test more errors
 
-DROP DATABASE IF EXISTS adb;
-DROP DATABASE IF EXISTS bdb;
-
-
+DROP DATABASE adb;
+DROP DATABASE bdb;
diff -Nrup a/sql/backup/meta_data.cc b/sql/backup/meta_data.cc
--- a/sql/backup/meta_data.cc	2007-11-30 19:20:34 +01:00
+++ b/sql/backup/meta_data.cc	2007-12-13 10:26:31 +01:00
@@ -106,6 +106,9 @@ int bcat_get_item_create_data(st_bstream
 
  *****************************************************************/
 
+int store_db_create_info(THD *thd, const char *dbname, uint create_options,
+                         String *buffer);
+
 namespace backup {
 
 /**
@@ -145,22 +148,12 @@ result_t meta::Item::drop(THD *thd)
 
 result_t meta::Db::get_create_stmt(::String &stmt)
 {
-  // TODO: get a full CREATE statement for a database
-  return ERROR;
-}
-
-result_t meta::Db::create(THD *thd, ::String&, byte*, byte*)
-{
-  String stmt;
-
-  // TODO: CREATE DATABASE statement should be taken from the backup image.
-
-  stmt.append("CREATE DATABASE ");
-  stmt.append(sql_name());
+  int res= ::store_db_create_info(::current_thd, sql_name(), 0, &stmt);
 
-  return silent_exec_query(thd,stmt) ? ERROR : OK;
+  return res ? ERROR : OK;
 }
 
+
 result_t meta::Table::get_create_stmt(::String &stmt)
 {
   stmt.free();
@@ -187,3 +180,78 @@ result_t meta::Table::get_create_stmt(::
 }
 
 } // backup namespace
+
+
+/**
+  Get complete CREATE statement for a database.
+
+  The database is identified by its name, passed as @c dbname parameter.
+  The name should be encoded using the system character set (UTF8 currently).
+
+  Resulting statement is stored in the string pointed by @c buffer. The string
+  is emptied first and its charset is set to the system character set.
+
+  If HA_LEX_CREATE_IF_NOT_EXISTS flag is set in @c create_options, then
+  the resulting CREATE statement contains "IF NOT EXISTS" clause. Other flags
+  in @c create_options are ignored.
+
+  @param  thd     The current thread instance.
+  @param  dbname  The name of the database.
+  @param  create_options Options influencing the resulting CRATE statement.
+  @param  buffer  A String instance where the statement is stored.
+
+  @retval 0                 All OK.
+  @retval ER_BAD_DB_ERROR   Wrong database name.
+*/
+
+int store_db_create_info(THD *thd, const char *dbname, uint create_options,
+                         String *buffer)
+{
+  HA_CREATE_INFO create;
+  DBUG_ENTER("store_db_create_info");
+
+  /*
+    This code is adapted from mysql_show_create_db() defined in sql_show.cc.
+
+    TODO: refactor above function so that it uses store_db_create_info()
+    internally. In that case, the later function should be moved to sql_show.cc.
+  */
+  if (!my_strcasecmp(system_charset_info, dbname,
+                     INFORMATION_SCHEMA_NAME.str))
+  {
+    dbname= INFORMATION_SCHEMA_NAME.str;
+    create.default_table_charset= system_charset_info;
+  }
+  else
+  {
+    if (check_db_dir_existence(dbname))
+      DBUG_RETURN(ER_BAD_DB_ERROR);
+
+    load_db_opt_by_name(thd, dbname, &create);
+  }
+
+  buffer->length(0);
+  buffer->free();
+  buffer->set_charset(system_charset_info);
+  buffer->append(STRING_WITH_LEN("CREATE DATABASE "));
+
+  if (create_options & HA_LEX_CREATE_IF_NOT_EXISTS)
+    buffer->append(STRING_WITH_LEN("/*!32312 IF NOT EXISTS*/ "));
+
+  append_identifier(thd, buffer, dbname, strlen(dbname));
+
+  if (create.default_table_charset)
+  {
+    buffer->append(STRING_WITH_LEN(" /*!40100"));
+    buffer->append(STRING_WITH_LEN(" DEFAULT CHARACTER SET "));
+    buffer->append(create.default_table_charset->csname);
+    if (!(create.default_table_charset->state & MY_CS_PRIMARY))
+    {
+      buffer->append(STRING_WITH_LEN(" COLLATE "));
+      buffer->append(create.default_table_charset->name);
+    }
+    buffer->append(STRING_WITH_LEN(" */"));
+  }
+
+  DBUG_RETURN(0);
+}
diff -Nrup a/sql/backup/meta_data.h b/sql/backup/meta_data.h
--- a/sql/backup/meta_data.h	2007-11-30 09:23:30 +01:00
+++ b/sql/backup/meta_data.h	2007-12-13 10:26:31 +01:00
@@ -84,6 +84,8 @@ class Item
  */
 class Db: public Item
 {
+ public:
+
   const enum_type type() const
   { return DB; }
 
@@ -91,7 +93,6 @@ class Db: public Item
   { return "DATABASE"; }
 
   result_t get_create_stmt(::String&);
-  result_t create(THD*, ::String&, byte*, byte*);
 };
 
 /**
Thread
bk commit into 6.0 tree (rafal:1.2748) BUG#32190rsomla13 Dec