1 2 3 4 5 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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 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 148 149 150 151 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 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 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 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 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
|
--source setup.inc
--source suite/ndb/include/backup_restore_setup.inc
#
# Case 1: Basic schema detection + synchronization test using
# the ndb_metadata_sync option. This is a duplicate of
# case 1 in the metadata_sync test.
# - Cause mismatch between NDB Dictionary and DD
# - Check if these mismatches are detected properly by
# Ndb_metadata_change_monitor thread
# - Check if these mismatches detected are synchronized
#
# Create logfile group, tablespace, and tables in addition to
# those created in setup.inc
CREATE LOGFILE GROUP lg1
ADD UNDOFILE 'lg1_undofile.dat'
INITIAL_SIZE 1M
UNDO_BUFFER_SIZE = 1M
ENGINE NDB;
CREATE TABLESPACE ts1
ADD DATAFILE 'ts1_datafile.dat'
USE LOGFILE GROUP lg1
INITIAL_SIZE 2M
ENGINE NDB;
USE ndb_ddl_test;
CREATE TABLE t10 (
a INT PRIMARY KEY,
b VARCHAR(255)
) ENGINE NDB
TABLESPACE ts1
STORAGE DISK;
INSERT INTO t10 VALUES(1, 'Beggars can\'t be choosers');
CREATE DATABASE ndb_ddl_test3;
USE ndb_ddl_test3;
CREATE TABLE t1 (
a INT,
b INT,
PRIMARY KEY(a,b)
) ENGINE NDB;
CREATE TABLE t2(
a INT PRIMARY KEY,
b VARCHAR(255)
) ENGINE NDB;
# backup
--disable_query_log
--source include/ndb_backup.inc
--enable_query_log
# Create a few more databases and tests
CREATE DATABASE ndb_ddl_test4;
USE ndb_ddl_test4;
CREATE TABLE t1 (
a INT,
b INT,
PRIMARY KEY(a,b)
) ENGINE NDB;
CREATE TABLE t2(
a INT PRIMARY KEY,
b VARCHAR(255)
) ENGINE NDB;
CREATE DATABASE ndb_ddl_test5;
USE ndb_ddl_test5;
CREATE TABLE t1 (
a INT,
b INT,
PRIMARY KEY(a,b)
) ENGINE NDB;
USE ndb_ddl_test;
# Drop half the tables from ndb_ddl_test database
--let $counter = 6
while ($counter <= 10)
{
let $tx=t$counter;
--eval DROP TABLE $tx
--inc $counter
}
ALTER TABLESPACE ts1
DROP DATAFILE 'ts1_datafile.dat';
DROP TABLESPACE ts1;
DROP LOGFILE GROUP lg1
ENGINE NDB;
# Drop all tables in ndb_ddl_test3
USE ndb_ddl_test3;
DROP TABLE t1;
DROP TABLE t2;
# Restore into NDB, skip tables in ndb_ddl_test database that already exist
--exec $NDB_RESTORE -b $the_backup_id -n 1 -m -r --exclude-tables=ndb_ddl_test.t1,ndb_ddl_test.t2,ndb_ddl_test.t3,ndb_ddl_test.t4,ndb_ddl_test.t5 $NDB_BACKUPS-$the_backup_id >> $NDB_TOOLS_OUTPUT
--exec $NDB_RESTORE -b $the_backup_id -n 2 -r --exclude-tables=ndb_ddl_test.t1,ndb_ddl_test.t2,ndb_ddl_test.t3,ndb_ddl_test.t4,ndb_ddl_test.t5 $NDB_BACKUPS-$the_backup_id >> $NDB_TOOLS_OUTPUT
# Drop tables from NDB only to cause mismatch
--exec $NDB_DROP_TABLE -d ndb_ddl_test4 t1 >> $NDB_TOOLS_OUTPUT
--exec $NDB_DROP_TABLE -d ndb_ddl_test5 t1 >> $NDB_TOOLS_OUTPUT
# Wait until the changes have been synced
--let $max_wait = 60
--source wait_immediate_metadata_sync.inc
# Check if the metadata is as expected after synchronization
SHOW DATABASES;
USE ndb_ddl_test;
SHOW TABLES;
USE ndb_ddl_test3;
SHOW TABLES;
USE ndb_ddl_test4;
SHOW TABLES;
USE ndb_ddl_test5;
SHOW TABLES;
# Run some DDL statements and queries on the tables synced
--sorted_result
SELECT * FROM ndb_ddl_test.t6;
--sorted_result
SELECT * FROM ndb_ddl_test.t8;
--sorted_result
SELECT * FROM ndb_ddl_test.t10;
ALTER TABLE ndb_ddl_test3.t1
ADD COLUMN c VARCHAR(255);
INSERT INTO ndb_ddl_test3.t1 VALUES(1, 1, 'Donkey\'s praise');
SELECT * FROM ndb_ddl_test3.t1;
--error ER_NO_SUCH_TABLE
SHOW CREATE TABLE ndb_ddl_test4.t1;
--error ER_NO_SUCH_TABLE
SHOW CREATE TABLE ndb_ddl_test5.t1;
# Check if tablespace and logfile group work fine after sync
CREATE TABLESPACE ts2
ADD DATAFILE 'ts2_datafile.dat'
USE LOGFILE GROUP lg1
INITIAL_SIZE 2M
ENGINE NDB;
ALTER TABLESPACE ts1
ADD DATAFILE 'ts1_datafile2.dat';
CREATE TABLE ndb_ddl_test4.t1 (
a INT PRIMARY KEY,
b INT
) ENGINE NDB;
INSERT INTO ndb_ddl_test4.t1 VALUES(1,1);
SELECT * FROM ndb_ddl_test4.t1;
# Cleanup
DROP DATABASE ndb_ddl_test3;
DROP DATABASE ndb_ddl_test4;
DROP DATABASE ndb_ddl_test5;
--source cleanup.inc
ALTER TABLESPACE ts1
DROP DATAFILE 'ts1_datafile.dat';
ALTER TABLESPACE ts1
DROP DATAFILE 'ts1_datafile2.dat';
DROP TABLESPACE ts1;
ALTER TABLESPACE ts2
DROP DATAFILE 'ts2_datafile.dat';
DROP TABLESPACE ts2;
DROP LOGFILE GROUP lg1
ENGINE NDB;
#
# Case 2: Automatic synchronization of schemata.
# This is a duplicate of case 2 in the metadata_sync test
# - Cause mismatch in terms of schema between NDB Dictionary and DD
# - Check if the schema mismatch is detected
# - Check if the schema mismatch is synchronized
#
# db1 - Only NDB tables
CREATE DATABASE db1;
USE db1;
CREATE TABLE t1_ndb (
a INT PRIMARY KEY,
b INT
) ENGINE NDB;
CREATE TABLE t2_ndb (
a INT PRIMARY KEY,
b VARCHAR(255)
) ENGINE NDB;
# db2 - Only NDB tables
CREATE DATABASE db2;
USE db2;
CREATE TABLE t1_ndb (
a INT PRIMARY KEY,
b INT
) ENGINE NDB;
CREATE TABLE t2_ndb (
a INT PRIMARY KEY,
b VARCHAR(255)
) ENGINE NDB;
# db3 - Only InnoDB tables
CREATE DATABASE db3;
USE db3;
CREATE TABLE t1_innodb (
a INT PRIMARY KEY,
b INT
);
CREATE TABLE t2_innodb (
a INT PRIMARY KEY,
b VARCHAR(255)
);
# db4 - Both NDB and InnoDB tables
CREATE DATABASE db4;
USE db4;
CREATE TABLE t1_ndb (
a INT PRIMARY KEY,
b INT
) ENGINE NDB;
CREATE TABLE t2_ndb (
a INT PRIMARY KEY,
b VARCHAR(255)
) ENGINE NDB;
CREATE TABLE t1_innodb (
a INT PRIMARY KEY,
b INT
);
CREATE TABLE t2_innodb (
a INT PRIMARY KEY,
b VARCHAR(255)
);
# backup
--disable_query_log
--source include/ndb_backup.inc
--enable_query_log
# Cause mismatch by dropping db1 and db4 and restoring metadata
DROP DATABASE db1;
DROP DATABASE db4;
--exec $NDB_RESTORE -b $the_backup_id -n 1 -m --exclude-databases=db2 $NDB_BACKUPS-$the_backup_id >> $NDB_TOOLS_OUTPUT
#
# At this point the state of the schemata is as follows:
# - db1: Used in NDB Dictionary, non-existent in DD
# - db2: Used in NDB Dictionary, exists in DD
# - db3: Not used in NDB Dictionary, exists in DD
# - db4: Used in NDB Dictionary, non-existent in DD
#
# The auto sync mechanism will create db1 and db4 in the DD.
# It will also synchronize all NDB tables contained in db1 and db4
#
# Wait until the changes have been synced
--let $max_wait = 60
--source wait_immediate_metadata_sync.inc
# Check if the objects have been synchronized as expected
SHOW DATABASES LIKE 'db%';
USE db1;
SHOW TABLES;
SHOW CREATE TABLE t1_ndb;
SHOW CREATE TABLE t2_ndb;
USE db2;
SHOW TABLES;
USE db3;
SHOW TABLES;
USE db4;
SHOW TABLES;
SHOW CREATE TABLE t1_ndb;
SHOW CREATE TABLE t2_ndb;
# Clean up
DROP DATABASE db1;
DROP DATABASE db2;
DROP DATABASE db3;
DROP DATABASE db4;
#
# Case 3: Automatic synchronization of tables restored
# with the --disable-indexes option.
# This is a variant of the metadata_sync_restore_disable_index test
# - Cause mismatch by restoring tables with --disable-indexes
# - Wait until the tables are excluded after 10 unsuccessful tries
# - Rebuild indexes and discover tables
# - Clear the excluded objects list
#
# Create tables with various indexes
USE test;
CREATE TABLE t1 (
a INT PRIMARY KEY,
b INT NOT NULL,
c INT NOT NULL,
UNIQUE ib(b),
INDEX ic(c)
) ENGINE NDB;
INSERT INTO t1 VALUES (1,2,3),(2,3,5),(3,4,6),(4,5,8),(5,6,2),(6,7,2);
CREATE TABLE parent (
c1 INT PRIMARY KEY
) ENGINE NDB;
INSERT INTO parent VALUES (1),(2);
CREATE TABLE child (
c1 INT PRIMARY KEY,
c2 INT,
INDEX xc2(c2),
FOREIGN KEY(c2)
REFERENCES parent(c1)
ON DELETE CASCADE
) ENGINE NDB;
INSERT INTO child VALUES (1,1),(2,2);
--echo Backup
--source include/ndb_backup.inc
DROP TABLE t1,child,parent;
# Suppress expected errors
--disable_query_log
call mtr.add_suppression("Metadata check has failed");
call mtr.add_suppression("The NDB Dictionary table definition is not identical to the DD table definition");
call mtr.add_suppression("Diff in 'index_count'");
--enable_query_log
--echo Restore with --disable-indexes
--exec $NDB_RESTORE -b $the_backup_id -n 1 -m -r --disable-indexes $NDB_BACKUPS-$the_backup_id >> $NDB_TOOLS_OUTPUT
--exec $NDB_RESTORE -b $the_backup_id -n 2 -r $NDB_BACKUPS-$the_backup_id >> $NDB_TOOLS_OUTPUT
# Wait until the changes have been synced
--let $max_wait = 60
--source wait_immediate_metadata_sync.inc
--sorted_result
SELECT schema_name, name, type FROM performance_schema.ndb_sync_excluded_objects;
--echo Rebuild indexes in NDB
--exec $NDB_RESTORE -b $the_backup_id -n 1 --rebuild-indexes $NDB_BACKUPS-$the_backup_id >> $NDB_TOOLS_OUTPUT
--echo Retry sync now that the indexes have been created
--let $max_wait = 60
--source wait_immediate_metadata_sync.inc
# Check that the tables have been synced
SHOW TABLES;
--sorted_result
SELECT * FROM t1;
--sorted_result
SELECT * FROM parent;
--sorted_result
SELECT * FROM child;
# Verify that no objects are excluded
SELECT COUNT(*) FROM performance_schema.ndb_sync_excluded_objects;
# Clean-up
DROP TABLE t1,child,parent;
#
# Case 4: Mock tables created with foreign_key_checks set to 0.
# Mock tables are created when foreign_key_checks is set to 0
# and a child table has a foreign key referencing a parent table
# that "does not exist". These tables should not be automatically
# synced.
#
SET @old_foreign_key_checks = @@foreign_key_checks;
SET foreign_key_checks=0;
# Create child table referencing non-existent parent table
CREATE TABLE child (
c1 INT PRIMARY KEY,
c2 INT,
INDEX xc2(c2),
FOREIGN KEY(c2)
REFERENCES parent(c1)
ON DELETE CASCADE
) ENGINE NDB;
INSERT INTO child VALUES (1,1),(2,2);
# Wait until all changes have been synced
--let $max_wait = 30
--source wait_immediate_metadata_sync.inc
# Sync of mock tables fails every time so we check if any such
# sync was attempted by looking at the ndb_sync_excluded_objects
# table. The table should contain zero rows which indicates that
# no mock tables were picked up for sync.
SELECT CASE COUNT(*) WHEN 0 THEN 'YES' ELSE 'NO' END AS mock_tables_sync_skipped
FROM performance_schema.ndb_sync_excluded_objects;
# Clean-up
DROP TABLE child;
SET foreign_key_checks = @old_foreign_key_checks;
--source suite/ndb/include/backup_restore_cleanup.inc
--remove_file $NDB_TOOLS_OUTPUT
|