1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
--source include/have_debug.inc
--source include/have_innodb.inc
--source include/have_csv.inc
--source include/not_valgrind.inc
--source include/not_embedded.inc
# Speed up wait_until_connected_again.inc
let NO_WSREP=1;
#
# Testing of atomic rename with forced crashes in a lot of different places
#
let $engine_count=5;
let $engines='myisam','aria','aria_notrans','innodb','csv';
let $crash_count=6;
let $crash_points='definition_file_after_create','ddl_log_rename_before_rename_table','ddl_log_rename_before_phase_trigger','ddl_log_rename_before_rename_trigger','ddl_log_rename_before_stat_tables','ddl_log_rename_after_stat_tables';
# Number of renames in the tested statement
let $renames=5;
let $old_debug=`select @@debug_dbug`;
let $e=0;
--disable_query_log
while ($e < $engine_count)
{
inc $e;
let $engine=`select ELT($e, $engines)`;
let $default_engine=$engine;
let $extra_option=;
if ($engine == "aria")
{
let $extra_option=transactional=1;
}
if ($engine == "aria_notrans")
{
let $default_engine="aria";
let $extra_option=transactional=0;
}
--eval set @@default_storage_engine=$default_engine
--eval create table t1 (a int not null) $extra_option;
--eval create table t2 (b int not null) $extra_option;
--eval create table t3 (c int not null) $extra_option;
--eval create table t4 (d int not null) $extra_option;
insert into t1 values(1);
insert into t2 values(2);
insert into t3 values(3);
insert into t4 values(4);
delimiter |;
create trigger t1_trg before insert on t1 for each row
begin
if isnull(new.a) then
set new.a:= 1000;
end if;
end|
create trigger t2_trg before insert on t2 for each row
begin
if isnull(new.b) then
set new.b:= 2000;
end if;
end|
create trigger t3_trg before insert on t3 for each row
begin
if isnull(new.c) then
set new.c:= 4000;
end if;
end|
create trigger t4_trg before insert on t4 for each row
begin
if isnull(new.d) then
set new.d:= 8000;
end if;
end|
delimiter ;|
let $c=0;
while ($c < $crash_count)
{
inc $c;
let $crash=`select ELT($c, $crash_points)`;
let $r=0;
while ($r < $renames)
{
inc $r;
echo "engine: $engine crash point: $crash position: $r";
flush tables;
--exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
--disable_reconnect
--eval set @@debug_dbug="+d,$crash",@debug_crash_counter=$r
let $errno=0;
--error 0,2013
rename table t1 to t5, t2 to t1, t5 to t2, t4 to t5, t3 to t4;
let $error=$errno;
--enable_reconnect
--source include/wait_until_connected_again.inc
--disable_query_log
--eval set @@debug_dbug="$old_debug"
if ($error == 0)
{
echo "No crash!";
# No crash, rename things back
rename table t4 to t3, t5 to t4, t2 to t5, t1 to t2, t5 to t1;
}
# Ensure that the tables are back to original
let $res=`select t1.a+t2.b+t3.c+t4.d from t1,t2,t3,t4`;
if ($res != 10)
{
die "Got result $res when 10 was expected";
}
# Ensure that triggers work
insert into t1 values(null);
insert into t2 values(null);
insert into t3 values(null);
insert into t4 values(null);
let $res=`select (select sum(t1.a) from t1)+ (select sum(t2.b) from t2) + (select sum(t3.c) from t3)+ (select sum(t4.d) from t4)`;
if ($res != 15010)
{
die "Got result $res when 15010 was expected";
}
# Restore tables
delete from t1 where a > 100;
delete from t2 where b > 100;
delete from t3 where c > 100;
delete from t4 where d > 100;
}
}
# Last test, check that rename really worked
rename table t1 to t5, t2 to t1, t5 to t2, t4 to t5, t3 to t4;
insert into t1 values(null);
insert into t2 values(null);
insert into t5 values(null);
insert into t4 values(null);
let $res=`select (select sum(t1.b) from t1)+ (select sum(t2.a) from t2) + (select sum(t4.c) from t4)+ (select sum(t5.d) from t5)`;
if ($res != 15010)
{
die "Got result $res when 15010 was expected";
}
let $res=`select (select count(*)=2 from t1) + (select count(*)=2 from t2) + (select count(*)=2 from t4)+ (select count(*)=2 from t5)`;
if ($res != 4)
{
die "Got result $res when 4 was expected";
}
drop table t1,t2,t4,t5;
}
--enable_query_log
|