#At file:///home/marty/MySQL/mysql-5.1-telco-7.0/
3245 Martin Skold 2009-12-02 [merge]
Bug #48907 ndb_restore with both --include-databases and -tables ignores databases: Changed semantics of include/exclude flags to be accumulative and evaluated right to left
modified:
mysql-test/suite/ndb/r/ndb_restore_options.result
mysql-test/suite/ndb/t/ndb_restore_options.test
storage/ndb/tools/restore/restore_main.cpp
=== modified file 'mysql-test/suite/ndb/r/ndb_restore_options.result'
--- a/mysql-test/suite/ndb/r/ndb_restore_options.result 2009-05-08 17:58:13 +0000
+++ b/mysql-test/suite/ndb/r/ndb_restore_options.result 2009-12-02 10:40:46 +0000
@@ -374,10 +374,12 @@ drop table db2.tab1, db2.tab2;
*********************************
Include db1, and include db2.tab1
*********************************
-Should result in db2.tab1 only restored.
+Should result in all tables in db1 and db2.tab1 being restored.
use db1;
show tables;
Tables_in_db1
+tab1
+tab2
use db2;
show tables;
Tables_in_db2
@@ -394,7 +396,7 @@ a
7
8
9
-drop table db2.tab1;
+drop table db1.tab1,db1.tab2,db2.tab1;
************************
Include unknown database
************************
@@ -479,13 +481,14 @@ a b c d
7 Highlea 7 UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU!
UUUUUUUUUUUUUUUUUUUUUUUU
drop table db1.tab1, db1.tab2;
drop table db2.tab1, db2.tab2;
-*********************************************
-Check that last argument of each type is used
-*********************************************
-Should result in just db1.tab2 restored.
+************************************
+Check accumulative include arguments
+************************************
+Should result in both db1.tab1 and db1.tab2 restored.
use db1;
show tables;
Tables_in_db1
+tab1
tab2
select * from tab2 order by a;
a b c d
@@ -499,6 +502,19 @@ a b c d
use db2;
show tables;
Tables_in_db2
-drop table db1.tab2;
+drop table db1.tab1, db1.tab2;
+************************************
+Check accumulative exclude arguments
+************************************
+Should result in both db2.tab1 and db2.tab2 restored.
+use db1;
+show tables;
+Tables_in_db1
+use db2;
+show tables;
+Tables_in_db2
+tab1
+tab2
+drop table db2.tab1, db2.tab2;
drop database db1;
drop database db2;
=== modified file 'mysql-test/suite/ndb/t/ndb_restore_options.test'
--- a/mysql-test/suite/ndb/t/ndb_restore_options.test 2009-04-09 15:25:11 +0000
+++ b/mysql-test/suite/ndb/t/ndb_restore_options.test 2009-12-02 13:54:07 +0000
@@ -163,9 +163,8 @@ drop table db1.tab2, db2.tab1;
--echo *********************************
--echo Should result in only db1.tab1 being restored
---exec $NDB_RESTORE --no-defaults -b $the_backup_id -n 1 -r -m $NDB_BACKUPS-$the_backup_id --include-tables db1.tab1 --exclude-databases db1 >> $NDB_TOOLS_OUTPUT
---exec $NDB_RESTORE --no-defaults -b $the_backup_id -n 2 -r $NDB_BACKUPS-$the_backup_id --include-tables db1.tab1 --exclude-databases db1 >> $NDB_TOOLS_OUTPUT
-
+--exec $NDB_RESTORE --no-defaults -b $the_backup_id -n 1 -r -m $NDB_BACKUPS-$the_backup_id --exclude-databases db1 --include-tables db1.tab1 >> $NDB_TOOLS_OUTPUT
+--exec $NDB_RESTORE --no-defaults -b $the_backup_id -n 2 -r $NDB_BACKUPS-$the_backup_id --exclude-databases db1 --include-tables db1.tab1>> $NDB_TOOLS_OUTPUT
use db1;
show tables;
@@ -181,9 +180,8 @@ drop table db1.tab1;
--echo Exclude db1.tab1, but include db1
--echo *********************************
--echo Should result in only db1.tab2 being restored
---exec $NDB_RESTORE --no-defaults -b $the_backup_id -n 1 -r -m $NDB_BACKUPS-$the_backup_id --exclude-tables db1.tab1 --include-databases db1 >> $NDB_TOOLS_OUTPUT
---exec $NDB_RESTORE --no-defaults -b $the_backup_id -n 2 -r $NDB_BACKUPS-$the_backup_id --exclude-tables db1.tab1 --include-databases db1 >> $NDB_TOOLS_OUTPUT
-
+--exec $NDB_RESTORE --no-defaults -b $the_backup_id -n 1 -r -m $NDB_BACKUPS-$the_backup_id --include-databases db1 --exclude-tables db1.tab1 >> $NDB_TOOLS_OUTPUT
+--exec $NDB_RESTORE --no-defaults -b $the_backup_id -n 2 -r $NDB_BACKUPS-$the_backup_id --include-databases db1 --exclude_tables db1.tab1 >> $NDB_TOOLS_OUTPUT
use db1;
show tables;
@@ -234,19 +232,20 @@ drop table db2.tab1, db2.tab2;
--echo *********************************
--echo Include db1, and include db2.tab1
--echo *********************************
---echo Should result in db2.tab1 only restored.
+--echo Should result in all tables in db1 and db2.tab1 being restored.
--exec $NDB_RESTORE --no-defaults -b $the_backup_id -n 1 -r -m $NDB_BACKUPS-$the_backup_id --include-databases db1 --include-tables db2.tab1 >> $NDB_TOOLS_OUTPUT
--exec $NDB_RESTORE --no-defaults -b $the_backup_id -n 2 -r $NDB_BACKUPS-$the_backup_id --include-databases db1 --include-tables db2.tab1 >> $NDB_TOOLS_OUTPUT
use db1;
+--sorted_result
show tables;
use db2;
show tables;
# checksum table tab1;
select * from tab1 order by a;
-drop table db2.tab1;
+drop table db1.tab1,db1.tab2,db2.tab1;
--echo ************************
@@ -285,14 +284,15 @@ select * from tab2 order by a;
drop table db1.tab1, db1.tab2;
drop table db2.tab1, db2.tab2;
---echo *********************************************
---echo Check that last argument of each type is used
---echo *********************************************
---echo Should result in just db1.tab2 restored.
+--echo ************************************
+--echo Check accumulative include arguments
+--echo ************************************
+--echo Should result in both db1.tab1 and db1.tab2 restored.
--exec $NDB_RESTORE --no-defaults -b $the_backup_id -n 1 -r -m $NDB_BACKUPS-$the_backup_id --include-tables db1.tab1 --include-tables db1.tab2 >> $NDB_TOOLS_OUTPUT
--exec $NDB_RESTORE --no-defaults -b $the_backup_id -n 2 -r $NDB_BACKUPS-$the_backup_id --include-tables db1.tab1 --include-tables db1.tab2 >> $NDB_TOOLS_OUTPUT
use db1;
+--sorted_result
show tables;
# checksum table tab2;
select * from tab2 order by a;
@@ -300,8 +300,22 @@ select * from tab2 order by a;
use db2;
show tables;
-drop table db1.tab2;
+drop table db1.tab1, db1.tab2;
+
+--echo ************************************
+--echo Check accumulative exclude arguments
+--echo ************************************
+--echo Should result in both db2.tab1 and db2.tab2 restored.
+--exec $NDB_RESTORE --no-defaults -b $the_backup_id -n 1 -r -m $NDB_BACKUPS-$the_backup_id --exclude-tables db1.tab1 --exclude-tables db1.tab2 >> $NDB_TOOLS_OUTPUT
+--exec $NDB_RESTORE --no-defaults -b $the_backup_id -n 2 -r $NDB_BACKUPS-$the_backup_id --exclude-tables db1.tab1 --exclude-tables db1.tab2 >> $NDB_TOOLS_OUTPUT
+use db1;
+show tables;
+use db2;
+--sorted_result
+show tables;
+
+drop table db2.tab1, db2.tab2;
drop database db1;
drop database db2;
=== modified file 'storage/ndb/tools/restore/restore_main.cpp'
--- a/storage/ndb/tools/restore/restore_main.cpp 2009-12-01 10:15:25 +0000
+++ b/storage/ndb/tools/restore/restore_main.cpp 2009-12-02 13:54:07 +0000
@@ -64,6 +64,17 @@ Vector<BaseString> g_include_databases,
NdbRecordPrintFormat g_ndbrecord_print_format;
unsigned int opt_no_binlog;
+class RestoreOption
+{
+public:
+ virtual ~RestoreOption() { }
+ int optid;
+ BaseString argument;
+};
+
+Vector<class RestoreOption *> g_include_exclude;
+static void save_include_exclude(int optid, char * argument);
+
/**
* print and restore flags
*/
@@ -419,6 +430,12 @@ get_one_option(int optid, const struct m
exit(NDBT_ProgramExit(NDBT_WRONGARGS));
}
break;
+ case OPT_INCLUDE_DATABASES:
+ case OPT_EXCLUDE_DATABASES:
+ case OPT_INCLUDE_TABLES:
+ case OPT_EXCLUDE_TABLES:
+ save_include_exclude(optid, argument);
+ break;
}
return 0;
}
@@ -788,6 +805,100 @@ getTableName(const TableS* table)
return table_name;
}
+static void save_include_exclude(int optid, char * argument)
+{
+ BaseString arg = argument;
+ Vector<BaseString> args;
+ arg.split(args, ",");
+ for (uint i = 0; i < args.size(); i++)
+ {
+ RestoreOption * option = new RestoreOption();
+ BaseString arg;
+
+ option->optid = optid;
+ switch (optid) {
+ case OPT_INCLUDE_TABLES:
+ case OPT_EXCLUDE_TABLES:
+ if (makeInternalTableName(args[i], arg))
+ {
+ info << "`" << args[i] << "` is not a valid tablename!" << endl;
+ exit(NDBT_ProgramExit(NDBT_WRONGARGS));
+ }
+ break;
+ default:
+ arg = args[i];
+ break;
+ }
+ option->argument = arg;
+ g_include_exclude.push_back(option);
+ }
+}
+static bool check_include_exclude(BaseString database, BaseString table)
+{
+ const char * db = database.c_str();
+ const char * tbl = table.c_str();
+ bool do_include = true;
+
+ if (g_include_databases.size() != 0 ||
+ g_include_tables.size() != 0)
+ {
+ /*
+ User has explicitly specified what databases
+ and/or tables should be restored. If no match is
+ found then DON'T restore table.
+ */
+ do_include = false;
+ }
+ if (do_include &&
+ (g_exclude_databases.size() != 0 ||
+ g_exclude_tables.size() != 0))
+ {
+ /*
+ User has not explicitly specified what databases
+ and/or tables should be restored.
+ User has explicitly specified what databases
+ and/or tables should NOT be restored. If no match is
+ found then DO restore table.
+ */
+ do_include = true;
+ }
+
+ if (g_include_exclude.size() != 0)
+ {
+ /*
+ Scan include exclude arguments in reverse.
+ First matching include causes table to be restored.
+ first matching exclude causes table NOT to be restored.
+ */
+ for(uint i = g_include_exclude.size(); i > 0; i--)
+ {
+ RestoreOption *option = g_include_exclude[i-1];
+ switch (option->optid) {
+ case OPT_INCLUDE_TABLES:
+ if (strcmp(tbl, option->argument.c_str()) == 0)
+ return true; // do include
+ break;
+ case OPT_EXCLUDE_TABLES:
+ if (strcmp(tbl, option->argument.c_str()) == 0)
+ return false; // don't include
+ break;
+ case OPT_INCLUDE_DATABASES:
+ if (strcmp(db, option->argument.c_str()) == 0)
+ return true; // do include
+ break;
+ case OPT_EXCLUDE_DATABASES:
+ if (strcmp(db, option->argument.c_str()) == 0)
+ return false; // don't include
+ break;
+ default:
+ continue;
+ }
+ }
+ }
+
+ return do_include;
+}
+
static inline bool
checkDoRestore(const TableS* table)
{
@@ -799,32 +910,16 @@ checkDoRestore(const TableS* table)
idx = tbl.indexOf('/');
db = tbl.substr(0, idx);
- /* Included tables overrides
- * Excluded tables which overrides
- * Included databases which overrides
- * Excluded databases.
- * If any databases are included, then only
- * included databases are restored.
- * If any tables are included, then only
- * included tables are restored.
+ /*
+ Include/exclude flags are evaluated right
+ to left, and first match overrides any other
+ matches. Non-overlapping arguments are accumulative.
+ If no include flags are specified this means all databases/tables
+ except any excluded are restored.
+ If include flags are specified than only those databases
+ or tables specified are restored.
*/
-
- if (g_exclude_databases.size() != 0) {
- if (isInList(db, g_exclude_databases))
- ret = false;
- }
- if (g_include_databases.size() != 0) {
- ret= isInList(db, g_include_databases);
- }
-
- if (g_exclude_tables.size() != 0) {
- if (isInList(tbl, g_exclude_tables))
- ret = false;
- }
- if (g_include_tables.size() != 0) {
- ret= isInList(tbl, g_include_tables);
- }
-
+ ret = check_include_exclude(db, tbl);
return ret;
}
@@ -1354,3 +1449,4 @@ main(int argc, char** argv)
template class Vector<BackupConsumer*>;
template class Vector<OutputStream*>;
+template class Vector<RestoreOption *>;
| Thread |
|---|
| • bzr commit into mysql-5.1-telco-7.0 branch (Martin.Skold:3245) Bug#48907 | Martin Skold | 2 Dec |