| 1 |
# ==== Purpose ==== |
| 2 |
# The test verifies attempt to recover by the semisync slave server whose |
| 3 |
# binlog is unsafe for truncation. |
| 4 |
# |
| 5 |
# ==== Implementation ==== |
| 6 |
# 2 binlog files are created with the 1st one destined to be the binlog |
| 7 |
# checkpoint file for recovery. |
| 8 |
# The final group of events is replication unsafe (myisam INSERT). |
| 9 |
# Therefore the semisync slave recovery may not. |
| 10 |
# |
| 11 |
# Steps: |
| 12 |
# 0 - Set max_binlog_size= 4096, to help an insert into a |
| 13 |
# transaction table 'ti' get binlog rotated while the |
| 14 |
# transaction won't be committed, being stopped at |
| 15 |
# a prior to commit debug_sync point |
| 16 |
# 1 - insert into a non-transactional 'tm' table completes with |
| 17 |
# binary logging as well |
| 18 |
# 2 - kill and attempt to restart the server as semisync slave that |
| 19 |
# must produce an expected unsafe-to-recover error |
| 20 |
# 3 - complete the test with a normal restart that successfully finds and |
| 21 |
# commits the transaction in doubt. |
| 22 |
# |
| 23 |
# ==== References ==== |
| 24 |
# |
| 25 |
# MDEV-21117: recovery for --rpl-semi-sync-slave-enabled server |
| 26 |
# |
| 27 |
|
| 28 |
--source include/have_innodb.inc |
| 29 |
--source include/have_debug_sync.inc |
| 30 |
--source include/have_binlog_format_row.inc |
| 31 |
|
| 32 |
SET @@global.max_binlog_size= 4096; |
| 33 |
|
| 34 |
call mtr.add_suppression("Table '.*tm' is marked as crashed and should be repaired"); |
| 35 |
call mtr.add_suppression("Got an error from unknown thread"); |
| 36 |
call mtr.add_suppression("Checking table: '.*tm'"); |
| 37 |
call mtr.add_suppression("Recovering table: '.*tm'"); |
| 38 |
call mtr.add_suppression("Cannot truncate the binary log to file"); |
| 39 |
call mtr.add_suppression("Crash recovery failed"); |
| 40 |
call mtr.add_suppression("Can.t init tc log"); |
| 41 |
call mtr.add_suppression("Aborting"); |
| 42 |
call mtr.add_suppression("Found 1 prepared transactions"); |
| 43 |
call mtr.add_suppression("mysqld: Table.*tm.*is marked as crashed"); |
| 44 |
call mtr.add_suppression("Checking table.*tm"); |
| 45 |
|
| 46 |
RESET MASTER; |
| 47 |
FLUSH LOGS; |
| 48 |
SET @@global.sync_binlog=1; |
| 49 |
CREATE TABLE ti (a INT PRIMARY KEY, b MEDIUMTEXT) ENGINE=Innodb; |
| 50 |
CREATE TABLE tm (f INT) ENGINE=MYISAM; |
| 51 |
|
| 52 |
--let $row_count = 5 |
| 53 |
--let $i = `select $row_count-2` |
| 54 |
--disable_query_log |
| 55 |
while ($i) |
| 56 |
{ |
| 57 |
--eval INSERT INTO ti VALUES ($i, REPEAT("x", 1)) |
| 58 |
--dec $i |
| 59 |
} |
| 60 |
--enable_query_log |
| 61 |
INSERT INTO tm VALUES(1); |
| 62 |
|
| 63 |
connect(master1,localhost,root,,); |
| 64 |
connect(master2,localhost,root,,); |
| 65 |
connect(master3,localhost,root,,); |
| 66 |
|
| 67 |
--connection master1 |
| 68 |
|
| 69 |
# The 1st trx binlogs, rotate binlog and hold on before committing at engine |
| 70 |
SET DEBUG_SYNC= "commit_after_release_LOCK_after_binlog_sync SIGNAL master1_ready WAIT_FOR master1_go_never_arrives"; |
| 71 |
--send_eval INSERT INTO ti VALUES ($row_count - 1, REPEAT("x", 4100)) |
| 72 |
|
| 73 |
--connection master2 |
| 74 |
SET DEBUG_SYNC= "now WAIT_FOR master1_ready"; |
| 75 |
# The 2nd trx for recovery, it does not rotate binlog |
| 76 |
SET DEBUG_SYNC= "commit_before_get_LOCK_commit_ordered SIGNAL master2_ready WAIT_FOR master2_go_never_arrives"; |
| 77 |
--send_eval INSERT INTO ti VALUES ($row_count, REPEAT("x", 1)) |
| 78 |
|
| 79 |
--connection master3 |
| 80 |
SET DEBUG_SYNC= "now WAIT_FOR master2_ready"; |
| 81 |
SET DEBUG_SYNC= "commit_before_get_LOCK_after_binlog_sync SIGNAL master3_ready"; |
| 82 |
--send INSERT INTO tm VALUES (2) |
| 83 |
|
| 84 |
--connection default |
| 85 |
SET DEBUG_SYNC= "now WAIT_FOR master3_ready"; |
| 86 |
--echo # The gtid binlog state prior the crash must be restored at the end of the test; |
| 87 |
SELECT @@global.gtid_binlog_state; |
| 88 |
--source include/kill_mysqld.inc |
| 89 |
|
| 90 |
# |
| 91 |
# Server restarts |
| 92 |
# |
| 93 |
--echo # Failed restart as the semisync slave |
| 94 |
--error 1 |
| 95 |
--exec $MYSQLD_LAST_CMD --init-rpl-role=SLAVE >> $MYSQLTEST_VARDIR/log/mysqld.1.err 2>&1 |
| 96 |
|
| 97 |
--echo # Normal restart |
| 98 |
--source include/start_mysqld.inc |
| 99 |
|
| 100 |
# Check error log for correct messages. |
| 101 |
let $log_error_ = $MYSQLTEST_VARDIR/log/mysqld.1.err; |
| 102 |
|
| 103 |
--let SEARCH_FILE=$log_error_ |
| 104 |
--let SEARCH_PATTERN=Cannot truncate the binary log to file |
| 105 |
--source include/search_pattern_in_file.inc |
| 106 |
|
| 107 |
--echo # Proof that the in-doubt transactions are recovered by the 2nd normal server restart |
| 108 |
--eval SELECT COUNT(*) = $row_count as 'True' FROM ti |
| 109 |
# myisam table may require repair (which is not tested here) |
| 110 |
--disable_warnings |
| 111 |
SELECT COUNT(*) <= 1 FROM tm; |
| 112 |
--enable_warnings |
| 113 |
|
| 114 |
--echo # The gtid binlog state prior the crash is restored now |
| 115 |
SELECT @@GLOBAL.gtid_binlog_state; |
| 116 |
SELECT @@GLOBAL.gtid_binlog_pos; |
| 117 |
|
| 118 |
--echo # Cleanup |
| 119 |
DROP TABLE ti, tm; |
| 120 |
--echo End of test |