| 1 |
--source include/have_innodb.inc |
| 2 |
--source include/not_embedded.inc |
| 3 |
--source include/have_debug.inc |
| 4 |
--source include/have_sequence.inc |
| 5 |
let MYSQLD_DATADIR= `SELECT @@datadir`; |
| 6 |
CREATE TABLE t1(a INT PRIMARY KEY) ENGINE=InnoDB STATS_PERSISTENT=0; |
| 7 |
SET GLOBAL innodb_log_checkpoint_now=ON; |
| 8 |
FLUSH TABLE t1 FOR EXPORT; |
| 9 |
UNLOCK TABLES; |
| 10 |
INSERT INTO t1 SET a=1; |
| 11 |
FLUSH TABLE t1 FOR EXPORT; |
| 12 |
UNLOCK TABLES; |
| 13 |
|
| 14 |
let INDEX_ID= `select INDEX_ID FROM INFORMATION_SCHEMA.INNODB_SYS_INDEXES WHERE TABLE_ID = (SELECT TABLE_ID FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES WHERE NAME="test/t1")`; |
| 15 |
|
| 16 |
let FLAG= `SELECT flag FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESPACES WHERE NAME="innodb_system"`; |
| 17 |
|
| 18 |
let $shutdown_timeout=0; |
| 19 |
--source include/shutdown_mysqld.inc |
| 20 |
let $resultlog=$MYSQLTEST_VARDIR/tmp/result.log; |
| 21 |
let $resultlog_1=$MYSQLTEST_VARDIR/tmp/result_1.log; |
| 22 |
|
| 23 |
exec $INNOCHECKSUM -S -r $MYSQLD_DATADIR/ibdata1 > $resultlog; |
| 24 |
--echo # Skip InnoDB Doublewrite Buffer |
| 25 |
exec $INNOCHECKSUM -S $MYSQLD_DATADIR/ibdata1 > $resultlog_1; |
| 26 |
|
| 27 |
perl; |
| 28 |
use strict; |
| 29 |
use warnings; |
| 30 |
use File::Spec::Functions qw(catfile); |
| 31 |
|
| 32 |
sub check_index_in_file { |
| 33 |
my ($filename, $search_id, $file_desc, $expect_found) = @_; |
| 34 |
my $found = 0; |
| 35 |
open(my $fh, '<', $filename) or die "Could not open file '$filename': $!\n"; |
| 36 |
my $line_count = 0; |
| 37 |
while (my $line = <$fh>) { |
| 38 |
$line_count++; |
| 39 |
chomp $line; |
| 40 |
# Skip empty lines and header lines |
| 41 |
next if $line =~ /^\s*$/; |
| 42 |
next if $line =~ /index_id.*#pages/; # Skip header line |
| 43 |
# Split the line by whitespace |
| 44 |
my @fields = grep { $_ ne '' } split(/\s+/, $line); |
| 45 |
next unless @fields; # Skip if no fields |
| 46 |
# The first field is the index_id |
| 47 |
my $current_id = $fields[0]; |
| 48 |
# Check if this is the ID we're looking for |
| 49 |
if (defined $current_id && $current_id eq $search_id) { |
| 50 |
$found = 1; |
| 51 |
last; |
| 52 |
} |
| 53 |
} |
| 54 |
close $fh; |
| 55 |
|
| 56 |
if ($found != $expect_found) { |
| 57 |
print "\n=== UNEXPECTED RESULT - SHOWING FILE CONTENTS ($file_desc) ===\n"; |
| 58 |
open($fh, '<', $filename) or die "Cannot reopen file: $!"; |
| 59 |
print while <$fh>; |
| 60 |
close $fh; |
| 61 |
print "=== END OF FILE ===\n\n"; |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
my $search_id = $ENV{'INDEX_ID'}; |
| 66 |
|
| 67 |
# Define file paths |
| 68 |
my $resultlog = catfile($ENV{'MYSQLTEST_VARDIR'}, 'tmp', 'result.log'); |
| 69 |
my $resultlog_1 = catfile($ENV{'MYSQLTEST_VARDIR'}, 'tmp', 'result_1.log'); |
| 70 |
|
| 71 |
# Check both files |
| 72 |
print "Should not exist when summary excludes dblwr pages\n"; |
| 73 |
check_index_in_file($resultlog, $search_id, 'result.log', 0); |
| 74 |
|
| 75 |
print "Should exist when summary includes dblwr pages\n"; |
| 76 |
check_index_in_file($resultlog_1, $search_id, 'result_1.log', 1); |
| 77 |
EOF |
| 78 |
|
| 79 |
remove_file $resultlog; |
| 80 |
remove_file $resultlog_1; |
| 81 |
|
| 82 |
# We expect deterministic checksum error when we pass |
| 83 |
# incorrect wrong flags to innochecksum. Below restart is needed |
| 84 |
# to make sure that we flush all the pages. |
| 85 |
--source include/start_mysqld.inc |
| 86 |
CREATE TABLE ibd_1(f1 INT PRIMARY KEY)ENGINE=InnoDB; |
| 87 |
INSERT INTO ibd_1 VALUES(1), (2), (3), (4); |
| 88 |
|
| 89 |
disable_warnings; |
| 90 |
SET GLOBAL innodb_file_per_table=0; |
| 91 |
enable_warnings; |
| 92 |
CREATE TABLE ibd_2(f1 INT PRIMARY KEY)ENGINE=InnoDB; |
| 93 |
INSERT INTO ibd_2 SELECT seq FROM seq_1_to_8451; |
| 94 |
|
| 95 |
let $shutdown_timeout=; |
| 96 |
--source include/shutdown_mysqld.inc |
| 97 |
--echo # Pass wrong tablespace flag for ibdata2 |
| 98 |
--error 1 |
| 99 |
exec $INNOCHECKSUM -S --tablespace_flags=39 $MYSQLD_DATADIR/ibdata2 > $resultlog 2>&1; |
| 100 |
|
| 101 |
let SEARCH_FILE=$resultlog; |
| 102 |
let SEARCH_PATTERN=Error: Page 0 checksum mismatch; |
| 103 |
--source include/search_pattern_in_file.inc |
| 104 |
remove_file $resultlog; |
| 105 |
|
| 106 |
--echo # Pass wrong tablespace flag for ibdata1 |
| 107 |
--error 1 |
| 108 |
exec $INNOCHECKSUM -S --tablespace_flags=39 $MYSQLD_DATADIR/ibdata1 > $resultlog 2>&1; |
| 109 |
|
| 110 |
let SEARCH_PATTERN=Error: Mismatch between provided tablespace flags; |
| 111 |
--source include/search_pattern_in_file.inc |
| 112 |
remove_file $resultlog; |
| 113 |
|
| 114 |
--echo # Pass invalid tablespace flag for ibdata1 |
| 115 |
--error 1 |
| 116 |
exec $INNOCHECKSUM -S --tablespace_flags=89 $MYSQLD_DATADIR/ibdata1 > $resultlog 2>&1; |
| 117 |
|
| 118 |
let SEARCH_PATTERN=Error: Provided --tablespace-flags is not valid; |
| 119 |
--source include/search_pattern_in_file.inc |
| 120 |
remove_file $resultlog; |
| 121 |
|
| 122 |
--echo # innochecksum should be succesfull |
| 123 |
exec $INNOCHECKSUM -S --tablespace_flags=$FLAG $MYSQLD_DATADIR/ibdata2 > $resultlog 2>&1; |
| 124 |
|
| 125 |
let SEARCH_PATTERN=Fail; |
| 126 |
--source include/search_pattern_in_file.inc |
| 127 |
|
| 128 |
--echo # Create a tablespace with page number > 2^31 |
| 129 |
--let $ibdata3 = $MYSQLD_DATADIR/ibdata3 |
| 130 |
perl; |
| 131 |
do "$ENV{MTR_SUITE_DIR}/include/crc32.pl"; |
| 132 |
my $polynomial = 0x82f63b78; # CRC-32C |
| 133 |
my $ps = 16384; # Default InnoDB page size |
| 134 |
my $page_num = 2147483649; # 2^31 + 1 |
| 135 |
my $filename = "$ENV{MYSQLD_DATADIR}/ibdata3"; |
| 136 |
|
| 137 |
# Create a zero-filled page |
| 138 |
my $page = "\0" x $ps; |
| 139 |
|
| 140 |
# Set page number (FIL_PAGE_OFFSET) |
| 141 |
substr($page, 4, 4) = pack('NN', $page_num); |
| 142 |
# Set a valid LSN (log sequence number) |
| 143 |
my $lsn = 0x12345678; |
| 144 |
substr($page, 16, 8) = pack('NN', $lsn & 0xFFFFFFFF, $lsn >> 32); |
| 145 |
|
| 146 |
# Calculate the checksum |
| 147 |
my $checksum = pack('N', |
| 148 |
mycrc32(substr($page, 4, 22), 0, $polynomial) ^ |
| 149 |
mycrc32(substr($page, 38, $ps - 38 - 8), 0, $polynomial) |
| 150 |
); |
| 151 |
# Write the checksum at the beginning (FIL_PAGE_SPACE_OR_CHKSUM) |
| 152 |
# and at the end (FIL_PAGE_END_LSN_OLD_CHKSUM) of the page |
| 153 |
substr($page, 0, 4) = $checksum; |
| 154 |
substr($page, $ps - 8, 4) = $checksum; |
| 155 |
|
| 156 |
# Write the page to file |
| 157 |
open(my $fh, '>', $filename) or die "Could not open file $filename: $!"; |
| 158 |
binmode $fh; |
| 159 |
print $fh $page; |
| 160 |
close $fh; |
| 161 |
EOF |
| 162 |
|
| 163 |
--echo # Test innochecksum with the modified ibdata3 |
| 164 |
--error 1 |
| 165 |
exec $INNOCHECKSUM -S $ibdata3 > $resultlog 2>&1; |
| 166 |
let SEARCH_PATTERN=Error: First page of the tablespace file should be 0, but encountered page number 2147483649; |
| 167 |
--source include/search_pattern_in_file.inc |
| 168 |
remove_file $resultlog; |
| 169 |
|
| 170 |
--echo # Test innochecksum with the modified ibdata3 with tablespace flags |
| 171 |
--error 1 |
| 172 |
exec $INNOCHECKSUM -S --tablespace_flags=$FLAG $ibdata3 > $resultlog 2>&1; |
| 173 |
let SEARCH_PATTERN=Exceeded the maximum allowed checksum mismatch; |
| 174 |
--source include/search_pattern_in_file.inc |
| 175 |
|
| 176 |
remove_file $ibdata3; |
| 177 |
--source include/start_mysqld.inc |
| 178 |
DROP TABLE t1, ibd_1, ibd_2; |
| 179 |
remove_file $resultlog; |