Debian Codegraph @

mysql-test/suite/innodb/t/import_recovery.test

raw
1 --source include/have_innodb.inc
2 --source include/have_debug.inc
3 --source include/not_embedded.inc
4
5 --echo #
6 --echo # MDEV-26137 ALTER TABLE IMPORT enhancement
7 --echo #
8
9 let MYSQLD_DATADIR = `SELECT @@datadir`;
10 let INNODB_PAGE_SIZE=`select @@innodb_page_size`;
11
12 call mtr.add_suppression('InnoDB: Tablespace for table `test`.`t1` is set as discarded.');
13 call mtr.add_suppression('InnoDB: Tablespace for table `test`.`t2` is set as discarded.');
14 call mtr.add_suppression('InnoDB: Tablespace for table `test`.`t3` is set as discarded.');
15 call mtr.add_suppression('InnoDB: ./test/t3.ibd: Page 0 at offset 0 looks corrupted.');
16 call mtr.add_suppression("mariadbd.*: Index for table 't3' is corrupt; try to repair it");
17 call mtr.add_suppression("InnoDB: Expected tablespace id \\d+ but found \\d+ in the file ./test/t3.ibd");
18 # In Windows etc.
19 call mtr.add_suppression("InnoDB: Corrupted page \\[page id: space=.*, page number=0\\] of datafile './test/t3.ibd' could not be found in the doublewrite buffer.");
20 call mtr.add_suppression('InnoDB: Tablespace for table `test`.`t4` is set as discarded.');
21 call mtr.add_suppression('InnoDB: ./test/t4.ibd: Page 0 at offset 0 looks corrupted.');
22 call mtr.add_suppression("mariadbd.*: Index for table 't4' is corrupt; try to repair it");
23 # In Windows etc.
24 call mtr.add_suppression("InnoDB: Corrupted page \\[page id: space=.*, page number=0\\] of datafile './test/t4.ibd' could not be found in the doublewrite buffer.");
25
26 --echo # Recovery from crashes
27 --echo ## t1: Creation of stub succeeds; server crashes; second import attempt succeeds
28 --echo ## t2: Creation of stub succeeds; server crashes; drop table
29 --echo ## t3: Creation of stub succeeds; server crashes; ibd corrupted; second import attempt fails; drop table
30 --echo ## t4: Did not copy .cfg; creation of stub succeeds; server crashes; ibd corrupted; second import attempt fails; drop table
31 CREATE TABLE t (a int) ENGINE=InnoDB;
32 INSERT INTO t VALUES(42);
33 FLUSH TABLES t FOR EXPORT;
34 --copy_file $MYSQLD_DATADIR/test/t.cfg $MYSQLD_DATADIR/test/t1.cfg
35 --copy_file $MYSQLD_DATADIR/test/t.frm $MYSQLD_DATADIR/test/t1.frm
36 --copy_file $MYSQLD_DATADIR/test/t.ibd $MYSQLD_DATADIR/test/t1.ibd
37 --copy_file $MYSQLD_DATADIR/test/t.cfg $MYSQLD_DATADIR/test/t2.cfg
38 --copy_file $MYSQLD_DATADIR/test/t.frm $MYSQLD_DATADIR/test/t2.frm
39 --copy_file $MYSQLD_DATADIR/test/t.ibd $MYSQLD_DATADIR/test/t2.ibd
40 --copy_file $MYSQLD_DATADIR/test/t.cfg $MYSQLD_DATADIR/test/t3.cfg
41 --copy_file $MYSQLD_DATADIR/test/t.frm $MYSQLD_DATADIR/test/t3.frm
42 --copy_file $MYSQLD_DATADIR/test/t.ibd $MYSQLD_DATADIR/test/t3.ibd
43 --copy_file $MYSQLD_DATADIR/test/t.frm $MYSQLD_DATADIR/test/t4.frm
44 --copy_file $MYSQLD_DATADIR/test/t.ibd $MYSQLD_DATADIR/test/t4.ibd
45 UNLOCK TABLES;
46
47 SET GLOBAL innodb_max_dirty_pages_pct_lwm=0.0;
48 SET GLOBAL innodb_max_dirty_pages_pct=0.0;
49
50 let $wait_condition =
51 SELECT variable_value = 0
52 FROM information_schema.global_status
53 WHERE variable_name = 'INNODB_BUFFER_POOL_PAGES_DIRTY';
54 --source include/wait_condition.inc
55
56 connect (hang1,localhost,root);
57 SET DEBUG_SYNC='ib_after_create_stub_for_import SIGNAL hung WAIT_FOR ever';
58 send ALTER TABLE t1 IMPORT TABLESPACE;
59 connection default;
60 SET DEBUG_SYNC='now WAIT_FOR hung';
61
62 connect (hang2,localhost,root);
63 SET DEBUG_SYNC='ib_after_create_stub_for_import SIGNAL hung WAIT_FOR ever';
64 send ALTER TABLE t2 IMPORT TABLESPACE;
65 connection default;
66 SET DEBUG_SYNC='now WAIT_FOR hung';
67
68 connect (hang3,localhost,root);
69 SET DEBUG_SYNC='ib_after_create_stub_for_import SIGNAL hung WAIT_FOR ever';
70 send ALTER TABLE t3 IMPORT TABLESPACE;
71 connection default;
72 SET DEBUG_SYNC='now WAIT_FOR hung';
73
74 connect (hang4,localhost,root);
75 SET DEBUG_SYNC='ib_after_create_stub_for_import SIGNAL hung WAIT_FOR ever';
76 send ALTER TABLE t4 IMPORT TABLESPACE;
77 connection default;
78 SET DEBUG_SYNC='now WAIT_FOR hung';
79
80 let $shutdown_timeout=0;
81 --source include/shutdown_mysqld.inc
82
83 --echo # corrupting the 0th page
84 perl;
85 my $ps = $ENV{INNODB_PAGE_SIZE};
86
87 @tables= ('t3', 't4');
88 foreach $table (@tables) {
89 my $file = "$ENV{MYSQLD_DATADIR}/test/$table.ibd";
90 open(FILE, "+<$file") || die "Unable to open $file";
91 binmode FILE;
92 sysseek(FILE, 0, 0) || die "Unable to seek $file\n";
93 die "Unable to read $file" unless sysread(FILE, $page, $ps) == $ps;
94 # Replace all NUL bytes with SOH bytes.
95 $page =~ tr/\x0/\x1/;
96 sysseek(FILE, 0, 0) || die "Unable to seek $file\n";
97 syswrite(FILE, $page, $ps)==$ps || die "Unable to write $file\n";
98 close FILE or die "close";
99 }
100 EOF
101
102 --echo # Restart mysqld after the crash and reconnect.
103 --source include/start_mysqld.inc
104
105 ALTER TABLE t1 IMPORT TABLESPACE;
106 SHOW CREATE TABLE t1;
107 SELECT * FROM t1;
108
109 --error ER_INTERNAL_ERROR
110 ALTER TABLE t3 IMPORT TABLESPACE;
111
112 --error ER_TABLE_SCHEMA_MISMATCH
113 ALTER TABLE t4 IMPORT TABLESPACE;
114
115 DROP TABLE t, t1, t2, t3, t4;
116
117 --echo # Recovery from corruption only, no server restart
118 --echo ## t5: Recovery from corruption, with cfg
119 --echo ## t6: Recovery from corruption, without cfg
120 call mtr.add_suppression('InnoDB: ./test/t5.ibd: Page 0 at offset 0 looks corrupted.');
121 call mtr.add_suppression("mariadbd.*: Index for table 't5' is corrupt; try to repair it");
122 # In Windows etc.
123 call mtr.add_suppression("InnoDB: Corrupted page \\[page id: space=.*, page number=0\\] of datafile './test/t5.ibd' could not be found in the doublewrite buffer.");
124 # In Windows etc.
125 call mtr.add_suppression("InnoDB: Corrupted page \\[page id: space=.*, page number=0\\] of datafile './test/t6.ibd' could not be found in the doublewrite buffer.");
126 call mtr.add_suppression("mariadbd.*: Index for table 't6' is corrupt; try to repair it");
127
128 CREATE TABLE t (a int) ENGINE=InnoDB;
129 INSERT INTO t VALUES(42);
130 FLUSH TABLES t FOR EXPORT;
131 --copy_file $MYSQLD_DATADIR/test/t.cfg $MYSQLD_DATADIR/test/t5.cfg
132 --copy_file $MYSQLD_DATADIR/test/t.frm $MYSQLD_DATADIR/test/t5.frm
133 --copy_file $MYSQLD_DATADIR/test/t.ibd $MYSQLD_DATADIR/test/t5.ibd
134 --copy_file $MYSQLD_DATADIR/test/t.frm $MYSQLD_DATADIR/test/t6.frm
135 --copy_file $MYSQLD_DATADIR/test/t.ibd $MYSQLD_DATADIR/test/t6.ibd
136 UNLOCK TABLES;
137
138 --echo # corrupting the 0th page
139 perl;
140 my $ps = $ENV{INNODB_PAGE_SIZE};
141
142 @tables= ('t5', 't6');
143 foreach $table (@tables) {
144 my $file = "$ENV{MYSQLD_DATADIR}/test/$table.ibd";
145 open(FILE, "+<$file") || die "Unable to open $file";
146 binmode FILE;
147 sysseek(FILE, 0, 0) || die "Unable to seek $file\n";
148 die "Unable to read $file" unless sysread(FILE, $page, $ps) == $ps;
149 # Replace all NUL bytes with SOH bytes.
150 $page =~ tr/\x0/\x1/;
151 sysseek(FILE, 0, 0) || die "Unable to seek $file\n";
152 syswrite(FILE, $page, $ps)==$ps || die "Unable to write $file\n";
153 close FILE or die "close";
154 }
155 EOF
156
157 --error ER_INTERNAL_ERROR
158 ALTER TABLE t5 IMPORT TABLESPACE;
159
160 --error ER_TABLE_SCHEMA_MISMATCH
161 ALTER TABLE t6 IMPORT TABLESPACE;
162
163 DROP TABLE t, t5, t6;