|
| 1 | +# |
| 2 | +# Test for persistent corrupt bit for corrupted index and table |
| 3 | +# |
| 4 | +-- source include/have_innodb.inc |
| 5 | + |
| 6 | +# This test needs debug server |
| 7 | +--source include/have_debug.inc |
| 8 | + |
| 9 | +-- disable_query_log |
| 10 | +# This test setup is extracted from bug56680.test: |
| 11 | +# The flag innodb_change_buffering_debug is only available in debug builds. |
| 12 | +# It instructs InnoDB to try to evict pages from the buffer pool when |
| 13 | +# change buffering is possible, so that the change buffer will be used |
| 14 | +# whenever possible. |
| 15 | +-- error 0,ER_UNKNOWN_SYSTEM_VARIABLE |
| 16 | +SET @innodb_change_buffering_debug_orig = @@innodb_change_buffering_debug; |
| 17 | +-- error 0,ER_UNKNOWN_SYSTEM_VARIABLE |
| 18 | +SET GLOBAL innodb_change_buffering_debug = 1; |
| 19 | + |
| 20 | +# Turn off Unique Check to create corrupted index with dup key |
| 21 | +SET UNIQUE_CHECKS=0; |
| 22 | + |
| 23 | +-- enable_query_log |
| 24 | + |
| 25 | +set names utf8; |
| 26 | + |
| 27 | +CREATE TABLE corrupt_bit_test_ā( |
| 28 | + a INT AUTO_INCREMENT PRIMARY KEY, |
| 29 | + b CHAR(100), |
| 30 | + c INT, |
| 31 | + z INT, |
| 32 | + INDEX(b)) |
| 33 | +ENGINE=InnoDB; |
| 34 | + |
| 35 | +INSERT INTO corrupt_bit_test_ā VALUES(0,'x',1, 1); |
| 36 | + |
| 37 | +# This is the first unique index we intend to corrupt |
| 38 | +CREATE UNIQUE INDEX idxā ON corrupt_bit_test_ā(c, b); |
| 39 | + |
| 40 | +# This is the second unique index we intend to corrupt |
| 41 | +CREATE UNIQUE INDEX idxē ON corrupt_bit_test_ā(z, b); |
| 42 | + |
| 43 | +SELECT * FROM corrupt_bit_test_ā; |
| 44 | + |
| 45 | +select @@unique_checks; |
| 46 | +select @@innodb_change_buffering_debug; |
| 47 | + |
| 48 | +# Create enough rows for the table, so that the insert buffer will be |
| 49 | +# used for modifying the secondary index page. There must be multiple |
| 50 | +# index pages, because changes to the root page are never buffered. |
| 51 | + |
| 52 | +INSERT INTO corrupt_bit_test_ā SELECT 0,b,c+1,z+1 FROM corrupt_bit_test_ā; |
| 53 | +INSERT INTO corrupt_bit_test_ā SELECT 0,b,c+10,z+10 FROM corrupt_bit_test_ā; |
| 54 | +INSERT INTO corrupt_bit_test_ā SELECT 0,b,c+20,z+20 FROM corrupt_bit_test_ā; |
| 55 | +INSERT INTO corrupt_bit_test_ā SELECT 0,b,c+50,z+50 FROM corrupt_bit_test_ā; |
| 56 | +INSERT INTO corrupt_bit_test_ā SELECT 0,b,c+100,z+100 FROM corrupt_bit_test_ā; |
| 57 | +INSERT INTO corrupt_bit_test_ā SELECT 0,b,c+200,z+200 FROM corrupt_bit_test_ā; |
| 58 | +INSERT INTO corrupt_bit_test_ā SELECT 0,b,c+400,z+400 FROM corrupt_bit_test_ā; |
| 59 | +INSERT INTO corrupt_bit_test_ā SELECT 0,b,c+800,z+800 FROM corrupt_bit_test_ā; |
| 60 | +INSERT INTO corrupt_bit_test_ā SELECT 0,b,c+1600,z+1600 FROM corrupt_bit_test_ā; |
| 61 | +INSERT INTO corrupt_bit_test_ā SELECT 0,b,c+4000,z+4000 FROM corrupt_bit_test_ā; |
| 62 | + |
| 63 | +select count(*) from corrupt_bit_test_ā; |
| 64 | + |
| 65 | +CREATE INDEX idx3 ON corrupt_bit_test_ā(b, c); |
| 66 | + |
| 67 | +# Create a dup key error on index "idxē" and "idxā" by inserting a dup value |
| 68 | +INSERT INTO corrupt_bit_test_ā VALUES(13000,'x',1,1); |
| 69 | + |
| 70 | +# creating an index should succeed even if other secondary indexes are corrupted |
| 71 | +CREATE INDEX idx4 ON corrupt_bit_test_ā(b, z); |
| 72 | + |
| 73 | +# Check table will find the unique indexes corrupted |
| 74 | +# with dup key |
| 75 | +check table corrupt_bit_test_ā; |
| 76 | + |
| 77 | +# This selection intend to use the corrupted index. Expect to fail |
| 78 | +-- error ER_NOT_KEYFILE |
| 79 | +select c from corrupt_bit_test_ā; |
| 80 | + |
| 81 | +-- error ER_NOT_KEYFILE |
| 82 | +select z from corrupt_bit_test_ā; |
| 83 | + |
| 84 | +show warnings; |
| 85 | + |
| 86 | +# Since corrupted index is a secondary index, we only disable such |
| 87 | +# index and allow other DML to proceed |
| 88 | +insert into corrupt_bit_test_ā values (10001, "a", 20001, 20001); |
| 89 | + |
| 90 | +# This does not use the corrupted index, expect to succeed |
| 91 | +select * from corrupt_bit_test_ā use index(primary) where a = 10001; |
| 92 | + |
| 93 | +# Some more DMLs |
| 94 | +begin; |
| 95 | +insert into corrupt_bit_test_ā values (10002, "a", 20002, 20002); |
| 96 | +delete from corrupt_bit_test_ā where a = 10001; |
| 97 | +insert into corrupt_bit_test_ā values (10001, "a", 20001, 20001); |
| 98 | +rollback; |
| 99 | + |
| 100 | +# Drop one corrupted index before reboot |
| 101 | +drop index idxā on corrupt_bit_test_ā; |
| 102 | + |
| 103 | +check table corrupt_bit_test_ā; |
| 104 | + |
| 105 | +# Shut down the server |
| 106 | +-- exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect |
| 107 | +-- shutdown_server 20 |
| 108 | +-- source include/wait_until_disconnected.inc |
| 109 | + |
| 110 | +# Restart the server |
| 111 | +-- disable_query_log |
| 112 | +--exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect |
| 113 | +--enable_reconnect |
| 114 | +--source include/wait_until_connected_again.inc |
| 115 | +--disable_reconnect |
| 116 | +-- enable_query_log |
| 117 | + |
| 118 | +set names utf8; |
| 119 | + |
| 120 | +# The index is marked as suspect in Sys_indexes too, so after server |
| 121 | +# reboot, the attempt to use the index will fail too. |
| 122 | +-- error ER_NOT_KEYFILE |
| 123 | +select z from corrupt_bit_test_ā; |
| 124 | + |
| 125 | +# Drop the corrupted index |
| 126 | +drop index idxē on corrupt_bit_test_ā; |
| 127 | + |
| 128 | +# Now select back to normal |
| 129 | +select z from corrupt_bit_test_ā limit 10; |
| 130 | + |
| 131 | +# Drop table |
| 132 | +drop table corrupt_bit_test_ā; |
| 133 | + |
| 134 | +-- error 0, ER_UNKNOWN_SYSTEM_VARIABLE |
| 135 | +SET GLOBAL innodb_change_buffering_debug = 0; |
0 commit comments