4256 Magnus Blåudd 2011-03-23
ndb dist priv
- ad mysql.host to list of tables to distribute
modified:
mysql-test/suite/ndb/t/ndb_distribute_user.test
mysql-test/suite/rpl_ndb/t/rpl_ndb_distribute_user.test
scripts/mysql_load_distribute_privilege_procedures.sql
sql/ndb_dist_priv_util.h
4255 Magnus Blåudd 2011-03-23
ndb
- remove drop of procedure which is not created by scripts
modified:
scripts/mysql_load_distribute_privilege_procedures.sql
4254 Magnus Blåudd 2011-03-23
ndb
- refactor the dist_priv code into it's own header file ndb_dist_priv_util.h to avoid code duplication
and improve encapsulation
added:
sql/ndb_dist_priv_util.h
modified:
sql/ha_ndbcluster.cc
sql/ha_ndbcluster_binlog.cc
sql/ha_ndbcluster_binlog.h
sql/ha_ndbcluster_tables.h
storage/ndb/tools/restore/restore_main.cpp
4253 Magnus Blåudd 2011-03-23
ndb
- remove unsued OPT_RESTORE_PRIVILEGES
modified:
storage/ndb/tools/restore/restore_main.cpp
4252 Magnus Blåudd 2011-03-23 [merge]
Merge
added:
HOWTO_distribute_privileges.txt
mysql-test/suite/ndb/r/ndb_distribute_user.result
mysql-test/suite/ndb/t/ndb_distribute_user.test
mysql-test/suite/rpl_ndb/r/rpl_ndb_distribute_user.result
mysql-test/suite/rpl_ndb/t/rpl_ndb_distribute_user.test
scripts/mysql_load_distribute_privilege_procedures.sql
modified:
scripts/Makefile.am
sql/ha_ndbcluster.cc
sql/ha_ndbcluster_binlog.cc
sql/ha_ndbcluster_binlog.h
sql/ha_ndbcluster_tables.h
sql/handler.h
sql/sql_acl.cc
storage/ndb/tools/restore/restore_main.cpp
=== modified file 'mysql-test/suite/ndb/t/ndb_distribute_user.test'
--- a/mysql-test/suite/ndb/t/ndb_distribute_user.test 2011-03-19 13:19:44 +0000
+++ b/mysql-test/suite/ndb/t/ndb_distribute_user.test 2011-03-23 12:06:50 +0000
@@ -128,11 +128,13 @@ drop table if exists mysql.db_backup;
drop table if exists mysql.tables_priv_backup;
drop table if exists mysql.columns_priv_backup;
drop table if exists mysql.procs_priv_backup;
+drop table if exists mysql.host_backup;
drop table if exists mysql.ndb_user_backup;
drop table if exists mysql.ndb_db_backup;
drop table if exists mysql.ndb_tables_priv_backup;
drop table if exists mysql.ndb_columns_priv_backup;
drop table if exists mysql.ndb_procs_priv_backup;
+drop table if exists mysql.ndb_host_backup;
drop function if exists mysql.mysql_cluster_privileges_are_distributed;
drop procedure if exists mysql.mysql_cluster_backup_privileges;
drop procedure if exists mysql.mysql_cluster_move_grant_tables;
@@ -156,11 +158,13 @@ drop table if exists mysql.db_backup;
drop table if exists mysql.tables_priv_backup;
drop table if exists mysql.columns_priv_backup;
drop table if exists mysql.procs_priv_backup;
+drop table if exists mysql.host_backup;
drop table if exists mysql.ndb_user_backup;
drop table if exists mysql.ndb_db_backup;
drop table if exists mysql.ndb_tables_priv_backup;
drop table if exists mysql.ndb_columns_priv_backup;
drop table if exists mysql.ndb_procs_priv_backup;
+drop table if exists mysql.ndb_host_backup;
drop function if exists mysql.mysql_cluster_privileges_are_distributed;
drop procedure if exists mysql.mysql_cluster_backup_privileges;
drop procedure if exists mysql.mysql_cluster_move_grant_tables;
=== modified file 'mysql-test/suite/rpl_ndb/t/rpl_ndb_distribute_user.test'
--- a/mysql-test/suite/rpl_ndb/t/rpl_ndb_distribute_user.test 2011-03-19 13:19:44 +0000
+++ b/mysql-test/suite/rpl_ndb/t/rpl_ndb_distribute_user.test 2011-03-23 12:06:50 +0000
@@ -152,11 +152,13 @@ drop table if exists mysql.db_backup;
drop table if exists mysql.tables_priv_backup;
drop table if exists mysql.columns_priv_backup;
drop table if exists mysql.procs_priv_backup;
+drop table if exists mysql.host_backup;
drop table if exists mysql.ndb_user_backup;
drop table if exists mysql.ndb_db_backup;
drop table if exists mysql.ndb_tables_priv_backup;
drop table if exists mysql.ndb_columns_priv_backup;
drop table if exists mysql.ndb_procs_priv_backup;
+drop table if exists mysql.ndb_host_backup;
drop function if exists mysql.mysql_cluster_privileges_are_distributed;
drop procedure if exists mysql.mysql_cluster_backup_privileges;
drop procedure if exists mysql.mysql_cluster_move_grant_tables;
@@ -180,11 +182,13 @@ drop table if exists mysql.db_backup;
drop table if exists mysql.tables_priv_backup;
drop table if exists mysql.columns_priv_backup;
drop table if exists mysql.procs_priv_backup;
+drop table if exists mysql.host_backup;
drop table if exists mysql.ndb_user_backup;
drop table if exists mysql.ndb_db_backup;
drop table if exists mysql.ndb_tables_priv_backup;
drop table if exists mysql.ndb_columns_priv_backup;
drop table if exists mysql.ndb_procs_priv_backup;
+drop table if exists mysql.ndb_host_backup;
drop function if exists mysql.mysql_cluster_privileges_are_distributed;
drop procedure if exists mysql.mysql_cluster_backup_privileges;
drop procedure if exists mysql.mysql_cluster_move_grant_tables;
@@ -209,11 +213,13 @@ drop table if exists mysql.db_backup;
drop table if exists mysql.tables_priv_backup;
drop table if exists mysql.columns_priv_backup;
drop table if exists mysql.procs_priv_backup;
+drop table if exists mysql.host_backup;
drop table if exists mysql.ndb_user_backup;
drop table if exists mysql.ndb_db_backup;
drop table if exists mysql.ndb_tables_priv_backup;
drop table if exists mysql.ndb_columns_priv_backup;
drop table if exists mysql.ndb_procs_priv_backup;
+drop table if exists mysql.ndb_host_backup;
drop function if exists mysql.mysql_cluster_privileges_are_distributed;
drop procedure if exists mysql.mysql_cluster_backup_privileges;
drop procedure if exists mysql.mysql_cluster_move_grant_tables;
=== modified file 'scripts/mysql_load_distribute_privilege_procedures.sql'
--- a/scripts/mysql_load_distribute_privilege_procedures.sql 2011-03-19 13:19:44 +0000
+++ b/scripts/mysql_load_distribute_privilege_procedures.sql 2011-03-23 12:06:50 +0000
@@ -3,7 +3,6 @@ delimiter |
drop function if exists mysql.mysql_cluster_privileges_are_distributed|
drop procedure if exists mysql.mysql_cluster_backup_privileges|
drop procedure if exists mysql.mysql_cluster_move_grant_tables|
-drop procedure if exists mysql.mysql_cluster_drop_grant_tables|
drop procedure if exists mysql.mysql_cluster_restore_privileges_from_local|
drop procedure if exists mysql.mysql_cluster_restore_privileges|
drop procedure if exists mysql.mysql_cluster_restore_local_privileges|
@@ -12,19 +11,38 @@ drop procedure if exists mysql.mysql_clu
create function mysql.mysql_cluster_privileges_are_distributed()
returns bool
begin
- declare distributed_user bool default 0;
- declare distributed_db bool default 0;
- declare distributed_tables_priv bool default 0;
- declare distributed_columns_priv bool default 0;
- declare distributed_procs_priv bool default 0;
-
- select engine = 'ndbcluster' into distributed_user from information_schema.tables where table_name = "user";
- select engine = 'ndbcluster' into distributed_db from information_schema.tables where table_name = "db";
- select engine = 'ndbcluster' into distributed_tables_priv from information_schema.tables where table_name = "tables_priv";
- select engine = 'ndbcluster' into distributed_columns_priv from information_schema.tables where table_name = "columns_priv";
- select engine = 'ndbcluster' into distributed_procs_priv from information_schema.tables where table_name = "procs_priv";
-
- if distributed_user = 1 and distributed_db = 1 and distributed_tables_priv = 1 and distributed_columns_priv = 1 and distributed_procs_priv = 1 then
+ declare distributed_user bool default 0;
+ declare distributed_db bool default 0;
+ declare distributed_tables_priv bool default 0;
+ declare distributed_columns_priv bool default 0;
+ declare distributed_procs_priv bool default 0;
+ declare distributed_host bool default 0;
+
+ select engine = 'ndbcluster' into distributed_user
+ from information_schema.tables
+ where table_schema = "mysql" and table_name = "user";
+ select engine = 'ndbcluster' into distributed_db
+ from information_schema.tables
+ where table_schema = "mysql" and table_name = "db";
+ select engine = 'ndbcluster' into distributed_tables_priv
+ from information_schema.tables
+ where table_schema = "mysql" and table_name = "tables_priv";
+ select engine = 'ndbcluster' into distributed_columns_priv
+ from information_schema.tables
+ where table_schema = "mysql" and table_name = "columns_priv";
+ select engine = 'ndbcluster' into distributed_procs_priv
+ from information_schema.tables
+ where table_schema = "mysql" and table_name = "procs_priv";
+ select engine = 'ndbcluster' into distributed_host
+ from information_schema.tables
+ where table_schema = "mysql" and table_name = "host";
+
+ if distributed_user = 1 and
+ distributed_db = 1 and
+ distributed_tables_priv = 1 and
+ distributed_columns_priv = 1 and
+ distributed_procs_priv = 1 and
+ distributed_host = 1 then
return 1;
else
return 0;
@@ -37,20 +55,26 @@ begin
declare first_backup bool default 1;
declare first_distributed_backup bool default 1;
select mysql_cluster_privileges_are_distributed() into distributed_privileges;
- select 0 into first_backup from information_schema.tables where table_name = "user_backup";
- select 0 into first_distributed_backup from information_schema.tables where table_name = "ndb_user_backup";
+ select 0 into first_backup
+ from information_schema.tables
+ where table_schema = "mysql" and table_name = "user_backup";
+ select 0 into first_distributed_backup
+ from information_schema.tables
+ where table_schema = "mysql" and table_name = "ndb_user_backup";
if first_backup = 1 then
create table if not exists user_backup like user;
create table if not exists db_backup like db;
create table if not exists tables_priv_backup like tables_priv;
create table if not exists columns_priv_backup like columns_priv;
create table if not exists procs_priv_backup like procs_priv;
+ create table if not exists host_backup like host;
if distributed_privileges = 1 then
alter table user_backup engine = myisam;
alter table db_backup engine = myisam;
alter table tables_priv_backup engine = myisam;
alter table columns_priv_backup engine = myisam;
alter table procs_priv_backup engine = myisam;
+ alter table host_backup engine = myisam;
end if;
else
truncate user_backup;
@@ -58,6 +82,7 @@ begin
truncate tables_priv_backup;
truncate columns_priv_backup;
truncate procs_priv_backup;
+ truncate host_backup;
end if;
if first_distributed_backup = 1 then
create table if not exists ndb_user_backup like user;
@@ -65,12 +90,14 @@ begin
create table if not exists ndb_tables_priv_backup like tables_priv;
create table if not exists ndb_columns_priv_backup like columns_priv;
create table if not exists ndb_procs_priv_backup like procs_priv;
+ create table if not exists ndb_host_backup like host;
if distributed_privileges = 0 then
alter table ndb_user_backup engine = ndbcluster;
alter table ndb_db_backup engine = ndbcluster;
alter table ndb_tables_priv_backup engine = ndbcluster;
alter table ndb_columns_priv_backup engine = ndbcluster;
alter table ndb_procs_priv_backup engine = ndbcluster;
+ alter table ndb_host_backup engine = ndbcluster;
end if;
else
truncate ndb_user_backup;
@@ -78,18 +105,21 @@ begin
truncate ndb_tables_priv_backup;
truncate ndb_columns_priv_backup;
truncate ndb_procs_priv_backup;
+ truncate ndb_host_backup;
end if;
insert into user_backup select * from user;
insert into db_backup select * from db;
insert into tables_priv_backup select * from tables_priv;
insert into columns_priv_backup select * from columns_priv;
insert into procs_priv_backup select * from procs_priv;
+ insert into host_backup select * from host;
insert into ndb_user_backup select * from user;
insert into ndb_db_backup select * from db;
insert into ndb_tables_priv_backup select * from tables_priv;
insert into ndb_columns_priv_backup select * from columns_priv;
insert into ndb_procs_priv_backup select * from procs_priv;
+ insert into ndb_host_backup select * from host;
end|
create procedure mysql.mysql_cluster_restore_privileges_from_local()
@@ -106,6 +136,7 @@ begin
create table if not exists tables_priv like tables_priv_backup;
create table if not exists columns_priv like columns_priv_backup;
create table if not exists procs_priv like procs_priv_backup;
+ create table if not exists host like host_backup;
delete from user;
insert into user select * from user_backup;
delete from db;
@@ -116,6 +147,8 @@ begin
insert into columns_priv select * from columns_priv_backup;
delete from procs_priv;
insert into procs_priv select * from procs_priv_backup;
+ delete from host;
+ insert into host select * from host_backup;
end if;
end if;
end|
@@ -134,6 +167,7 @@ begin
create table if not exists tables_priv like ndb_tables_priv_backup;
create table if not exists columns_priv like ndb_columns_priv_backup;
create table if not exists procs_priv like ndb_procs_priv_backup;
+ create table if not exists host like ndb_host_backup;
delete from user;
insert into user select * from ndb_user_backup;
delete from db;
@@ -144,6 +178,8 @@ begin
insert into columns_priv select * from ndb_columns_priv_backup;
delete from procs_priv;
insert into procs_priv select * from ndb_procs_priv_backup;
+ delete from host;
+ insert into host select * from ndb_host_backup;
end if;
else
call mysql_cluster_restore_privileges_from_local();
@@ -161,6 +197,7 @@ begin
drop table tables_priv;
drop table columns_priv;
drop table procs_priv;
+ drop table host;
end;
end if;
call mysql_cluster_restore_privileges();
@@ -179,6 +216,7 @@ begin
alter table tables_priv engine = ndb;
alter table columns_priv engine = ndb;
alter table procs_priv engine = ndb;
+ alter table host engine = ndb;
end;
end if;
if revert = 1 then
=== modified file 'sql/ha_ndbcluster.cc'
--- a/sql/ha_ndbcluster.cc 2011-03-21 09:00:49 +0000
+++ b/sql/ha_ndbcluster.cc 2011-03-23 10:02:55 +0000
@@ -43,6 +43,7 @@
#include "ha_ndbcluster_binlog.h"
#include "ha_ndbcluster_tables.h"
#include "ha_ndbcluster_connection.h"
+#include "ndb_dist_priv_util.h"
#include <mysql/plugin.h>
#include <ndb_version.h>
@@ -10130,7 +10131,7 @@ int ndbcluster_discover(handlerton *hton
}
#ifdef HAVE_NDB_BINLOG
if (ndbcluster_check_if_local_table(db, name) &&
- (! table_in_binlog_exclude_list(db, name)))
+ !Ndb_dist_priv_util::is_distributed_priv_table(db, name))
{
DBUG_PRINT("info", ("ndbcluster_discover: Skipping locally defined table '%s.%s'",
db, name));
=== modified file 'sql/ha_ndbcluster_binlog.cc'
--- a/sql/ha_ndbcluster_binlog.cc 2011-03-23 07:33:23 +0000
+++ b/sql/ha_ndbcluster_binlog.cc 2011-03-23 10:02:55 +0000
@@ -59,6 +59,8 @@ bool ndb_log_empty_epochs(void);
static char repdb[]= NDB_REP_DB;
static char reptable[]= NDB_REP_TABLE;
+#include "ndb_dist_priv_util.h"
+
/*
Timeout for syncing schema events between
mysql servers, and between mysql server and the binlog
@@ -740,26 +742,27 @@ ndbcluster_binlog_index_purge_file(THD *
DBUG_RETURN(0);
}
-static const char* ndbcluster_distributed_tables[] =
-{
- NDB_USER_TABLE,
- NDB_DB_TABLE,
- NDB_TABLES_PRIV_TABLE,
- NDB_COLUMNS_PRIV_TABLE,
- NDB_PROCS_PRIV_TABLE
-};
+// Determine if privilege tables are distributed, ie. stored in NDB
static bool
-ndbcluster_distributed_privileges(THD *thd)
+priv_tables_are_in_ndb(THD *thd)
{
- Ndb *ndb= check_ndb_in_thd(thd);
- NDBDICT *dict= ndb->getDictionary();
bool distributed= false;
+ Ndb_dist_priv_util dist_priv;
DBUG_ENTER("ndbcluster_distributed_privileges");
- ndb->setDatabaseName(NDB_PRIV_DB);
- for(uint i= 0; i < 5; i++)
+
+ Ndb *ndb= check_ndb_in_thd(thd);
+ if (!ndb)
+ DBUG_RETURN(false); // MAGNUS, error message?
+
+ if (ndb->setDatabaseName(dist_priv.database()) != 0)
+ DBUG_RETURN(false);
+
+ const char* table_name;
+ while((table_name= dist_priv.iter_next_table()))
{
- Ndb_table_guard ndbtab_g(dict, ndbcluster_distributed_tables[i]);
+ DBUG_PRINT("info", ("table_name: %s", table_name));
+ Ndb_table_guard ndbtab_g(ndb->getDictionary(), table_name);
const NDBTAB *ndbtab= ndbtab_g.get_table();
if (ndbtab)
{
@@ -767,13 +770,16 @@ ndbcluster_distributed_privileges(THD *t
}
else if (distributed)
{
- sql_print_error("NDB: Inconsistency detected, not all privilege tables have been distributed");
+ sql_print_error("NDB: Inconsistency detected in distributed "
+ "privilege tables. Table '%s.%s' is not distributed",
+ dist_priv.database(), table_name);
DBUG_RETURN(false);
}
}
DBUG_RETURN(distributed);
}
+
static void
ndbcluster_binlog_log_query(handlerton *hton, THD *thd, enum_binlog_command binlog_command,
const char *query, uint query_length,
@@ -806,7 +812,7 @@ ndbcluster_binlog_log_query(handlerton *
break;
case LOGCOM_RENAME_TABLE:
type= SOT_RENAME_TABLE;
- //DBUG_ASSERT(FALSE);
+ DBUG_ASSERT(FALSE);
break;
case LOGCOM_DROP_TABLE:
type= SOT_DROP_TABLE;
@@ -826,7 +832,7 @@ ndbcluster_binlog_log_query(handlerton *
break;
case LOGCOM_CREATE_USER:
type= SOT_CREATE_USER;
- if (ndbcluster_distributed_privileges(thd))
+ if (priv_tables_are_in_ndb(thd))
{
DBUG_PRINT("info", ("Privilege tables have been distributed, logging statement"));
log= 1;
@@ -834,7 +840,7 @@ ndbcluster_binlog_log_query(handlerton *
break;
case LOGCOM_DROP_USER:
type= SOT_DROP_USER;
- if (ndbcluster_distributed_privileges(thd))
+ if (priv_tables_are_in_ndb(thd))
{
DBUG_PRINT("info", ("Privilege tables have been distributed, logging statement"));
log= 1;
@@ -842,7 +848,7 @@ ndbcluster_binlog_log_query(handlerton *
break;
case LOGCOM_RENAME_USER:
type= SOT_RENAME_USER;
- if (ndbcluster_distributed_privileges(thd))
+ if (priv_tables_are_in_ndb(thd))
{
DBUG_PRINT("info", ("Privilege tables have been distributed, logging statement"));
log= 1;
@@ -850,7 +856,7 @@ ndbcluster_binlog_log_query(handlerton *
break;
case LOGCOM_GRANT:
type= SOT_GRANT;
- if (ndbcluster_distributed_privileges(thd))
+ if (priv_tables_are_in_ndb(thd))
{
DBUG_PRINT("info", ("Privilege tables have been distributed, logging statement"));
log= 1;
@@ -858,7 +864,7 @@ ndbcluster_binlog_log_query(handlerton *
break;
case LOGCOM_REVOKE:
type= SOT_REVOKE;
- if (ndbcluster_distributed_privileges(thd))
+ if (priv_tables_are_in_ndb(thd))
{
DBUG_PRINT("info", ("Privilege tables have been distributed, logging statement"));
log= 1;
@@ -3319,7 +3325,8 @@ ndb_binlog_thread_handle_schema_event_po
thd_ndb_options.set(TNO_NO_LOCK_SCHEMA_OP);
mysql_mutex_lock(&LOCK_open);
if (ndbcluster_check_if_local_table(schema->db, schema->name) &&
- (!table_in_binlog_exclude_list(schema->db, schema->name)))
+ !Ndb_dist_priv_util::is_distributed_priv_table(schema->db,
+ schema->name))
{
sql_print_error("NDB Binlog: Skipping locally defined table '%s.%s' "
"from binlog schema event '%s' from node %d.",
@@ -3687,7 +3694,6 @@ add_ndb_binlog_index_err:
return error;
}
-
/*********************************************************************
Functions for start, stop, wait for ndbcluster binlog thread
*********************************************************************/
@@ -4501,21 +4507,6 @@ ndbcluster_check_if_local_tables_in_db(T
DBUG_RETURN(false);
}
-bool
-table_in_binlog_exclude_list(const char *db, const char *table)
-{
- if (strcmp(db, NDB_PRIV_DB) == 0)
- {
- if (strcmp(table, NDB_USER_TABLE) == 0 ||
- strcmp(table, NDB_DB_TABLE) == 0 ||
- strcmp(table, NDB_TABLES_PRIV_TABLE) == 0 ||
- strcmp(table, NDB_COLUMNS_PRIV_TABLE) == 0 ||
- strcmp(table, NDB_PROCS_PRIV_TABLE) == 0)
- return TRUE;
- }
- return FALSE;
-}
-
/*
Common function for setting up everything for logging a table at
create/discover.
@@ -4541,8 +4532,11 @@ int ndbcluster_create_binlog_setup(THD *
if (share && share_may_exist)
{
- if (table_in_binlog_exclude_list(db, table_name))
+ if (Ndb_dist_priv_util::is_distributed_priv_table(db, table_name))
{
+ // The distributed privilege tables are distributed by writing
+ // the CREATE USER, GRANT, REVOKE etc. to ndb_schema -> no need
+ // to listen to events from this table
DBUG_PRINT("info", ("Skipping binlogging of table %s/%s", db, table_name));
set_binlog_nologging(share);
}
=== modified file 'sql/ha_ndbcluster_binlog.h'
--- a/sql/ha_ndbcluster_binlog.h 2011-03-19 13:19:44 +0000
+++ b/sql/ha_ndbcluster_binlog.h 2011-03-23 10:02:55 +0000
@@ -329,9 +329,6 @@ ndbcluster_check_if_local_table(const ch
bool
ndbcluster_check_if_local_tables_in_db(THD *thd, const char *dbname);
-bool
-table_in_binlog_exclude_list(const char *db, const char *table);
-
inline
Thd_ndb *
get_thd_ndb(THD *thd)
=== modified file 'sql/ha_ndbcluster_tables.h'
--- a/sql/ha_ndbcluster_tables.h 2011-03-19 13:19:44 +0000
+++ b/sql/ha_ndbcluster_tables.h 2011-03-23 10:02:55 +0000
@@ -22,13 +22,6 @@
#define NDB_SCHEMA_TABLE "ndb_schema"
#define NDB_REPLICATION_TABLE "ndb_replication"
-#define NDB_PRIV_DB "mysql"
-#define NDB_USER_TABLE "user"
-#define NDB_DB_TABLE "db"
-#define NDB_TABLES_PRIV_TABLE "tables_priv"
-#define NDB_COLUMNS_PRIV_TABLE "columns_priv"
-#define NDB_PROCS_PRIV_TABLE "procs_priv"
-
enum Ndb_binlog_type
{
NBT_DEFAULT = 0
=== added file 'sql/ndb_dist_priv_util.h'
--- a/sql/ndb_dist_priv_util.h 1970-01-01 00:00:00 +0000
+++ b/sql/ndb_dist_priv_util.h 2011-03-23 12:06:50 +0000
@@ -0,0 +1,67 @@
+/*
+ Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; version 2 of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#ifndef NDB_DIST_PRIV_UTIL_H
+#define NDB_DIST_PRIV_UTIL_H
+
+class Ndb_dist_priv_util {
+ size_t m_iter_curr_table;
+public:
+ Ndb_dist_priv_util()
+ {
+ iter_reset();
+ }
+
+ const char* database() const { return "mysql"; }
+
+ // Iterator for distributed priv tables name
+ const char* iter_next_table()
+ {
+ static const char* tables[] =
+ { "user", "db", "tables_priv", "columns_priv", "procs_priv", "host" };
+
+ if (m_iter_curr_table >= (sizeof(tables) / sizeof(tables[0])))
+ return NULL;
+ m_iter_curr_table++;
+ return tables[m_iter_curr_table-1];
+ }
+
+ // Reset iterator to start at first table name
+ void iter_reset() { m_iter_curr_table = 0; }
+
+ // Determine if a given table name is in the list
+ // of distributed priv tables
+ static
+ bool
+ is_distributed_priv_table(const char *db, const char *table)
+ {
+ Ndb_dist_priv_util dist_priv;
+ if (strcmp(db, dist_priv.database()))
+ return false; // Ignore tables not in dist_priv database
+
+ const char* priv_table_name;
+ while((priv_table_name= dist_priv.iter_next_table()))
+ {
+ if (strcmp(table, priv_table_name) == 0)
+ return true;
+ }
+ return false;
+ }
+
+};
+
+#endif
=== modified file 'storage/ndb/tools/restore/restore_main.cpp'
--- a/storage/ndb/tools/restore/restore_main.cpp 2011-03-19 13:55:51 +0000
+++ b/storage/ndb/tools/restore/restore_main.cpp 2011-03-23 10:02:55 +0000
@@ -110,8 +110,7 @@ enum ndb_restore_options {
OPT_EXCLUDE_TABLES,
OPT_INCLUDE_DATABASES,
OPT_EXCLUDE_DATABASES,
- OPT_REWRITE_DATABASE,
- OPT_RESTORE_PRIVILEGE_TABLES
+ OPT_REWRITE_DATABASE
};
static const char *opt_fields_enclosed_by= NULL;
static const char *opt_fields_terminated_by= NULL;
@@ -125,7 +124,7 @@ static const char *opt_include_tables= N
static const char *opt_exclude_databases= NULL;
static const char *opt_include_databases= NULL;
static const char *opt_rewrite_database= NULL;
-static const char *opt_restore_privilege_tables= NULL;
+static bool opt_restore_privilege_tables = false;
static struct my_option my_long_options[] =
{
@@ -532,40 +531,24 @@ makeExternalTableName(const BaseString &
return externalName;
}
+#include "../../../../sql/ndb_dist_priv_util.h"
+
+// Exclude privilege tables unless explicitely included
void
exclude_privilege_tables()
{
- // Exclude privilege tables unless explicitely included
- BaseString priv_tab_prefix, priv_tab;
- priv_tab_prefix.append(NDB_PRIV_DB);
- priv_tab_prefix.append(".");
- // mysql.user
- priv_tab.assign(priv_tab_prefix);
- priv_tab.append(NDB_USER_TABLE);
- g_exclude_tables.push_back(priv_tab);
- save_include_exclude(OPT_EXCLUDE_TABLES, (char *)priv_tab.c_str());
- // mysql.db
- priv_tab.assign(priv_tab_prefix);
- priv_tab.append(NDB_DB_TABLE);
- g_exclude_tables.push_back(priv_tab);
- save_include_exclude(OPT_EXCLUDE_TABLES, (char *)priv_tab.c_str());
- // mysql.tables_priv
- priv_tab.assign(priv_tab_prefix);
- priv_tab.append(NDB_TABLES_PRIV_TABLE);
- g_exclude_tables.push_back(priv_tab);
- save_include_exclude(OPT_EXCLUDE_TABLES, (char *)priv_tab.c_str());
- // mysql.columns_priv
- priv_tab.assign(priv_tab_prefix);
- priv_tab.append(NDB_COLUMNS_PRIV_TABLE);
- g_exclude_tables.push_back(priv_tab);
- save_include_exclude(OPT_EXCLUDE_TABLES, (char *)priv_tab.c_str());
- // mysql.procs_priv
- priv_tab.assign(priv_tab_prefix);
- priv_tab.append(NDB_PROCS_PRIV_TABLE);
- g_exclude_tables.push_back(priv_tab);
- save_include_exclude(OPT_EXCLUDE_TABLES, (char *)priv_tab.c_str());
+ const char* table_name;
+ Ndb_dist_priv_util dist_priv;
+ while((table_name= dist_priv.iter_next_table()))
+ {
+ BaseString priv_tab;
+ priv_tab.assfmt("%s.%s", dist_priv.database(), table_name);
+ g_exclude_tables.push_back(priv_tab);
+ save_include_exclude(OPT_EXCLUDE_TABLES, (char *)priv_tab.c_str());
+ }
}
+
bool
readArguments(int *pargc, char*** pargv)
{
@@ -743,7 +726,7 @@ o verify nodegroup mapping
if (ga_restore)
{
- // We always exclude privilege tables
+ // Exclude privilege tables unless explicitely included
if (!opt_restore_privilege_tables)
exclude_privilege_tables();
@@ -1048,6 +1031,7 @@ static bool check_include_exclude(BaseSt
}
}
}
+
return do_include;
}
@@ -1081,7 +1065,6 @@ checkDbAndTableName(const TableS* table)
return false;
// If new options are given, ignore the old format
-
if (opt_include_tables || g_exclude_tables.size() > 0 ||
opt_include_databases || opt_exclude_databases ) {
return (checkDoRestore(table));
No bundle (reason: useless for push emails).| Thread |
|---|
| • bzr push into mysql-5.1-telco-7.0 branch (magnus.blaudd:4252 to 4256) | Magnus Blåudd | 23 Mar |