Debian Codegraph @

mysql-test/suite/innodb_undo/include/truncate_at_shutdown.inc

raw
1 --echo # While the purge thread is turned off, perform enough DML to cause
2 --echo # undo tablespace sizes grow beyond the truncation threshold.
3
4 if ($CRASH_ON_SHUTDOWN == 0)
5 {
6 --echo # Then check if truncation is accomplished by restarting mysqld
7 --echo # causing each undo tablespace to be truncated.
8 }
9
10 if ($CRASH_ON_SHUTDOWN == 1)
11 {
12 --echo # Then inject a crash at $CRASH_POINT and check that recovery occurs
13 --echo # and that the truncation is completed if it was started.
14 }
15
16 # This test uses debug settings like innodb_purge_stop_now.
17 --source include/have_debug.inc
18
19 # Valgrind would complain about memory leaks when we crash on purpose.
20 --source include/not_valgrind.inc
21
22 # Avoid CrashReporter popup on Mac
23 --source include/not_crashrep.inc
24
25 # The test must start with only 2 undo tablespaces
26 --source include/have_innodb_default_undo_tablespaces.inc
27
28 --echo # Create 2 explicit undo tablespaces.
29 CREATE UNDO TABLESPACE undo_003 ADD DATAFILE 'undo_003.ibu';
30 CREATE UNDO TABLESPACE undo_004 ADD DATAFILE 'undo_004.ibu';
31
32 --echo # Make the 2 implicit undo tablespaces inactive so they get truncated.
33 SET GLOBAL innodb_purge_rseg_truncate_frequency=1;
34 ALTER UNDO TABLESPACE innodb_undo_001 SET INACTIVE;
35 ALTER UNDO TABLESPACE innodb_undo_002 SET INACTIVE;
36 let $inactive_undo_space = innodb_undo_001;
37 source include/wait_until_undo_space_is_empty.inc;
38 let $inactive_undo_space = innodb_undo_002;
39 source include/wait_until_undo_space_is_empty.inc;
40
41 if ($USE_EXPLICIT == 0)
42 {
43 --echo # Make the 2 implicit undo tablespaces active.
44 ALTER UNDO TABLESPACE innodb_undo_001 SET ACTIVE;
45 ALTER UNDO TABLESPACE innodb_undo_002 SET ACTIVE;
46
47 --echo # Get rid of the explcit undo tablespaces.
48 ALTER UNDO TABLESPACE undo_003 SET INACTIVE;
49 ALTER UNDO TABLESPACE undo_004 SET INACTIVE;
50 let $inactive_undo_space = undo_003;
51 source include/wait_until_undo_space_is_empty.inc;
52 let $inactive_undo_space = undo_004;
53 source include/wait_until_undo_space_is_empty.inc;
54 DROP UNDO TABLESPACE undo_003;
55 DROP UNDO TABLESPACE undo_004;
56
57 --let UNDO_NAME_1 = innodb_undo_001
58 --let UNDO_NAME_2 = innodb_undo_002
59 }
60
61 if ($USE_EXPLICIT == 1) {
62 --let UNDO_NAME_1 = undo_003
63 --let UNDO_NAME_2 = undo_004
64 }
65
66 SET GLOBAL innodb_purge_rseg_truncate_frequency=default;
67
68 --echo # The two undo tablespaces to truncate at shutdown will be $UNDO_NAME_1 and $UNDO_NAME_2
69
70 SELECT NAME, SPACE_TYPE, STATE, AUTOEXTEND_SIZE FROM INFORMATION_SCHEMA.INNODB_TABLESPACES
71 WHERE SPACE_TYPE = 'Undo' ORDER BY NAME;
72
73 let FILE_SIZE_11 = `SELECT FILE_SIZE FROM INFORMATION_SCHEMA.INNODB_TABLESPACES WHERE NAME = '$UNDO_NAME_1'`;
74 let FILE_SIZE_21 = `SELECT FILE_SIZE FROM INFORMATION_SCHEMA.INNODB_TABLESPACES WHERE NAME = '$UNDO_NAME_2'`;
75
76 let MYSQLD_DATADIR = `select @@datadir`;
77
78 --echo # Turn off purging so that undo logs build up in the undo tablespaces.
79 SET GLOBAL innodb_purge_stop_now=ON;
80
81 --echo # Perform enough DML action so that undo tablespace sizes grow beyond
82 --echo # the threshold set by --innodb-max-undo-log-size.
83 --connect(con1,localhost,root,,test)
84 --connection con1
85
86 create table t1(
87 keyc int,
88 c1 char(255),
89 c2 char(255),
90 c3 char(255),
91 c4 char(255),
92 c5 char(255),
93 c6 char(255),
94 primary key(keyc)) engine = innodb;
95
96 delimiter |;
97 CREATE PROCEDURE populate_t1()
98 BEGIN
99 DECLARE i INT DEFAULT 1;
100 while (i <= 16000) DO
101 insert into t1 values (i, 'a', 'b', 'c', 'd', 'e', 'f' );
102 SET i = i + 1;
103 END WHILE;
104 END |
105 delimiter ;|
106
107 call populate_t1();
108 delete from t1 where keyc < 10000;
109 update t1 set c1 = 'mysql' where keyc > 10000;
110 update t1 set c2 = 'mysql' where keyc > 10000;
111 update t1 set c3 = 'mysql' where keyc > 10000;
112 update t1 set c4 = 'mysql' where keyc > 10000;
113 update t1 set c5 = 'mysql' where keyc > 10000;
114 update t1 set c6 = 'mysql' where keyc > 10000;
115
116 --echo # Start a new transaction for both tablespaces to get utilized
117 --connect(con2,localhost,root,,test)
118 --connection con2
119
120 create table t2 (
121 keyc int,
122 c1 char(255),
123 c2 char(255),
124 c3 char(255),
125 c4 char(255),
126 c5 char(255),
127 c6 char(255),
128 primary key(keyc)) engine = innodb;
129
130 delimiter |;
131 CREATE PROCEDURE populate_t2()
132 BEGIN
133 DECLARE i INT DEFAULT 1;
134 while (i <= 16000) DO
135 insert into t2 values (i, 'a', 'b', 'c', 'd', 'e', 'f' );
136 SET i = i + 1;
137 END WHILE;
138 END |
139 delimiter ;|
140
141 call populate_t2();
142 delete from t2 where keyc < 10000;
143 update t2 set c1 = 'mysql' where keyc > 10000;
144 update t2 set c2 = 'mysql' where keyc > 10000;
145 update t2 set c3 = 'mysql' where keyc > 10000;
146 update t2 set c4 = 'mysql' where keyc > 10000;
147 update t2 set c5 = 'mysql' where keyc > 10000;
148 update t2 set c6 = 'mysql' where keyc > 10000;
149
150 --connection default
151
152 drop PROCEDURE populate_t1;
153 drop PROCEDURE populate_t2;
154 drop table t1, t2;
155 --disconnect con1
156 --disconnect con2
157
158 SELECT NAME, SPACE_TYPE, STATE, AUTOEXTEND_SIZE FROM INFORMATION_SCHEMA.INNODB_TABLESPACES
159 WHERE SPACE_TYPE = 'Undo' ORDER BY NAME;
160
161 --echo # Compare the undo tablespace sizes before and after DML growth.
162 let FILE_SIZE_12 = `SELECT FILE_SIZE FROM INFORMATION_SCHEMA.INNODB_TABLESPACES WHERE NAME = '$UNDO_NAME_1'`;
163 let FILE_SIZE_22 = `SELECT FILE_SIZE FROM INFORMATION_SCHEMA.INNODB_TABLESPACES WHERE NAME = '$UNDO_NAME_2'`;
164 if($FILE_SIZE_11 > $FILE_SIZE_12)
165 {
166 echo ERROR: Size increase did not happen for $UNDO_NAME_1: Initial size is $FILE_SIZE_11, Size after DML is $FILE_SIZE_12;
167 }
168 if($FILE_SIZE_21 > $FILE_SIZE_22)
169 {
170 echo ERROR: Size increase did not happen for $UNDO_NAME_2: Initial size is $FILE_SIZE_21, Size after DML is $FILE_SIZE_22;
171 }
172
173 if ($CRASH_ON_SHUTDOWN == 1)
174 {
175 --echo Setting crash point = '$CRASH_POINT'.
176 eval SET GLOBAL DEBUG = "+d,$CRASH_POINT";
177 }
178
179 --echo # Do a slow shut down so the undo tablespaces can be truncated.
180 SET GLOBAL innodb_max_undo_log_size=20000000;
181 SET GLOBAL innodb_fast_shutdown=0;
182 SET GLOBAL innodb_purge_rseg_truncate_frequency=1;
183 SET GLOBAL innodb_purge_run_now=ON;
184 --let $shutdown_server_timeout= 300
185 --source include/shutdown_mysqld.inc
186
187 if ($CRASH_ON_SHUTDOWN == 1)
188 {
189 --echo Recovery from crash point = '$CRASH_POINT'.
190 let SEARCH_FILE = $MYSQLTEST_VARDIR/log/mysqld.1.err;
191 let SEARCH_PATTERN = $CRASH_POINT;
192 --source include/search_pattern.inc
193 --remove_files_wildcard $MYSQLD_DATADIR cht_logbin.*
194 --remove_files_wildcard $MYSQLD_DATADIR binlog.*
195 }
196
197 # The truncate will get started during shutdown using the settings above.
198 # The restarted engine does not need these settings to complete the truncate
199 # if the injected crash was far enough along.
200 --let $restart_parameters="restart:"
201 --let $explicit_default_wait_counter = 15000
202 --source include/start_mysqld.inc
203
204 let FILE_SIZE_13 = `SELECT FILE_SIZE FROM INFORMATION_SCHEMA.INNODB_TABLESPACES WHERE NAME = '$UNDO_NAME_1'`;
205 let FILE_SIZE_23 = `SELECT FILE_SIZE FROM INFORMATION_SCHEMA.INNODB_TABLESPACES WHERE NAME = '$UNDO_NAME_2'`;
206
207 if ($CRASH_ON_SHUTDOWN == 0)
208 {
209 --echo # Compare the undo tablespace sizes before and after truncation.
210 if ($FILE_SIZE_12 <= $FILE_SIZE_13)
211 {
212 --echo ERROR: Truncated size is wrong for $UNDO_NAME_1: Size before truncation is $FILE_SIZE_12, Size after truncation is $FILE_SIZE_13;
213 }
214 if ($FILE_SIZE_22 <= $FILE_SIZE_23)
215 {
216 --echo ERROR: Truncated size is wrong for $UNDO_NAME_2: Size before truncation is $FILE_SIZE_22, Size after truncation is $FILE_SIZE_23;
217 }
218 }
219
220 SELECT NAME, SPACE_TYPE, STATE, AUTOEXTEND_SIZE FROM INFORMATION_SCHEMA.INNODB_TABLESPACES
221 WHERE SPACE_TYPE = 'Undo' ORDER BY NAME;
222
223 --echo #
224 --echo # Cleanup
225 --echo #
226
227 if ($USE_EXPLICIT == 1)
228 {
229 ALTER UNDO TABLESPACE innodb_undo_001 SET ACTIVE;
230 ALTER UNDO TABLESPACE innodb_undo_002 SET ACTIVE;
231 ALTER UNDO TABLESPACE undo_003 SET INACTIVE;
232 ALTER UNDO TABLESPACE undo_004 SET INACTIVE;
233
234 SET GLOBAL innodb_purge_rseg_truncate_frequency=1;
235 let $inactive_undo_space = undo_003;
236 source include/wait_until_undo_space_is_empty.inc;
237 let $inactive_undo_space = undo_004;
238 source include/wait_until_undo_space_is_empty.inc;
239 SET GLOBAL innodb_purge_rseg_truncate_frequency=default;
240
241 DROP UNDO TABLESPACE undo_003;
242 DROP UNDO TABLESPACE undo_004;
243 }
244
245 SELECT NAME, SPACE_TYPE, STATE, AUTOEXTEND_SIZE FROM INFORMATION_SCHEMA.INNODB_TABLESPACES
246 WHERE SPACE_TYPE = 'Undo' ORDER BY NAME;