ndb_autodiscover.test 11.8 KB
Newer Older
1
-- source include/have_ndb.inc
unknown's avatar
unknown committed
2
-- source include/not_embedded.inc
3 4

--disable_warnings
unknown's avatar
unknown committed
5
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
--enable_warnings

################################################
# Test that a table that does not exist as a 
# frm file on disk can be "discovered" from a 
# connected NDB Cluster
#

flush status;

#
# Test discover + SELECT
#

create table t1(
  id int not null primary key,
  name char(20)
) engine=ndb;

insert into t1 values(1, "Autodiscover");
flush tables;
system rm var/master-data/test/t1.frm ;
select * from t1;
show status like 'handler_discover%';

#
# Test discover + INSERT
#

flush tables;
system rm var/master-data/test/t1.frm ;
insert into t1 values (2, "Auto 2");
show status like 'handler_discover%';
insert into t1 values (3, "Discover 3");
show status like 'handler_discover%';
flush tables;
system rm var/master-data/test/t1.frm ;
43
select * from t1 order by id;
44 45 46 47 48 49 50 51 52 53
show status like 'handler_discover%';

#
# Test discover + UPDATE
#

flush tables;
system rm var/master-data/test/t1.frm ;
update t1 set name="Autodiscover" where id = 2;
show status like 'handler_discover%';
unknown's avatar
unknown committed
54
select * from t1 order by id;
55 56 57 58 59 60 61 62 63
show status like 'handler_discover%';

#
# Test discover + DELETE
#

flush tables;
system rm var/master-data/test/t1.frm ;
delete from  t1 where id = 3;
64
select * from t1 order by id;
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
show status like 'handler_discover%';

drop table t1;



######################################################
# Test that a table that is outdated on disk
# can be "discovered" from a connected NDB Cluster
#

flush status;

create table t2(
  id int not null primary key,
  name char(22)
) engine=ndb;
insert into t2 values (1, "Discoverer");
select * from t2;
show status like 'handler_discover%';
flush tables;

# Modify the frm file on disk
system echo "blaj" >> var/master-data/test/t2.frm ;
select * from t2;

show status like 'handler_discover%';

drop table t2;


##################################################
# Test that a table that already exists in NDB 
# is only discovered if CREATE TABLE IF NOT EXISTS 
# is used
#

flush status;

create table t3(
  id int not null primary key,
  name char(255)
) engine=ndb;
insert into t3 values (1, "Explorer");
select * from t3;
show status like 'handler_discover%';
flush tables;

# Remove the frm file from disk
system rm var/master-data/test/t3.frm ;

--error 1050
create table t3(
  id int not null primary key,
  name char(20), a int, b float, c char(24)
) engine=ndb;

# The table shall not have been discovered since
# IF NOT EXISTS wasn't specified

show status like 'handler_discover%';

# now it should be discovered
create table IF NOT EXISTS t3(
  id int not null primary key,
  id2 int not null,
  name char(20)
) engine=ndb;

# NOTE! the table called t3 have now been updated to 
# use the same frm as in NDB, thus it's not certain that 
# the table schema is the same as was stated in the 
# CREATE TABLE statement above

show status like 'handler_discover%';

SHOW CREATE TABLE t3;

select * from t3;
show status like 'handler_discover%';

drop table t3;

148 149 150 151
##################################################
# Test that a table that already exists in NDB 
# is discovered when SHOW TABLES
# is used
152 153
#

154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
flush status;

create table t7(
  id int not null primary key,
  name char(255)
) engine=ndb;
create table t6(
  id int not null primary key,
  name char(255)
) engine=MyISAM;
insert into t7 values (1, "Explorer");
insert into t6 values (2, "MyISAM table");
select * from t7;
show status like 'handler_discover%';

# Remove the frm file from disk
flush tables;
system rm var/master-data/test/t7.frm ;

show tables from test;
show status like 'handler_discover%';

# Remove the frm file from disk again
flush tables;
system rm var/master-data/test/t7.frm ;

--replace_column 7 # 8 # 9 # 12 # 13 # 15 #
show table status;
show status like 'handler_discover%';

drop table t6, t7;


#######################################################
# Test that a table that has been dropped from NDB
# but still exists on disk, get a consistent error message
# saying "No such table existed"
191
#
192

193 194 195 196 197 198 199 200
flush status;

create table t4(
  id int not null primary key,
  name char(27)
) engine=ndb;
insert into t4 values (1, "Automatic");
select * from t4;
201

202
# Remove the table from NDB
203
system exec $NDB_TOOLS_DIR/ndb_drop_table --no-defaults -d test t4 >> $NDB_TOOLS_OUTPUT ; 
204

205
#
206
# Test that correct error is returned
207 208 209 210 211 212 213
--error 1146
select * from t4;
--error 1146
select * from t4;

show status like 'handler_discover%';
drop table t4;
214

215

unknown's avatar
unknown committed
216 217 218 219 220
#######################################################
# Test that a table that has been dropped from NDB
# but still exists on disk is deleted from disk 
# when SHOW TABLES is called
#
221 222 223 224 225 226 227 228 229 230 231 232 233

flush status;

create table t4(
  id int not null primary key,
  id2 int,
  name char(27)
) engine=ndb;
insert into t4 values (1, 76, "Automatic2");
select * from t4;
flush tables;

# Remove the table from NDB
234
system exec $NDB_TOOLS_DIR/ndb_drop_table --no-defaults -d test t4 >> $NDB_TOOLS_OUTPUT ;
235 236 237 238 239 240 241 242 243

SHOW TABLES;

--error 1146
select * from t4;

#######################################################
# Test SHOW TABLES ability to detect new and delete old
# tables. Test all at once using many tables
unknown's avatar
unknown committed
244
#
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267

flush status;

# Create tables
create table t1(id int) engine=ndbcluster;
create table t2(id int, b char(255)) engine=myisam;
create table t3(id int, c char(255)) engine=ndbcluster;
create table t4(id int) engine=myisam;
create table t5(id int, d char(56)) engine=ndbcluster;
create table t6(id int) engine=ndbcluster;
create table t7(id int) engine=ndbcluster;
create table t8(id int, e char(34)) engine=myisam;
create table t9(id int) engine=myisam;

# Populate tables
insert into t2 values (2, "myisam table 2");
insert into t3 values (3, "ndb table 3");
insert into t5 values (5, "ndb table 5");
insert into t6 values (6);
insert into t8 values (8, "myisam table 8");
insert into t9 values (9);

# Remove t3, t5 from NDB
268 269
system exec $NDB_TOOLS_DIR/ndb_drop_table --no-defaults -d test t3 >> $NDB_TOOLS_OUTPUT ;
system exec $NDB_TOOLS_DIR/ndb_drop_table --no-defaults -d test t5 >> $NDB_TOOLS_OUTPUT ;
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
# Remove t6, t7 from disk
system rm var/master-data/test/t6.frm > /dev/null ; 
system rm var/master-data/test/t7.frm > /dev/null ; 

SHOW TABLES;

select * from t6;
select * from t7;

show status like 'handler_discover%';

drop table t1, t2, t4, t6, t7, t8, t9;

#######################################################
# Test SHOW TABLES LIKE ability to detect new and delete old
# tables. Test all at once using many tables.
unknown's avatar
unknown committed
286
#
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309

flush status;

# Create tables
create table t1(id int) engine=ndbcluster;
create table t2(id int, b char(255)) engine=myisam;
create table t3(id int, c char(255)) engine=ndbcluster;
create table t4(id int) engine=myisam;
create table t5(id int, d char(56)) engine=ndbcluster;
create table t6(id int) engine=ndbcluster;
create table t7(id int) engine=ndbcluster;
create table t8(id int, e char(34)) engine=myisam;
create table t9(id int) engine=myisam;

# Populate tables
insert into t2 values (2, "myisam table 2");
insert into t3 values (3, "ndb table 3");
insert into t5 values (5, "ndb table 5");
insert into t6 values (6);
insert into t8 values (8, "myisam table 8");
insert into t9 values (9);

# Remove t3, t5 from NDB
310 311
system exec $NDB_TOOLS_DIR/ndb_drop_table --no-defaults -d test t3 > /dev/null  ;
system exec $NDB_TOOLS_DIR/ndb_drop_table --no-defaults -d test t5 > /dev/null  ;
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338
# Remove t6, t7 from disk
system rm var/master-data/test/t6.frm > /dev/null ; 
system rm var/master-data/test/t7.frm > /dev/null ; 


SHOW TABLES LIKE 't6';

show status like 'handler_discover%';

# Check that t3 or t5 can't be created
# frm files for these tables is stilll on disk
--error 1050
create table t3(a int);
--error 1050
create table t5(a int);

SHOW TABLES LIKE 't%';

show status like 'handler_discover%';

drop table t1, t2, t4, t6, t7, t8, t9;



######################################################
# Test that several tables can be discovered when 
# one statement access several table at once.
unknown's avatar
unknown committed
339 340
#

341
flush status;
unknown's avatar
unknown committed
342

343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
# Create tables
create table t1(id int) engine=ndbcluster;
create table t2(id int, b char(255)) engine=ndbcluster;
create table t3(id int, c char(255)) engine=ndbcluster;
create table t4(id int) engine=myisam;

# Populate tables
insert into t1 values (1);
insert into t2 values (2, "table 2");
insert into t3 values (3, "ndb table 3");
insert into t4 values (4);

# Remove t1, t2, t3 from disk
system rm var/master-data/test/t1.frm > /dev/null ; 
system rm var/master-data/test/t2.frm > /dev/null ; 
system rm var/master-data/test/t3.frm > /dev/null ; 
flush tables;
unknown's avatar
unknown committed
360

361 362
# Select from the table which only exists in NDB.
select * from t1, t2, t3, t4;
unknown's avatar
unknown committed
363

364 365 366 367
# 3 table should have been discovered
show status like 'handler_discover%';

drop table t1, t2, t3, t4;
unknown's avatar
unknown committed
368

369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430

#########################################################
# Test that a table that has been changed in NDB 
# since it's been opened will be refreshed and discovered
# again
#

flush status;

show status like 'handler_discover%';

create table t5(
  id int not null primary key,
  name char(200)
) engine=ndb;
insert into t5 values (1, "Magnus");
select * from t5;

ALTER TABLE t5 ADD COLUMN adress char(255) FIRST;

select * from t5;

insert into t5 values 
 ("Adress for record 2", 2, "Carl-Gustav"), 
 ("Adress for record 3", 3, "Karl-Emil");
update t5 set name="Bertil" where id = 2;
select * from t5 order by id;

show status like 'handler_discover%';

drop table t5;


################################################################
# Test that a table that has been changed with ALTER TABLE
# can be used from the same thread
#

flush status;

show status like 'handler_discover%';

create table t6(
  id int not null primary key,
  name char(20)
) engine=ndb;
insert into t6 values (1, "Magnus");
select * from t6;

ALTER TABLE t6 ADD COLUMN adress char(255) FIRST;

select * from t6;
insert into t6 values 
 ("Adress for record 2", 2, "Carl-Gustav"), 
 ("Adress for record 3", 3, "Karl-Emil");
update t6 set name="Bertil" where id = 2;
select * from t6 order by id;

show status like 'handler_discover%';

drop table t6;

431 432 433 434 435 436 437
#####################################################
# Test that only tables in the current database shows 
# up in SHOW TABLES
#

show tables;

438
create table t1 (a int,b longblob) engine=ndb;
439 440 441 442 443 444
show tables;
create database test2;
use test2;
show tables;
--error 1146
select * from t1;
445
create table t2 (b int,c longblob) engine=ndb;
446 447 448 449 450 451 452 453 454 455
use test;
select * from t1;
show tables;
drop table t1;
use test2;
drop table t2;
drop database test2;
show databases;
use test;

456 457 458 459 460 461 462
#####################################################
# Test that it's not possible to create tables
# with same name as NDB internal tables
# This will also test that it's not possible to create
# a table with tha same name as a table that can't be
# discovered( for example a table created via NDBAPI)

463 464 465 466 467 468 469 470 471 472 473 474 475 476
# Test disabled since it doesn't work on case insensitive systems
#--error 1050
#CREATE TABLE sys.SYSTAB_0 (a int);
#--error 1105
#select * from sys.SYSTAB_0;

#CREATE TABLE IF NOT EXISTS sys.SYSTAB_0 (a int);
#show warnings;
#--error 1105
#select * from sys.SYSTAB_0;

#--error 1051
#drop table sys.SYSTAB_0;
#drop table IF EXISTS sys.SYSTAB_0;
477

478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495
######################################################
# Note! This should always be the last step in this 
# file, the table t9 will be used and dropped 
# by ndb_autodiscover2
#

CREATE TABLE t9 (
  a int NOT NULL PRIMARY KEY,
  b int
) engine=ndb;

insert t9 values(1, 2), (2,3), (3, 4), (4, 5);

#Don't drop the table, instead remove the frm file
system rm var/master-data/test/t9.frm ;

# Now leave test case, when ndb_autodiscover2 will  run, this 
# MySQL Server will have been restarted because it has a 
496
# ndb_autodiscover2-master.opt file.
497

unknown's avatar
unknown committed
498 499 500 501
create table t10 (
  a int not null primary key,
  b blob
) engine=ndb;
502

unknown's avatar
unknown committed
503
insert into t10 values (1, 'kalle');
504

505
--exec $NDB_TOOLS_DIR/ndb_drop_table --no-defaults -d test `$NDB_TOOLS_DIR/ndb_show_tables --no-defaults | grep BLOB` >> $NDB_TOOLS_OUTPUT 2>&1 || true