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