summaryrefslogtreecommitdiffstats
path: root/mysql-test/suite/mariabackup/include
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 18:00:34 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 18:00:34 +0000
commit3f619478f796eddbba6e39502fe941b285dd97b1 (patch)
treee2c7b5777f728320e5b5542b6213fd3591ba51e2 /mysql-test/suite/mariabackup/include
parentInitial commit. (diff)
downloadmariadb-upstream.tar.xz
mariadb-upstream.zip
Adding upstream version 1:10.11.6.upstream/1%10.11.6upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'mysql-test/suite/mariabackup/include')
-rw-r--r--mysql-test/suite/mariabackup/include/corrupt-page.pl146
-rw-r--r--mysql-test/suite/mariabackup/include/restart_and_restore.inc8
-rw-r--r--mysql-test/suite/mariabackup/include/show_xtrabackup_slave_info.inc14
-rw-r--r--mysql-test/suite/mariabackup/include/show_xtrabackup_slave_info_out.inc20
4 files changed, 188 insertions, 0 deletions
diff --git a/mysql-test/suite/mariabackup/include/corrupt-page.pl b/mysql-test/suite/mariabackup/include/corrupt-page.pl
new file mode 100644
index 00000000..d5c75dbd
--- /dev/null
+++ b/mysql-test/suite/mariabackup/include/corrupt-page.pl
@@ -0,0 +1,146 @@
+use strict;
+use warnings;
+use Fcntl qw(:DEFAULT :seek);
+do "$ENV{MTR_SUITE_DIR}/../innodb/include/crc32.pl";
+
+sub corrupt_space_page_id {
+ my $file_name = shift;
+ my @pages_to_corrupt = @_;
+
+ my $page_size = $ENV{INNODB_PAGE_SIZE};
+
+ sysopen my $ibd_file, $file_name, O_RDWR || die "Cannot open $file_name\n";
+ sysread($ibd_file, $_, 38) || die "Cannot read $file_name\n";
+ my $space = unpack("x[34]N", $_);
+ foreach my $page_no (@pages_to_corrupt) {
+ $space += 10; # generate wrong space id
+ sysseek($ibd_file, $page_size * $page_no, SEEK_SET)
+ || die "Cannot seek $file_name\n";
+
+ my $head = pack("Nx[18]", $page_no + 10); # generate wrong page number
+ my $body = chr(0) x ($page_size - 38 - 8);
+
+ # Calculate innodb_checksum_algorithm=crc32 for the unencrypted page.
+ # The following bytes are excluded:
+ # bytes 0..3 (the checksum is stored there)
+ # bytes 26..37 (encryption key version, post-encryption checksum, tablespace id)
+ # bytes $page_size-8..$page_size-1 (checksum, LSB of FIL_PAGE_LSN)
+ my $polynomial = 0x82f63b78; # CRC-32C
+ my $ck = mycrc32($head, 0, $polynomial) ^ mycrc32($body, 0, $polynomial);
+
+ my $page= pack("N",$ck).$head.pack("NNN",1,$ck,$space).$body.pack("Nx[4]",$ck);
+ die unless syswrite($ibd_file, $page, $page_size) == $page_size;
+ }
+ close $ibd_file;
+}
+
+sub extend_space {
+ my $file_name = shift;
+ my $n_pages = shift;
+
+ my $page_size = $ENV{INNODB_PAGE_SIZE};
+ my $page;
+
+ sysopen my $ibd_file, $file_name, O_RDWR || die "Cannot open $file_name\n";
+ sysread($ibd_file, $page, $page_size)
+ || die "Cannot read $file_name\n";
+ my $size = unpack("N", substr($page, 46, 4));
+ my $packed_new_size = pack("N", $size + $n_pages);
+ substr($page, 46, 4, $packed_new_size);
+
+ my $head = substr($page, 4, 22);
+ my $body = substr($page, 38, $page_size - 38 - 8);
+ my $polynomial = 0x82f63b78; # CRC-32C
+ my $ck = mycrc32($head, 0, $polynomial) ^ mycrc32($body, 0, $polynomial);
+ my $packed_ck = pack("N", $ck);
+ substr($page, 0, 4, $packed_ck);
+ substr($page, $page_size - 8, 4, $packed_ck);
+
+ sysseek($ibd_file, 0, SEEK_SET)
+ || die "Cannot seek $file_name\n";
+ die unless syswrite($ibd_file, $page, $page_size) == $page_size;
+
+ sysseek($ibd_file, 0, SEEK_END)
+ || die "Cannot seek $file_name\n";
+ my $pages_size = $page_size*$n_pages;
+ my $pages = chr(0) x $pages_size;
+ die unless syswrite($ibd_file, $pages, $pages_size) == $pages_size;
+ close $ibd_file;
+ return $size;
+}
+
+sub die_if_page_is_not_zero {
+ my $file_name = shift;
+ my @pages_to_check = @_;
+
+ no locale;
+ my $page_size = $ENV{INNODB_PAGE_SIZE};
+ my $zero_page = chr(0) x $page_size;
+ sysopen my $ibd_file, $file_name, O_RDWR || die "Cannot open $file_name\n";
+ foreach my $page_no_to_check (@pages_to_check) {
+ sysseek($ibd_file, $page_size*$page_no_to_check, SEEK_SET) ||
+ die "Cannot seek $file_name\n";
+ sysread($ibd_file, my $read_page, $page_size) ||
+ die "Cannot read $file_name\n";
+ die "The page $page_no_to_check is not zero-filed in $file_name"
+ if ($read_page cmp $zero_page);
+ }
+ close $ibd_file;
+}
+
+sub print_corrupted_pages_file {
+ my $file_in = shift;
+ my $file_out = shift;
+ open my $fh, '<', $file_in || die $!;
+ my $line_number = 0;
+ my $space = {};
+ my @spaces;
+ while (my $line = <$fh>) {
+ ++$line_number;
+ if ($line_number & 1) {
+ my ($name, $id) = split(/ /, $line);
+ $space->{name} = $name;
+ }
+ else {
+ $space->{pages} = $line;
+ push (@spaces, $space);
+ $space = {};
+ }
+ }
+ close $fh;
+ my @sorted_spaces = sort { $a->{name} cmp $b->{name} } @spaces;
+ open $fh, '>', $file_out || die $!;
+ foreach my $space (@sorted_spaces) {
+ print $fh $space->{name};
+ print $fh "\n";
+ print $fh $space->{pages};
+ }
+ close $fh;
+}
+
+sub append_corrupted_pages {
+ my $file_name = shift;
+ my $space_name = shift;
+ my $pages = shift;
+ open my $fh, '<', $file_name || die $!;
+ my $line_number = 0;
+ my $space_line;
+ while (my $line = <$fh>) {
+ ++$line_number;
+ if ($line_number & 1) {
+ my ($name, $id) = split(/ /, $line);
+ if ($name eq $space_name) {
+ $space_line = $line;
+ last;
+ }
+ }
+ }
+ close $fh;
+ if (not defined $space_line) {
+ die "Can't find requested space $space_name in file $file_name";
+ }
+ open $fh, '>>', $file_name || die $!;
+ print $fh $space_line;
+ print $fh "$pages\n";
+ close $fh;
+}
diff --git a/mysql-test/suite/mariabackup/include/restart_and_restore.inc b/mysql-test/suite/mariabackup/include/restart_and_restore.inc
new file mode 100644
index 00000000..aa26d28e
--- /dev/null
+++ b/mysql-test/suite/mariabackup/include/restart_and_restore.inc
@@ -0,0 +1,8 @@
+let $_datadir= `SELECT @@datadir`;
+echo # shutdown server;
+--source include/shutdown_mysqld.inc
+echo # remove datadir;
+rmdir $_datadir;
+echo # xtrabackup move back;
+exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --copy-back --datadir=$_datadir --target-dir=$targetdir --parallel=2 --throttle=1 $backup_opts;
+--source include/start_mysqld.inc
diff --git a/mysql-test/suite/mariabackup/include/show_xtrabackup_slave_info.inc b/mysql-test/suite/mariabackup/include/show_xtrabackup_slave_info.inc
new file mode 100644
index 00000000..4a83c9c3
--- /dev/null
+++ b/mysql-test/suite/mariabackup/include/show_xtrabackup_slave_info.inc
@@ -0,0 +1,14 @@
+--disable_query_log
+--file_exists $targetdir/xtrabackup_slave_info
+CREATE TEMPORARY TABLE tmp_slave_info(lineno SERIAL, line TEXT);
+--replace_result $targetdir TARGETDIR
+--eval LOAD DATA LOCAL INFILE '$targetdir/xtrabackup_slave_info' INTO TABLE tmp_slave_info (line);
+SELECT
+ lineno,
+ regexp_replace(
+ regexp_replace(line, '(?<=MASTER_LOG_POS=)[0-9]+', '<NUM>'),
+ '[0-9]+-[0-9]+-[0-9]+', '<NUM-NUM-NUM>')
+ AS line
+FROM tmp_slave_info ORDER BY lineno;
+DROP TEMPORARY TABLE tmp_slave_info;
+--enable_query_log
diff --git a/mysql-test/suite/mariabackup/include/show_xtrabackup_slave_info_out.inc b/mysql-test/suite/mariabackup/include/show_xtrabackup_slave_info_out.inc
new file mode 100644
index 00000000..90b2d00b
--- /dev/null
+++ b/mysql-test/suite/mariabackup/include/show_xtrabackup_slave_info_out.inc
@@ -0,0 +1,20 @@
+--disable_query_log
+--file_exists $XTRABACKUP_OUT
+CREATE TEMPORARY TABLE tmp_slave_info_out(lineno SERIAL, line TEXT);
+--replace_result $targetdir TARGETDIR
+--eval LOAD DATA LOCAL INFILE '$XTRABACKUP_OUT' INTO TABLE tmp_slave_info_out (line);
+SELECT
+ replace(
+ regexp_replace(
+ regexp_replace(line,
+ '[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9]',
+ 'YYYY-MM-DD hh:mm:ss'),
+ '[0-9]+-[0-9]+-[0-9]+', '<NUM-NUM-NUM>'),
+ '\r','' /* Remove CR on Windows */)
+ AS line
+FROM tmp_slave_info_out
+WHERE line LIKE '%MySQL slave binlog position%'
+ OR line LIKE '%Failed to get master binlog coordinates%'
+ORDER BY lineno;
+DROP TEMPORARY TABLE tmp_slave_info_out;
+--enable_query_log