File: innodb_corrupt_bit.test

package info (click to toggle)
mysql-8.0 8.0.43-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,924 kB
  • sloc: cpp: 4,684,605; ansic: 412,450; pascal: 108,398; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; sh: 24,181; python: 21,816; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,076; makefile: 2,194; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (404 lines) | stat: -rw-r--r-- 10,770 bytes parent folder | download
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
#
# Test for persistent corrupt bit for corrupted index and table
#
--source include/no_valgrind_without_big.inc
# This test needs debug server
--source include/have_debug.inc
--source include/not_hypergraph.inc  # Depends on using indexes, which are not supported.

--disable_query_log
call mtr.add_suppression("Flagged corruption of.* in table .* in CHECK TABLE");
--enable_query_log

set names utf8;

CREATE TABLE corrupt_bit_test_ā(
       a INT AUTO_INCREMENT PRIMARY KEY,
       b CHAR(100),
       c INT,
       z INT,
       INDEX idx(b))
ENGINE=InnoDB STATS_PERSISTENT=0;

INSERT INTO corrupt_bit_test_ā VALUES(0,'x',1, 1);

CREATE UNIQUE INDEX idxā ON corrupt_bit_test_ā(c, b);

CREATE UNIQUE INDEX idxē ON corrupt_bit_test_ā(z, b);

SELECT * FROM corrupt_bit_test_ā;

INSERT INTO corrupt_bit_test_ā SELECT 0,b,c+1,z+1 FROM corrupt_bit_test_ā;

select count(*) from corrupt_bit_test_ā;

# This will flag all secondary indexes corrupted
SET SESSION debug="+d,dict_set_index_corrupted";
check table corrupt_bit_test_ā;
SET SESSION debug="-d,dict_set_index_corrupted";
# Cannot create new indexes while corrupted indexes exist
--error ER_CHECK_NO_SUCH_TABLE
CREATE INDEX idx3 ON corrupt_bit_test_ā(b, c);
--error ER_CHECK_NO_SUCH_TABLE
CREATE INDEX idx4 ON corrupt_bit_test_ā(b, z);

# This selection intend to use the corrupted index. Expect to fail
-- error ER_INDEX_CORRUPT
select c from corrupt_bit_test_ā;

-- error ER_INDEX_CORRUPT
select z from corrupt_bit_test_ā;

show warnings;

# Since corrupted index is a secondary index, we only disable such
# index and allow other DML to proceed
insert into corrupt_bit_test_ā values (10001, "a", 20001, 20001);

# This does not use the corrupted index, expect to succeed
select * from corrupt_bit_test_ā use index(primary) where a = 10001;

# Some more DMLs
begin;
insert into corrupt_bit_test_ā values (10002, "a", 20002, 20002);
delete from corrupt_bit_test_ā where a = 10001;
insert into corrupt_bit_test_ā values (10001, "a", 20001, 20001);
rollback;

drop index idxā on corrupt_bit_test_ā;

check table corrupt_bit_test_ā;

set names utf8;

-- error ER_INDEX_CORRUPT
select z from corrupt_bit_test_ā;

# Drop the corrupted index
drop index idxē on corrupt_bit_test_ā;

# Cannot create new indexes while a corrupt index exists.
--error ER_CHECK_NO_SUCH_TABLE
CREATE INDEX idx3 ON corrupt_bit_test_ā(b, c);
--error ER_CHECK_NO_SUCH_TABLE
CREATE INDEX idx4 ON corrupt_bit_test_ā(b, z);

drop index idx on corrupt_bit_test_ā;

# Now that there exist no corrupted indexes, we can create new indexes.
CREATE INDEX idx3 ON corrupt_bit_test_ā(b, c);
CREATE INDEX idx4 ON corrupt_bit_test_ā(b, z);

# Now select back to normal
select z from corrupt_bit_test_ā limit 10;

# Drop table
drop table corrupt_bit_test_ā;

--disable_query_log
call mtr.add_suppression("\\[ERROR\\] .*MY-\\d+.* Load table `corrupted`\\.`t[16]` failed, the table contains a corrupted clustered index");
call mtr.add_suppression("\\[Warning\\] .*MY-\\d+.* Cannot open table corrupted/t[16]");
call mtr.add_suppression("\\[ERROR\\] .*MY-\\d+.* Failed to find tablespace for table `corrupted`\\.`t[56]` in the cache");
--enable_query_log

CREATE DATABASE corrupted;
use corrupted;

CREATE TABLE t1 (
	a INT NOT NULL PRIMARY KEY,
	b INT,
	c CHAR(10),
	v VARCHAR(100),
	t TEXT,
	p POINT NOT NULL);

CREATE TABLE t2 LIKE t1;
CREATE TEMPORARY TABLE t3 LIKE t2;

CREATE FULLTEXT INDEX ft ON t2(t);
CREATE INDEX idx_c ON t3(c);

INSERT INTO t1 VALUES (1, 2, 'aaa', 'abcdefghij', 'This is a', st_pointfromtext('POINT(0 0)')),
(2, 4, 'bb', 'qwerty', 'test case', st_pointfromtext('POINT(1 1)')),
(3, 6, 'ccccc', 'poiuy', 'for corrupted index', st_pointfromtext('POINT(2 2)'));

INSERT INTO t2 SELECT * FROM t1;
INSERT INTO t3 SELECT * FROM t1;

SELECT count(*) FROM t1;
SELECT count(*) FROM t2;
SELECT count(*) FROM t3;

--echo # Marking clustered index as corrupted results in ER_NO_SUCH_TABLE
set debug = "+d, dict_set_clust_index_corrupted";
CHECK TABLE t1;
set debug = "-d, dict_set_clust_index_corrupted";

--error ER_NO_SUCH_TABLE
CREATE INDEX b ON t1(b);

--echo # Mark the secondary index as corrupted
set debug = "+d, dict_set_index_corrupted";
CHECK TABLE t2;
set debug = "-d, dict_set_index_corrupted";

--error ER_TABLE_HAS_NO_FT
SELECT * FROM t2 WHERE MATCH(t) AGAINST('corrupted');
SELECT a, b, c FROM t2 WHERE ST_Equals(p, st_pointfromtext('POINT(2 2)'));

set debug = "+d, dict_set_index_corrupted";
CHECK TABLE t3;
set debug = "-d, dict_set_index_corrupted";

--error ER_INDEX_CORRUPT
SELECT c FROM t3 WHERE c = 'bb';

--source include/restart_mysqld.inc

--echo # Make sure the corrupted indexes are still corrupted
use corrupted;
SHOW TABLES;

--error ER_CHECK_NO_SUCH_TABLE
CREATE INDEX b ON t1(b);

--error ER_TABLE_HAS_NO_FT
SELECT t FROM t2 WHERE MATCH(t) AGAINST('corrupted');

# Re-create the fulltext indee
DROP INDEX ft ON t2;

--error ER_CHECK_NO_SUCH_TABLE
ALTER TABLE t2 ADD FULLTEXT INDEX(t);
--echo # Have to use ALTER TABLE ... COPY, in case 'Incorrect key file for table...'
--echo # would be reported
ALTER TABLE t2 ADD FULLTEXT INDEX(t), ALGORITHM=COPY;
--echo # This should be fine
SELECT t FROM t2 WHERE MATCH(t) AGAINST('corrupted');

CHECK TABLE t1;
CHECK TABLE t2;

--echo # We can drop the corrupted table t1 directly here
DROP TABLE t1, t2;

use corrupted;

CREATE TABLE t3 (
        a INT NOT NULL PRIMARY KEY,
        b INT,
        c CHAR(10),
        v VARCHAR(100),
        t TEXT,
        p POINT NOT NULL SRID 0);

CREATE INDEX idx_b ON t3(b);

INSERT INTO t3 VALUES (1, 2, 'aaa', 'abcdefghij', 'This is a', st_pointfromtext('POINT(0 0)')),
(2, 4, 'bb', 'qwerty', 'test case', st_pointfromtext('POINT(1 1)')),
(3, 6, 'ccccc', 'poiuy', 'for corrupted index', st_pointfromtext('POINT(2 2)'));

set debug = "+d, dict_set_index_corrupted";
CHECK TABLE t3;
set debug = "-d, dict_set_index_corrupted";

--error ER_INDEX_CORRUPT
SELECT b FROM t3 WHERE b > 2;

CREATE TABLE t4 LIKE t3;
CREATE INDEX idx_c ON t4(c);
CREATE INDEX idx_v ON t4(v);

INSERT INTO t4 SELECT * FROM t3;

set debug = "+d, dict_set_index_corrupted";
CHECK TABLE t4;
set debug = "-d, dict_set_index_corrupted";

--error ER_INDEX_CORRUPT
SELECT b FROM t4 WHERE b > 3;
show warnings;
--error ER_INDEX_CORRUPT
SELECT c FROM t4 WHERE c = 'bb';
--error ER_INDEX_CORRUPT
SELECT v FROM t4 WHERE v = 'abcdefg';

CREATE TABLE t5 LIKE t3;
CREATE SPATIAL INDEX idx_p ON t5(p);

INSERT INTO t5 SELECT * FROM t3;

set debug = "+d, dict_set_index_corrupted";
CHECK TABLE t5;
set debug = "-d, dict_set_index_corrupted";

--error ER_INDEX_CORRUPT
SELECT b FROM t5 WHERE b > 5;

--source include/kill_and_restart_mysqld.inc

use corrupted;

--echo # Check that all corrupted indexes are still marked as corrupted,
--echo # and non-corrupted indexes are still good.
CHECK TABLE t3;
--error ER_INDEX_CORRUPT
SELECT b FROM t3 WHERE b > 2;

CHECK TABLE t4;
--error ER_INDEX_CORRUPT
SELECT b FROM t4 WHERE b > 3;
--error ER_INDEX_CORRUPT
SELECT c FROM t4 WHERE c = 'bb';
--error ER_INDEX_CORRUPT
SELECT v FROM t4 WHERE v = 'abcdefg';

CHECK TABLE t5;
--error ER_INDEX_CORRUPT
SELECT b FROM t5 WHERE b > 5;

--echo # Let's just fix corrupted index for t5
DROP INDEX idx_b ON t5;
DROP INDEX idx_p ON t5;
CREATE INDEX idx_b ON t5(b);

--source include/restart_mysqld.inc

use corrupted;

CHECK TABLE t3;
--error ER_INDEX_CORRUPT
SELECT b FROM t3 WHERE b > 2;

CHECK TABLE t4;
--error ER_INDEX_CORRUPT
SELECT b FROM t4 WHERE b > 3;
--error ER_INDEX_CORRUPT
SELECT c FROM t4 WHERE c = 'bb';
--error ER_INDEX_CORRUPT
SELECT v FROM t4 WHERE v = 'abcdefg';

CHECK TABLE t5;
SELECT b FROM t5 WHERE b > 5;

--echo # Based on these tables, let's test more on checkpoint
CREATE TABLE t6 LIKE t3;

CREATE INDEX idx_c ON t6(c);

INSERT INTO t6 SELECT * FROM t3;

--echo # Corrupt new table indexes
set debug = "+d, dict_set_index_corrupted";
CHECK TABLE t6;
set debug = "-d, dict_set_index_corrupted";

SET @start_global_value = @@global.innodb_log_checkpoint_now;
SELECT @start_global_value;

--echo # Invoke a checkpoint, which would persist the corrupted bits
--echo # of t6 into DD Table Buffer
set global innodb_log_checkpoint_now=ON;

--echo # Then mark the clustered index as corrupted, make sure that new
--echo # corruption bits would take effect as well
set debug = "+d, dict_set_clust_index_corrupted";
CHECK TABLE t6;
set debug = "-d, dict_set_clust_index_corrupted";

--echo # Corrupt old table indexes
set debug = "+d, dict_set_index_corrupted";
CHECK TABLE t5;
set debug = "-d, dict_set_index_corrupted";

SELECT @start_global_value;
SET @@global.innodb_log_checkpoint_now = @start_global_value;
SELECT @@global.innodb_log_checkpoint_now;

--echo # This crash would leave latest corruption bits un-persisted
--source include/kill_and_restart_mysqld.inc

use corrupted;

CHECK TABLE t3;

CHECK TABLE t4;

CHECK TABLE t5;
--error ER_INDEX_CORRUPT
SELECT b FROM t5 WHERE b > 5;

CHECK TABLE t6;
--error ER_NO_SUCH_TABLE
CREATE INDEX idx_v ON t6(v);

--echo # Invoke checkpoint to persist the latest corruption bits again
SET @start_global_value = @@global.innodb_log_checkpoint_now;
SELECT @start_global_value;
set global innodb_log_checkpoint_now=ON;
SELECT @start_global_value;
SET @@global.innodb_log_checkpoint_now = @start_global_value;
SELECT @@global.innodb_log_checkpoint_now;

--source include/restart_mysqld.inc

use corrupted;

--echo # After a shutdown and restart, the corrupted bits should be persisted
--echo # to DD Table Buffer, and we can get them correctly.
CHECK TABLE t5;
CHECK TABLE t6;

--echo # An IN-PLACE 'ALTER TABLE' would not recover the table
ALTER TABLE t5 CHANGE c c1 CHAR(10), ALGORITHM = INPLACE;
CHECK TABLE t5;

--echo # An 'ALTER TABLE' requiring rebuild would recover the table
ALTER TABLE t5 ADD COLUMN d INT NOT NULL, ALGORITHM=INPLACE;
CHECK TABLE t5;
SELECT a, b, c1, v, t, st_astext(p) FROM t5 WHERE b > 2;

--echo # Re-create the table should recover the table
DROP TABLE t6;
CREATE TABLE t6 LIKE t3;
INSERT INTO t6 SELECT * FROM t3;

CHECK TABLE t6;

--source include/kill_and_restart_mysqld.inc

use corrupted;

CHECK TABLE t5;
SELECT a, b, c1, v, t, st_astext(p) FROM t5 WHERE b > 2;
CHECK TABLE t6;

--source include/restart_mysqld.inc

use corrupted;

CHECK TABLE t5;
CHECK TABLE t6;

# Uncomment these after WL#6795.
#--echo # Truncate table should recover the corrupted indexes
#set debug = "+d, dict_set_sec_index_corrupted";
#CHECK TABLE t5;
#set debug = "-d, dict_set_sec_index_corrupted";

#--error ER_INDEX_CORRUPT
#SELECT b FROM t5 WHERE b > 5;

#TRUNCATE TABLE t5;
#CHECK TABLE t5;

#INSERT INTO t5 SELECT * FROM t3;

#--source include/restart_mysqld.inc

#use corrupted;
#CHECK TABLE t5;
#SELECT b FROM t5 WHERE b > 5;

DROP TABLE t3, t4, t5, t6;
DROP DATABASE corrupted;