Debian Codegraph @

mysql-test/suite/storage_engine/repair_table.inc

raw
1 #
2 # REPAIR TABLE statements
3 #
4 # Note: the output is likely to be different for the engine under test,
5 # in which case rdiff will be needed. Or, the output might say that
6 # the storage engine does not support REPAIR.
7 #
8
9 --disable_warnings
10 DROP TABLE IF EXISTS t1,t2;
11 --enable_warnings
12
13 --source create_table.inc
14 INSERT INTO t1 (a,b) VALUES (1,'a'),(2,'b');
15 --let $table_name = t2
16 --source create_table.inc
17
18 REPAIR TABLE t1;
19 if ($mysql_errname)
20 {
21 --source unexpected_result.inc
22 }
23 INSERT INTO t1 (a,b) VALUES (3,'c');
24 INSERT INTO t2 (a,b) VALUES (4,'d');
25 REPAIR NO_WRITE_TO_BINLOG TABLE t1, t2;
26 INSERT INTO t2 (a,b) VALUES (5,'e'),(6,'f');
27 REPAIR LOCAL TABLE t2;
28 INSERT INTO t1 (a,b) VALUES (7,'g'),(8,'h');
29 INSERT INTO t2 (a,b) VALUES (9,'i');
30 REPAIR LOCAL TABLE t2, t1 EXTENDED;
31 INSERT INTO t1 (a,b) VALUES (10,'j');
32 INSERT INTO t2 (a,b) VALUES (11,'k');
33 REPAIR TABLE t1, t2 QUICK USE_FRM;
34 INSERT INTO t1 (a,b) VALUES (12,'l');
35 INSERT INTO t2 (a,b) VALUES (13,'m');
36 REPAIR NO_WRITE_TO_BINLOG TABLE t1, t2 QUICK EXTENDED USE_FRM;
37 FLUSH TABLE t1;
38
39 let my_datadir = `SELECT @@datadir`;
40
41 # Now we'll override all table files except for frm.
42 # Some engines are more enduring to table files corruption
43 # than others, so the result of the following INSERT and REPAIR
44 # will be different for different engines
45
46 --perl
47 @files = glob "$ENV{my_datadir}/test/t1.*";
48 foreach (@files)
49 {
50 next if /.frm$/;
51 rename($_,"$_.save");
52 open(FILE,">$_") || print "Could not open $_\n" && exit;
53 print FILE "";
54 close(FILE);
55 }
56 EOF
57
58 # We don't worry so much about the INSERT or SELECT result,
59 # it's REPAIR that we are after.
60 # The preceding INSERT, however, helps to trigger
61 # a bit more internals
62 --let $error_codes = 0,130,ER_FAILED_READ_FROM_PAR_FILE,ER_OPEN_AS_READONLY
63 INSERT INTO t1 (a,b) VALUES (14,'n');
64 --source check_errors.inc
65 CHECK TABLE t1;
66 --let $error_codes = 0,130,ER_FAILED_READ_FROM_PAR_FILE,ER_OPEN_AS_READONLY
67 SELECT a,b FROM t1;
68 --source check_errors.inc
69 --enable_warnings
70 REPAIR TABLE t1;
71
72 --perl
73 @files = glob "$ENV{my_datadir}/test/t1.*.save";
74 foreach (@files)
75 {
76 $nm = $_;
77 $nm =~ s/\.save$//;
78 rename($_,$nm);
79 }
80 EOF
81
82 DROP TABLE t1, t2;
83
84 --let $continue = 1
85 --source have_default_index.inc
86
87 if ($have_default_index)
88 {
89 call mtr.add_suppression("Got an error from thread_id=.*");
90 call mtr.add_suppression("MariaDB thread id .*, query id .* localhost.*root Checking table");
91 call mtr.add_suppression(" '\..test.t1'");
92 call mtr.add_suppression("Couldn't repair table: test.t1");
93
94 # In 10.2 with log_warnings=2 the error message is printed to the error log
95 call mtr.add_suppression("Table 't1' is marked as crashed.*");
96
97 --let $create_definition = a $int_indexed_col, b $char_col, $default_index (a)
98 --source create_table.inc
99 REPAIR TABLE t1;
100 INSERT INTO t1 (a,b) VALUES (7,'g'),(8,'h');
101 REPAIR TABLE t1 EXTENDED;
102 INSERT INTO t1 (a,b) VALUES (10,'j');
103 REPAIR TABLE t1 USE_FRM;
104
105 # We will take files one by one (except for frm file),
106 # save the file, update the table, then restore the file
107 # and check the table.
108 # Results here can be very different depending on the engine.
109
110 let $my_errno = 0;
111
112 --list_files $my_datadir/test
113
114 while (!$my_errno)
115 {
116 --error 0,2
117 --perl
118 use File::Copy;
119 @files = glob "$ENV{my_datadir}/test/t1*";
120 foreach (@files)
121 {
122 next if /.(?:frm|save|done)$/;
123 next if -e "$_.done";
124 copy($_,"$_.save");
125 exit 0;
126 }
127 # No more files
128 exit 2;
129 EOF
130 let $my_errno = $errno;
131 if (!$my_errno)
132 {
133 --let $error_codes = 0,144
134 INSERT INTO t1 (a,b) VALUES (14,'n'),(15,'o');
135 --source check_errors.inc
136 FLUSH TABLE t1;
137 --replace_result $my_datadir <DATADIR>
138 --perl
139 use File::Copy;
140 @files = glob "$ENV{my_datadir}/test/t1*.save";
141 $nm = $files[0];
142 $nm =~ s/\.save$//;
143 print "Restoring $nm\n";
144 copy($files[0],"$nm.done");
145 rename($files[0],$nm);
146 EOF
147 CHECK TABLE t1;
148 --let $error_codes = 0,ER_NOT_KEYFILE,144
149 SELECT a,b FROM t1;
150 --source check_errors.inc
151 }
152 }
153 DROP TABLE t1;
154 }
155
156 --remove_files_wildcard $my_datadir/test t1*
157
158