Debian Codegraph @

mysql-test/suite/ndb_ddl/metadata_sync_debug.test

raw
1 --source connect.inc
2 --source include/have_debug.inc
3 --source suite/ndb/include/backup_restore_setup.inc
4
5 #
6 # Schema detection + synchronization test
7 # This test contains all the cases that require debug options to be
8 # set in order to cause mismatches between NDB Dictionary and DD.
9 #
10
11 #
12 # Case 1:
13 # - Logfile group exists in DD but not NDB
14 # - Tablespace exists in DD but not NDB
15 #
16
17 SET GLOBAL debug = '+d,ndb_dd_client_lfg_force_commit,ndb_schema_trans_commit_fail,ndb_skip_create_tablespace_in_NDB';
18
19 SET @old_ndb_metadata_check = @@global.ndb_metadata_check;
20 SET @old_ndb_metadata_check_interval = @@global.ndb_metadata_check_interval;
21
22 --let $initial_detected_count = query_get_value(SHOW STATUS LIKE 'Ndb_metadata_detected_count', Value, 1)
23 --let $initial_synced_count = query_get_value(SHOW STATUS LIKE 'Ndb_metadata_synced_count', Value, 1)
24
25 CREATE LOGFILE GROUP lg1
26 ADD UNDOFILE 'lg1_undofile.dat'
27 INITIAL_SIZE 1M
28 UNDO_BUFFER_SIZE = 1M
29 ENGINE NDB;
30
31 CREATE TABLESPACE ts1
32 ADD DATAFILE 'ts1_datafile.dat'
33 USE LOGFILE GROUP lg1
34 INITIAL_SIZE 2M
35 ENGINE NDB;
36
37 SET GLOBAL debug = '-d,ndb_dd_client_lfg_force_commit,ndb_schema_trans_commit_fail,ndb_skip_create_tablespace_in_NDB';
38
39 # Enable metadata check with no interval so changes are detected quickly
40 SET GLOBAL ndb_metadata_check_interval = 0;
41 SET GLOBAL ndb_metadata_check = true;
42
43 # Wait until 2 mismatches (lg1 and ts1) are detected
44 --let $expected_changes = 2
45 --let $max_wait = 30
46 --source wait_metadata_changes_detected.inc
47
48 # Reset values
49 SET GLOBAL ndb_metadata_check = @old_ndb_metadata_check;
50 SET GLOBAL ndb_metadata_check_interval = @old_ndb_metadata_check_interval;
51
52 # Wait until the changes detected have been synced
53 --let $max_wait = 30
54 --source wait_metadata_synced.inc
55
56 # Check if the tablespace and logfile group have been removed from DD
57 CREATE LOGFILE GROUP lg1
58 ADD UNDOFILE 'lg1_undofile.dat'
59 INITIAL_SIZE 1M
60 UNDO_BUFFER_SIZE = 1M
61 ENGINE NDB;
62
63 CREATE TABLESPACE ts1
64 ADD DATAFILE 'ts1_datafile.dat'
65 USE LOGFILE GROUP lg1
66 INITIAL_SIZE 2M
67 ENGINE NDB;
68 ALTER TABLESPACE ts1
69 ADD DATAFILE 'ts1_datafile2.dat';
70 CREATE TABLE t1 (
71 a INT PRIMARY KEY,
72 b INT
73 ) ENGINE NDB
74 TABLESPACE ts1
75 STORAGE DISK;
76 INSERT INTO t1 VALUES(1,1);
77 SELECT * FROM t1;
78
79 CREATE TABLESPACE ts2
80 ADD DATAFILE 'ts2_datafile.dat'
81 USE LOGFILE GROUP lg1
82 INITIAL_SIZE 2M
83 ENGINE NDB;
84
85 # Cleanup
86 DROP TABLE t1;
87 ALTER TABLESPACE ts1
88 DROP DATAFILE 'ts1_datafile.dat';
89 ALTER TABLESPACE ts1
90 DROP DATAFILE 'ts1_datafile2.dat';
91 DROP TABLESPACE ts1;
92 ALTER TABLESPACE ts2
93 DROP DATAFILE 'ts2_datafile.dat';
94 DROP TABLESPACE ts2;
95 DROP LOGFILE GROUP lg1
96 ENGINE NDB;
97
98 #
99 # Case 2:
100 # Check if the failure to sync objects is handled as expected. This involves
101 # the exclusion of objects from sync. While these objects are excluded, they
102 # shall not be detected.
103 #
104
105 CREATE TABLE t1 (
106 a INT PRIMARY KEY,
107 b VARCHAR(255)
108 ) ENGINE NDB;
109
110 INSERT INTO t1 VALUES
111 (1, 'Rino'),
112 (2, 'Rino'),
113 (3, 'Rino Anto');
114
115 CREATE TABLE t2 (
116 a INT PRIMARY KEY,
117 b VARCHAR(255)
118 ) ENGINE NDB;
119
120 INSERT INTO t2 VALUES
121 (4, 'Rino'),
122 (5, 'Rino'),
123 (6, 'Rino Anto');
124
125 CREATE TABLE t3 (
126 a INT PRIMARY KEY,
127 b VARCHAR(255)
128 ) ENGINE NDB;
129
130 INSERT INTO t3 VALUES
131 (7, 'Rino'),
132 (8, 'Rino'),
133 (9, 'Rino Anto');
134
135 CREATE TABLE t4 (
136 a INT PRIMARY KEY,
137 b VARCHAR(255)
138 ) ENGINE NDB;
139
140 INSERT INTO t4 VALUES(1, 'Hey Rino Anto');
141
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
153 # backup
154 --disable_query_log
155 --source include/ndb_backup.inc
156 --enable_query_log
157
158 # Drop tables
159 DROP TABLE t1,t2,t3,t4;
160 DROP DATABASE db1;
161
162 # Restore into NDB
163 --exec $NDB_RESTORE -b $the_backup_id -n 1 -m -r $NDB_BACKUPS-$the_backup_id >> $NDB_TOOLS_OUTPUT
164 --exec $NDB_RESTORE -b $the_backup_id -n 2 -r $NDB_BACKUPS-$the_backup_id >> $NDB_TOOLS_OUTPUT
165
166 CREATE TABLE t5 (
167 a INT PRIMARY KEY,
168 b VARCHAR(255)
169 ) ENGINE NDB;
170
171 # Drop table from NDB only to cause mismatch
172 --exec $NDB_DROP_TABLE -d test t5 >> $NDB_TOOLS_OUTPUT
173
174 # Store initial counts of both detected and synchronized objects
175 --let $initial_detected_count = query_get_value(SHOW STATUS LIKE 'Ndb_metadata_detected_count', Value, 1)
176 --let $initial_synced_count = query_get_value(SHOW STATUS LIKE 'Ndb_metadata_synced_count', Value, 1)
177
178 # Force synch to fail
179 SET GLOBAL debug = '+d,ndb_metadata_sync_fail';
180 # Suppress error
181 --disable_query_log ONCE
182 CALL mtr.add_suppression("Binlog: Failed to synchronize table");
183
184 # Enable metadata check with no interval so changes are detected quickly
185 SET GLOBAL ndb_metadata_check_interval = 0;
186 SET GLOBAL ndb_metadata_check = true;
187
188 # Wait until the following 6 object changes are detected:
189 # Schema 'db1'
190 # Table 'ndb_ddl_test.t1'
191 # Table 'ndb_ddl_test.t2'
192 # Table 'ndb_ddl_test.t3'
193 # Table 'ndb_ddl_test.t4'
194 # Table 'ndb_ddl_test.t5'
195 --let $expected_changes = 6
196 --let $max_wait = 60
197 --source wait_metadata_changes_detected.inc
198
199 # Reset values
200 SET GLOBAL ndb_metadata_check = @old_ndb_metadata_check;
201 SET GLOBAL ndb_metadata_check_interval = @old_ndb_metadata_check_interval;
202
203 # Wait until the changes detected have been synced
204 --let $max_wait = 60
205 --source wait_metadata_synced.inc
206
207 # Verify that the objects have been excluded
208 SHOW STATUS LIKE 'Ndb_metadata_excluded_count';
209 --sorted_result
210 SELECT * FROM performance_schema.ndb_sync_excluded_objects;
211
212 # Sleep for some time to let a couple of cycles of detection
213 # occur. Since the objects have been excluded, the mismatches
214 # should not be detected and the number of changes detected
215 # should remain unchanged
216 --let $initial_detected_count = query_get_value(SHOW STATUS LIKE 'Ndb_metadata_detected_count', Value, 1)
217 # Enable metadata check with no interval so changes are detected quickly
218 SET GLOBAL ndb_metadata_check_interval = 0;
219 SET GLOBAL ndb_metadata_check = true;
220 --sleep 5
221 --let $current_changes_detected = query_get_value(SHOW STATUS LIKE 'Ndb_metadata_detected_count', Value, 1)
222 if ($current_changes_detected != $initial_detected_count)
223 {
224 --echo $current_changes_detected changes detected when $initial_detected_count changes were expected
225 --die Changes detected even when objects were excluded
226 }
227
228 # Reset values
229 SET GLOBAL ndb_metadata_check = @old_ndb_metadata_check;
230 SET GLOBAL ndb_metadata_check_interval = @old_ndb_metadata_check_interval;
231
232 # Manually sync the tables through "discovery".
233 # This will result in the tables being no longer
234 # excluded during the next detection cycle
235 --sorted_result
236 SELECT * FROM t1;
237 --sorted_result
238 SELECT * FROM t2;
239 --sorted_result
240 SELECT * FROM t3;
241 --sorted_result
242 SELECT * FROM t4;
243 DROP TABLE IF EXISTS t5;
244 CREATE DATABASE db1;
245 --sorted_result
246 SELECT * FROM db1.t1;
247
248 # Enable metadata check with no interval to clear the excluded objects
249 # list quickly
250 SET GLOBAL ndb_metadata_check_interval = 0;
251 SET GLOBAL ndb_metadata_check = true;
252
253 # Wait until the objects are no longer excluded
254 --let $max_wait = 30
255 --source wait_metadata_sync_zero_excluded.inc
256 SELECT COUNT(*) FROM performance_schema.ndb_sync_excluded_objects;
257
258 # Reset values
259 SET GLOBAL ndb_metadata_check = @old_ndb_metadata_check;
260 SET GLOBAL ndb_metadata_check_interval = @old_ndb_metadata_check_interval;
261 SET GLOBAL debug = '-d,ndb_metadata_sync_fail';
262
263 # Cleanup
264 DROP TABLE t1,t2,t3,t4;
265 DROP DATABASE db1;
266 --source suite/ndb/include/backup_restore_cleanup.inc
267 --remove_file $NDB_TOOLS_OUTPUT