1--echo #
2--echo # Bug #20445525	ADD A CONSISTENCY CHECK AGAINST DB_TRX_ID BEING
3--echo #		IN THE FUTURE
4--echo #
5
6--source include/have_nodebug.inc
7
8let PAGE_SIZE=`select @@innodb_page_size`;
9
10CREATE TABLE t1(a INT) row_format=redundant engine=innoDB;
11INSERT INTO t1 VALUES(1);
12
13let MYSQLD_DATADIR=`select @@datadir`;
14
15--source include/shutdown_mysqld.inc
16
17perl;
18
19$page_size=$ENV{PAGE_SIZE};
20
21my $file = "$ENV{MYSQLD_DATADIR}/test/t1.ibd";
22open(FILE, "+<", $file) || die "Unable to open $file";
23
24#Seek the the infimum record and get the offset to next record
25#Infimum record exist at offset 101 for redundant format
26#And offset to the next record is present 2 bytes prior to
27#infimum record
28
29seek(FILE, 4*$page_size+101-2, 0) || die "Unable to seek $file";
30die unless read(FILE, $_, 2) == 2;
31my $record_offset  =  unpack("n*", $_);
32
33#In this case the first record should be at offset 135
34die unless $record_offset == 135;
35
36my $trx_id_of_rec = 4*$page_size + $record_offset + 6;
37
38# Modify DB_TRX_ID of the record to a value which is greater than
39# max_trx_id
40seek(FILE, $trx_id_of_rec , 0) || die "Unable to seek $file";
41
42my $corrupted_trx_id = "\xff" x 6;
43syswrite(FILE, $corrupted_trx_id) || die "Unable to write";
44
45#Modify the checksums of the page
46
47seek(FILE, 4*$page_size, 0) || die "Unable to seek $file";
48syswrite(FILE, pack("H*","deadbeef",4)) || die "Unable to write";
49
50seek(FILE, 5*$page_size-8, 0) || die "Unable to seek $file";
51syswrite(FILE, pack("H*","deadbeef",4)) || die "Unable to write";
52
53close(FILE)
54EOF
55
56--source include/start_mysqld.inc
57
58--disable_query_log
59call mtr.add_suppression("\\[Warning\\] .*MY-\\d+.* A transaction id in a record of table `\.\.*`\.`\.\.*` is newer than the system-wide maximum.");
60--enable_query_log
61
62SELECT * FROM t1;
63DROP TABLE t1;
64