| 1 |
# Convert tablespace flags to the format understood by MariaDB 10.1.0..10.1.20, |
| 2 |
# with the assumption that the flags were correct. |
| 3 |
|
| 4 |
sub convert_to_mariadb_101 |
| 5 |
{ |
| 6 |
my ($file, $page_size) = @_; |
| 7 |
open(FILE, "+<", $file) or die "Unable to open $file\n"; |
| 8 |
sysread(FILE, $_, $page_size)==$page_size||die "Unable to read $file\n"; |
| 9 |
sysseek(FILE, 0, 0)||die "Unable to seek $file\n"; |
| 10 |
|
| 11 |
# FIL_PAGE_DATA + FSP_SPACE_FLAGS = 38 + 16 = 54 bytes from the start |
| 12 |
my($flags) = unpack "x[54]N", $_; |
| 13 |
my $badflags = ($flags & 0x3f); |
| 14 |
my $compression_level=3; |
| 15 |
$badflags |= 1<<6|$compression_level<<7 if ($flags & 1 << 16); |
| 16 |
$badflags |= ($flags & 15 << 6) << 7; # PAGE_SSIZE |
| 17 |
|
| 18 |
if ($badflags != $flags) |
| 19 |
{ |
| 20 |
warn "$file: changing $flags to $badflags\n"; |
| 21 |
substr ($_, 54, 4) = pack("N", $badflags); |
| 22 |
# Compute and replace the innodb_checksum_algorithm=crc32 checksum |
| 23 |
my $polynomial = 0x82f63b78; # CRC-32C |
| 24 |
if ($page_size == 1024) |
| 25 |
{ |
| 26 |
# ROW_FORMAT=COMPRESSED |
| 27 |
substr($_,0,4)=pack("N", |
| 28 |
mycrc32(substr($_, 4, 12), 0, $polynomial) ^ |
| 29 |
mycrc32(substr($_, 24, 2), 0, $polynomial) ^ |
| 30 |
mycrc32(substr($_, 34, $page_size - 34), 0, |
| 31 |
$polynomial)); |
| 32 |
} |
| 33 |
else |
| 34 |
{ |
| 35 |
my $ck=pack("N", |
| 36 |
mycrc32(substr($_, 4, 22), 0, $polynomial) ^ |
| 37 |
mycrc32(substr($_, 38, $page_size - 38 - 8), 0, |
| 38 |
$polynomial)); |
| 39 |
substr($_, 0, 4) = $ck; |
| 40 |
substr ($_, $page_size - 8, 4) = $ck; |
| 41 |
} |
| 42 |
syswrite(FILE, $_, $page_size)==$page_size||die "Unable to write $file\n"; |
| 43 |
} |
| 44 |
close(FILE); |
| 45 |
} |