| 1 |
# |
| 2 |
# Purpose: |
| 3 |
# This test ensures that, during mysqld initialization, the mysql handle |
| 4 |
# manager starts before the binlog background thread. This is because the |
| 5 |
# binlog background thread uses the mysql handle manager, and if the background |
| 6 |
# thread tries to submit a job to the handle manager before it is |
| 7 |
# initialized/started, mysqld can crash (the actual behavior is undefined). |
| 8 |
# This race condition lead to the problem described in MDEV-26473. |
| 9 |
# |
| 10 |
# Methodology: |
| 11 |
# This test ensures that the binlog background thread cannot be started |
| 12 |
# before the mysql manager is started. Specifically, it forces a path in |
| 13 |
# the binlog background thread to call mysql_manager_submit() by reducing |
| 14 |
# --gtid-cleanup-batch-size to be 1 (which submits a job to delete unused rows |
| 15 |
# from the mysql.gtid_slave_pos* tables). With this path forced, the main |
| 16 |
# mysqld thread is suspended just before its handle manager initialization to |
| 17 |
# allow time for the binlog thread to call mysql_manager_submit. The fix |
| 18 |
# associated with this test should enforce that the binlog background thread is |
| 19 |
# not created before the handle manager is initialized. |
| 20 |
# |
| 21 |
# Addendum 1) This test is extended for MDEV-33799, as the original fix |
| 22 |
# left out the possibility that the binlog background thread can be |
| 23 |
# started during recovery if the binary log is used as the transaction |
| 24 |
# coordinator. This resulted in similar segfaults as seen by MDEV-26473. |
| 25 |
# |
| 26 |
# References: |
| 27 |
# MDEV-26473 mysqld got exception 0xc0000005 (rpl_slave_state/rpl_load_gtid_slave_state) |
| 28 |
# MDEV-33799 mysql_manager_submit Segfault at Startup Still Possible During Recovery |
| 29 |
# |
| 30 |
|
| 31 |
--source include/have_debug.inc |
| 32 |
--source include/master-slave.inc |
| 33 |
|
| 34 |
# The race condition discovered from MDEV-26473 is binlog format independent. |
| 35 |
# We use ROW format though because it was used by the reporter. |
| 36 |
--source include/have_binlog_format_row.inc |
| 37 |
|
| 38 |
--connection master |
| 39 |
|
| 40 |
--echo # Create a GTID event so the binlog background thread will submit a |
| 41 |
--echo # mysql handler job the next time mysqld is restarted. |
| 42 |
create table t1 (a int); |
| 43 |
--source include/save_master_gtid.inc |
| 44 |
|
| 45 |
--connection slave |
| 46 |
--source include/sync_with_master_gtid.inc |
| 47 |
|
| 48 |
--echo # Set a debug point that forces the main mysqld thread to sleep before |
| 49 |
--echo # anything is initialized for the mysql handle manager |
| 50 |
--let $rpl_server_parameters=--debug_dbug="+d,delay_start_handle_manager" |
| 51 |
|
| 52 |
|
| 53 |
--echo # Restart the slave mysqld instance so it re-initializes with the |
| 54 |
--echo # binlog background thread submitting a mysql handler job and the |
| 55 |
--echo # mysql handler initialization suspending for a second. Without the fix |
| 56 |
--echo # associated with this test/patch, the following restart will error |
| 57 |
--echo # with a failed assertion. |
| 58 |
--source include/rpl_restart_server.inc |
| 59 |
--source include/start_slave.inc |
| 60 |
|
| 61 |
|
| 62 |
--echo # |
| 63 |
--echo # MDEV-33799 |
| 64 |
--echo # Ensure that when the binary log is used for recovery (as tc log), that |
| 65 |
--echo # the recovery process cannot start the binlog background thread before |
| 66 |
--echo # the mysql handle manager has started. |
| 67 |
--connection slave |
| 68 |
|
| 69 |
--echo # Add test suppresssions so crash recovery messages don't fail the test |
| 70 |
set session sql_log_bin=0; |
| 71 |
call mtr.add_suppression("mariadbd: Got error '145.*"); |
| 72 |
call mtr.add_suppression("Checking table:.*"); |
| 73 |
call mtr.add_suppression("mysql.gtid_slave_pos:.*hasn't closed the table properly"); |
| 74 |
call mtr.add_suppression("Can't init tc log"); |
| 75 |
call mtr.add_suppression("Aborting"); |
| 76 |
set session sql_log_bin=1; |
| 77 |
|
| 78 |
--echo # Create slave-side only table |
| 79 |
create table t2 (a int) engine=innodb; |
| 80 |
|
| 81 |
--write_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect |
| 82 |
wait |
| 83 |
EOF |
| 84 |
|
| 85 |
--echo # Crash mariadbd when binlogging transaction to corrupt database state |
| 86 |
--connection slave1 |
| 87 |
set @@session.debug_dbug="+d,crash_before_writing_xid"; |
| 88 |
--send insert into t2 values (1) |
| 89 |
|
| 90 |
--connection slave |
| 91 |
--source include/wait_until_disconnected.inc |
| 92 |
|
| 93 |
--connection slave1 |
| 94 |
--error 2013,ER_CONNECTION_KILLED |
| 95 |
--reap |
| 96 |
|
| 97 |
--echo # Restart mariadbd in recovery mode. Note --tc-heuristic-recover |
| 98 |
--echo # forces mysqld to exit with error, so we run mariadbd via CLI |
| 99 |
--echo # MYSQLD_LAST_CMD --debug_dbug="+d,delay_start_handle_manager" --tc-heuristic-recover=COMMIT |
| 100 |
--error 1 |
| 101 |
--exec $MYSQLD_LAST_CMD --debug_dbug="+d,delay_start_handle_manager" --tc-heuristic-recover=COMMIT |
| 102 |
|
| 103 |
--append_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect |
| 104 |
restart |
| 105 |
EOF |
| 106 |
|
| 107 |
--connection server_2 |
| 108 |
--enable_reconnect |
| 109 |
--source include/wait_until_connected_again.inc |
| 110 |
--connection slave1 |
| 111 |
--enable_reconnect |
| 112 |
--source include/wait_until_connected_again.inc |
| 113 |
--connection slave |
| 114 |
--enable_reconnect |
| 115 |
--source include/wait_until_connected_again.inc |
| 116 |
--source include/start_slave.inc |
| 117 |
|
| 118 |
|
| 119 |
--echo # |
| 120 |
--echo # Cleanup |
| 121 |
--echo # |
| 122 |
|
| 123 |
--connection master |
| 124 |
drop table t1; |
| 125 |
--source include/save_master_gtid.inc |
| 126 |
|
| 127 |
--connection slave |
| 128 |
--source include/sync_with_master_gtid.inc |
| 129 |
drop table t2; |
| 130 |
|
| 131 |
--source include/rpl_end.inc |