Debian Codegraph @

mysql-test/suite/binlog/t/binlog_open_errors.test

raw
1 # === Purpose ===
2 #
3 # Check errors returned by MYSQL_BIN_LOG::open_binlog
4 #
5 # ==== Requirements ====
6 #
7 # R1. When the binary log file is opened during recovery,
8 # the following error conditions and boundary conditions should be handled:
9 # * If the file is truncated just after the magic header,
10 # it should report an error and start ha_recover().
11 # * If the file is missing a format_description_log_event,
12 # recovery should report an error and start ha_recover().
13 # * If the Format_description_log_event exists but
14 # does not have LOG_EVENT_BINLOG_IN_USE_F set,
15 # it should report a warning and start ha_recover().
16 #
17 # === Implementation ====
18 #
19 # 1. Start server so that binary log is created
20 # 2. Prepare binary log with header only
21 # 3. Check error ER_READ_LOG_EVENT_FAILED is reported
22 # "Error in Log_event::read_log_event()"
23 # 4. Perpare binary log without Format_desc event
24 # 5. Check error ER_BINLOG_CRASH_RECOVERY_MALFORMED_LOG is reported
25 # "Found invalid event sequence while recovering from binary log file."
26 # 6. Set debug points binlog_crash_between_close_and_open so that server is crashed
27 # after binary log LOG_EVENT_BINLOG_IN_USE_F is set to false
28 # 7. Check error ER_BINLOG_CANT_OPEN_CRASHED_BINLOG is reported
29 # "Failed to open the crashed binlog file when source server is recovering it."
30 #
31 # === References ===
32 #
33 # BUG #33658850 Binlog recovery not reporting all error states
34 #
35 --source include/have_debug.inc
36 --source include/have_binlog_format_mixed.inc
37
38 RESET MASTER;
39
40 --let $MYSQLD_DATADIR = `SELECT @@DATADIR`
41 --let $binlog = query_get_value(SHOW MASTER STATUS, File, 1)
42 --let $event_following_format_desc_start = query_get_value(SHOW BINLOG EVENTS IN '$binlog', Pos, 2)
43 --let $event_following_format_desc_stop = query_get_value(SHOW BINLOG EVENTS IN '$binlog', End_log_pos, 2)
44
45 --file_exists $MYSQLD_DATADIR/$binlog
46
47 #
48 # Use save_error_log_position.inc before the first call to assert_error_log.inc.
49 # The error log may contain errors from earlier test runs.
50 #
51 --source include/save_error_log_position.inc
52
53 #
54 # Shutdown server
55 #
56 --source include/shutdown_mysqld.inc
57
58 #
59 # Prepare binary log with header only
60 #
61 --echo Prepare binary log with header only
62
63 --let $in_filename = $MYSQLD_DATADIR/$binlog
64 --let $out_filename = $MYSQLD_DATADIR/$binlog.header
65 --let $file_start_pos = 0
66 --let $file_stop_pos = 4
67 --source include/copy_file_segment.inc
68
69 #
70 # Prepare binary log with truncated Format_desc event
71 #
72 --echo Prepare binary log without Format_desc event
73
74 --let $in_filename = $MYSQLD_DATADIR/$binlog
75 --let $out_filename = $MYSQLD_DATADIR/$binlog.truncformat
76 --let $file_start_pos = 0
77 --let $file_stop_pos = $event_following_format_desc_start
78 --dec $file_stop_pos
79 --source include/copy_file_segment.inc
80
81 #
82 # Prepare binary log without Format_desc event
83 #
84 --echo Prepare binary log without Format_desc event
85
86 --let $in_filename = $MYSQLD_DATADIR/$binlog
87 --let $out_filename = $MYSQLD_DATADIR/$binlog.formatless
88 --let $file_start_pos = 0
89 --let $file_stop_pos = 4
90 --source include/copy_file_segment.inc
91 --let $file_start_pos = $event_following_format_desc_start
92 --let $file_stop_pos = $event_following_format_desc_stop
93 --source include/copy_file_segment.inc
94
95 #
96 # Backup binlog file
97 #
98 --echo Backup binlog file
99
100 --copy_file $MYSQLD_DATADIR/$binlog $MYSQLD_DATADIR/$binlog.backup
101
102 --echo
103 --echo # 1. Test Error in Log_event::read_log_event() #
104 --echo ################################################
105
106 #
107 # Swap header only event
108 #
109 --remove_file $MYSQLD_DATADIR/$binlog
110 --copy_file $MYSQLD_DATADIR/$binlog.header $MYSQLD_DATADIR/$binlog
111
112 #
113 # Start server
114 #
115 --source include/start_mysqld.inc
116
117 RESET MASTER;
118
119 #
120 # Search for error message : 'arrived the end of the file'
121 #
122 --let $error_pattern = Error in Log_event::read_log_event().*
123 --source include/assert_error_log.inc
124
125 #
126 # Shutdown server
127 #
128 --source include/shutdown_mysqld.inc
129
130 --echo
131 --echo # 2. Truncated binary log
132 --echo ##############################################################################
133
134 #
135 # Swap header only event
136 #
137 --remove_file $MYSQLD_DATADIR/$binlog
138 --copy_file $MYSQLD_DATADIR/$binlog.truncformat $MYSQLD_DATADIR/$binlog
139
140 #
141 # Start server
142 #
143 --source include/start_mysqld.inc
144
145 RESET MASTER;
146
147 #
148 # Search for error message : 'binlog truncated in the middle of event; consider out of disk space'
149 #
150 let $error_pattern = Error in Log_event::read_log_event().*
151 Error reading GTIDs from binary log.*
152 ;
153 --source include/assert_error_log.inc
154
155 #
156 # Shutdown server
157 #
158 --source include/shutdown_mysqld.inc
159
160 --echo
161 --echo # 3. Test Found invalid event sequence while recovering from binary log file #
162 --echo ##############################################################################
163
164 #
165 # Swap format less binary log
166 #
167 --remove_file $MYSQLD_DATADIR/$binlog
168 --copy_file $MYSQLD_DATADIR/$binlog.formatless $MYSQLD_DATADIR/$binlog
169
170 #
171 # Start server
172 #
173 --source include/start_mysqld.inc
174
175 RESET MASTER;
176
177 #
178 # Search for error message
179 #
180 --let $error_pattern = Found invalid event sequence while recovering from binary log file.*
181 --source include/assert_error_log.inc
182
183 #
184 # Shutdown server
185 #
186 --source include/shutdown_mysqld.inc
187
188 #
189 # Restore binary log file
190 #
191 --remove_file $MYSQLD_DATADIR/$binlog
192 --copy_file $MYSQLD_DATADIR/$binlog.backup $MYSQLD_DATADIR/$binlog
193
194 #
195 # Now the server should start
196 #
197 --source include/start_mysqld.inc
198
199 --echo
200 --echo # 4. Test check !(ev->common_header->flags & LOG_EVENT_BINLOG_IN_USE_F) #
201 --echo #########################################################################
202
203 --let $debug_point = binlog_crash_between_close_and_open
204 --source include/add_debug_point.inc
205
206 --source include/expect_crash.inc
207 --error CR_SERVER_LOST
208 FLUSH BINARY LOGS;
209
210 #
211 # Start server
212 #
213 --source include/start_mysqld.inc
214
215 #
216 # Search for note message
217 #
218 --let SEARCH_FILE = $MYSQLTEST_VARDIR/log/mysqld.1.err
219 --let SEARCH_PATTERN = \[Note\] \[[^]]*\] \[[^]]*\] Failed to open the crashed binlog file when source server is recovering it\.
220 --echo # Check for the "Failed to open the crashed binlog file when source server is recovering it\."
221 --source include/search_pattern.inc
222
223 #
224 # Cleanup
225 #
226 --remove_file $MYSQLD_DATADIR/$binlog.backup
227 --remove_file $MYSQLD_DATADIR/$binlog.header
228 --remove_file $MYSQLD_DATADIR/$binlog.truncformat
229 --remove_file $MYSQLD_DATADIR/$binlog.formatless