Debian Codegraph @

mysql-test/suite/atomic/rename_trigger.test

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