| 1 |
# ==== Purpose ==== |
| 2 |
# |
| 3 |
# Verify that mysqlbinlog generates an error and returns nonzero exit |
| 4 |
# code, when the binary log is corrupted. |
| 5 |
# |
| 6 |
# ==== Requirements ==== |
| 7 |
# |
| 8 |
# R1. When a binary log file is corrupted, mysqlbinlog should generate |
| 9 |
# an error and stop with a nonzero exit code. |
| 10 |
# |
| 11 |
# R2. In the special case where the format_description_log_event has |
| 12 |
# the IN_USE flag set, and the binary log ends with a truncated |
| 13 |
# event, mysqlbinlog should only print a commented message and |
| 14 |
# return exit code zero. |
| 15 |
# |
| 16 |
# ==== Implementation ==== |
| 17 |
# |
| 18 |
# 1. Use a debug symbol to produce a corrupted binary log file. |
| 19 |
# 2. Check that mysqlbinlog fails. |
| 20 |
# 3. Repeat the above to test both the active binary log file, and an |
| 21 |
# inactive one. |
| 22 |
# |
| 23 |
# ==== References ==== |
| 24 |
# |
| 25 |
# BUG#35083373: mysqlbinlog ignores errors in files having |
| 26 |
# LOG_EVENT_BINLOG_IN_USE_F set |
| 27 |
|
| 28 |
--source include/have_debug.inc |
| 29 |
# No need to run the test serveral times |
| 30 |
--source include/have_binlog_format_row.inc |
| 31 |
|
| 32 |
--echo # Init: Clear binary logs from previous tests. |
| 33 |
RESET MASTER; |
| 34 |
|
| 35 |
--echo ==== R1: Error for corrupted file ==== |
| 36 |
|
| 37 |
--echo # Create a corrupted binary log. |
| 38 |
--let $debug_point = set_query_log_event_size_to_5 |
| 39 |
--source include/add_debug_point.inc |
| 40 |
CREATE TABLE t (a INT); |
| 41 |
--source include/remove_debug_point.inc |
| 42 |
|
| 43 |
--echo # Verify that mysqlbinlog fails |
| 44 |
--source include/save_binlog_position.inc |
| 45 |
--let $assert_command = $MYSQL_BINLOG --force-if-open $binlog_fullpath 2>&1 |
| 46 |
--let $assert_regex = ERROR: Could not read entry at offset .*: Error in log format or read error 1..*ERROR: corrupted data in log event |
| 47 |
--let $assert_status = 1 |
| 48 |
--source include/assert_command_output.inc |
| 49 |
|
| 50 |
--echo # Rotate and verify that mysqlbinlog still fails. |
| 51 |
FLUSH BINARY LOGS; |
| 52 |
--source include/assert_command_output.inc |
| 53 |
|
| 54 |
--echo # Clean up. |
| 55 |
DROP TABLE t; |
| 56 |
RESET MASTER; |
| 57 |
|
| 58 |
--echo ==== R2.1: No error for truncated file when IN_USE flag is set ==== |
| 59 |
|
| 60 |
--echo # Create a truncated binary log. |
| 61 |
CREATE TABLE t (a INT); |
| 62 |
|
| 63 |
--source include/save_binlog_position.inc |
| 64 |
--let $in_filename = $binlog_fullpath |
| 65 |
--let $out_filename = $in_filename.tmp |
| 66 |
--let $file_start_pos = 0 |
| 67 |
--let $ten = 10 |
| 68 |
--expr $file_stop_pos = $binlog_position - $ten |
| 69 |
--source include/copy_file_segment.inc |
| 70 |
|
| 71 |
--let $dev_null = /dev/null |
| 72 |
--source include/check_windows.inc |
| 73 |
if ($have_windows) { |
| 74 |
--let $dev_null = NUL |
| 75 |
} |
| 76 |
|
| 77 |
--let $assert_command = $MYSQL_BINLOG --force-if-open $out_filename 2>&1 > $dev_null |
| 78 |
--let $assert_regex = WARNING: File ends with a truncated event |
| 79 |
--let $assert_status = 0 |
| 80 |
--source include/assert_command_output.inc |
| 81 |
|
| 82 |
--echo # Clean up. |
| 83 |
--remove_file $binlog_fullpath.tmp |
| 84 |
DROP TABLE t; |
| 85 |
RESET MASTER; |
| 86 |
|
| 87 |
--echo ==== R2.2: Error for truncated file when IN_USE flag is not set ==== |
| 88 |
|
| 89 |
--echo # Create a truncated binary log. |
| 90 |
CREATE TABLE t (a INT); |
| 91 |
|
| 92 |
--source include/save_binlog_position.inc |
| 93 |
FLUSH BINARY LOGS; |
| 94 |
|
| 95 |
--let $in_filename = $binlog_fullpath |
| 96 |
--let $out_filename = $in_filename.tmp |
| 97 |
--let $file_start_pos = 0 |
| 98 |
--let $ten = 10 |
| 99 |
--expr $file_stop_pos = $binlog_position - $ten |
| 100 |
--source include/copy_file_segment.inc |
| 101 |
--echo # Rotate and verify that mysqlbinlog now fails. |
| 102 |
|
| 103 |
--let $assert_command = $MYSQL_BINLOG --force-if-open $binlog_fullpath.tmp 2>&1 |
| 104 |
--let $assert_regex = ERROR: Could not read entry at offset .*: Error in log format or read error 1..*ERROR: binlog truncated in the middle of event; consider out of disk space |
| 105 |
--let $assert_status = 1 |
| 106 |
--source include/assert_command_output.inc |
| 107 |
|
| 108 |
--echo # Clean up. |
| 109 |
--remove_file $binlog_fullpath.tmp |
| 110 |
DROP TABLE t; |
| 111 |
RESET MASTER; |