Skip to content

Commit 6c2abd1

Browse files
committed
WL#13490 Automatic Synchronization: Create missing databases
- The automatic synchronization mechanism previously only synchronized logfile groups, tablespaces, and tables but not schemata - This led to a limitation in a particular scenario with ndb_restore (for example) where the metadata of NDB tables belonging to a schema that does not exist in the DD was restored. In such situations, the user had to manually create the schema in order for the auto sync mechanism to detect and synchronize tables belonging to that particular schema - This WL extends the auto sync mechanism to ensure that this scenario, i.e. where the schema is being used in NDB Dictionary and does not exist in the DD, is handled by creating the schema in the DD with default settings - Auto sync of schemata differs a bit from logfile groups, tablespaces, and tables in the sense that only the above scenario is handled and that a schema is never removed from the DD. The rest of the behaviour is in line with that of the other types of metadata objects in terms of blacklisting, GSL protection, and so on as detailed in WL#11913 and WL#11914 Change-Id: I828710a95f7c1f6a931d0ead9b8fdcf7df7d5a6f
1 parent e3fa141 commit 6c2abd1

18 files changed

+805
-219
lines changed

mysql-test/suite/ndb_ddl/metadata_sync.result

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,111 @@ DROP DATAFILE 'ts2_datafile.dat';
126126
DROP TABLESPACE ts2;
127127
DROP LOGFILE GROUP lg1
128128
ENGINE NDB;
129+
CREATE DATABASE db1;
130+
USE db1;
131+
CREATE TABLE t1_ndb (
132+
a INT PRIMARY KEY,
133+
b INT
134+
) ENGINE NDB;
135+
CREATE TABLE t2_ndb (
136+
a INT PRIMARY KEY,
137+
b VARCHAR(255)
138+
) ENGINE NDB;
139+
CREATE DATABASE db2;
140+
USE db2;
141+
CREATE TABLE t1_ndb (
142+
a INT PRIMARY KEY,
143+
b INT
144+
) ENGINE NDB;
145+
CREATE TABLE t2_ndb (
146+
a INT PRIMARY KEY,
147+
b VARCHAR(255)
148+
) ENGINE NDB;
149+
CREATE DATABASE db3;
150+
USE db3;
151+
CREATE TABLE t1_innodb (
152+
a INT PRIMARY KEY,
153+
b INT
154+
);
155+
CREATE TABLE t2_innodb (
156+
a INT PRIMARY KEY,
157+
b VARCHAR(255)
158+
);
159+
CREATE DATABASE db4;
160+
USE db4;
161+
CREATE TABLE t1_ndb (
162+
a INT PRIMARY KEY,
163+
b INT
164+
) ENGINE NDB;
165+
CREATE TABLE t2_ndb (
166+
a INT PRIMARY KEY,
167+
b VARCHAR(255)
168+
) ENGINE NDB;
169+
CREATE TABLE t1_innodb (
170+
a INT PRIMARY KEY,
171+
b INT
172+
);
173+
CREATE TABLE t2_innodb (
174+
a INT PRIMARY KEY,
175+
b VARCHAR(255)
176+
);
177+
DROP DATABASE db1;
178+
DROP DATABASE db4;
179+
SHOW DATABASES LIKE 'db%';
180+
Database (db%)
181+
db1
182+
db2
183+
db3
184+
db4
185+
USE db1;
186+
SHOW TABLES;
187+
Tables_in_db1
188+
t1_ndb
189+
t2_ndb
190+
SHOW CREATE TABLE t1_ndb;
191+
Table Create Table
192+
t1_ndb CREATE TABLE `t1_ndb` (
193+
`a` int(11) NOT NULL,
194+
`b` int(11) DEFAULT NULL,
195+
PRIMARY KEY (`a`)
196+
) ENGINE=ndbcluster DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='NDB_TABLE=READ_BACKUP=1'
197+
SHOW CREATE TABLE t2_ndb;
198+
Table Create Table
199+
t2_ndb CREATE TABLE `t2_ndb` (
200+
`a` int(11) NOT NULL,
201+
`b` varchar(255) DEFAULT NULL,
202+
PRIMARY KEY (`a`)
203+
) ENGINE=ndbcluster DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='NDB_TABLE=READ_BACKUP=1'
204+
USE db2;
205+
SHOW TABLES;
206+
Tables_in_db2
207+
t1_ndb
208+
t2_ndb
209+
USE db3;
210+
SHOW TABLES;
211+
Tables_in_db3
212+
t1_innodb
213+
t2_innodb
214+
USE db4;
215+
SHOW TABLES;
216+
Tables_in_db4
217+
t1_ndb
218+
t2_ndb
219+
SHOW CREATE TABLE t1_ndb;
220+
Table Create Table
221+
t1_ndb CREATE TABLE `t1_ndb` (
222+
`a` int(11) NOT NULL,
223+
`b` int(11) DEFAULT NULL,
224+
PRIMARY KEY (`a`)
225+
) ENGINE=ndbcluster DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='NDB_TABLE=READ_BACKUP=1'
226+
SHOW CREATE TABLE t2_ndb;
227+
Table Create Table
228+
t2_ndb CREATE TABLE `t2_ndb` (
229+
`a` int(11) NOT NULL,
230+
`b` varchar(255) DEFAULT NULL,
231+
PRIMARY KEY (`a`)
232+
) ENGINE=ndbcluster DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='NDB_TABLE=READ_BACKUP=1'
233+
DROP DATABASE db1;
234+
DROP DATABASE db2;
235+
DROP DATABASE db3;
236+
DROP DATABASE db4;

mysql-test/suite/ndb_ddl/metadata_sync.test

Lines changed: 137 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
--source suite/ndb/include/backup_restore_setup.inc
33

44
#
5-
# Basic schema detection + synchronization test
5+
# Case 1: Basic schema detection + synchronization test
66
# - Cause mismatch between NDB Dictionary and DD
77
# - Check if these mismatches are detected properly by
88
# Ndb_metadata_change_monitor thread
@@ -197,5 +197,141 @@ DROP TABLESPACE ts2;
197197
DROP LOGFILE GROUP lg1
198198
ENGINE NDB;
199199

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;
200336
--source suite/ndb/include/backup_restore_cleanup.inc
201337
--remove_file $NDB_TOOLS_OUTPUT

mysql-test/suite/ndb_ddl/metadata_sync_debug.result

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,17 @@ a INT PRIMARY KEY,
8686
b VARCHAR(255)
8787
) ENGINE NDB;
8888
INSERT INTO t4 VALUES(1, 'Hey Rino Anto');
89+
CREATE DATABASE db1;
90+
CREATE TABLE db1.t1 (
91+
a INT PRIMARY KEY,
92+
b VARCHAR(255)
93+
) ENGINE NDB;
94+
INSERT INTO db1.t1 VALUES
95+
(1, 'Weasley'),
96+
(2, 'Is Our'),
97+
(3, 'King');
8998
DROP TABLE t1,t2,t3,t4;
99+
DROP DATABASE db1;
90100
CREATE TABLE t5 (
91101
a INT PRIMARY KEY,
92102
b VARCHAR(255)
@@ -99,9 +109,11 @@ SET GLOBAL ndb_metadata_check = @old_ndb_metadata_check;
99109
SET GLOBAL ndb_metadata_check_interval = @old_ndb_metadata_check_interval;
100110
SHOW STATUS LIKE 'Ndb_metadata_blacklist_size';
101111
Variable_name Value
102-
Ndb_metadata_blacklist_size 5
112+
Ndb_metadata_blacklist_size 6
103113
SET GLOBAL ndb_metadata_check_interval = 0;
104114
SET GLOBAL ndb_metadata_check = true;
115+
SET GLOBAL ndb_metadata_check = @old_ndb_metadata_check;
116+
SET GLOBAL ndb_metadata_check_interval = @old_ndb_metadata_check_interval;
105117
SELECT * FROM t1;
106118
a b
107119
1 Rino
@@ -121,7 +133,16 @@ SELECT * FROM t4;
121133
a b
122134
1 Hey Rino Anto
123135
DROP TABLE IF EXISTS t5;
136+
CREATE DATABASE db1;
137+
SELECT * FROM db1.t1;
138+
a b
139+
1 Weasley
140+
2 Is Our
141+
3 King
142+
SET GLOBAL ndb_metadata_check_interval = 0;
143+
SET GLOBAL ndb_metadata_check = true;
124144
SET GLOBAL ndb_metadata_check = @old_ndb_metadata_check;
125145
SET GLOBAL ndb_metadata_check_interval = @old_ndb_metadata_check_interval;
126146
SET GLOBAL debug = '-d,ndb_metadata_sync_fail';
127147
DROP TABLE t1,t2,t3,t4;
148+
DROP DATABASE db1;

mysql-test/suite/ndb_ddl/metadata_sync_debug.test

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,25 @@ CREATE TABLE t4 (
139139

140140
INSERT INTO t4 VALUES(1, 'Hey Rino Anto');
141141

142+
CREATE DATABASE db1;
143+
CREATE TABLE db1.t1 (
144+
a INT PRIMARY KEY,
145+
b VARCHAR(255)
146+
) ENGINE NDB;
147+
148+
INSERT INTO db1.t1 VALUES
149+
(1, 'Weasley'),
150+
(2, 'Is Our'),
151+
(3, 'King');
152+
142153
# backup
143154
--disable_query_log
144155
--source include/ndb_backup.inc
145156
--enable_query_log
146157

147158
# Drop tables
148159
DROP TABLE t1,t2,t3,t4;
160+
DROP DATABASE db1;
149161

150162
# Restore into NDB
151163
--exec $NDB_RESTORE -b $the_backup_id -n 1 -m -r $NDB_BACKUPS-$the_backup_id >> $NDB_TOOLS_OUTPUT
@@ -172,13 +184,14 @@ CALL mtr.add_suppression("NDB Binlog: Failed to synchronize table");
172184
SET GLOBAL ndb_metadata_check_interval = 0;
173185
SET GLOBAL ndb_metadata_check = true;
174186

175-
# Wait until the following 5 object changes are detected:
187+
# Wait until the following 6 object changes are detected:
188+
# Schema 'db1'
176189
# Table 'ndb_ddl_test.t1'
177190
# Table 'ndb_ddl_test.t2'
178191
# Table 'ndb_ddl_test.t3'
179192
# Table 'ndb_ddl_test.t4'
180193
# Table 'ndb_ddl_test.t5'
181-
--let $expected_changes = 5
194+
--let $expected_changes = 6
182195
--let $max_wait = 60
183196
--source wait_metadata_changes_detected.inc
184197

@@ -209,6 +222,10 @@ if ($current_changes_detected != $initial_detected_count)
209222
--die Changes detected even when objects were blacklisted
210223
}
211224

225+
# Reset values
226+
SET GLOBAL ndb_metadata_check = @old_ndb_metadata_check;
227+
SET GLOBAL ndb_metadata_check_interval = @old_ndb_metadata_check_interval;
228+
212229
# Manually synch the tables through "discovery".
213230
# This will result in the tables being removed from the
214231
# blacklist during the next detection cycle
@@ -221,6 +238,13 @@ SELECT * FROM t3;
221238
--sorted_result
222239
SELECT * FROM t4;
223240
DROP TABLE IF EXISTS t5;
241+
CREATE DATABASE db1;
242+
--sorted_result
243+
SELECT * FROM db1.t1;
244+
245+
# Enable metadata check with no interval to clear the blacklist quickly
246+
SET GLOBAL ndb_metadata_check_interval = 0;
247+
SET GLOBAL ndb_metadata_check = true;
224248

225249
# Wait until the blacklist is empty
226250
--let $max_wait = 30
@@ -233,5 +257,6 @@ SET GLOBAL debug = '-d,ndb_metadata_sync_fail';
233257

234258
# Cleanup
235259
DROP TABLE t1,t2,t3,t4;
260+
DROP DATABASE db1;
236261
--source suite/ndb/include/backup_restore_cleanup.inc
237262
--remove_file $NDB_TOOLS_OUTPUT

0 commit comments

Comments
 (0)