Debian Codegraph @

mysql-test/suite/ndb_ddl/metadata_sync.test

raw
1 --source setup.inc
2 --source suite/ndb/include/backup_restore_setup.inc
3
4 #
5 # Case 1: Basic schema detection + synchronization test
6 # - Cause mismatch between NDB Dictionary and DD
7 # - Check if these mismatches are detected properly by
8 # Ndb_metadata_change_monitor thread
9 # - Check if these mismatches detected are synchronized
10 #
11
12 # Create logfile group, tablespace, and tables in addition to
13 # those created in setup.inc
14 CREATE LOGFILE GROUP lg1
15 ADD UNDOFILE 'lg1_undofile.dat'
16 INITIAL_SIZE 1M
17 UNDO_BUFFER_SIZE = 1M
18 ENGINE NDB;
19
20 CREATE TABLESPACE ts1
21 ADD DATAFILE 'ts1_datafile.dat'
22 USE LOGFILE GROUP lg1
23 INITIAL_SIZE 2M
24 ENGINE NDB;
25
26 USE ndb_ddl_test;
27
28 CREATE TABLE t10 (
29 a INT PRIMARY KEY,
30 b VARCHAR(255)
31 ) ENGINE NDB
32 TABLESPACE ts1
33 STORAGE DISK;
34
35 INSERT INTO t10 VALUES(1, 'Poirot');
36
37 CREATE DATABASE ndb_ddl_test3;
38 USE ndb_ddl_test3;
39
40 CREATE TABLE t1 (
41 a INT,
42 b INT,
43 PRIMARY KEY(a,b)
44 ) ENGINE NDB;
45
46 CREATE TABLE t2(
47 a INT PRIMARY KEY,
48 b VARCHAR(255)
49 ) ENGINE NDB;
50
51 # backup
52 --disable_query_log
53 --source include/ndb_backup.inc
54 --enable_query_log
55
56 # Create a few more databases and tests
57 CREATE DATABASE ndb_ddl_test4;
58 USE ndb_ddl_test4;
59
60 CREATE TABLE t1 (
61 a INT,
62 b INT,
63 PRIMARY KEY(a,b)
64 ) ENGINE NDB;
65
66 CREATE TABLE t2(
67 a INT PRIMARY KEY,
68 b VARCHAR(255)
69 ) ENGINE NDB;
70
71 CREATE DATABASE ndb_ddl_test5;
72 USE ndb_ddl_test5;
73
74 CREATE TABLE t1 (
75 a INT,
76 b INT,
77 PRIMARY KEY(a,b)
78 ) ENGINE NDB;
79
80 USE ndb_ddl_test;
81
82 # Drop half the tables from ndb_ddl_test database
83 --let $counter = 6
84 while ($counter <= 10)
85 {
86 let $tx=t$counter;
87 --eval DROP TABLE $tx
88 --inc $counter
89 }
90
91 ALTER TABLESPACE ts1
92 DROP DATAFILE 'ts1_datafile.dat';
93 DROP TABLESPACE ts1;
94 DROP LOGFILE GROUP lg1
95 ENGINE NDB;
96
97 # Drop all tables in ndb_ddl_test3
98 USE ndb_ddl_test3;
99 DROP TABLE t1;
100 DROP TABLE t2;
101
102 # Restore into NDB, skip tables in ndb_ddl_test database that already exist
103 --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
104 --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
105
106 # Drop tables from NDB only to cause mismatch
107 --exec $NDB_DROP_TABLE -d ndb_ddl_test4 t1 >> $NDB_TOOLS_OUTPUT
108 --exec $NDB_DROP_TABLE -d ndb_ddl_test5 t1 >> $NDB_TOOLS_OUTPUT
109
110 SET @old_ndb_metadata_check = @@global.ndb_metadata_check;
111 SET @old_ndb_metadata_check_interval = @@global.ndb_metadata_check_interval;
112
113 # Store initial counts of both detected and synchronized objects
114 --let $initial_detected_count = query_get_value(SHOW STATUS LIKE 'Ndb_metadata_detected_count', Value, 1)
115 --let $initial_synced_count = query_get_value(SHOW STATUS LIKE 'Ndb_metadata_synced_count', Value, 1)
116
117 # Check if both variables are global
118 --error ER_GLOBAL_VARIABLE
119 SET SESSION ndb_metadata_check = 1;
120 --error ER_GLOBAL_VARIABLE
121 SET SESSION ndb_metadata_check_interval = 5;
122
123 # Enable metadata check with no interval so changes are detected quickly
124 SET GLOBAL ndb_metadata_check_interval = 0;
125 SET GLOBAL ndb_metadata_check = 1;
126
127 # Wait until the following 11 object changes are detected:
128 # Logfile group 'lg1'
129 # Tablespace 'ts1'
130 # Table 'ndb_ddl_test.t6'
131 # Table 'ndb_ddl_test.t7'
132 # Table 'ndb_ddl_test.t8'
133 # Table 'ndb_ddl_test.t9'
134 # Table 'ndb_ddl_test.t10'
135 # Table 'ndb_ddl_test3.t1'
136 # Table 'ndb_ddl_test3.t2'
137 # Table 'ndb_ddl_test4.t1'
138 # Table 'ndb_ddl_test5.t1'
139 --let $expected_changes = 11
140 --let $max_wait = 60
141 --source wait_metadata_changes_detected.inc
142
143 # Changes have been detected, reset values
144 SET GLOBAL ndb_metadata_check = @old_ndb_metadata_check;
145 SET GLOBAL ndb_metadata_check_interval = @old_ndb_metadata_check_interval;
146
147 # Wait until the changes detected have been synced
148 --let $max_wait = 60
149 --source wait_metadata_synced.inc
150
151 # Run some DDL statements and queries on the tables synced
152 --sorted_result
153 SELECT * FROM ndb_ddl_test.t6;
154 --sorted_result
155 SELECT * FROM ndb_ddl_test.t8;
156 --sorted_result
157 SELECT * FROM ndb_ddl_test.t10;
158 ALTER TABLE ndb_ddl_test3.t1
159 ADD COLUMN c VARCHAR(255);
160 INSERT INTO ndb_ddl_test3.t1 VALUES(1, 1, 'Use your little grey cells mon ami');
161 SELECT * FROM ndb_ddl_test3.t1;
162 --error ER_NO_SUCH_TABLE
163 SHOW CREATE TABLE ndb_ddl_test4.t1;
164 --error ER_NO_SUCH_TABLE
165 SHOW CREATE TABLE ndb_ddl_test5.t1;
166
167 # Check if tablespace and logfile group work fine after sync
168 CREATE TABLESPACE ts2
169 ADD DATAFILE 'ts2_datafile.dat'
170 USE LOGFILE GROUP lg1
171 INITIAL_SIZE 2M
172 ENGINE NDB;
173
174 ALTER TABLESPACE ts1
175 ADD DATAFILE 'ts1_datafile2.dat';
176 CREATE TABLE ndb_ddl_test4.t1 (
177 a INT PRIMARY KEY,
178 b INT
179 ) ENGINE NDB;
180 INSERT INTO ndb_ddl_test4.t1 VALUES(1,1);
181 SELECT * FROM ndb_ddl_test4.t1;
182
183 # Cleanup
184 DROP DATABASE ndb_ddl_test3;
185 DROP DATABASE ndb_ddl_test4;
186 DROP DATABASE ndb_ddl_test5;
187 --source cleanup.inc
188
189 ALTER TABLESPACE ts1
190 DROP DATAFILE 'ts1_datafile.dat';
191 ALTER TABLESPACE ts1
192 DROP DATAFILE 'ts1_datafile2.dat';
193 DROP TABLESPACE ts1;
194 ALTER TABLESPACE ts2
195 DROP DATAFILE 'ts2_datafile.dat';
196 DROP TABLESPACE ts2;
197 DROP LOGFILE GROUP lg1
198 ENGINE NDB;
199
200 #
201 # Case 2: Automatic synchronization of schemata
202 # - Cause mismatch in terms of schema between NDB Dictionary and DD
203 # - Check if the schema mismatch is detected
204 # - Check if the schema mismatch is synchronized
205 #
206
207 # db1 - Only NDB tables
208 CREATE DATABASE db1;
209 USE db1;
210 CREATE TABLE t1_ndb (
211 a INT PRIMARY KEY,
212 b INT
213 ) ENGINE NDB;
214 CREATE TABLE t2_ndb (
215 a INT PRIMARY KEY,
216 b VARCHAR(255)
217 ) ENGINE NDB;
218
219 # db2 - Only NDB tables
220 CREATE DATABASE db2;
221 USE db2;
222 CREATE TABLE t1_ndb (
223 a INT PRIMARY KEY,
224 b INT
225 ) ENGINE NDB;
226 CREATE TABLE t2_ndb (
227 a INT PRIMARY KEY,
228 b VARCHAR(255)
229 ) ENGINE NDB;
230
231 # db3 - Only InnoDB tables
232 CREATE DATABASE db3;
233 USE db3;
234 CREATE TABLE t1_innodb (
235 a INT PRIMARY KEY,
236 b INT
237 );
238 CREATE TABLE t2_innodb (
239 a INT PRIMARY KEY,
240 b VARCHAR(255)
241 );
242
243 # db4 - Both NDB and InnoDB tables
244 CREATE DATABASE db4;
245 USE db4;
246 CREATE TABLE t1_ndb (
247 a INT PRIMARY KEY,
248 b INT
249 ) ENGINE NDB;
250 CREATE TABLE t2_ndb (
251 a INT PRIMARY KEY,
252 b VARCHAR(255)
253 ) ENGINE NDB;
254 CREATE TABLE t1_innodb (
255 a INT PRIMARY KEY,
256 b INT
257 );
258 CREATE TABLE t2_innodb (
259 a INT PRIMARY KEY,
260 b VARCHAR(255)
261 );
262
263 # backup
264 --disable_query_log
265 --source include/ndb_backup.inc
266 --enable_query_log
267
268 # Cause mismatch by dropping db1 and db4 and restoring metadata
269 DROP DATABASE db1;
270 DROP DATABASE db4;
271
272 --exec $NDB_RESTORE -b $the_backup_id -n 1 -m --exclude-databases=db2 $NDB_BACKUPS-$the_backup_id >> $NDB_TOOLS_OUTPUT
273
274 #
275 # At this point the state of the schemata is as follows:
276 # - db1: Used in NDB Dictionary, non-existent in DD
277 # - db2: Used in NDB Dictionary, exists in DD
278 # - db3: Not used in NDB Dictionary, exists in DD
279 # - db4: Used in NDB Dictionary, non-existent in DD
280 #
281 # The auto sync mechanism will create db1 and db4 in the DD.
282 # It will also synchronize all NDB tables contained in db1 and db4
283 #
284
285 # Store initial counts of both detected and synchronized objects
286 --let $initial_detected_count = query_get_value(SHOW STATUS LIKE 'Ndb_metadata_detected_count', Value, 1)
287 --let $initial_synced_count = query_get_value(SHOW STATUS LIKE 'Ndb_metadata_synced_count', Value, 1)
288
289 --disable_query_log
290 # Enable metadata check with no interval so changes are detected quickly
291 SET GLOBAL ndb_metadata_check_interval = 0;
292 SET GLOBAL ndb_metadata_check = true;
293 --enable_query_log
294
295 # Wait until the following 6 object changes are detected:
296 # Schema 'db1'
297 # Schema 'db4'
298 # Table 'db1.t1_ndb'
299 # Table 'db1.t2_ndb'
300 # Table 'db4.t1_ndb'
301 # Table 'db4.t2_ndb'
302 --let $expected_changes = 6
303 --let $max_wait = 30
304 --source wait_metadata_changes_detected.inc
305
306 --disable_query_log
307 # Changes have been detected, reset values
308 SET GLOBAL ndb_metadata_check = @old_ndb_metadata_check;
309 SET GLOBAL ndb_metadata_check_interval = @old_ndb_metadata_check_interval;
310 --enable_query_log
311
312 # Wait until the changes detected have been synced
313 --let $max_wait = 30
314 --source wait_metadata_synced.inc
315
316 # Check if the objects have been synchronized as expected
317 SHOW DATABASES LIKE 'db%';
318 USE db1;
319 SHOW TABLES;
320 SHOW CREATE TABLE t1_ndb;
321 SHOW CREATE TABLE t2_ndb;
322 USE db2;
323 SHOW TABLES;
324 USE db3;
325 SHOW TABLES;
326 USE db4;
327 SHOW TABLES;
328 SHOW CREATE TABLE t1_ndb;
329 SHOW CREATE TABLE t2_ndb;
330
331 # Clean up
332 DROP DATABASE db1;
333 DROP DATABASE db2;
334 DROP DATABASE db3;
335 DROP DATABASE db4;
336
337 #
338 # Case 3: Automatic synchronization of schema with an upper case name
339 # - Cause mismatch in terms of schema between NDB Dictionary and DD
340 # - Check if the schema mismatch is detected
341 # - Check if the schema mismatch is synchronized
342 #
343
344 # Create schema and table
345 CREATE DATABASE DB1;
346 ALTER DATABASE DB1
347 CHARACTER SET latin1;
348 USE DB1;
349 CREATE TABLE t1(
350 id INT PRIMARY KEY
351 ) ENGINE NDB;
352 INSERT INTO t1 VALUES (1),(2),(3),(4),(5);
353
354 # backup
355 --disable_query_log
356 --source include/ndb_backup.inc
357 --enable_query_log
358
359 DROP TABLE t1;
360
361 --exec $NDB_RESTORE -b $the_backup_id -n 1 -m -r $NDB_BACKUPS-$the_backup_id >> $NDB_TOOLS_OUTPUT
362 --exec $NDB_RESTORE -b $the_backup_id -n 2 -r $NDB_BACKUPS-$the_backup_id >> $NDB_TOOLS_OUTPUT
363
364 # Store initial counts of both detected and synchronized objects
365 --let $initial_detected_count = query_get_value(SHOW STATUS LIKE 'Ndb_metadata_detected_count', Value, 1)
366 --let $initial_synced_count = query_get_value(SHOW STATUS LIKE 'Ndb_metadata_synced_count', Value, 1)
367
368 --disable_query_log
369 # Set low interval so changes are detected quickly
370 SET GLOBAL ndb_metadata_check = true;
371 SET GLOBAL ndb_metadata_check_interval = 0;
372 --enable_query_log
373
374 # Wait until the following object change is detected:
375 # Table 'DB.t1'
376 --let $expected_changes = 1
377 --let $max_wait = 30
378 --source wait_metadata_changes_detected.inc
379
380 --disable_query_log
381 # Changes have been detected, reset values
382 SET GLOBAL ndb_metadata_check = @old_ndb_metadata_check;
383 SET GLOBAL ndb_metadata_check_interval = @old_ndb_metadata_check_interval;
384 --enable_query_log
385
386 # Wait until the changes detected have been synced
387 --let $max_wait = 30
388 --source wait_metadata_synced.inc
389
390 # Check if auto sync has worked properly
391 --replace_result Tables_in_DB1 Tables_in_database Tables_in_db1 Tables_in_database
392 SHOW TABLES;
393 --sorted_result
394 SELECT * FROM t1;
395
396 # Clean up
397 DROP DATABASE DB1;
398 --source suite/ndb/include/backup_restore_cleanup.inc
399 --remove_file $NDB_TOOLS_OUTPUT