summaryrefslogtreecommitdiff
path: root/mysql-test/suite/innodb/t/innodb-wl5522-debug-zip.test
blob: 80aa8f558fd2569a745f8ab4a00f1eddf7b6543d (plain)
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
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
# Not supported in embedded
--source include/not_embedded.inc

# This test case needs to crash the server. Needs a debug server.
--source include/have_debug.inc

# Don't test this under valgrind, memory leaks will occur.
--source include/not_valgrind.inc

# Avoid CrashReporter popup on Mac
--source include/not_crashrep.inc

-- source include/have_innodb.inc

# compressed table in tests are with sizes KEY_BLOCK_SIZE 1,2,4,8,16 
# Table creatation fails if KEY_BLOCK_SIZE > innodb-page-size,so 
# allow test to run only when innodb-page-size=16  
--source include/have_innodb_16k.inc

call mtr.add_suppression("InnoDB: Page for tablespace .* ");
FLUSH TABLES;

let MYSQLD_DATADIR =`SELECT @@datadir`;
let $innodb_file_per_table = `SELECT @@innodb_file_per_table`;
let $innodb_file_format = `SELECT @@innodb_file_format`;
let $innodb_strict_mode_orig=`select @@session.innodb_strict_mode`;
let $pathfix=/: '.*test_wl5522.*t1.ibd'/: 'test_wl5522_t1.ibd'/;

SET GLOBAL innodb_file_per_table = 1;
SELECT @@innodb_file_per_table;

SET GLOBAL innodb_file_format = `Barracuda`;
SELECT @@innodb_file_format;

SET SESSION innodb_strict_mode=1;
SELECT @@SESSION.innodb_strict_mode;



DROP DATABASE IF EXISTS test_wl5522;
CREATE DATABASE test_wl5522;

# Create the table that we will use for crash recovery (during IMPORT)
CREATE TABLE test_wl5522.t1 (c1 INT) ENGINE = Innodb
ROW_FORMAT=COMPRESSED;
INSERT INTO test_wl5522.t1 VALUES (1), (2), (3), (4);

--replace_regex /, .*\).*t1.cfg/, Bad file descriptor) t1.cfg/

FLUSH TABLES test_wl5522.t1 FOR EXPORT;

perl;
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
ib_backup_tablespaces("test_wl5522", "t1");
EOF
UNLOCK TABLES;

DROP TABLE test_wl5522.t1;

CREATE TABLE test_wl5522.t1 (c1 INT) ENGINE = Innodb
ROW_FORMAT=COMPRESSED;
INSERT INTO test_wl5522.t1 VALUES (1);

ALTER TABLE test_wl5522.t1 DISCARD TABLESPACE;

perl;
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
ib_discard_tablespaces("test_wl5522", "t1");
EOF

--error ER_TABLESPACE_DISCARDED
SELECT COUNT(*) FROM test_wl5522.t1;

# Restore files
perl;
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
ib_restore_tablespaces("test_wl5522", "t1");
EOF

##### Before commit crash
SET SESSION debug_dbug="+d,ib_import_before_commit_crash";

--error ER_TABLESPACE_DISCARDED
SELECT * FROM test_wl5522.t1;

# Write file to make mysql-test-run.pl start up the server again
--exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect

# Execute the statement that causes the crash
--error 2013
ALTER TABLE test_wl5522.t1 IMPORT TABLESPACE;

--enable_reconnect
--source include/wait_until_connected_again.inc
--disable_reconnect

SET SESSION debug_dbug="-d,ib_import_before_commit_crash";
#### Before commit crash

# Check that the DD is consistent after recovery

##### Before checkpoint crash
SET SESSION debug_dbug="+d,ib_import_before_checkpoint_crash";

--error ER_TABLESPACE_DISCARDED
SELECT COUNT(*) FROM test_wl5522.t1;

# Don't start up the server right away.
--exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect

# Execute the statement that causes the crash
--error 2013
ALTER TABLE test_wl5522.t1 IMPORT TABLESPACE;

# After the above test the results are non-deterministic,
# delete the old tablespace files and drop the table,
# recreate the table and do a proper import.
-- source include/wait_until_disconnected.inc
perl;
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
ib_unlink_tablespace("test_wl5522", "t1");
EOF

--echo # Restart and reconnect to the server
--enable_reconnect
--exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
--source include/wait_until_connected_again.inc
--disable_reconnect

SET SESSION debug_dbug="-d,ib_import_before_checkpoint_crash";
#### Before checkpoint crash

# After the above test the results are non-deterministic, recreate the table
# and do a proper import.

DROP TABLE test_wl5522.t1;

SET GLOBAL innodb_file_per_table = 1;
SELECT @@innodb_file_per_table;

SET GLOBAL innodb_file_format = `Barracuda`;
SELECT @@innodb_file_format;

SET SESSION innodb_strict_mode=1;
SELECT @@SESSION.innodb_strict_mode;

CREATE TABLE test_wl5522.t1 (c1 INT) ENGINE = Innodb
ROW_FORMAT=COMPRESSED;

ALTER TABLE test_wl5522.t1 DISCARD TABLESPACE;

perl;
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
ib_restore_tablespaces("test_wl5522", "t1");
EOF

ALTER TABLE test_wl5522.t1 IMPORT TABLESPACE;
CHECK TABLE test_wl5522.t1;

SELECT COUNT(*) FROM test_wl5522.t1;

INSERT INTO test_wl5522.t1 VALUES(400), (500), (600);

SELECT * FROM test_wl5522.t1;

DROP TABLE test_wl5522.t1;

# Test handling of internal failure error
CREATE TABLE test_wl5522.t1 (c1 INT) ENGINE = Innodb
ROW_FORMAT=COMPRESSED;

ALTER TABLE test_wl5522.t1 DISCARD TABLESPACE;

--error ER_TABLESPACE_DISCARDED
SELECT COUNT(*) FROM test_wl5522.t1;

# Restore files
perl;
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
ib_restore_tablespaces("test_wl5522", "t1");
EOF

# Test failure after reset of space id and LSN in the tablespace
SET SESSION debug_dbug="+d,ib_import_internal_error";

--replace_regex /'.*t1.cfg'/'t1.cfg'/

--error ER_INTERNAL_ERROR
ALTER TABLE test_wl5522.t1 IMPORT TABLESPACE;

SET SESSION debug_dbug="-d,ib_import_internal_error";

# Restore files
perl;
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
ib_restore_tablespaces("test_wl5522", "t1");
EOF

ALTER TABLE test_wl5522.t1 IMPORT TABLESPACE;

DROP TABLE test_wl5522.t1;


# Test failure after reset of space id and LSN in the tablespace
CREATE TABLE test_wl5522.t1 (c1 INT) ENGINE = Innodb
ROW_FORMAT=COMPRESSED;

ALTER TABLE test_wl5522.t1 DISCARD TABLESPACE;

--error ER_TABLESPACE_DISCARDED
SELECT COUNT(*) FROM test_wl5522.t1;

# Restore files
perl;
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
ib_restore_tablespaces("test_wl5522", "t1");
EOF

# Test failure after reset of space id and LSN in the tablespace
SET SESSION debug_dbug="+d,ib_import_reset_space_and_lsn_failure";

--replace_regex /'.*t1.cfg'/'t1.cfg'/

--error ER_INTERNAL_ERROR
ALTER TABLE test_wl5522.t1 IMPORT TABLESPACE;

# Restore files
perl;
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
ib_restore_tablespaces("test_wl5522", "t1");
EOF

SET SESSION debug_dbug="-d,ib_import_reset_space_and_lsn_failure";

# Test failure after attempting a tablespace open
SET SESSION debug_dbug="+d,ib_import_open_tablespace_failure";

--replace_regex /'.*[\/\\]/'/
--error ER_GET_ERRMSG
ALTER TABLE test_wl5522.t1 IMPORT TABLESPACE;

SET SESSION debug_dbug="-d,ib_import_open_tablespace_failure";

# Restore files
perl;
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
ib_restore_tablespaces("test_wl5522", "t1");
EOF

# Test failure after ibuf check
SET SESSION debug_dbug="+d,ib_import_check_bitmap_failure";

# Need proper mapping of error codes :-(
--error ER_NOT_KEYFILE
ALTER TABLE test_wl5522.t1 IMPORT TABLESPACE;

SET SESSION debug_dbug="-d,ib_import_check_bitmap_failure";

# Restore files
perl;
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
ib_restore_tablespaces("test_wl5522", "t1");
EOF

# Test failure after adjusting the cluster index root page
SET SESSION debug_dbug="+d,ib_import_cluster_root_adjust_failure";

--error ER_NOT_KEYFILE
ALTER TABLE test_wl5522.t1 IMPORT TABLESPACE;

SET SESSION debug_dbug="-d,ib_import_cluster_root_adjust_failure";

# Restore files
perl;
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
ib_restore_tablespaces("test_wl5522", "t1");
EOF

# Test failure after importing the cluster index
SET SESSION debug_dbug="+d,ib_import_cluster_failure";

--error ER_NOT_KEYFILE
ALTER TABLE test_wl5522.t1 IMPORT TABLESPACE;

SET SESSION debug_dbug="-d,ib_import_cluster_failure";

# Restore files
perl;
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
ib_restore_tablespaces("test_wl5522", "t1");
EOF

# Test failure after importing the secondary index(es)
SET SESSION debug_dbug="+d,ib_import_sec_root_adjust_failure";

--error ER_NOT_KEYFILE
ALTER TABLE test_wl5522.t1 IMPORT TABLESPACE;

SET SESSION debug_dbug="-d,ib_import_sec_root_adjust_failure";

# Restore files
perl;
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
ib_restore_tablespaces("test_wl5522", "t1");
EOF

# Test failure after importing the cluster index
SET SESSION debug_dbug="+d,ib_import_set_max_rowid_failure";

--error ER_NOT_KEYFILE
ALTER TABLE test_wl5522.t1 IMPORT TABLESPACE;

SET SESSION debug_dbug="-d,ib_import_set_max_rowid_failure";

# Left over from the failed IMPORT
perl;
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
ib_unlink_tablespace("test_wl5522", "t1");
EOF

DROP TABLE test_wl5522.t1;

--disable_query_log
# Enable metrics for the counters we are going to use
set global innodb_monitor_enable = purge_stop_count;
set global innodb_monitor_enable = purge_resume_count;
set global innodb_monitor_enable = ibuf_merges;
set global innodb_monitor_enable = ibuf_merges_insert;
--enable_query_log

#
# Create a large table with delete marked records, disable purge during
# the update so that we can test the IMPORT purge code.
#
CREATE TABLE test_wl5522.t1 (
	c1 BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
	c2 BIGINT,
	c3 VARCHAR(2048),
	c4 VARCHAR(2048),
	INDEX idx1(c2),
	INDEX idx2(c3(512)),
	INDEX idx3(c4(512))) Engine=InnoDB
        ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8;

# Stop purge so that it doesn't remove the delete marked entries.
SET GLOBAL INNODB_PURGE_STOP_NOW=ON;

# Disable change buffer merge from the master thread, additionally
# enable aggressive flushing so that more changes are buffered.
SET GLOBAL innodb_disable_background_merge=ON;
SET GLOBAL innodb_monitor_reset = ibuf_merges;
SET GLOBAL innodb_monitor_reset = ibuf_merges_insert;

INSERT INTO test_wl5522.t1(c2, c3, c4) VALUES
	(1, REPEAT('a', 2048), REPEAT('a', 2048)),
	(2, REPEAT('b', 2048), REPEAT('b', 2048)),
	(3, REPEAT('c', 2048), REPEAT('c', 2048)),
	(4, REPEAT('d', 2048), REPEAT('d', 2048));

INSERT INTO test_wl5522.t1(c2, c3, c4) SELECT c2, c3, c4 FROM test_wl5522.t1;
INSERT INTO test_wl5522.t1(c2, c3, c4) SELECT c2, c3, c4 FROM test_wl5522.t1;
INSERT INTO test_wl5522.t1(c2, c3, c4) SELECT c2, c3, c4 FROM test_wl5522.t1;
INSERT INTO test_wl5522.t1(c2, c3, c4) SELECT c2, c3, c4 FROM test_wl5522.t1;
INSERT INTO test_wl5522.t1(c2, c3, c4) SELECT c2, c3, c4 FROM test_wl5522.t1;

DELETE FROM test_wl5522.t1 WHERE c2 = 1;

UPDATE test_wl5522.t1 SET c2 = c2 + c1;
UPDATE test_wl5522.t1 SET c2 = c2 + c1;
UPDATE test_wl5522.t1 SET c2 = c2 + c1;
UPDATE test_wl5522.t1 SET c2 = c2 + c1;
UPDATE test_wl5522.t1 SET c2 = c2 + c1;
UPDATE test_wl5522.t1 SET c2 = c2 + c1;
UPDATE test_wl5522.t1 SET c2 = c2 + c1;
UPDATE test_wl5522.t1 SET c2 = c2 + c1;
UPDATE test_wl5522.t1 SET c2 = c2 + c1;
UPDATE test_wl5522.t1 SET c2 = c2 + c1;
UPDATE test_wl5522.t1 SET c2 = c2 + c1;
UPDATE test_wl5522.t1 SET c2 = c2 + c1;
UPDATE test_wl5522.t1 SET c2 = c2 + c1;
UPDATE test_wl5522.t1 SET c2 = c2 + c1;
UPDATE test_wl5522.t1 SET c2 = c2 + c1;
UPDATE test_wl5522.t1 SET c3 = REPEAT("c2", 1024);
UPDATE test_wl5522.t1 SET c4 = REPEAT("c4", 1024);

SHOW CREATE TABLE test_wl5522.t1;

SELECT c1, c2 FROM test_wl5522.t1;
SELECT COUNT(*) FROM test_wl5522.t1;
SELECT SUM(c2) FROM test_wl5522.t1;

SELECT name
  FROM information_schema.innodb_metrics
  WHERE name = 'ibuf_merges_insert' AND count = 0;

FLUSH TABLES test_wl5522.t1 FOR EXPORT;

perl;
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
ib_backup_tablespaces("test_wl5522", "t1");
EOF

UNLOCK TABLES;

SELECT name
  FROM information_schema.innodb_metrics
  WHERE name = 'ibuf_merges' AND count > 0;

SELECT name
  FROM information_schema.innodb_metrics
  WHERE name = 'ibuf_merges_inserts' AND count > 0;

SET GLOBAL innodb_disable_background_merge=OFF;

# Enable normal operation
SET GLOBAL INNODB_PURGE_RUN_NOW=ON;

DROP TABLE test_wl5522.t1;

CREATE TABLE test_wl5522.t1 (
	c1 BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
	c2 BIGINT,
	c3 VARCHAR(2048),
	c4 VARCHAR(2048),
	INDEX idx1(c2),
	INDEX idx2(c3(512)),
	INDEX idx3(c4(512))) Engine=InnoDB
        ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8;

SELECT c1, c2 FROM test_wl5522.t1;

ALTER TABLE test_wl5522.t1 DISCARD TABLESPACE;

perl;
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
ib_restore_tablespaces("test_wl5522", "t1");
EOF

ALTER TABLE test_wl5522.t1 IMPORT TABLESPACE;
CHECK TABLE test_wl5522.t1;

SELECT c1,c2 FROM test_wl5522.t1;
SELECT COUNT(*) FROM test_wl5522.t1;
SELECT SUM(c2) FROM test_wl5522.t1;

SHOW CREATE TABLE test_wl5522.t1;

DROP TABLE test_wl5522.t1;

####
# Create a table and save the tablespace and .cfg file, we need to create
# a Btree that has several levels
CREATE TABLE test_wl5522.t1 (c1 INT, c2 VARCHAR(1024), c3 BLOB) ENGINE = Innodb
ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=4;

INSERT INTO test_wl5522.t1 VALUES
	(100, REPEAT('Karanbir', 899), REPEAT('Ajeeth', 1200));

INSERT INTO test_wl5522.t1 SELECT * FROM test_wl5522.t1;
INSERT INTO test_wl5522.t1 SELECT * FROM test_wl5522.t1;
INSERT INTO test_wl5522.t1 SELECT * FROM test_wl5522.t1;
INSERT INTO test_wl5522.t1 SELECT * FROM test_wl5522.t1;
INSERT INTO test_wl5522.t1 SELECT * FROM test_wl5522.t1;
INSERT INTO test_wl5522.t1 SELECT * FROM test_wl5522.t1;
INSERT INTO test_wl5522.t1 SELECT * FROM test_wl5522.t1;
INSERT INTO test_wl5522.t1 SELECT * FROM test_wl5522.t1;
SELECT COUNT(*) FROM test_wl5522.t1;
FLUSH TABLES test_wl5522.t1 FOR EXPORT;

perl;
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
ib_backup_tablespaces("test_wl5522", "t1");
EOF

UNLOCK TABLES;

DROP TABLE test_wl5522.t1;

CREATE TABLE test_wl5522.t1 (c1 INT, c2 VARCHAR(1024), c3 BLOB) ENGINE = Innodb
ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=4;

ALTER TABLE test_wl5522.t1 DISCARD TABLESPACE;

--error ER_TABLESPACE_DISCARDED
SELECT COUNT(*) FROM test_wl5522.t1;

# Restore files
perl;
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
ib_restore_tablespaces("test_wl5522", "t1");
EOF

SET SESSION debug_dbug="+d,ib_import_trigger_corruption_1";

--replace_regex /'.*t1.cfg'/'t1.cfg'/

--error ER_INTERNAL_ERROR
ALTER TABLE test_wl5522.t1 IMPORT TABLESPACE;

SET SESSION debug_dbug="-d,ib_import_trigger_corruption_1";

DROP TABLE test_wl5522.t1;

perl;
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
ib_unlink_tablespace("test_wl5522", "t1");
EOF

#

CREATE TABLE test_wl5522.t1 (c1 INT, c2 VARCHAR(1024), c3 BLOB) ENGINE = Innodb
ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=4;

ALTER TABLE test_wl5522.t1 DISCARD TABLESPACE;

--error ER_TABLESPACE_DISCARDED
SELECT COUNT(*) FROM test_wl5522.t1;

# Restore files
perl;
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
ib_restore_tablespaces("test_wl5522", "t1");
EOF

SET SESSION debug_dbug="+d,buf_page_is_corrupt_failure";

--replace_regex /'.*t1.cfg'/'t1.cfg'/

# Following alter is not failing 
#--error ER_INTERNAL_ERROR
ALTER TABLE test_wl5522.t1 IMPORT TABLESPACE;

SET SESSION debug_dbug="-d,buf_page_is_corrupt_failure";

DROP TABLE test_wl5522.t1;

perl;
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
ib_unlink_tablespace("test_wl5522", "t1");
EOF

CREATE TABLE test_wl5522.t1 (c1 INT, c2 VARCHAR(1024), c3 BLOB) ENGINE = Innodb
ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=4;

ALTER TABLE test_wl5522.t1 DISCARD TABLESPACE;

--error ER_TABLESPACE_DISCARDED
SELECT COUNT(*) FROM test_wl5522.t1;

# Restore files
perl;
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
ib_restore_tablespaces("test_wl5522", "t1");
EOF

SET SESSION debug_dbug="+d,ib_import_trigger_corruption_2";

--replace_regex $pathfix

--error ER_INNODB_INDEX_CORRUPT
ALTER TABLE test_wl5522.t1 IMPORT TABLESPACE;

SET SESSION debug_dbug="-d,ib_import_trigger_corruption_2";

DROP TABLE test_wl5522.t1;

perl;
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
ib_unlink_tablespace("test_wl5522", "t1");
EOF

CREATE TABLE test_wl5522.t1 (c1 INT, c2 VARCHAR(1024), c3 BLOB) ENGINE = Innodb
ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=4;

ALTER TABLE test_wl5522.t1 DISCARD TABLESPACE;

--error ER_TABLESPACE_DISCARDED
SELECT COUNT(*) FROM test_wl5522.t1;

# Restore files
perl;
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
ib_restore_tablespaces("test_wl5522", "t1");
EOF

SET SESSION debug_dbug="+d,ib_import_trigger_corruption_3";

--replace_regex /'.*t1.cfg'/'t1.cfg'/

--error ER_NOT_KEYFILE
ALTER TABLE test_wl5522.t1 IMPORT TABLESPACE;

SET SESSION debug_dbug="-d,ib_import_trigger_corruption_3";

DROP TABLE test_wl5522.t1;

perl;
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
ib_unlink_tablespace("test_wl5522", "t1");
EOF

CREATE TABLE test_wl5522.t1 (c1 INT, c2 VARCHAR(1024), c3 BLOB) ENGINE = Innodb
ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=4;

ALTER TABLE test_wl5522.t1 DISCARD TABLESPACE;

--error ER_TABLESPACE_DISCARDED
SELECT COUNT(*) FROM test_wl5522.t1;

SET SESSION debug_dbug="+d,ib_import_create_index_failure_1";

ALTER TABLE test_wl5522.t1 ADD INDEX idx(c1);

SET SESSION debug_dbug="-d,ib_import_create_index_failure_1";

DROP TABLE test_wl5522.t1;

perl;
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
ib_unlink_tablespace("test_wl5522", "t1");
EOF

#

CREATE TABLE test_wl5522.t1 (c1 INT, c2 VARCHAR(1024), c3 BLOB) ENGINE = Innodb
ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=4;

ALTER TABLE test_wl5522.t1 DISCARD TABLESPACE;

--error ER_TABLESPACE_DISCARDED
SELECT COUNT(*) FROM test_wl5522.t1;

# Restore files
perl;
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
ib_restore_tablespaces("test_wl5522", "t1");
EOF

SET SESSION debug_dbug="+d,fil_space_create_failure";

--replace_regex /'.*[\/\\]/'/
--error ER_GET_ERRMSG
ALTER TABLE test_wl5522.t1 IMPORT TABLESPACE;

SET SESSION debug_dbug="-d,fil_space_create_failure";

DROP TABLE test_wl5522.t1;

perl;
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
ib_unlink_tablespace("test_wl5522", "t1");
EOF

#

CREATE TABLE test_wl5522.t1 (c1 INT, c2 VARCHAR(1024), c3 BLOB) ENGINE = Innodb
ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=4;

ALTER TABLE test_wl5522.t1 DISCARD TABLESPACE;

--error ER_TABLESPACE_DISCARDED
SELECT COUNT(*) FROM test_wl5522.t1;

# Restore files
perl;
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
ib_restore_tablespaces("test_wl5522", "t1");
EOF

SET SESSION debug_dbug="+d,dict_tf_to_fsp_flags_failure";

--replace_regex /'.*[\/\\]/'/
--error ER_GET_ERRMSG
ALTER TABLE test_wl5522.t1 IMPORT TABLESPACE;

SET SESSION debug_dbug="-d,dict_tf_to_fsp_flags_failure";

DROP TABLE test_wl5522.t1;

perl;
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
ib_unlink_tablespace("test_wl5522", "t1");
EOF

#

CREATE TABLE test_wl5522.t1 (c1 INT, c2 VARCHAR(1024), c3 BLOB) ENGINE = Innodb
ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=4;

ALTER TABLE test_wl5522.t1 DISCARD TABLESPACE;

--error ER_TABLESPACE_DISCARDED
SELECT COUNT(*) FROM test_wl5522.t1;

# Restore files
perl;
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
ib_restore_tablespaces("test_wl5522", "t1");
EOF

SET SESSION debug_dbug="+d,fsp_flags_is_valid_failure";

--replace_regex /'.*t1.cfg'/'t1.cfg'/

--error ER_INTERNAL_ERROR
ALTER TABLE test_wl5522.t1 IMPORT TABLESPACE;

SET SESSION debug_dbug="-d,fsp_flags_is_valid_failure";

DROP TABLE test_wl5522.t1;

perl;
do "$ENV{MTR_SUITE_DIR}/include/innodb-util.pl";
ib_unlink_tablespace("test_wl5522", "t1");
EOF


DROP DATABASE test_wl5522;

set global innodb_monitor_disable = all;
set global innodb_monitor_reset_all = all;

-- disable_warnings
set global innodb_monitor_enable = default;
set global innodb_monitor_disable = default;
set global innodb_monitor_reset = default;
set global innodb_monitor_reset_all = default;
-- enable_warnings

--disable_query_log
call mtr.add_suppression("'Resource temporarily unavailable'");
call mtr.add_suppression("Monitor ibuf_merges is already enabled");
call mtr.add_suppression("Monitor ibuf_merges_insert is already enabled");
call mtr.add_suppression("Got error -1 when reading table '.*'");
call mtr.add_suppression("InnoDB: Table '.*' tablespace is set as discarded.");
call mtr.add_suppression("InnoDB: Tablespace '.*' exists in the cache.*");
call mtr.add_suppression("InnoDB: Freeing existing tablespace '.*' entry from the cache with id.*");
call mtr.add_suppression("InnoDB: The table .* doesn't have a corresponding tablespace, it was discarded");
call mtr.add_suppression(".*There was an error writing to the meta data file.*");
call mtr.add_suppression("InnoDB: Trying to import a tablespace, but could not open the tablespace file");
call mtr.add_suppression("Unsupported tablespace format");
call mtr.add_suppression("Error in page .* of index \"GEN_CLUST_INDEX\" of table \"test_wl5522\".\"t1\"");
call mtr.add_suppression("Page is marked as free");
call mtr.add_suppression("t1.ibd: Page .* at offset .* looks corrupted");
call mtr.add_suppression("but tablespace with that id or name does not exist");
call mtr.add_suppression("Failed to find tablespace for table '\"test_wl5522\".\"t1\"' in the cache");
call mtr.add_suppression("Could not find a valid tablespace file for 'test_wl5522.*t1'");
--enable_query_log

#cleanup
--remove_file $MYSQLTEST_VARDIR/tmp/t1.cfg
--remove_file $MYSQLTEST_VARDIR/tmp/t1.ibd

eval SET GLOBAL INNODB_FILE_PER_TABLE=$innodb_file_per_table;
eval SET GLOBAL INNODB_FILE_FORMAT=$innodb_file_format;
eval SET SESSION innodb_strict_mode=$innodb_strict_mode_orig;