1#
2# Tests for corrupted MyISAM tables and MyISAMMRG tables with corrupted
3# children..
4#
5# Run with --myisam-recover=force option.
6#
7# Preparation: we need to make sure that the merge parent
8# is never left in the table cache when closed, since this may
9# have effect on merge children.
10# For that, we set the table cache to minimal size and populate it
11# in a concurrent connection.
12#
13# Switching to connection con1
14#
15#
16# Minimal values.
17#
18call mtr.add_suppression("Got an error from thread_id=.*ha_myisam.cc:");
19call mtr.add_suppression("MySQL thread id .*, query id .* localhost.*root Checking table");
20call mtr.add_suppression(" '\..test.t1'");
21set @start_table_open_cache=@@global.table_open_cache;
22set @start_table_definition_cache=@@global.table_definition_cache;
23set global table_open_cache=256;
24set global table_definition_cache=400;
25drop procedure if exists p_create;
26create procedure p_create()
27begin
28declare i int default 1;
29set @lock_table_stmt="lock table ";
30set @drop_table_stmt="drop table ";
31while i < @@global.table_definition_cache + 1 do
32set @table_name=concat("t_", i);
33set @opt_comma=if(i=1, "", ", ");
34set @lock_table_stmt=concat(@lock_table_stmt, @opt_comma,
35@table_name, " read");
36set @drop_table_stmt=concat(@drop_table_stmt, @opt_comma, @table_name);
37set @create_table_stmt=concat("create table if not exists ",
38@table_name, " (a int)");
39prepare stmt from @create_table_stmt;
40execute stmt;
41deallocate prepare stmt;
42set i= i+1;
43end while;
44end|
45call p_create();
46drop procedure p_create;
47#
48# Switching to connection 'default'
49#
50#
51# We have to disable the ps-protocol, to avoid
52# "Prepared statement needs to be re-prepared" errors
53# -- table def versions change all the time with full table cache.
54#
55drop table if exists t1, t1_mrg, t1_copy;
56#
57# Prepare a MERGE engine table, that refers to a corrupted
58# child.
59#
60create table t1 (a int, key(a)) engine=myisam;
61create table t1_mrg (a int) union (t1) engine=merge;
62#
63# Create a table with a corrupted index file:
64# save an old index file, insert more rows,
65# overwrite the new index file with the old one.
66#
67insert into  t1 (a) values (1), (2), (3);
68flush table t1;
69insert into  t1 (a) values (4), (5), (6);
70flush table t1;
71# check table is needed to mark the table as crashed.
72check table t1;
73Table	Op	Msg_type	Msg_text
74test.t1	check	warning	Size of datafile is: 42       Should be: 21
75test.t1	check	error	Record-count is not ok; is 6   Should be: 3
76test.t1	check	warning	Found 6 key parts. Should be: 3
77test.t1	check	error	Corrupt
78#
79# At this point we have a merge table t1_mrg pointing to t1,
80# and t1 is corrupted, and will be auto-repaired at open.
81# Check that this doesn't lead to memory corruption.
82#
83select * from t1_mrg;
84a
851
862
873
884
895
906
91Warnings:
92Error	145	Table 't1' is marked as crashed and should be repaired
93Error	1194	Table 't1' is marked as crashed and should be repaired
94Error	1034	Number of rows changed from 3 to 6
95#
96# Cleanup
97#
98drop table t1, t1_mrg;
99#
100# Switching to connection con1
101#
102unlock tables;
103prepare stmt from @drop_table_stmt;
104execute stmt;
105deallocate prepare stmt;
106set @@global.table_definition_cache=@start_table_definition_cache;
107set @@global.table_open_cache=@start_table_open_cache;
108#
109# 18075170 - sql node restart required to avoid deadlock after
110#            restore
111#
112# Check that auto-repair for MyISAM tables can now happen in the
113# middle of transaction, without aborting it.
114create table t1 (a int, key(a)) engine=myisam;
115create table t2 (a int);
116insert into t2 values (1);
117# Create a table with a corrupted index file:
118# save an old index file, insert more rows,
119# overwrite the new index file with the old one.
120insert into  t1 (a) values (1);
121flush table t1;
122insert into  t1 (a) values (4);
123flush table t1;
124# Check table is needed to mark the table as crashed.
125check table t1;
126Table	Op	Msg_type	Msg_text
127test.t1	check	warning	Size of datafile is: 14       Should be: 7
128test.t1	check	error	Record-count is not ok; is 2   Should be: 1
129test.t1	check	warning	Found 2 key parts. Should be: 1
130test.t1	check	error	Corrupt
131# At this point we have a corrupt t1
132set autocommit = 0;
133select * from t2;
134a
1351
136# Without fix select from t1 will break the transaction. After the fix
137# transaction should be active and should hold lock on table t2. Alter
138# table from con2 will wait only if the transaction is not broken.
139select * from t1;
140a
1411
1424
143Warnings:
144Error	145	Table 't1' is marked as crashed and should be repaired
145Error	1194	Table 't1' is marked as crashed and should be repaired
146Error	1034	Number of rows changed from 1 to 2
147ALTER TABLE t2 ADD val INT;
148# With fix we should have alter table waiting for t2 lock here.
149ROLLBACK;
150SET autocommit = 1;
151# Cleanup
152drop table t1, t2;
153