Debian Codegraph @

mysql-test/suite/rpl/t/rpl_row_jsondiff_stress.test

raw
1 # ==== Requirements ====
2 #
3 # Test combinations of updates in multiple columns and multiple rows,
4 # with value updates of the following different kinds:
5 # - Columns of the following types:
6 # - T1. JSON
7 # - T2. INT
8 # - Column values in the following modes:
9 # - Mode of field in before-image:
10 # B1. Not included in image
11 # B2. NULL
12 # B3. Non-NULL
13 # - Mode of field in after-image:
14 # A1. Not included in image
15 # A2. NULL
16 # A3. Full format
17 # A4. Partial format, using zero diffs (not for T2 or B2)
18 # A5. Partial format, using one or more diffs (not for T2 or B2)
19 # - Modes of slave applier accepting the update:
20 # S1. Update succeeds
21 # S2. Column does not exist in slave table
22 # S3. Column exists in slave table but is generated
23 #! S4. Row not found on slave
24 #! S5. Column exists on slave but field is NULL (for T1 + B1 + A4/A5)
25 #! S6. Partial JSON fails to apply due to mismatch on JSON path
26 # (for T1 + A5)
27 #! S7. Partial or full JSON fails due to non-NULL constraint violation
28 # in index on generated column (for T1 + A4/A5)
29 #! S8. Partial or full JSON fails due to uniqueness constraint
30 # violation in index on generated column (for T1 + A4/A5).
31 # - Slave configuration:
32 # C1. partial JSON enabled/disabled
33 # C2. binlog_row_image=MINIMAL/NOBLOB/FULL
34 # C3. slave_rows_search_algorithms=INDEX_SCAN/HASH_SCAN/TABLE_SCAN
35 # C4. replica_exec_mode=idempotent/strict
36 #! C5. replica_skip_errors includes expected error, or not
37
38
39 --source include/have_binlog_format_row.inc
40 # mysqlbinlog.inc with $only_decoded_rows needs have_grep.inc
41 --source include/have_grep.inc
42 --let $rpl_topology= 1->2->3
43 --source include/rpl_init.inc
44 --source include/rpl_default_connections.inc
45
46 --source include/rpl_connection_slave.inc
47 SET @old_binlog_row_image= @@GLOBAL.BINLOG_ROW_IMAGE;
48 SET @old_binlog_row_value_options= @@GLOBAL.BINLOG_ROW_VALUE_OPTIONS;
49 SET @old_slave_rows_search_algorithms= @@GLOBAL.SLAVE_ROWS_SEARCH_ALGORITHMS;
50 SET @old_replica_exec_mode= @@GLOBAL.REPLICA_EXEC_MODE;
51
52 --source include/rpl_connection_master.inc
53 SET @@SESSION.BINLOG_ROW_IMAGE = 'MINIMAL';
54 SET @@SESSION.BINLOG_ROW_VALUE_OPTIONS = 'PARTIAL_JSON';
55
56 # Verbosity. Set to different value for debugging.
57 # 0=quiet, 1=table+update+binlog, 2=decisions, 3=progress
58 if (!$verb) {
59 --let $verb= 0
60 }
61 # Maximum number of scenarios to execute before test ends.
62 if (!$iteration_max) {
63 --let $iteration_max= 200
64 }
65 # Maximum time before test ends.
66 if (!$time_max) {
67 --let $time_max= 60
68 }
69 # Number of columns on master will be randomized.
70 # This sets the min (inclusive) and max (exlusive).
71 if (!$master_column_count_min) {
72 --let $master_column_count_min= 1
73 }
74 if (!$master_column_count_max) {
75 --let $master_column_count_max= 20
76 }
77 # Number of columns on master will be randomized.
78 # This sets the min (inclusive); the max (inclusive) is equal to the
79 # number of columns on master.
80 if (!$slave_column_count_min) {
81 --let $slave_column_count_min= 0
82 }
83 # Number of inserted rows will be randomized.
84 # This sets the min (inclusive) and max (exclusive)
85 if (!$row_count_min) {
86 --let $row_count_min= 1
87 }
88 if (!$row_count_max) {
89 --let $row_count_max= 10
90 }
91
92 --let $dollar_func= CHAR(36)
93 --let $dollar= `SELECT $dollar_func`
94
95 if ($verb<3) {
96 --disable_warnings
97 --disable_query_log
98 --let $include_silent= 1
99 --let $rpl_connection_silent= 1
100 }
101
102 --let $rand_type= init
103 --source include/rand.inc
104
105 if ($verb>=1) { echo # - rand_seed=$rand_seed; }
106
107 if ($verb==3) { echo # Compute statement to compare tables on master and slave; }
108
109 --let $start_time= `SELECT UNIX_TIMESTAMP()`
110 --let $done= 0
111 --let $iteration= 1
112 while (!$done)
113 {
114 if ($verb>=1) { echo ==== $iteration ====; }
115
116 --let $table_def_master= CREATE TABLE t (i INT PRIMARY KEY
117 --let $table_def_slave= CREATE TABLE t (i INT PRIMARY KEY
118 --let $fix=
119 # --let $where= i != 0
120 --let $set=
121 --let $rpl_diff_statement= SELECT i
122
123 --source include/rpl_connection_slave.inc
124
125 if ($verb==3) { echo # Decide master_column_count; }
126 --let $rand_type= int
127 --let $rand_min= $master_column_count_min
128 --let $rand_max= $master_column_count_max
129 --source include/rand.inc
130 --let $master_column_count= $rand
131 if ($verb>=2) { echo # - master_column_count=$master_column_count; }
132
133 if ($verb==3) { echo # Decide slave_column_count; }
134 if ($slave_column_count_min >= $master_column_count)
135 {
136 --let $slave_column_count= $master_column_count
137 }
138 if ($slave_column_count_min < $master_column_count)
139 {
140 --let $rand_type= int
141 --let $rand_min= $slave_column_count_min
142 # 0.5 probability that slave_column_count==master_column_count;
143 # 0.5 probability that slave_column_count_min<=slave_column_count<master_column_count
144 --let $rand_max= $master_column_count + ($master_column_count - $slave_column_count_min)
145 --source include/rand.inc
146 if ($rand <= $master_column_count) {
147 --let $slave_column_count= $rand
148 }
149 if ($rand > $master_column_count) {
150 --let $slave_column_count= $master_column_count
151 }
152 }
153 if ($verb>=2) { echo # - slave_column_count=$slave_column_count; }
154
155 if ($verb==3) { echo # Decide row_count; }
156 --let $rand_type= int
157 --let $rand_min= $row_count_min
158 --let $rand_max= $row_count_max
159 --source include/rand.inc
160 --let $row_count= $rand
161 if ($verb>=2) { echo # - row_count=$row_count; }
162
163 if ($verb==3) { echo # Decide binlog_row_value_options; }
164 --let $rand_type= decide
165 --let $rand_probability= 0.5
166 --source include/rand.inc
167 --let $partial_json=$rand
168 if ($verb>=2) { echo # - partial_json=$partial_json; }
169 if ($verb>=1) { enable_query_log; }
170 if ($partial_json) {
171 SET @@GLOBAL.BINLOG_ROW_VALUE_OPTIONS = 'PARTIAL_JSON';
172 }
173 if (!$partial_json) {
174 SET @@GLOBAL.BINLOG_ROW_VALUE_OPTIONS = '';
175 }
176
177 if ($verb==3) { echo # Decide binlog_row_image; }
178 --let $rand_type= int
179 --let $rand_min= 0
180 --let $rand_max= 3
181 --source include/rand.inc
182 --let $binlog_row_image=$rand
183 if ($verb>=2) { echo # - binlog_row_image=$binlog_row_image; }
184 if ($binlog_row_image == 0) {
185 SET @@GLOBAL.BINLOG_ROW_IMAGE = 'MINIMAL';
186 }
187 if ($binlog_row_image == 1) {
188 SET @@GLOBAL.BINLOG_ROW_IMAGE = 'NOBLOB';
189 }
190 if ($binlog_row_image == 2) {
191 SET @@GLOBAL.BINLOG_ROW_IMAGE = 'FULL';
192 }
193
194 if ($verb==3) { echo # Decide slave_rows_search_algorithms; }
195 --let $rand_type= int
196 --let $rand_min= 0
197 --let $rand_max= 3
198 --source include/rand.inc
199 --let $slave_rows_search_algorithms=$rand
200 if ($verb>=2) { echo # - slave_rows_search_algorithms=$slave_rows_search_algorithms; }
201 if ($slave_rows_search_algorithms == 0) {
202 SET @@GLOBAL.SLAVE_ROWS_SEARCH_ALGORITHMS = 'INDEX_SCAN,HASH_SCAN';
203 }
204 if ($slave_rows_search_algorithms == 1) {
205 SET @@GLOBAL.SLAVE_ROWS_SEARCH_ALGORITHMS = 'INDEX_SCAN,TABLE_SCAN';
206 }
207 if ($slave_rows_search_algorithms == 2) {
208 SET @@GLOBAL.SLAVE_ROWS_SEARCH_ALGORITHMS = 'HASH_SCAN,TABLE_SCAN';
209 }
210
211 if ($verb==3) { echo # Decide replica_exec_mode; }
212 --let $rand_type= decide
213 --let $rand_probability= 0.5
214 --source include/rand.inc
215 --let $idempotent=$rand
216 if ($verb>=2) { echo # - idempotent=$idempotent; }
217 if ($idempotent) {
218 SET @@GLOBAL.REPLICA_EXEC_MODE = 'IDEMPOTENT';
219 }
220 if (!$idempotent) {
221 SET @@GLOBAL.REPLICA_EXEC_MODE = 'STRICT';
222 }
223
224 if ($verb<3) { disable_query_log; }
225
226 --source include/rpl_connection_master.inc
227
228 --let $col_i= 1
229 while ($col_i <= $master_column_count)
230 {
231 if ($verb==3) { echo ---- c$col_i ----; }
232
233 if ($verb==3) { echo # Decide JSON or INT; }
234 --let $rand_type= decide
235 --let $rand_probability= 0.75
236 --source include/rand.inc
237 if (!$rand) {
238 --let $col_type= INT
239 }
240 if ($rand) {
241 --let $col_type= JSON
242 }
243 --let $table_def_master= $table_def_master, c$col_i $col_type
244 if ($col_i <= $slave_column_count) {
245 --let $table_def_slave= $table_def_slave, c$col_i $col_type
246 }
247 if ($verb>=2) { echo # - col_type=$col_type; }
248
249 if ($col_i <= $slave_column_count) {
250 if ($verb==3) { echo # Decide generated on slave or not; }
251 --let $rand_type= int
252 --let $rand_min= 0
253 --let $rand_max= 4
254 --source include/rand.inc
255 --let $generated= $rand
256 # Disable generated columns due to BUG#26283971
257 --let $generated= 9
258 if ($verb>=2) { echo # - generated=$generated; }
259 if ($generated < 2) {
260 if ($col_type == JSON) {
261 --let $gcol_def= CAST(CONCAT('[', i + 1, ']') AS JSON)
262 }
263 if ($col_type == INT) {
264 --let $gcol_def= i + 1
265 }
266 --let $table_def_slave= $table_def_slave AS ($gcol_def)
267 if ($generated == 0) {
268 --let $table_def_slave= $table_def_slave VIRTUAL
269 }
270 if ($generated == 1) {
271 --let $table_def_slave= $table_def_slave STORED
272 }
273 }
274 # Compare non-generated columns between master and slave
275 if ($generated >= 2) {
276 --let $rpl_diff_statement= $rpl_diff_statement, c$col_i
277 }
278 }
279
280 # Doesn't work - this won't put it in the BI
281 if (0) {
282 if ($verb==3) { echo # Decide if in BI or not; }
283 --let $rand_type= decide
284 --let $rand_probability= 0.5
285 --source include/rand.inc
286 --let $in_bi= $rand
287 if ($in_bi) {
288 --let $where= $where OR (c$col_i + NULL) IS NULL
289 }
290 if ($verb>=2) { echo # - in_bi=$in_bi; }
291 }
292
293 if ($verb==3) { echo # Decide if in AI or not; }
294 --let $rand_type= decide
295 --let $rand_probability= 0.75
296 --source include/rand.inc
297 --let $in_ai= $rand
298 if ($verb>=2) { echo # - in_ai=$in_ai; }
299
300 if ($verb==3) { echo # Decide if update uses JSON function or just sets the value; }
301 --let $use_json_func= 0
302 if ($in_ai) {
303 if ($col_type == JSON) {
304 --let $rand_type= decide
305 --let $rand_probability= 0.666666
306 --source include/rand.inc
307 --let $use_json_func= $rand
308 }
309 }
310 if ($verb>=2) { echo # - use_json_func=$use_json_func; }
311
312 --let $null_rows= 0
313
314 --let $row_i= 1
315 while ($row_i <= $row_count)
316 {
317 if ($verb==3) { echo -- r$row_i --; }
318 if ($verb==3) { echo # Decide mode of BI; }
319 --let $rand_type= decide
320 --let $rand_probability= 0.8
321 --source include/rand.inc
322 # 0=NULL 1=VALUE
323 --let $bi_type= $rand
324 if ($verb>=2) { echo # - bi_type=$bi_type; }
325
326 if ($verb==3) { echo # Decide mode of AI; }
327 if ($in_ai)
328 {
329 --let $rand_type= int
330 --let $ai_type= -1
331 if ($use_json_func) {
332 if ($bi_type == 0) {
333 --let $ai_type= 0
334 }
335 if ($bi_type == 1) {
336 --let $rand_min= 0
337 --let $rand_max= 4
338 --let $rant_type= int
339 --source include/rand.inc
340 --let $ai_type= $rand
341 }
342 }
343 if (!$use_json_func) {
344 --let $rand_type= int
345 --let $rand_min= 0
346 --let $rand_max= 3
347 --source include/rand.inc
348 --let $ai_type= $rand
349 }
350 if ($verb>=2) { echo # - ai_type=$ai_type; }
351
352 if ($verb==3) { echo # Add to NULL rows; }
353 if ($ai_type == 0) {
354 # NULL
355 --let $null_rows= $null_rows, $row_i
356 }
357
358 if ($verb==3) { echo # Set before-value; }
359 if ($bi_type == 1) {
360 if ($ai_type <= 1) {
361 # NULL, FULL
362 if ($col_type == INT) {
363 --let $fix= $fix UPDATE t SET c$col_i = 1 WHERE i = $row_i;
364 }
365 if ($col_type == JSON) {
366 --let $fix= $fix UPDATE t SET c$col_i = '[1]' WHERE i = $row_i;
367 }
368 }
369 if ($ai_type == 2) {
370 # NOP
371 if ($col_type == INT) {
372 --let $fix= $fix UPDATE t SET c$col_i = 2 WHERE i = $row_i;
373 }
374 if ($col_type == JSON) {
375 --let $fix= $fix UPDATE t SET c$col_i = '[2]' WHERE i = $row_i;
376 }
377 }
378 if ($ai_type == 3) {
379 # PARTIAL
380 --let $fix= $fix UPDATE t SET c$col_i = '[1, "long string in col $col_i, row $row_i"]' WHERE i = $row_i;
381 }
382 }
383 }
384 if (!$in_ai) {
385 if ($bi_type == 1) {
386 if ($col_type == INT) {
387 --let $fix= $fix UPDATE t SET c$col_i = 1 WHERE i = $row_i;
388 }
389 if ($col_type == JSON) {
390 --let $fix= $fix UPDATE t SET c$col_i = '[1]' WHERE i = $row_i;
391 }
392 }
393 }
394
395 --inc $row_i
396 }
397
398 if ($in_ai) {
399 if ($set) {
400 --let $set= $set,
401 }
402 if ($use_json_func) {
403 --let $set= $set c$col_i = JSON_SET(c$col_i, '$dollar[0]', 'astring', IF(i IN ($null_rows), NULL, '$dollar[0]'), 2)
404 }
405 if (!$use_json_func) {
406 if ($col_type == INT) {
407 --let $set= $set c$col_i = IF(i IN ($null_rows), NULL, 2)
408 }
409 if ($col_type == JSON) {
410 --let $set= $set c$col_i = IF(i IN ($null_rows), NULL, '[2]')
411 }
412 }
413 }
414
415 --inc $col_i
416 }
417
418 --let $table_def_master= $table_def_master)
419 --let $table_def_slave= $table_def_slave)
420 --let $rpl_diff_statement= $rpl_diff_statement FROM t ORDER BY i
421
422 if ($verb>=1) {
423 --echo master: $table_def_master
424 --echo slave: $table_def_slave
425 }
426 if ($verb>=2) {
427 --echo # fix=[$fix]
428 --echo # set=[$set]
429 #--echo # where=[$where]
430 --echo # rpl_diff_statement=[$rpl_diff_statement]
431 }
432
433 if (!$set)
434 {
435 if ($verb>=1) { echo # No SET clause - skipping scenario; }
436 }
437 if ($set)
438 {
439 if ($verb==3) { echo # Create and populate table; }
440 --source include/rpl_connection_master.inc
441 SET SQL_LOG_BIN = 0;
442 eval $table_def_master;
443 SET SQL_LOG_BIN = 1;
444 --source include/rpl_connection_slave.inc
445 eval $table_def_slave;
446 --source include/rpl_connection_master.inc
447 BEGIN;
448 --let $row_i= 1
449 while ($row_i <= $row_count)
450 {
451 eval INSERT INTO t(i) VALUES ($row_i);
452 --inc $row_i
453 }
454 if ($fix)
455 {
456 --eval $fix
457 }
458 COMMIT;
459
460 if ($verb>=1) { SELECT * FROM t; }
461
462 if ($verb==3) { echo # Replicate, reset binlogs, reset replication, pickup new slave config; }
463
464 --source include/rpl_sync.inc
465
466 --source include/rpl_connection_master.inc
467 RESET MASTER;
468
469 --source include/rpl_connection_slave.inc
470 --source include/stop_slave.inc
471 RESET MASTER;
472 RESET SLAVE;
473 --source include/start_slave.inc
474
475 --let $rpl_connection_name=server_3
476 --source include/rpl_connection.inc
477 --source include/stop_slave.inc
478 RESET MASTER;
479 RESET SLAVE;
480 --source include/start_slave.inc
481
482 --source include/rpl_connection_master.inc
483 --source include/save_binlog_position.inc
484
485 if ($verb==3) { echo # Execute UPDATE; }
486 --let $statement= UPDATE t SET $set
487 if ($verb>=1) { echo $statement; }
488 eval $statement;
489
490 if ($verb==3) { echo # See decoded rows; }
491 if ($verb>=1) {
492 --let $mysqlbinlog_only_decoded_rows= 1
493 --let $mysqlbinlog_allow_error= 1
494 --source include/mysqlbinlog.inc
495 }
496
497 --source include/rpl_sync.inc
498 --source include/rpl_diff.inc
499
500 DROP TABLE t;
501 --source include/rpl_sync.inc
502 }
503
504 --inc $iteration
505 if ($iteration_max) {
506 if ($iteration > $iteration_max) {
507 --let $done= 1
508 }
509 }
510 if ($time_max) {
511 if (`SELECT UNIX_TIMESTAMP() - $start_time >= $time_max`) {
512 --let $done= 1
513 }
514 }
515 }
516
517 --source include/rpl_connection_slave.inc
518 --enable_query_log
519 SET @@GLOBAL.BINLOG_ROW_IMAGE= @old_binlog_row_image;
520 SET @@GLOBAL.BINLOG_ROW_VALUE_OPTIONS= @old_binlog_row_value_options;
521 SET @@GLOBAL.SLAVE_ROWS_SEARCH_ALGORITHMS= @old_slave_rows_search_algorithms;
522 SET @@GLOBAL.REPLICA_EXEC_MODE= @old_replica_exec_mode;
523
524 --disable_query_log
525
526 if ($verb < 3) {
527 --enable_warnings
528 }
529
530 --source include/rpl_end.inc