1-- source include/have_innodb.inc
2-- source include/not_embedded.inc
3-- source include/have_example_key_management_plugin.inc
4
5let $MYSQLD_DATADIR=`select @@datadir`;
6let INNODB_PAGE_SIZE= `select @@innodb_page_size`;
7
8create table snapshot_status engine = myisam
9select * from information_schema.global_status
10where variable_name like 'innodb_scrub_background%';
11
12let $rowcount=500;
13let $maxformatno= 4;
14let $formatno= $maxformatno;
15
16--echo # MDEV-8139 Fix scrubbing tests
17--echo # FIXME: Add index(b) to each table; ensure that undo logs are scrubbed.
18let $tableformat= (
19  a int auto_increment primary key,
20  b varchar(256),
21  c text) engine = innodb row_format;
22
23while ($formatno)
24{
25dec $formatno;
26let $format = `select case $formatno
27               when 0 then 'dynamic'
28               when 1 then 'redundant'
29               when 2 then 'compact'
30	       when 3 then 'compressed'
31               end`;
32
33let $t= delete_$formatno;
34eval create table $t $tableformat=$format;
35
36let $numinserts = $rowcount;
37--disable_query_log
38begin;
39while ($numinserts)
40{
41  dec $numinserts;
42  eval insert into $t(b,c) values ('repairman', repeat('unicycle', 1000));
43}
44commit;
45--enable_query_log
46
47eval delete from $t;
48
49let $t= delete_rollback_delete_$formatno;
50eval create table $t $tableformat=$format;
51
52let $numinserts = $rowcount;
53--disable_query_log
54begin;
55while ($numinserts)
56{
57  dec $numinserts;
58  eval insert into $t(b,c) values ('breakhuman', repeat('bicycle', 1000));
59}
60commit;
61--enable_query_log
62
63begin;
64eval delete from $t;
65rollback;
66eval delete from $t;
67
68let $t= insert_rollback_$formatno;
69
70eval create table $t $tableformat=$format;
71
72let $numinserts = $rowcount;
73begin;
74--disable_query_log
75while ($numinserts)
76{
77  dec $numinserts;
78  eval insert into $t(b,c) values ('wonderwoman', repeat('tricycle', 1000));
79}
80--enable_query_log
81
82rollback;
83}
84
85SET GLOBAL innodb_fast_shutdown=0;
86-- source include/shutdown_mysqld.inc
87
88let SEARCH_ABORT= FOUND;
89let SEARCH_PATTERN= (un|b|tr)icycle|(repair|breakhu|wonderwo)man;
90let SEARCH_RANGE= 12582912;
91let SEARCH_FILE= $MYSQLD_DATADIR/ibdata1;
92
93# We may randomly find copies of unscrubbed pages in the doublewrite buffer.
94# Let us scrub the doublewrite buffer ourselves.
95perl;
96use Fcntl 'SEEK_SET';
97my $page_size = $ENV{INNODB_PAGE_SIZE};
98open(FILE, "+<", "$ENV{SEARCH_FILE}") or die "cannot open: $!\n";
99seek(FILE, $page_size * 64, SEEK_SET) or die "cannot seek: $!\n";
100print(FILE chr(0) x ($page_size * 128)) or die "cannot write: $!\n";
101close FILE or die "cannot close: $!\n";;
102EOF
103
104-- source include/search_pattern_in_file.inc
105
106let $formatno= $maxformatno;
107while ($formatno)
108{
109dec $formatno;
110
111let $t= delete_$formatno.ibd;
112let SEARCH_FILE= $MYSQLD_DATADIR/test/$t;
113-- echo # $t
114-- source include/search_pattern_in_file.inc
115let $t= delete_rollback_delete_$formatno.ibd;
116let SEARCH_FILE= $MYSQLD_DATADIR/test/$t;
117-- echo # $t
118-- source include/search_pattern_in_file.inc
119let $t= insert_rollback_$formatno.ibd;
120let SEARCH_FILE= $MYSQLD_DATADIR/test/$t;
121-- echo # $t
122-- source include/search_pattern_in_file.inc
123}
124
125-- source include/start_mysqld.inc
126
127let $formatno= $maxformatno;
128while ($formatno)
129{
130dec $formatno;
131
132let $t= delete_$formatno, delete_rollback_delete_$formatno, insert_rollback_$formatno;
133
134eval check table $t;
135eval drop table $t;
136}
137
138show variables like 'innodb_%scrub_data%';
139
140--echo # verify that this test have not caused any background scrubbing
141--sorted_result
142select ss.variable_name, gs.variable_value - ss.variable_value as variable_value
143from snapshot_status ss,
144     information_schema.global_status gs
145where ss.variable_name = gs.variable_name;
146
147drop table snapshot_status;
148