Skip to content

Commit f1397df

Browse files
committed
ndbinfo
- auto create the ndbinfo database and tables in mysql_install_db and mysql_upgrade - only auto create if version >= 7.1 - don't auto create if the ndbinfo/ndb$ namespace is occupied - hide the ndbinfo database in 'ndbinfo_find_files' if ndbcluster and thus ndbinfo is not enabled. This way the ndbinfo database and tables will only show up when mysqld is started with --ndbcluster - fix one test case in suite/ndb that does SHOW DATABASES to only show the two database it has created
1 parent b16c2d6 commit f1397df

File tree

7 files changed

+373
-80
lines changed

7 files changed

+373
-80
lines changed

mysql-test/suite/ndb/r/ndb_restore_options.result

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -401,14 +401,10 @@ drop table db1.tab1,db1.tab2,db2.tab1;
401401
Include unknown database
402402
************************
403403
Should result in nothing restored
404-
show databases;
405-
Database
406-
information_schema
404+
show databases like "db%";
405+
Database (db%)
407406
db1
408407
db2
409-
mtr
410-
mysql
411-
test
412408
use db1;
413409
show tables;
414410
Tables_in_db1
@@ -419,14 +415,10 @@ Tables_in_db2
419415
Exclude unknown table
420416
*********************
421417
Should result in everything restored
422-
show databases;
423-
Database
424-
information_schema
418+
show databases like "db%";
419+
Database (db%)
425420
db1
426421
db2
427-
mtr
428-
mysql
429-
test
430422
use db1;
431423
show tables;
432424
Tables_in_db1

mysql-test/suite/ndb/r/ndbinfo.result

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ CREATE TEMPORARY TABLE `t1` (
1313
) ENGINE=NDBINFO;
1414
ERROR HY000: Table storage engine 'ndbinfo' does not support the create option 'TEMPORARY'
1515

16-
@have_ndbinfo:= COUNT(*)
17-
1
16+
1817
USE ndbinfo;
1918

2019
SHOW CREATE TABLE ndb$tables;
@@ -165,5 +164,3 @@ SELECT count(*) >= 20 FROM blocks;
165164
count(*) >= 20
166165
1
167166

168-
## Cleanup
169-
DROP DATABASE ndbinfo;

mysql-test/suite/ndb/t/ndb_restore_options.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ drop table db1.tab1,db1.tab2,db2.tab1;
255255
--exec $NDB_RESTORE --no-defaults -b $the_backup_id -n 1 -r -m $NDB_BACKUPS-$the_backup_id --include-databases unhappy_customer >> $NDB_TOOLS_OUTPUT
256256
--exec $NDB_RESTORE --no-defaults -b $the_backup_id -n 2 -r $NDB_BACKUPS-$the_backup_id --include-databases unhappy_customer >> $NDB_TOOLS_OUTPUT
257257

258-
show databases;
258+
show databases like "db%";
259259
use db1;
260260
show tables;
261261
use db2;
@@ -268,7 +268,7 @@ show tables;
268268
--exec $NDB_RESTORE --no-defaults -b $the_backup_id -n 1 -r -m $NDB_BACKUPS-$the_backup_id --exclude-tables db1.unhappy_customer >> $NDB_TOOLS_OUTPUT
269269
--exec $NDB_RESTORE --no-defaults -b $the_backup_id -n 2 -r $NDB_BACKUPS-$the_backup_id --exclude-tables db1.unhappy_customer >> $NDB_TOOLS_OUTPUT
270270

271-
show databases;
271+
show databases like "db%";
272272

273273
use db1;
274274
show tables;

mysql-test/suite/ndb/t/ndbinfo.test

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,18 @@ CREATE TEMPORARY TABLE `t1` (
1212
`dummy` INT UNSIGNED
1313
) ENGINE=NDBINFO;
1414

15-
# Run the ndbinfo.sql script that creates ndbinfo database, tables and views
16-
--disable_warnings
17-
--disable_query_log
18-
source $NDBINFO_SQL;
19-
--enable_query_log
20-
--enable_warnings
15+
if (`select @@ndbinfo_version < ((7<<16) | (1 << 8))`)
16+
{
17+
# Run the ndbinfo.sql script that creates ndbinfo database, tables and views
18+
--disable_warnings
19+
--disable_query_log
20+
--disable_result_log
21+
set @ndbinfo_skip_version_check=1;
22+
source $NDBINFO_SQL;
23+
--enable_result_log
24+
--enable_query_log
25+
--enable_warnings
26+
}
2127

2228
USE ndbinfo;
2329

@@ -87,5 +93,9 @@ set @@ndbinfo_database="somethingelse";
8793
# Check that block table has been created and contain data
8894
SELECT count(*) >= 20 FROM blocks;
8995

90-
## Cleanup
91-
DROP DATABASE ndbinfo;
96+
if (`select @@ndbinfo_version < ((7<<16) | (1 << 8))`)
97+
{
98+
--disable_query_log
99+
DROP DATABASE ndbinfo;
100+
--enable_query_log
101+
}

scripts/mysql_system_tables.sql

Lines changed: 267 additions & 0 deletions
Large diffs are not rendered by default.

sql/ha_ndbinfo.cc

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,15 +422,32 @@ ndbinfo_find_files(handlerton *hton, THD *thd,
422422
const char *wild, bool dir, List<LEX_STRING> *files)
423423
{
424424
DBUG_ENTER("ndbinfo_find_files");
425-
DBUG_PRINT("enter", ("db: '%s', dir: %d", db, dir));
425+
DBUG_PRINT("enter", ("db: '%s', dir: %d, path: '%s'", db, dir, path));
426426

427427
const bool show_hidden = THDVAR(thd, show_hidden);
428428

429429
if(show_hidden)
430430
DBUG_RETURN(0); // Don't filter out anything
431431

432432
if (dir)
433-
DBUG_RETURN(0); // Don't care about filtering databases
433+
{
434+
if (!ndbcluster_is_disabled())
435+
DBUG_RETURN(0);
436+
437+
// Hide our database when ndbcluster is disabled
438+
LEX_STRING *dir_name;
439+
List_iterator<LEX_STRING> it(*files);
440+
while ((dir_name=it++))
441+
{
442+
if (strcmp(dir_name->str, ndbinfo_dbname))
443+
continue;
444+
445+
DBUG_PRINT("info", ("Hiding own databse '%s'", dir_name->str));
446+
it.remove();
447+
}
448+
449+
DBUG_RETURN(0);
450+
}
434451

435452
DBUG_ASSERT(db);
436453
if (strcmp(db, ndbinfo_dbname))

storage/ndb/tools/ndbinfo_sql.cpp

Lines changed: 62 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ my_long_options[] =
3131
"Name of the database used by ndbinfo",
3232
(uchar**) &opt_ndbinfo_db, (uchar**) &opt_ndbinfo_db, 0,
3333
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
34-
{ "database", 'd',
34+
{ "prefix", 256,
3535
"Prefix to use for all virtual tables loaded from NDB",
3636
(uchar**) &opt_table_prefix, (uchar**) &opt_table_prefix, 0,
3737
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
@@ -159,7 +159,7 @@ size_t num_views = sizeof(views)/sizeof(views[0]);
159159

160160
#include "../src/mgmsrv/ConfigInfo.cpp"
161161
static ConfigInfo g_info;
162-
static void fill_config_params(void)
162+
static void fill_config_params(BaseString& sql)
163163
{
164164
const char* separator = "";
165165
const ConfigInfo::ParamInfo* pinfo= NULL;
@@ -170,28 +170,28 @@ static void fill_config_params(void)
170170
if (pinfo->_paramId == 0 || // KEY_INTERNAL
171171
pinfo->_status != ConfigInfo::CI_USED)
172172
continue;
173-
printf("%s(%u, \"%s\")", separator, pinfo->_paramId, pinfo->_fname);
173+
sql.appfmt("%s(%u, \"%s\")", separator, pinfo->_paramId, pinfo->_fname);
174174
separator = ", ";
175175
}
176176
}
177177

178178

179179
#include "../src/common/debugger/BlockNames.cpp"
180-
static void fill_blocks(void)
180+
static void fill_blocks(BaseString& sql)
181181
{
182182
const char* separator = "";
183183
for (BlockNumber i = 0; i < NO_OF_BLOCK_NAMES; i++)
184184
{
185185
const BlockName& bn = BlockNames[i];
186-
printf("%s(%u, \"%s\")", separator, bn.number, bn.name);
186+
sql.appfmt("%s(%u, \"%s\")", separator, bn.number, bn.name);
187187
separator = ", ";
188188
}
189189
}
190190

191191
struct lookup {
192192
const char* name;
193193
const char* columns;
194-
void (*fill)(void);
194+
void (*fill)(BaseString&);
195195
} lookups[] =
196196
{
197197
{ "blocks",
@@ -256,40 +256,69 @@ BaseString replace_tags(const char* str)
256256
return result;
257257
}
258258

259+
static void
260+
print_conditional_sql(const BaseString& sql)
261+
{
262+
printf("SET @str=IF(@have_ndbinfo,'%s','SET @dummy = 0');\n",
263+
sql.c_str());
264+
printf("PREPARE stmt FROM @str;\n");
265+
printf("EXECUTE stmt;\n");
266+
printf("DROP PREPARE stmt;\n\n");
267+
}
259268

260269
int main(int argc, char** argv){
261270

271+
BaseString sql;
262272
if ((handle_options(&argc, &argv, my_long_options, NULL)))
263273
return 2;
264274

265275
printf("#\n");
266-
printf("# SQL commands for creating the tables in MySQL Server which \n");
267-
printf("# are used by the NDBINFO storage engine to access system \n");
276+
printf("# SQL commands for creating the tables in MySQL Server which\n");
277+
printf("# are used by the NDBINFO storage engine to access system\n");
268278
printf("# information and statistics from MySQL Cluster\n");
269279
printf("#\n");
270280

271-
printf("CREATE DATABASE IF NOT EXISTS `%s`;\n\n", opt_ndbinfo_db);
272-
273-
printf("# Only create tables if NDBINFO is enabled\n");
281+
printf("# Only create objects if NDBINFO is supported\n");
274282
printf("SELECT @have_ndbinfo:= COUNT(*) FROM "
275283
"information_schema.engines WHERE engine='NDBINFO' "
276284
"AND support IN ('YES', 'DEFAULT');\n\n");
277285

278-
printf("# drop any old views in %s\n", opt_ndbinfo_db);
286+
printf("# Only create objects if version >= 7.1\n");
287+
sql.assfmt("SELECT @have_ndbinfo:="
288+
" (@@ndbinfo_version >= (7 << 16) | (1 << 8)) || @ndbinfo_skip_version_check");
289+
print_conditional_sql(sql);
290+
291+
printf("# Only create objects if ndbinfo namespace is free\n");
292+
sql.assfmt("SET @@ndbinfo_show_hidden=TRUE");
293+
print_conditional_sql(sql);
294+
sql.assfmt("SELECT @have_ndbinfo:= COUNT(*) = 0"
295+
" FROM information_schema.tables WHERE"
296+
" table_schema = @@ndbinfo_database AND"
297+
" LEFT(table_name, LENGTH(@@ndbinfo_table_prefix)) ="
298+
" @@ndbinfo_table_prefix AND"
299+
" engine != \"ndbinfo\"");
300+
print_conditional_sql(sql);
301+
sql.assfmt("SET @@ndbinfo_show_hidden=default");
302+
print_conditional_sql(sql);
303+
304+
sql.assfmt("CREATE DATABASE IF NOT EXISTS `%s`", opt_ndbinfo_db);
305+
print_conditional_sql(sql);
306+
307+
printf("# Drop any old views in %s\n", opt_ndbinfo_db);
279308
for (size_t i = 0; i < num_views; i++)
280309
{
281-
printf("DROP VIEW IF EXISTS %s.%s;\n",
282-
opt_ndbinfo_db, views[i].name);
310+
sql.assfmt("DROP VIEW IF EXISTS %s.%s",
311+
opt_ndbinfo_db, views[i].name);
312+
print_conditional_sql(sql);
283313
}
284-
printf("\n");
285314

286-
printf("# drop any old lookup tables in %s\n", opt_ndbinfo_db);
315+
printf("# Drop any old lookup tables in %s\n", opt_ndbinfo_db);
287316
for (size_t i = 0; i < num_lookups; i++)
288317
{
289-
printf("DROP TABLE IF EXISTS %s.%s;\n",
290-
opt_ndbinfo_db, lookups[i].name);
318+
sql.assfmt("DROP TABLE IF EXISTS %s.%s",
319+
opt_ndbinfo_db, lookups[i].name);
320+
print_conditional_sql(sql);
291321
}
292-
printf("\n");
293322

294323
for (int i = 0; i < Ndbinfo::getNumTables(); i++)
295324
{
@@ -299,16 +328,11 @@ int main(int argc, char** argv){
299328
opt_ndbinfo_db, opt_table_prefix, table.m.name);
300329

301330
/* Drop the table if it exists */
302-
printf("SET @str=IF(@have_ndbinfo,"
303-
"'DROP TABLE IF EXISTS `%s`.`%s%s`',"
304-
"'SET @dummy = 0');\n",
305-
opt_ndbinfo_db, opt_table_prefix, table.m.name);
306-
printf("PREPARE stmt FROM @str;\n");
307-
printf("EXECUTE stmt;\n");
308-
printf("DROP PREPARE stmt;\n\n");
331+
sql.assfmt("DROP TABLE IF EXISTS `%s`.`%s%s`",
332+
opt_ndbinfo_db, opt_table_prefix, table.m.name);
333+
print_conditional_sql(sql);
309334

310335
/* Create the table */
311-
BaseString sql;
312336
sql.assfmt("CREATE TABLE `%s`.`%s%s` (",
313337
opt_ndbinfo_db, opt_table_prefix, table.m.name);
314338

@@ -344,37 +368,28 @@ int main(int argc, char** argv){
344368

345369
}
346370

347-
sql.appfmt(") COMMENT=\"%s\" ENGINE=NDBINFO;", table.m.comment);
371+
sql.appfmt(") COMMENT=\"%s\" ENGINE=NDBINFO", table.m.comment);
348372

349-
printf("SET @str=IF(@have_ndbinfo,'%s','SET @dummy = 0');\n", sql.c_str());
350-
printf("PREPARE stmt FROM @str;\n");
351-
printf("EXECUTE stmt;\n");
352-
printf("DROP PREPARE stmt;\n\n");
373+
print_conditional_sql(sql);
353374

354375
}
355376

356-
357377
for (size_t i = 0; i < num_lookups; i++)
358378
{
359379
lookup l = lookups[i];
360380
printf("# %s.%s\n", opt_ndbinfo_db, l.name);
361381

362382
/* Create lookup table */
363-
printf("CREATE TABLE `%s`.`%s` (%s);\n",
364-
opt_ndbinfo_db, l.name, l.columns);
383+
sql.assfmt("CREATE TABLE `%s`.`%s` (%s)",
384+
opt_ndbinfo_db, l.name, l.columns);
385+
print_conditional_sql(sql);
365386

366387
/* Insert data */
367-
printf("INSERT INTO `%s`.`%s` VALUES ",
368-
opt_ndbinfo_db, l.name);
369-
l.fill();
370-
printf(";\n");
371-
388+
sql.assfmt("INSERT INTO `%s`.`%s` VALUES ",
389+
opt_ndbinfo_db, l.name);
390+
l.fill(sql);
391+
print_conditional_sql(sql);
372392
}
373-
printf("\n");
374-
375-
printf("#\n");
376-
printf("# %s views\n", opt_ndbinfo_db);
377-
printf("#\n\n");
378393

379394
for (size_t i = 0; i < num_views; i++)
380395
{
@@ -386,15 +401,10 @@ int main(int argc, char** argv){
386401

387402
/* Create or replace the view */
388403
BaseString sql;
389-
sql.assfmt("CREATE OR REPLACE DEFINER=`root@localhost` "
404+
sql.assfmt("CREATE OR REPLACE "
390405
"SQL SECURITY INVOKER VIEW `%s`.`%s` AS %s",
391406
opt_ndbinfo_db, v.name, view_sql.c_str());
392-
393-
printf("SET @str=IF(@have_ndbinfo,'%s','SET @dummy = 0');\n",
394-
sql.c_str());
395-
printf("PREPARE stmt FROM @str;\n");
396-
printf("EXECUTE stmt;\n");
397-
printf("DROP PREPARE stmt;\n\n");
407+
print_conditional_sql(sql);
398408
}
399409

400410
return 0;

0 commit comments

Comments
 (0)