| 1 |
# === Purpose === |
| 2 |
# |
| 3 |
# Verify that disk full/out of space errors generated during the flush |
| 4 |
# stage of binlog commit are properly handled by the server. |
| 5 |
# |
| 6 |
# === Implementation === |
| 7 |
# |
| 8 |
# Simulate tempoary file write failures in below scenarios and verify the |
| 9 |
# failures can be handled correctly. |
| 10 |
# - Simulate binlog cache write failure in an INSERT which write data more than |
| 11 |
# cache size. |
| 12 |
# - Simulate my_b_flush_io_cache failure in an ROLLBACK TO. |
| 13 |
# - Simulate my_b_flush_io_cache failure when reseting binlog cache in a |
| 14 |
# ROLLBACK. |
| 15 |
# - Simulate my_b_flush_io_cache failure when reseting binlog cache in a |
| 16 |
# COMMIT |
| 17 |
# - Simulate write failure |
| 18 |
# - Simulate my_b_flush_io_cache failure when reseting binlog cache in |
| 19 |
# disconnect |
| 20 |
# - Simulate a binlog cache write failure when reinitializing it for |
| 21 |
# copying to binlog. It should cause server abort if binlog_error_action |
| 22 |
# is ABORT_SERVER |
| 23 |
# |
| 24 |
# === References === |
| 25 |
# |
| 26 |
# Bug #27399620 BINLOG AND ENGINE BECOME INCONSISTENT WHEN BINLOG CACHE FILE |
| 27 |
# GETS OUT OF SPACE |
| 28 |
|
| 29 |
--source include/have_binlog_format_row.inc |
| 30 |
--source include/have_log_bin.inc |
| 31 |
--source include/have_debug.inc |
| 32 |
# Don't test this under valgrind, memory leaks will occur |
| 33 |
--source include/not_valgrind.inc |
| 34 |
# Avoid CrashReporter popup on Mac |
| 35 |
--source include/not_crashrep.inc |
| 36 |
|
| 37 |
call mtr.add_suppression("An error occurred during flush stage of the commit"); |
| 38 |
call mtr.add_suppression("Attempting backtrace. You can use the following information to find out*"); |
| 39 |
call mtr.add_suppression(".*Error writing file.*"); |
| 40 |
RESET MASTER; |
| 41 |
CREATE TABLE t1(c1 varchar(8192)); |
| 42 |
CREATE TABLE t2(c1 varchar(8192)); |
| 43 |
CREATE TABLE t3(c1 varchar(8192)); |
| 44 |
|
| 45 |
SET GLOBAL binlog_cache_size = 4096; |
| 46 |
connect(con1,localhost,root,,); |
| 47 |
|
| 48 |
--echo |
| 49 |
--echo # Case 1 Simulate my_b_flush_io_cache failure when truncating binlog |
| 50 |
--echo # cache. ROLLBACK TO triggers binlog cache truncation process. |
| 51 |
--source include/save_binlog_position.inc |
| 52 |
|
| 53 |
BEGIN; |
| 54 |
INSERT INTO t1 VALUES (repeat('a', 2048)); |
| 55 |
|
| 56 |
# Below statemens in sp1 should not be binlogged |
| 57 |
SAVEPOINT sp1; |
| 58 |
INSERT INTO t2 VALUES (repeat('a', 4096)); |
| 59 |
INSERT INTO t3 VALUES (repeat('b', 4096)); |
| 60 |
|
| 61 |
# ROLLBACK to savepoint should not call my_b_flush_io_cache which |
| 62 |
# caused extra events were logged before the fix. |
| 63 |
SET SESSION debug = "+d,simulate_error_during_flush_cache_to_file"; |
| 64 |
ROLLBACK TO sp1; |
| 65 |
SET SESSION debug = "-d,simulate_error_during_flush_cache_to_file"; |
| 66 |
|
| 67 |
INSERT INTO t1 VALUES (repeat('c', 8192)); |
| 68 |
COMMIT; |
| 69 |
|
| 70 |
# The transaction should be binlogged correctly |
| 71 |
--let $binlog_start= $binlog_position |
| 72 |
--source include/show_binlog_events.inc |
| 73 |
|
| 74 |
--echo |
| 75 |
--echo # Case 2 Simulate my_b_flush_io_cache failure when reseting binlog cache |
| 76 |
--echo # in ROLLBACK statement |
| 77 |
BEGIN; |
| 78 |
INSERT INTO t1 VALUES (repeat('a', 8192)); |
| 79 |
|
| 80 |
# When reseting binlog cache, it should not call my_b_flush_io_cache to flush |
| 81 |
# data in binlog cache to temporary file. It caused assertion failure: |
| 82 |
# binlog_cache_data::reset(): Assertion `is_binlog_empty()' before the fix. |
| 83 |
SET SESSION debug = "+d,simulate_error_during_flush_cache_to_file"; |
| 84 |
ROLLBACK; |
| 85 |
SET SESSION debug = "-d,simulate_error_during_flush_cache_to_file"; |
| 86 |
|
| 87 |
--echo |
| 88 |
--echo # Case 3 CLIENT DISCONNECT. it is same to ROLLBACK |
| 89 |
BEGIN; |
| 90 |
INSERT INTO t1 VALUES (repeat('a', 8192)); |
| 91 |
|
| 92 |
SET SESSION debug = "+d,simulate_error_during_flush_cache_to_file"; |
| 93 |
--disconnect con1 |
| 94 |
|
| 95 |
--echo |
| 96 |
--echo # Case 4 Simulate write failure when reinitializing binlog cache for |
| 97 |
--echo # copying to binlog. The error should be ignored and cache |
| 98 |
--echo # is cleared correctly if binlog_error_action is IGNORE_ERROR |
| 99 |
--echo # |
| 100 |
--connect(con1,localhost,root,,) |
| 101 |
TRUNCATE t1; |
| 102 |
--source include/save_binlog_position.inc |
| 103 |
|
| 104 |
SET GLOBAL binlog_error_action = IGNORE_ERROR; |
| 105 |
BEGIN; |
| 106 |
INSERT INTO t1 VALUES (repeat('a', 8192)); |
| 107 |
|
| 108 |
SET SESSION debug = "+d,fault_injection_reinit_io_cache_while_flushing_to_file"; |
| 109 |
--replace_regex /.*Error writing file.*/Error writing file <tmp_file_name> (Errcode: ##)/ |
| 110 |
COMMIT; |
| 111 |
SET SESSION debug = "-d,fault_injection_reinit_io_cache_while_flushing_to_file"; |
| 112 |
|
| 113 |
# Check that transaction is committed |
| 114 |
--let $assert_cond = COUNT(*) = 1 FROM t1; |
| 115 |
--let $assert_text = Count of elements in t1 should be 1. |
| 116 |
|
| 117 |
# Check that error is present in error log |
| 118 |
--let $assert_file= $MYSQLTEST_VARDIR/log/mysqld.1.err |
| 119 |
--let $assert_count = 1 |
| 120 |
--let $assert_select = An error occurred during flush stage of the commit. 'binlog_error_action' is set to 'IGNORE_ERROR'. |
| 121 |
--let $assert_text = An error occurred during flush stage of the commit. 'binlog_error_action' is set to 'IGNORE_ERROR'. |
| 122 |
--source include/assert_grep.inc |
| 123 |
|
| 124 |
# Restart so that binary log is enabled again and we can do the below test |
| 125 |
--disconnect con1 |
| 126 |
--connection default |
| 127 |
--source include/restart_mysqld.inc |
| 128 |
|
| 129 |
# Nothing should be logged |
| 130 |
--let $binlog_start= $binlog_position |
| 131 |
--source include/show_binlog_events.inc |
| 132 |
|
| 133 |
--echo |
| 134 |
--echo # Case 5 Simulate write failure when reinitializing binlog cache for |
| 135 |
--echo # copying to binlog with ABORT_SERVER |
| 136 |
--echo # |
| 137 |
SET GLOBAL binlog_cache_size = 4096; |
| 138 |
|
| 139 |
--connect(con1,localhost,root,,) |
| 140 |
|
| 141 |
select @@global.binlog_cache_size; |
| 142 |
TRUNCATE t2; |
| 143 |
--source include/save_binlog_position.inc |
| 144 |
|
| 145 |
SET GLOBAL binlog_error_action = ABORT_SERVER; |
| 146 |
BEGIN; |
| 147 |
INSERT INTO t2 VALUES (repeat('b', 8192)); |
| 148 |
|
| 149 |
--exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect |
| 150 |
SET SESSION debug = "+d,fault_injection_reinit_io_cache_while_flushing_to_file"; |
| 151 |
--error ER_BINLOG_LOGGING_IMPOSSIBLE |
| 152 |
COMMIT; |
| 153 |
|
| 154 |
--exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect |
| 155 |
--enable_reconnect |
| 156 |
--source include/wait_until_connected_again.inc |
| 157 |
|
| 158 |
# Restart so that binary log is enabled again and we can do the below test |
| 159 |
--source include/restart_mysqld.inc |
| 160 |
select * from t2; |
| 161 |
# Check that transaction is not committed |
| 162 |
--let $assert_cond = COUNT(*) = 0 FROM t2; |
| 163 |
--let $assert_text = Count of elements in t2 should be 0. |
| 164 |
--source include/assert.inc |
| 165 |
|
| 166 |
# Nothing should be logged |
| 167 |
--let $binlog_start= $binlog_position |
| 168 |
--source include/show_binlog_events.inc |
| 169 |
|
| 170 |
# Cleanup |
| 171 |
--disconnect con1 |
| 172 |
--connection default |
| 173 |
--enable_reconnect |
| 174 |
DROP TABLE t1, t2, t3; |
| 175 |
RESET MASTER; |
| 176 |
|