summaryrefslogtreecommitdiff
path: root/storage/rocksdb/mysql-test/rocksdb/t/rocksdb_checksums.test
blob: 1a0364ebaee0eb9d21abe21b9ec480dbb19a1f6d (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
--source include/have_rocksdb.inc

#
#  Tests for row checksums feature
#
--source include/have_debug.inc

set @save_rocksdb_store_checksums=@@global.rocksdb_store_checksums;
set @save_rocksdb_verify_checksums=@@global.rocksdb_verify_checksums;
set @save_rocksdb_checksums_pct=@@global.rocksdb_checksums_pct;

# wiping mysql log for repeatable tests
--exec echo "" > $MYSQLTEST_VARDIR/log/mysqld.1.err

--disable_warnings
drop table if exists t1,t2,t3;
--enable_warnings
-- exec echo "" > $MYSQLTEST_VARDIR/log/mysqld.1.err

show variables like 'rocksdb_%checksum%';

create table t1 (pk int primary key, a int, b int, key(a), key(b)) engine=rocksdb;
insert into t1 values (1,1,1),(2,2,2),(3,3,3);
check table t1;
--exec grep "^[0-9-]* [0-9:]* [0-9]* \[Note\] CHECKTABLE t1" $MYSQLTEST_VARDIR/log/mysqld.1.err | cut -d] -f2

drop table t1;

set session rocksdb_store_checksums=on;
create table t2 (pk int primary key, a int, b int, key(a), key(b)) engine=rocksdb;
insert into t2 values (1,1,1),(2,2,2),(3,3,3);
check table t2;
--exec grep "^[0-9-]* [0-9:]* [0-9]* \[Note\] CHECKTABLE t2" $MYSQLTEST_VARDIR/log/mysqld.1.err | cut -d] -f2

--echo # Now, make a table that has both rows with checksums and without
create table t3 (pk int primary key, a int, b int, key(a), key(b)) engine=rocksdb;
insert into t3 values (1,1,1),(2,2,2),(3,3,3);
set session rocksdb_store_checksums=off;
update t3 set b=3 where a=2;
set session rocksdb_store_checksums=on;
check table t3;
--exec grep "^[0-9-]* [0-9:]* [0-9]* \[Note\] CHECKTABLE t3" $MYSQLTEST_VARDIR/log/mysqld.1.err | cut -d] -f2

set session rocksdb_store_checksums=on;
set session rocksdb_checksums_pct=5;
create table t4 (pk int primary key, a int, b int, key(a), key(b)) engine=rocksdb;
--disable_query_log
let $i=0;
let $x= 100000;
while ($i<10000)
{
  inc $i;
  eval insert t4(pk,a,b) values($i, $i, $i div 10);
  eval update t4 set a= a+$x where a=$i;
  eval update t4 set pk=pk+$x where pk=$i;
}
--enable_query_log
check table t4;
--exec grep "^[0-9-]* [0-9:]* [0-9]* \[Note\] CHECKTABLE t4" $MYSQLTEST_VARDIR/log/mysqld.1.err | cut -d] -f2 > $MYSQL_TMP_DIR/rocksdb_checksums.log
--exec perl suite/rocksdb/t/rocksdb_checksums.pl $MYSQL_TMP_DIR/rocksdb_checksums.log 10000 5
--remove_file $MYSQL_TMP_DIR/rocksdb_checksums.log
set session rocksdb_checksums_pct=100;

--echo #
--echo # Ok, table t2 has all rows with checksums. Simulate a few checksum mismatches.
--echo #
insert into mtr.test_suppressions values 
 ('Checksum mismatch in key of key-value pair for index'),
 ('Checksum mismatch in value of key-value pair for index'),
 ('Data with incorrect checksum');

--echo # 1. Start with mismatch in key checksum of the PK.
set session debug= "+d,myrocks_simulate_bad_pk_checksum1";
set session rocksdb_verify_checksums=off;
select * from t3;
set session rocksdb_verify_checksums=on;
--error ER_INTERNAL_ERROR
select * from t3;
--error ER_INTERNAL_ERROR
select * from t4;
set session debug= "-d,myrocks_simulate_bad_pk_checksum1";

--echo # 2. Continue with mismatch in pk value checksum.
set session debug= "+d,myrocks_simulate_bad_pk_checksum2";
set session rocksdb_verify_checksums=off;
select * from t3;
set session rocksdb_verify_checksums=on;
--error ER_INTERNAL_ERROR
select * from t3;
--error ER_INTERNAL_ERROR
select * from t4;
set session debug= "-d,myrocks_simulate_bad_pk_checksum2";

--echo # 3. Check if we catch checksum mismatches for secondary indexes
--replace_column 9 #
explain
select * from t3 force index(a) where a<4;
select * from t3 force index(a) where a<4;

set session debug= "+d,myrocks_simulate_bad_key_checksum1";
--error ER_INTERNAL_ERROR
select * from t3 force index(a) where a<4;
--error ER_INTERNAL_ERROR
select * from t4 force index(a) where a<1000000;
set session debug= "-d,myrocks_simulate_bad_key_checksum1";

--echo # 4. The same for index-only reads?
--replace_column 9 #
explain 
select a from t3 force index(a) where a<4;
select a from t3 force index(a) where a<4;

set session debug= "+d,myrocks_simulate_bad_key_checksum1";
--error ER_INTERNAL_ERROR
select a from t3 force index(a) where a<4;
--error ER_INTERNAL_ERROR
select a from t4 force index(a) where a<1000000;
set session debug= "-d,myrocks_simulate_bad_key_checksum1";

set @@global.rocksdb_store_checksums=@save_rocksdb_store_checksums;
set @@global.rocksdb_verify_checksums=@save_rocksdb_verify_checksums;
set @@global.rocksdb_checksums_pct=@save_rocksdb_checksums_pct;

drop table t2,t3,t4;