4162 Martin Zaun 2011-02-01 [merge]
merge from ndb-6.3 to ndb-7.0
added:
mysql-test/suite/ndb/r/ndb_restore_rewrite_db.result
mysql-test/suite/ndb/t/ndb_restore_rewrite_db.test
modified:
storage/ndb/tools/restore/consumer_restore.cpp
storage/ndb/tools/restore/restore_main.cpp
4161 Magnus Blåudd 2011-02-01
ndb
- mark up MCP patch for bug58082
modified:
sql/rpl_injector.cc
sql/rpl_injector.h
=== added file 'mysql-test/suite/ndb/r/ndb_restore_rewrite_db.result'
--- a/mysql-test/suite/ndb/r/ndb_restore_rewrite_db.result 1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/ndb/r/ndb_restore_rewrite_db.result 2011-02-02 06:52:12 +0000
@@ -0,0 +1,328 @@
+************************************************************
+* Creating multiple databases with identical tables
+* (have blobs and indexes to cover the hidden tables)
+************************************************************
+CREATE DATABASE db0;
+CREATE DATABASE db1;
+CREATE DATABASE db2;
+USE db0;
+CREATE TABLE t0 (
+id INT PRIMARY KEY,
+cint INT,
+cvarchar VARCHAR(5),
+cblob BLOB(1000004),
+UNIQUE INDEX UNIQUE_t0_0 USING BTREE (cint ASC),
+UNIQUE INDEX UNIQUE_t0_2 USING BTREE (cvarchar ASC)
+) ENGINE=NDB;
+USE db1;
+CREATE TABLE t0 (
+id INT PRIMARY KEY,
+cint INT,
+cvarchar VARCHAR(5),
+cblob BLOB(1000004),
+UNIQUE INDEX UNIQUE_t0_0 USING BTREE (cint ASC),
+UNIQUE INDEX UNIQUE_t0_2 USING BTREE (cvarchar ASC)
+) ENGINE=NDB;
+USE db2;
+CREATE TABLE t0 (
+id INT PRIMARY KEY,
+cint INT,
+cvarchar VARCHAR(5),
+cblob BLOB(1000004),
+UNIQUE INDEX UNIQUE_t0_0 USING BTREE (cint ASC),
+UNIQUE INDEX UNIQUE_t0_2 USING BTREE (cvarchar ASC)
+) ENGINE=NDB;
+************************************************************
+* Inserting data
+* (create disjunct sets of rows to merge without conflicts;
+* at this time, ndb_restore does not offer any detection
+* of data conflicts between databases in the backup or in
+* memory; databases are restored in an unspecified order)
+* (make blob data long enough to be held in extra table)
+************************************************************
+USE db0;
+INSERT INTO t0 VALUES (0, 0, '00000', '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890');
+INSERT INTO t0 VALUES (1, 1, '11111', '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890');
+INSERT INTO t0 VALUES (2, 2, '22222', '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890');
+USE db1;
+INSERT INTO t0 VALUES (3, 3, '33333', '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890');
+INSERT INTO t0 VALUES (4, 4, '44444', '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890');
+INSERT INTO t0 VALUES (5, 5, '55555', '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890');
+USE db2;
+INSERT INTO t0 VALUES (6, 6, '66666', '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890');
+INSERT INTO t0 VALUES (7, 7, '77777', '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890');
+INSERT INTO t0 VALUES (8, 8, '88888', '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890');
+************************************************************
+* Creating in-memory copies of the NDB tables
+************************************************************
+CREATE TABLE db0.t0_data ENGINE=MYISAM AS SELECT * FROM db0.t0;
+CREATE TABLE db1.t0_data ENGINE=MYISAM AS SELECT * FROM db1.t0;
+CREATE TABLE db2.t0_data ENGINE=MYISAM AS SELECT * FROM db2.t0;
+************************************************************
+* Backing up databases
+************************************************************
+************************************************************
+* Restoring databases with no rewrite (sanity check)
+************************************************************
+CREATE TABLE db0.t0_temp ENGINE=MYISAM AS SELECT * FROM db0.t0_data;
+CREATE TABLE db1.t0_temp ENGINE=MYISAM AS SELECT * FROM db1.t0_data;
+CREATE TABLE db2.t0_temp ENGINE=MYISAM AS SELECT * FROM db2.t0_data;
+DELETE FROM db0.t0;
+DELETE FROM db1.t0;
+DELETE FROM db2.t0;
+SELECT COUNT(*) FROM db0.t0;
+COUNT(*)
+3
+SELECT COUNT(*) FROM db1.t0;
+COUNT(*)
+3
+SELECT COUNT(*) FROM db2.t0;
+COUNT(*)
+3
+SELECT COUNT(*) FROM db0.t0 NATURAL JOIN db0.t0_temp;
+COUNT(*)
+3
+SELECT COUNT(*) FROM db1.t0 NATURAL JOIN db1.t0_temp;
+COUNT(*)
+3
+SELECT COUNT(*) FROM db2.t0 NATURAL JOIN db2.t0_temp;
+COUNT(*)
+3
+DROP TABLE db0.t0_temp;
+DROP TABLE db1.t0_temp;
+DROP TABLE db2.t0_temp;
+************************************************************
+* Negative testing: check wrong usage of command-line option
+* (expected exit code for usage errors: NDBT_WRONGARGS = 2)
+************************************************************
+************************************************************
+* Restoring databases with redundant/self-rewrite options
+************************************************************
+CREATE TABLE db0.t0_temp ENGINE=MYISAM AS SELECT * FROM db0.t0_data;
+CREATE TABLE db1.t0_temp ENGINE=MYISAM AS SELECT * FROM db1.t0_data;
+CREATE TABLE db2.t0_temp ENGINE=MYISAM AS SELECT * FROM db2.t0_data;
+DELETE FROM db0.t0;
+DELETE FROM db1.t0;
+DELETE FROM db2.t0;
+SELECT COUNT(*) FROM db0.t0;
+COUNT(*)
+3
+SELECT COUNT(*) FROM db1.t0;
+COUNT(*)
+3
+SELECT COUNT(*) FROM db2.t0;
+COUNT(*)
+3
+SELECT COUNT(*) FROM db0.t0 NATURAL JOIN db0.t0_temp;
+COUNT(*)
+3
+SELECT COUNT(*) FROM db1.t0 NATURAL JOIN db1.t0_temp;
+COUNT(*)
+3
+SELECT COUNT(*) FROM db2.t0 NATURAL JOIN db2.t0_temp;
+COUNT(*)
+3
+DROP TABLE db0.t0_temp;
+DROP TABLE db1.t0_temp;
+DROP TABLE db2.t0_temp;
+************************************************************
+* Restoring databases with overriding rewrite options
+************************************************************
+CREATE TABLE db0.t0_temp ENGINE=MYISAM AS SELECT * FROM db0.t0_data;
+CREATE TABLE db1.t0_temp ENGINE=MYISAM AS SELECT * FROM db1.t0_data;
+CREATE TABLE db2.t0_temp ENGINE=MYISAM AS SELECT * FROM db2.t0_data;
+DELETE FROM db0.t0;
+DELETE FROM db1.t0;
+DELETE FROM db2.t0;
+SELECT COUNT(*) FROM db0.t0;
+COUNT(*)
+3
+SELECT COUNT(*) FROM db1.t0;
+COUNT(*)
+3
+SELECT COUNT(*) FROM db2.t0;
+COUNT(*)
+3
+SELECT COUNT(*) FROM db0.t0 NATURAL JOIN db0.t0_temp;
+COUNT(*)
+3
+SELECT COUNT(*) FROM db1.t0 NATURAL JOIN db1.t0_temp;
+COUNT(*)
+3
+SELECT COUNT(*) FROM db2.t0 NATURAL JOIN db2.t0_temp;
+COUNT(*)
+3
+DROP TABLE db0.t0_temp;
+DROP TABLE db1.t0_temp;
+DROP TABLE db2.t0_temp;
+************************************************************
+* Restoring databases with a single rewrite
+************************************************************
+CREATE TABLE db0.t0_temp LIKE db0.t0_data;
+CREATE TABLE db1.t0_temp LIKE db1.t0_data;
+CREATE TABLE db2.t0_temp LIKE db2.t0_data;
+DELETE FROM db0.t0;
+DELETE FROM db1.t0;
+DELETE FROM db2.t0;
+SELECT COUNT(*) FROM db0.t0;
+COUNT(*)
+0
+SELECT COUNT(*) FROM db1.t0;
+COUNT(*)
+6
+SELECT COUNT(*) FROM db2.t0;
+COUNT(*)
+3
+INSERT db1.t0_temp SELECT * FROM db0.t0_data;
+INSERT db1.t0_temp SELECT * FROM db1.t0_data;
+INSERT db2.t0_temp SELECT * FROM db2.t0_data;
+SELECT COUNT(*) FROM db0.t0 NATURAL JOIN db0.t0_temp;
+COUNT(*)
+0
+SELECT COUNT(*) FROM db1.t0 NATURAL JOIN db1.t0_temp;
+COUNT(*)
+6
+SELECT COUNT(*) FROM db2.t0 NATURAL JOIN db2.t0_temp;
+COUNT(*)
+3
+DROP TABLE db0.t0_temp;
+DROP TABLE db1.t0_temp;
+DROP TABLE db2.t0_temp;
+************************************************************
+* Restoring databases with multiple rewrites
+************************************************************
+CREATE TABLE db0.t0_temp LIKE db0.t0_data;
+CREATE TABLE db1.t0_temp LIKE db1.t0_data;
+CREATE TABLE db2.t0_temp LIKE db2.t0_data;
+DELETE FROM db0.t0;
+DELETE FROM db1.t0;
+DELETE FROM db2.t0;
+SELECT COUNT(*) FROM db0.t0;
+COUNT(*)
+0
+SELECT COUNT(*) FROM db1.t0;
+COUNT(*)
+3
+SELECT COUNT(*) FROM db2.t0;
+COUNT(*)
+6
+INSERT db1.t0_temp SELECT * FROM db0.t0_data;
+INSERT db2.t0_temp SELECT * FROM db1.t0_data;
+INSERT db2.t0_temp SELECT * FROM db2.t0_data;
+SELECT COUNT(*) FROM db0.t0 NATURAL JOIN db0.t0_temp;
+COUNT(*)
+0
+SELECT COUNT(*) FROM db1.t0 NATURAL JOIN db1.t0_temp;
+COUNT(*)
+3
+SELECT COUNT(*) FROM db2.t0 NATURAL JOIN db2.t0_temp;
+COUNT(*)
+6
+DROP TABLE db0.t0_temp;
+DROP TABLE db1.t0_temp;
+DROP TABLE db2.t0_temp;
+************************************************************
+* Restoring databases with multiple rewrites into same target
+************************************************************
+CREATE TABLE db0.t0_temp LIKE db0.t0_data;
+CREATE TABLE db1.t0_temp LIKE db1.t0_data;
+CREATE TABLE db2.t0_temp LIKE db2.t0_data;
+DELETE FROM db0.t0;
+DELETE FROM db1.t0;
+DELETE FROM db2.t0;
+SELECT COUNT(*) FROM db0.t0;
+COUNT(*)
+0
+SELECT COUNT(*) FROM db1.t0;
+COUNT(*)
+0
+SELECT COUNT(*) FROM db2.t0;
+COUNT(*)
+9
+INSERT db2.t0_temp SELECT * FROM db0.t0_data;
+INSERT db2.t0_temp SELECT * FROM db1.t0_data;
+INSERT db2.t0_temp SELECT * FROM db2.t0_data;
+SELECT COUNT(*) FROM db0.t0 NATURAL JOIN db0.t0_temp;
+COUNT(*)
+0
+SELECT COUNT(*) FROM db1.t0 NATURAL JOIN db1.t0_temp;
+COUNT(*)
+0
+SELECT COUNT(*) FROM db2.t0 NATURAL JOIN db2.t0_temp;
+COUNT(*)
+9
+DROP TABLE db0.t0_temp;
+DROP TABLE db1.t0_temp;
+DROP TABLE db2.t0_temp;
+************************************************************
+* Restoring databases with swapping rewrites
+************************************************************
+CREATE TABLE db0.t0_temp LIKE db0.t0_data;
+CREATE TABLE db1.t0_temp LIKE db1.t0_data;
+CREATE TABLE db2.t0_temp LIKE db2.t0_data;
+DELETE FROM db0.t0;
+DELETE FROM db1.t0;
+DELETE FROM db2.t0;
+SELECT COUNT(*) FROM db0.t0;
+COUNT(*)
+3
+SELECT COUNT(*) FROM db1.t0;
+COUNT(*)
+3
+SELECT COUNT(*) FROM db2.t0;
+COUNT(*)
+3
+INSERT db1.t0_temp SELECT * FROM db0.t0_data;
+INSERT db0.t0_temp SELECT * FROM db1.t0_data;
+INSERT db2.t0_temp SELECT * FROM db2.t0_data;
+SELECT COUNT(*) FROM db0.t0 NATURAL JOIN db0.t0_temp;
+COUNT(*)
+3
+SELECT COUNT(*) FROM db1.t0 NATURAL JOIN db1.t0_temp;
+COUNT(*)
+3
+SELECT COUNT(*) FROM db2.t0 NATURAL JOIN db2.t0_temp;
+COUNT(*)
+3
+DROP TABLE db0.t0_temp;
+DROP TABLE db1.t0_temp;
+DROP TABLE db2.t0_temp;
+************************************************************
+* Restoring databases with permutating rewrites
+************************************************************
+CREATE TABLE db0.t0_temp LIKE db0.t0_data;
+CREATE TABLE db1.t0_temp LIKE db1.t0_data;
+CREATE TABLE db2.t0_temp LIKE db2.t0_data;
+DELETE FROM db0.t0;
+DELETE FROM db1.t0;
+DELETE FROM db2.t0;
+SELECT COUNT(*) FROM db0.t0;
+COUNT(*)
+3
+SELECT COUNT(*) FROM db1.t0;
+COUNT(*)
+3
+SELECT COUNT(*) FROM db2.t0;
+COUNT(*)
+3
+INSERT db1.t0_temp SELECT * FROM db0.t0_data;
+INSERT db2.t0_temp SELECT * FROM db1.t0_data;
+INSERT db0.t0_temp SELECT * FROM db2.t0_data;
+SELECT COUNT(*) FROM db0.t0 NATURAL JOIN db0.t0_temp;
+COUNT(*)
+3
+SELECT COUNT(*) FROM db1.t0 NATURAL JOIN db1.t0_temp;
+COUNT(*)
+3
+SELECT COUNT(*) FROM db2.t0 NATURAL JOIN db2.t0_temp;
+COUNT(*)
+3
+DROP TABLE db0.t0_temp;
+DROP TABLE db1.t0_temp;
+DROP TABLE db2.t0_temp;
+************************************************************
+* Deleting tables and databases
+************************************************************
+DROP DATABASE db0;
+DROP DATABASE db1;
+DROP DATABASE db2;
=== added file 'mysql-test/suite/ndb/t/ndb_restore_rewrite_db.test'
--- a/mysql-test/suite/ndb/t/ndb_restore_rewrite_db.test 1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/ndb/t/ndb_restore_rewrite_db.test 2011-02-02 06:52:12 +0000
@@ -0,0 +1,420 @@
+######################################################################
+# Author: Martin Zaun
+# Date: 2011-01
+# Purpose: test of rewrite-database feature
+######################################################################
+
+-- source include/have_ndb.inc
+
+# mysqld's configuration is not relevant to this test
+-- source include/not_embedded.inc
+
+--echo ************************************************************
+--echo * Creating multiple databases with identical tables
+--echo * (have blobs and indexes to cover the hidden tables)
+--echo ************************************************************
+
+CREATE DATABASE db0;
+CREATE DATABASE db1;
+CREATE DATABASE db2;
+
+USE db0;
+CREATE TABLE t0 (
+ id INT PRIMARY KEY,
+ cint INT,
+ cvarchar VARCHAR(5),
+ cblob BLOB(1000004),
+ UNIQUE INDEX UNIQUE_t0_0 USING BTREE (cint ASC),
+ UNIQUE INDEX UNIQUE_t0_2 USING BTREE (cvarchar ASC)
+) ENGINE=NDB;
+
+USE db1;
+CREATE TABLE t0 (
+ id INT PRIMARY KEY,
+ cint INT,
+ cvarchar VARCHAR(5),
+ cblob BLOB(1000004),
+ UNIQUE INDEX UNIQUE_t0_0 USING BTREE (cint ASC),
+ UNIQUE INDEX UNIQUE_t0_2 USING BTREE (cvarchar ASC)
+) ENGINE=NDB;
+
+USE db2;
+CREATE TABLE t0 (
+ id INT PRIMARY KEY,
+ cint INT,
+ cvarchar VARCHAR(5),
+ cblob BLOB(1000004),
+ UNIQUE INDEX UNIQUE_t0_0 USING BTREE (cint ASC),
+ UNIQUE INDEX UNIQUE_t0_2 USING BTREE (cvarchar ASC)
+) ENGINE=NDB;
+
+
+--echo ************************************************************
+--echo * Inserting data
+--echo * (create disjunct sets of rows to merge without conflicts;
+--echo * at this time, ndb_restore does not offer any detection
+--echo * of data conflicts between databases in the backup or in
+--echo * memory; databases are restored in an unspecified order)
+--echo * (make blob data long enough to be held in extra table)
+--echo ************************************************************
+
+USE db0;
+INSERT INTO t0 VALUES (0, 0, '00000', '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890');
+INSERT INTO t0 VALUES (1, 1, '11111', '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890');
+INSERT INTO t0 VALUES (2, 2, '22222', '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890');
+
+USE db1;
+INSERT INTO t0 VALUES (3, 3, '33333', '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890');
+INSERT INTO t0 VALUES (4, 4, '44444', '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890');
+INSERT INTO t0 VALUES (5, 5, '55555', '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890');
+
+USE db2;
+INSERT INTO t0 VALUES (6, 6, '66666', '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890');
+INSERT INTO t0 VALUES (7, 7, '77777', '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890');
+INSERT INTO t0 VALUES (8, 8, '88888', '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890');
+
+--echo ************************************************************
+--echo * Creating in-memory copies of the NDB tables
+--echo ************************************************************
+
+CREATE TABLE db0.t0_data ENGINE=MYISAM AS SELECT * FROM db0.t0;
+CREATE TABLE db1.t0_data ENGINE=MYISAM AS SELECT * FROM db1.t0;
+CREATE TABLE db2.t0_data ENGINE=MYISAM AS SELECT * FROM db2.t0;
+
+--echo ************************************************************
+--echo * Backing up databases
+--echo ************************************************************
+
+--source include/ndb_backup.inc
+
+# command shortcuts, cover rebuilding of indexes
+#--let $restore_cmd=$NDB_RESTORE --no-defaults
+#--let $restore_cmd=$restore_cmd --disable-indexes --rebuild-indexes
+#--let $restore_cmd=$restore_cmd -b $the_backup_id -r
+#--let $restore_cmd=$restore_cmd --backup_path=$NDB_BACKUPS-$the_backup_id
+# for ndb 6.3:
+--let $restore_cmd=$NDB_TOOLS_DIR/ndb_restore --no-defaults
+--let $restore_cmd=$restore_cmd --disable-indexes --rebuild-indexes
+--let $restore_cmd=$restore_cmd -b $the_backup_id -r
+--let $restore_cmd=$restore_cmd --backup_path=$NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id
+
+--echo ************************************************************
+--echo * Restoring databases with no rewrite (sanity check)
+--echo ************************************************************
+
+# create temporary tables against which to compare data
+CREATE TABLE db0.t0_temp ENGINE=MYISAM AS SELECT * FROM db0.t0_data;
+CREATE TABLE db1.t0_temp ENGINE=MYISAM AS SELECT * FROM db1.t0_data;
+CREATE TABLE db2.t0_temp ENGINE=MYISAM AS SELECT * FROM db2.t0_data;
+
+# restore NDB tables
+DELETE FROM db0.t0;
+DELETE FROM db1.t0;
+DELETE FROM db2.t0;
+--let $restore_opt=
+--exec $restore_cmd -n 1 $restore_opt --print > /dev/null
+--exec $restore_cmd -n 2 $restore_opt --print > /dev/null
+
+# summary-check ndb tables
+SELECT COUNT(*) FROM db0.t0;
+SELECT COUNT(*) FROM db1.t0;
+SELECT COUNT(*) FROM db2.t0;
+
+# verify ndb tables
+SELECT COUNT(*) FROM db0.t0 NATURAL JOIN db0.t0_temp;
+SELECT COUNT(*) FROM db1.t0 NATURAL JOIN db1.t0_temp;
+SELECT COUNT(*) FROM db2.t0 NATURAL JOIN db2.t0_temp;
+
+# delete temporary tables
+DROP TABLE db0.t0_temp;
+DROP TABLE db1.t0_temp;
+DROP TABLE db2.t0_temp;
+
+--echo ************************************************************
+--echo * Negative testing: check wrong usage of command-line option
+--echo * (expected exit code for usage errors: NDBT_WRONGARGS = 2)
+--echo ************************************************************
+
+# empty argument
+--let $restore_opt=--rewrite-database=
+--error 2
+--exec $restore_cmd -n 1 $restore_opt > /dev/null
+
+# missing separator
+--let $restore_opt=--rewrite-database=aaaa
+--error 2
+--exec $restore_cmd -n 1 $restore_opt > /dev/null
+
+# missing source and target
+--let $restore_opt=--rewrite-database=,
+--error 2
+--exec $restore_cmd -n 1 $restore_opt > /dev/null
+
+# missing source
+--let $restore_opt=--rewrite-database=,a
+--error 2
+--exec $restore_cmd -n 1 $restore_opt > /dev/null
+
+# missing target
+--let $restore_opt=--rewrite-database=a,
+--error 2
+--exec $restore_cmd -n 1 $restore_opt > /dev/null
+
+--echo ************************************************************
+--echo * Restoring databases with redundant/self-rewrite options
+--echo ************************************************************
+
+# create temporary tables against which to compare data
+CREATE TABLE db0.t0_temp ENGINE=MYISAM AS SELECT * FROM db0.t0_data;
+CREATE TABLE db1.t0_temp ENGINE=MYISAM AS SELECT * FROM db1.t0_data;
+CREATE TABLE db2.t0_temp ENGINE=MYISAM AS SELECT * FROM db2.t0_data;
+
+# restore NDB tables
+DELETE FROM db0.t0;
+DELETE FROM db1.t0;
+DELETE FROM db2.t0;
+--let $restore_opt=--rewrite-database=db0,db0 --rewrite-database=db1,db1
+--exec $restore_cmd -n 1 $restore_opt --print > /dev/null
+--exec $restore_cmd -n 2 $restore_opt --print > /dev/null
+
+# summary-check ndb tables
+SELECT COUNT(*) FROM db0.t0;
+SELECT COUNT(*) FROM db1.t0;
+SELECT COUNT(*) FROM db2.t0;
+
+# verify ndb tables
+SELECT COUNT(*) FROM db0.t0 NATURAL JOIN db0.t0_temp;
+SELECT COUNT(*) FROM db1.t0 NATURAL JOIN db1.t0_temp;
+SELECT COUNT(*) FROM db2.t0 NATURAL JOIN db2.t0_temp;
+
+# delete temporary tables
+DROP TABLE db0.t0_temp;
+DROP TABLE db1.t0_temp;
+DROP TABLE db2.t0_temp;
+
+--echo ************************************************************
+--echo * Restoring databases with overriding rewrite options
+--echo ************************************************************
+
+# create temporary tables against which to compare data
+CREATE TABLE db0.t0_temp ENGINE=MYISAM AS SELECT * FROM db0.t0_data;
+CREATE TABLE db1.t0_temp ENGINE=MYISAM AS SELECT * FROM db1.t0_data;
+CREATE TABLE db2.t0_temp ENGINE=MYISAM AS SELECT * FROM db2.t0_data;
+
+# restore NDB tables
+DELETE FROM db0.t0;
+DELETE FROM db1.t0;
+DELETE FROM db2.t0;
+# no rewrite, since the later option overrides the former
+--let $restore_opt=--rewrite-database=db0,db1 --rewrite-database=db0,db0
+--exec $restore_cmd -n 1 $restore_opt --print > /dev/null
+--exec $restore_cmd -n 2 $restore_opt --print > /dev/null
+
+# summary-check ndb tables
+SELECT COUNT(*) FROM db0.t0;
+SELECT COUNT(*) FROM db1.t0;
+SELECT COUNT(*) FROM db2.t0;
+
+# verify ndb tables
+SELECT COUNT(*) FROM db0.t0 NATURAL JOIN db0.t0_temp;
+SELECT COUNT(*) FROM db1.t0 NATURAL JOIN db1.t0_temp;
+SELECT COUNT(*) FROM db2.t0 NATURAL JOIN db2.t0_temp;
+
+# delete temporary tables
+DROP TABLE db0.t0_temp;
+DROP TABLE db1.t0_temp;
+DROP TABLE db2.t0_temp;
+
+--echo ************************************************************
+--echo * Restoring databases with a single rewrite
+--echo ************************************************************
+
+# create temporary tables against which to compare data
+CREATE TABLE db0.t0_temp LIKE db0.t0_data;
+CREATE TABLE db1.t0_temp LIKE db1.t0_data;
+CREATE TABLE db2.t0_temp LIKE db2.t0_data;
+
+# restore NDB tables
+DELETE FROM db0.t0;
+DELETE FROM db1.t0;
+DELETE FROM db2.t0;
+--let $restore_opt=--rewrite-database=db0,db1
+--exec $restore_cmd -n 1 $restore_opt --print > /dev/null
+--exec $restore_cmd -n 2 $restore_opt --print > /dev/null
+
+# summary-check ndb tables
+SELECT COUNT(*) FROM db0.t0;
+SELECT COUNT(*) FROM db1.t0;
+SELECT COUNT(*) FROM db2.t0;
+
+# fill temporary tables
+INSERT db1.t0_temp SELECT * FROM db0.t0_data;
+INSERT db1.t0_temp SELECT * FROM db1.t0_data;
+INSERT db2.t0_temp SELECT * FROM db2.t0_data;
+
+# verify ndb tables
+SELECT COUNT(*) FROM db0.t0 NATURAL JOIN db0.t0_temp;
+SELECT COUNT(*) FROM db1.t0 NATURAL JOIN db1.t0_temp;
+SELECT COUNT(*) FROM db2.t0 NATURAL JOIN db2.t0_temp;
+
+# delete temporary tables
+DROP TABLE db0.t0_temp;
+DROP TABLE db1.t0_temp;
+DROP TABLE db2.t0_temp;
+
+--echo ************************************************************
+--echo * Restoring databases with multiple rewrites
+--echo ************************************************************
+
+# create temporary tables against which to compare data
+CREATE TABLE db0.t0_temp LIKE db0.t0_data;
+CREATE TABLE db1.t0_temp LIKE db1.t0_data;
+CREATE TABLE db2.t0_temp LIKE db2.t0_data;
+
+# restore NDB tables
+DELETE FROM db0.t0;
+DELETE FROM db1.t0;
+DELETE FROM db2.t0;
+--let $restore_opt=--rewrite-database=db0,db1 --rewrite-database=db1,db2
+--exec $restore_cmd -n 1 $restore_opt --print > /dev/null
+--exec $restore_cmd -n 2 $restore_opt --print > /dev/null
+
+# summary-check ndb tables
+SELECT COUNT(*) FROM db0.t0;
+SELECT COUNT(*) FROM db1.t0;
+SELECT COUNT(*) FROM db2.t0;
+
+# fill temporary tables
+INSERT db1.t0_temp SELECT * FROM db0.t0_data;
+INSERT db2.t0_temp SELECT * FROM db1.t0_data;
+INSERT db2.t0_temp SELECT * FROM db2.t0_data;
+
+# verify ndb tables
+SELECT COUNT(*) FROM db0.t0 NATURAL JOIN db0.t0_temp;
+SELECT COUNT(*) FROM db1.t0 NATURAL JOIN db1.t0_temp;
+SELECT COUNT(*) FROM db2.t0 NATURAL JOIN db2.t0_temp;
+
+# delete temporary tables
+DROP TABLE db0.t0_temp;
+DROP TABLE db1.t0_temp;
+DROP TABLE db2.t0_temp;
+
+--echo ************************************************************
+--echo * Restoring databases with multiple rewrites into same target
+--echo ************************************************************
+
+# create temporary tables against which to compare data
+CREATE TABLE db0.t0_temp LIKE db0.t0_data;
+CREATE TABLE db1.t0_temp LIKE db1.t0_data;
+CREATE TABLE db2.t0_temp LIKE db2.t0_data;
+
+# restore NDB tables
+DELETE FROM db0.t0;
+DELETE FROM db1.t0;
+DELETE FROM db2.t0;
+--let $restore_opt=--rewrite-database=db0,db2 --rewrite-database=db1,db2
+--exec $restore_cmd -n 1 $restore_opt --print > /dev/null
+--exec $restore_cmd -n 2 $restore_opt --print > /dev/null
+
+# summary-check ndb tables
+SELECT COUNT(*) FROM db0.t0;
+SELECT COUNT(*) FROM db1.t0;
+SELECT COUNT(*) FROM db2.t0;
+
+# fill temporary tables
+INSERT db2.t0_temp SELECT * FROM db0.t0_data;
+INSERT db2.t0_temp SELECT * FROM db1.t0_data;
+INSERT db2.t0_temp SELECT * FROM db2.t0_data;
+
+# verify ndb tables
+SELECT COUNT(*) FROM db0.t0 NATURAL JOIN db0.t0_temp;
+SELECT COUNT(*) FROM db1.t0 NATURAL JOIN db1.t0_temp;
+SELECT COUNT(*) FROM db2.t0 NATURAL JOIN db2.t0_temp;
+
+# delete temporary tables
+DROP TABLE db0.t0_temp;
+DROP TABLE db1.t0_temp;
+DROP TABLE db2.t0_temp;
+
+--echo ************************************************************
+--echo * Restoring databases with swapping rewrites
+--echo ************************************************************
+
+# create temporary tables against which to compare data
+CREATE TABLE db0.t0_temp LIKE db0.t0_data;
+CREATE TABLE db1.t0_temp LIKE db1.t0_data;
+CREATE TABLE db2.t0_temp LIKE db2.t0_data;
+
+# restore NDB tables
+DELETE FROM db0.t0;
+DELETE FROM db1.t0;
+DELETE FROM db2.t0;
+--let $restore_opt=--rewrite-database=db0,db1 --rewrite-database=db1,db0
+--exec $restore_cmd -n 1 $restore_opt --print > /dev/null
+--exec $restore_cmd -n 2 $restore_opt --print > /dev/null
+
+# summary-check ndb tables
+SELECT COUNT(*) FROM db0.t0;
+SELECT COUNT(*) FROM db1.t0;
+SELECT COUNT(*) FROM db2.t0;
+
+# fill temporary tables
+INSERT db1.t0_temp SELECT * FROM db0.t0_data;
+INSERT db0.t0_temp SELECT * FROM db1.t0_data;
+INSERT db2.t0_temp SELECT * FROM db2.t0_data;
+
+# verify ndb tables
+SELECT COUNT(*) FROM db0.t0 NATURAL JOIN db0.t0_temp;
+SELECT COUNT(*) FROM db1.t0 NATURAL JOIN db1.t0_temp;
+SELECT COUNT(*) FROM db2.t0 NATURAL JOIN db2.t0_temp;
+
+# delete temporary tables
+DROP TABLE db0.t0_temp;
+DROP TABLE db1.t0_temp;
+DROP TABLE db2.t0_temp;
+
+--echo ************************************************************
+--echo * Restoring databases with permutating rewrites
+--echo ************************************************************
+
+# create temporary tables against which to compare data
+CREATE TABLE db0.t0_temp LIKE db0.t0_data;
+CREATE TABLE db1.t0_temp LIKE db1.t0_data;
+CREATE TABLE db2.t0_temp LIKE db2.t0_data;
+
+# restore NDB tables
+DELETE FROM db0.t0;
+DELETE FROM db1.t0;
+DELETE FROM db2.t0;
+--let $restore_opt=--rewrite-database=db0,db1 --rewrite-database=db1,db2
+--let $restore_opt=$restore_opt --rewrite-database=db2,db0
+--exec $restore_cmd -n 1 $restore_opt --print > /dev/null
+--exec $restore_cmd -n 2 $restore_opt --print > /dev/null
+
+# summary-check ndb tables
+SELECT COUNT(*) FROM db0.t0;
+SELECT COUNT(*) FROM db1.t0;
+SELECT COUNT(*) FROM db2.t0;
+
+# fill temporary tables
+INSERT db1.t0_temp SELECT * FROM db0.t0_data;
+INSERT db2.t0_temp SELECT * FROM db1.t0_data;
+INSERT db0.t0_temp SELECT * FROM db2.t0_data;
+
+# verify ndb tables
+SELECT COUNT(*) FROM db0.t0 NATURAL JOIN db0.t0_temp;
+SELECT COUNT(*) FROM db1.t0 NATURAL JOIN db1.t0_temp;
+SELECT COUNT(*) FROM db2.t0 NATURAL JOIN db2.t0_temp;
+
+# delete temporary tables
+DROP TABLE db0.t0_temp;
+DROP TABLE db1.t0_temp;
+DROP TABLE db2.t0_temp;
+
+--echo ************************************************************
+--echo * Deleting tables and databases
+--echo ************************************************************
+
+DROP DATABASE db0;
+DROP DATABASE db1;
+DROP DATABASE db2;
=== modified file 'storage/ndb/tools/restore/consumer_restore.cpp'
--- a/storage/ndb/tools/restore/consumer_restore.cpp 2011-01-17 13:17:32 +0000
+++ b/storage/ndb/tools/restore/consumer_restore.cpp 2011-02-02 07:16:41 +0000
@@ -22,6 +22,7 @@
#include <my_sys.h>
#include <NdbSleep.h>
#include <NdbTick.h>
+#include <Properties.hpp>
#include <ndb_internal.hpp>
#include <ndb_logevent.h>
@@ -41,6 +42,8 @@ extern BaseString g_options;
extern unsigned int opt_no_binlog;
extern bool ga_skip_broken_objects;
+extern Properties g_rewrite_databases;
+
bool BackupRestore::m_preserve_trailing_spaces = false;
const PromotionRules
@@ -267,6 +270,40 @@ match_blob(const char * name){
return -1;
}
+/**
+ * Extracts the database, schema, and table name from an internal table name;
+ * prints an error message and returns false in case of a format violation.
+ */
+static
+bool
+dissect_table_name(const char * qualified_table_name,
+ BaseString & db_name,
+ BaseString & schema_name,
+ BaseString & table_name) {
+ Vector<BaseString> split;
+ BaseString tmp(qualified_table_name);
+ if (tmp.split(split, "/") != 3) {
+ err << "Invalid table name format `" << qualified_table_name
+ << "`" << endl;
+ return false;
+ }
+ db_name = split[0];
+ schema_name = split[1];
+ table_name = split[2];
+ return true;
+}
+
+/**
+ * Assigns the new name for a database, if and only if to be rewritten.
+ */
+static
+void
+check_rewrite_database(BaseString & db_name) {
+ const char * new_db_name;
+ if (g_rewrite_databases.get(db_name.c_str(), &new_db_name))
+ db_name.assign(new_db_name);
+}
+
const NdbDictionary::Table*
BackupRestore::get_table(const NdbDictionary::Table* tab){
if(m_cache.m_old_table == tab)
@@ -348,29 +385,31 @@ BackupRestore::rebuild_indexes(const Tab
if (m_index_per_table.size() <= id)
return true;
- BaseString tmp(tablename);
- Vector<BaseString> split;
- if (tmp.split(split, "/") != 3)
- {
- err << "Invalid table name format " << tablename << endl;
+ BaseString db_name, schema_name, table_name;
+ if (!dissect_table_name(tablename, db_name, schema_name, table_name)) {
return false;
}
- m_ndb->setDatabaseName(split[0].c_str());
- m_ndb->setSchemaName(split[1].c_str());
+ check_rewrite_database(db_name);
+
+ m_ndb->setDatabaseName(db_name.c_str());
+ m_ndb->setSchemaName(schema_name.c_str());
NdbDictionary::Dictionary* dict = m_ndb->getDictionary();
Vector<NdbDictionary::Index*> & indexes = m_index_per_table[id];
for(size_t i = 0; i<indexes.size(); i++)
{
- NdbDictionary::Index * idx = indexes[i];
+ const NdbDictionary::Index * const idx = indexes[i];
+ const char * const idx_name = idx->getName();
+ const char * const tab_name = idx->getTable();
Uint64 start = NdbTick_CurrentMillisecond();
- info << "Rebuilding index " << idx->getName() << " on table "
- << tab->getName() << " ..." << flush;
- if (dict->createIndex(* idx, 1) != 0)
+ info << "Rebuilding index `" << idx_name << "` on table `"
+ << tab_name << "` ..." << flush;
+ if ((dict->getIndex(idx_name, tab_name) == NULL)
+ && (dict->createIndex(* idx, 1) != 0))
{
info << "FAIL!" << endl;
- err << "Rebuilding index " << idx->getName() << " on table "
- << tab->getName() <<" failed: ";
+ err << "Rebuilding index `" << idx_name << "` on table `"
+ << tab_name <<"` failed: ";
err << dict->getNdbError() << endl;
return false;
@@ -1217,19 +1256,19 @@ BackupRestore::table_compatible_check(co
return true;
}
- BaseString tmp(tablename);
- Vector<BaseString> split;
- if(tmp.split(split, "/") != 3){
- err << "Invalid table name format " << tablename << endl;
+ BaseString db_name, schema_name, table_name;
+ if (!dissect_table_name(tablename, db_name, schema_name, table_name)) {
return false;
}
- m_ndb->setDatabaseName(split[0].c_str());
- m_ndb->setSchemaName(split[1].c_str());
+ check_rewrite_database(db_name);
+
+ m_ndb->setDatabaseName(db_name.c_str());
+ m_ndb->setSchemaName(schema_name.c_str());
NdbDictionary::Dictionary* dict = m_ndb->getDictionary();
- const NdbDictionary::Table* tab = dict->getTable(split[2].c_str());
+ const NdbDictionary::Table* tab = dict->getTable(table_name.c_str());
if(tab == 0){
- err << "Unable to find table: " << split[2].c_str() << endl;
+ err << "Unable to find table: " << table_name << endl;
return false;
}
@@ -1428,18 +1467,18 @@ BackupRestore::createSystable(const Tabl
return true;
}
- BaseString tmp(tablename);
- Vector<BaseString> split;
- if(tmp.split(split, "/") != 3){
- err << "Invalid table name format " << tablename << endl;
+ BaseString db_name, schema_name, table_name;
+ if (!dissect_table_name(tablename, db_name, schema_name, table_name)) {
return false;
}
+ // do not rewrite database for system tables:
+ // check_rewrite_database(db_name);
- m_ndb->setDatabaseName(split[0].c_str());
- m_ndb->setSchemaName(split[1].c_str());
+ m_ndb->setDatabaseName(db_name.c_str());
+ m_ndb->setSchemaName(schema_name.c_str());
NdbDictionary::Dictionary* dict = m_ndb->getDictionary();
- if( dict->getTable(split[2].c_str()) != NULL ){
+ if( dict->getTable(table_name.c_str()) != NULL ){
return true;
}
return table(tables);
@@ -1464,22 +1503,21 @@ BackupRestore::table(const TableS & tabl
return true;
}
- BaseString tmp(name);
- Vector<BaseString> split;
- if(tmp.split(split, "/") != 3){
- err << "Invalid table name format `" << name << "`" << endl;
+ BaseString db_name, schema_name, table_name;
+ if (!dissect_table_name(name, db_name, schema_name, table_name)) {
return false;
}
+ check_rewrite_database(db_name);
- m_ndb->setDatabaseName(split[0].c_str());
- m_ndb->setSchemaName(split[1].c_str());
+ m_ndb->setDatabaseName(db_name.c_str());
+ m_ndb->setSchemaName(schema_name.c_str());
NdbDictionary::Dictionary* dict = m_ndb->getDictionary();
if(m_restore_meta)
{
NdbDictionary::Table copy(*table.m_dictTable);
- copy.setName(split[2].c_str());
+ copy.setName(table_name.c_str());
Uint32 id;
if (copy.getTablespace(&id))
{
@@ -1598,9 +1636,9 @@ BackupRestore::table(const TableS & tabl
<< table.getTableName() << "`" << endl;
}
- const NdbDictionary::Table* tab = dict->getTable(split[2].c_str());
+ const NdbDictionary::Table* tab = dict->getTable(table_name.c_str());
if(tab == 0){
- err << "Unable to find table: `" << split[2].c_str() << "`" << endl;
+ err << "Unable to find table: `" << table_name << "`" << endl;
return false;
}
if(m_restore_meta)
@@ -1609,9 +1647,9 @@ BackupRestore::table(const TableS & tabl
{
// a MySQL Server table is restored, thus an event should be created
BaseString event_name("REPL$");
- event_name.append(split[0].c_str());
+ event_name.append(db_name.c_str());
event_name.append("/");
- event_name.append(split[2].c_str());
+ event_name.append(table_name.c_str());
NdbDictionary::Event my_event(event_name.c_str());
my_event.setTable(*tab);
@@ -1642,7 +1680,7 @@ BackupRestore::table(const TableS & tabl
}
err << "Create table event for " << table.getTableName() << " failed: "
<< dict->getNdbError() << endl;
- dict->dropTable(split[2].c_str());
+ dict->dropTable(table_name.c_str());
return false;
}
info.setLevel(254);
@@ -1667,23 +1705,19 @@ BackupRestore::endOfTables(){
for(size_t i = 0; i<m_indexes.size(); i++){
NdbTableImpl & indtab = NdbTableImpl::getImpl(* m_indexes[i]);
- Vector<BaseString> split;
- {
- BaseString tmp(indtab.m_primaryTable.c_str());
- if (tmp.split(split, "/") != 3)
- {
- err << "Invalid table name format `" << indtab.m_primaryTable.c_str()
- << "`" << endl;
- return false;
- }
+ BaseString db_name, schema_name, table_name;
+ if (!dissect_table_name(indtab.m_primaryTable.c_str(),
+ db_name, schema_name, table_name)) {
+ return false;
}
-
- m_ndb->setDatabaseName(split[0].c_str());
- m_ndb->setSchemaName(split[1].c_str());
-
- const NdbDictionary::Table * prim = dict->getTable(split[2].c_str());
+ check_rewrite_database(db_name);
+
+ m_ndb->setDatabaseName(db_name.c_str());
+ m_ndb->setSchemaName(schema_name.c_str());
+
+ const NdbDictionary::Table * prim = dict->getTable(table_name.c_str());
if(prim == 0){
- err << "Unable to find base table `" << split[2].c_str()
+ err << "Unable to find base table `" << table_name
<< "` for index `"
<< indtab.getName() << "`" << endl;
if (ga_skip_broken_objects)
@@ -1706,7 +1740,7 @@ BackupRestore::endOfTables(){
if(NdbDictInterface::create_index_obj_from_table(&idx, &indtab, &base))
{
err << "Failed to create index `" << split_idx[3]
- << "` on " << split[2].c_str() << endl;
+ << "` on " << table_name << endl;
return false;
}
idx->setName(split_idx[3].c_str());
@@ -1716,13 +1750,13 @@ BackupRestore::endOfTables(){
{
delete idx;
err << "Failed to create index `" << split_idx[3].c_str()
- << "` on `" << split[2].c_str() << "`" << endl
+ << "` on `" << table_name << "`" << endl
<< dict->getNdbError() << endl;
return false;
}
info << "Successfully created index `" << split_idx[3].c_str()
- << "` on `" << split[2].c_str() << "`" << endl;
+ << "` on `" << table_name << "`" << endl;
}
else if (m_disable_indexes)
{
@@ -1730,7 +1764,7 @@ BackupRestore::endOfTables(){
if (res == 0)
{
info << "Dropped index `" << split_idx[3].c_str()
- << "` on `" << split[2].c_str() << "`" << endl;
+ << "` on `" << table_name << "`" << endl;
}
}
Uint32 id = prim->getObjectId();
=== modified file 'storage/ndb/tools/restore/restore_main.cpp'
--- a/storage/ndb/tools/restore/restore_main.cpp 2010-12-03 09:36:45 +0000
+++ b/storage/ndb/tools/restore/restore_main.cpp 2011-02-02 07:16:41 +0000
@@ -19,6 +19,7 @@
#include <ndb_global.h>
#include <ndb_opts.h>
#include <Vector.hpp>
+#include <Properties.hpp>
#include <ndb_limits.h>
#include <NdbTCP.h>
#include <NdbMem.h>
@@ -63,6 +64,7 @@ Vector<BaseString> g_databases;
Vector<BaseString> g_tables;
Vector<BaseString> g_include_tables, g_exclude_tables;
Vector<BaseString> g_include_databases, g_exclude_databases;
+Properties g_rewrite_databases;
NdbRecordPrintFormat g_ndbrecord_print_format;
unsigned int opt_no_binlog;
@@ -77,6 +79,8 @@ public:
Vector<class RestoreOption *> g_include_exclude;
static void save_include_exclude(int optid, char * argument);
+static inline void parse_rewrite_database(char * argument);
+
/**
* print and restore flags
*/
@@ -106,7 +110,8 @@ enum ndb_restore_options {
OPT_INCLUDE_TABLES,
OPT_EXCLUDE_TABLES,
OPT_INCLUDE_DATABASES,
- OPT_EXCLUDE_DATABASES
+ OPT_EXCLUDE_DATABASES,
+ OPT_REWRITE_DATABASE
};
static const char *opt_fields_enclosed_by= NULL;
static const char *opt_fields_terminated_by= NULL;
@@ -119,6 +124,7 @@ static const char *opt_exclude_tables= N
static const char *opt_include_tables= NULL;
static const char *opt_exclude_databases= NULL;
static const char *opt_include_databases= NULL;
+static const char *opt_rewrite_database= NULL;
static struct my_option my_long_options[] =
{
@@ -247,6 +253,11 @@ static struct my_option my_long_options[
"Comma separated list of databases to not restore. Example: db1,db3",
(uchar**) &opt_exclude_databases, (uchar**) &opt_exclude_databases, 0,
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
+ { "rewrite-database", OPT_REWRITE_DATABASE,
+ "A pair 'source,dest' of database names from/into which to restore. "
+ "Example: --rewrite-database=oldDb,newDb",
+ (uchar**) &opt_rewrite_database, (uchar**) &opt_rewrite_database, 0,
+ GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
{ "include-tables", OPT_INCLUDE_TABLES, "Comma separated list of tables to "
"restore. Table name should include database name. Example: db1.t1,db3.t1",
(uchar**) &opt_include_tables, (uchar**) &opt_include_tables, 0,
@@ -449,6 +460,9 @@ get_one_option(int optid, const struct m
case OPT_EXCLUDE_TABLES:
save_include_exclude(optid, argument);
break;
+ case OPT_REWRITE_DATABASE:
+ parse_rewrite_database(argument);
+ break;
}
return 0;
}
@@ -710,6 +724,20 @@ o verify nodegroup mapping
info << endl;
}
+ if (opt_rewrite_database)
+ {
+ info << "Rewriting databases:";
+ Properties::Iterator it(&g_rewrite_databases);
+ const char * src;
+ for (src = it.first(); src != NULL; src = it.next()) {
+ const char * dst = NULL;
+ bool r = g_rewrite_databases.get(src, &dst);
+ assert(r && (dst != NULL));
+ info << " (" << src << "->" << dst << ")";
+ }
+ info << endl;
+ }
+
if (opt_include_tables)
{
processTableList(opt_include_tables, g_include_tables);
@@ -840,6 +868,27 @@ getTableName(const TableS* table)
return table_name;
}
+static void parse_rewrite_database(char * argument)
+{
+ const BaseString arg(argument);
+ Vector<BaseString> args;
+ unsigned int n = arg.split(args, ",");
+ if ((n == 2)
+ && (args[0].length() > 0)
+ && (args[1].length() > 0)) {
+ const BaseString src = args[0];
+ const BaseString dst = args[1];
+ const bool replace = true;
+ bool r = g_rewrite_databases.put(src.c_str(), dst.c_str(), replace);
+ assert(r);
+ return; // ok
+ }
+
+ info << "argument `" << arg.c_str()
+ << "` is not a pair 'a,b' of non-empty names." << endl;
+ exit(NDBT_ProgramExit(NDBT_WRONGARGS));
+}
+
static void save_include_exclude(int optid, char * argument)
{
BaseString arg = argument;
Attachment: [text/bzr-bundle] bzr/martin.zaun@oracle.com-20110202071641-075u8ua13s1ckk47.bundle
| Thread |
|---|
| • bzr push into mysql-5.1-telco-7.0 branch (martin.zaun:4161 to 4162) | Martin Zaun | 2 Feb |