Skip to content

Commit d16c3ac

Browse files
committed
MDEV-26473: mysqld got exception 0xc0000005 (rpl_slave_state/rpl_load_gtid_slave_state)
Problem: ======== During mysqld initialization, if the number of GTIDs added since that last purge of the mysql.gtid_slave_pos tables is greater than or equal to the –-gtid-cleanup-batch-size value, a race condition can occur. Specifically, the binlog background thread will submit the bg_gtid_delete_pending job to the mysql handle manager; however, the mysql handle manager may not be initialized, leading to crashes. Solution: ======== Force the mysql handle manager to initialize/start before the binlog background thread is created. Reviewed By: ============ Andrei Elkin <andrei.elkin@mariadb.com>
1 parent a83c7ab commit d16c3ac

File tree

5 files changed

+97
-1
lines changed

5 files changed

+97
-1
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
include/master-slave.inc
2+
[connection master]
3+
connection master;
4+
# Create a GTID event so the binlog background thread will submit a
5+
# mysql handler job the next time mysqld is restarted.
6+
create table t1 (a int);
7+
include/save_master_gtid.inc
8+
connection slave;
9+
include/sync_with_master_gtid.inc
10+
# Set a debug point that forces the main mysqld thread to sleep before
11+
# anything is initialized for the mysql handle manager
12+
# Restart the slave mysqld instance so it re-initializes with the
13+
# binlog background thread submitting a mysql handler job and the
14+
# mysql handler initialization suspending for a second. Without the fix
15+
# associated with this test/patch, the following restart will error
16+
# with a failed assertion.
17+
include/rpl_restart_server.inc [server_number=2 parameters: --debug_dbug="+d,delay_start_handle_manager"]
18+
include/start_slave.inc
19+
#
20+
# Cleanup
21+
#
22+
connection master;
23+
drop table t1;
24+
include/save_master_gtid.inc
25+
connection slave;
26+
include/sync_with_master_gtid.inc
27+
include/rpl_end.inc
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--gtid-cleanup-batch-size=1
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
# References:
22+
# MDEV-26473 mysqld got exception 0xc0000005 (rpl_slave_state/rpl_load_gtid_slave_state)
23+
#
24+
25+
--source include/have_debug.inc
26+
--source include/master-slave.inc
27+
28+
# The race condition discovered from MDEV-26473 is binlog format independent.
29+
# We use ROW format though because it was used by the reporter.
30+
--source include/have_binlog_format_row.inc
31+
32+
--connection master
33+
34+
--echo # Create a GTID event so the binlog background thread will submit a
35+
--echo # mysql handler job the next time mysqld is restarted.
36+
create table t1 (a int);
37+
--source include/save_master_gtid.inc
38+
39+
--connection slave
40+
--source include/sync_with_master_gtid.inc
41+
42+
--echo # Set a debug point that forces the main mysqld thread to sleep before
43+
--echo # anything is initialized for the mysql handle manager
44+
--let $rpl_server_parameters=--debug_dbug="+d,delay_start_handle_manager"
45+
46+
47+
--echo # Restart the slave mysqld instance so it re-initializes with the
48+
--echo # binlog background thread submitting a mysql handler job and the
49+
--echo # mysql handler initialization suspending for a second. Without the fix
50+
--echo # associated with this test/patch, the following restart will error
51+
--echo # with a failed assertion.
52+
--source include/rpl_restart_server.inc
53+
--source include/start_slave.inc
54+
55+
56+
--echo #
57+
--echo # Cleanup
58+
--echo #
59+
60+
--connection master
61+
drop table t1;
62+
--source include/save_master_gtid.inc
63+
64+
--connection slave
65+
--source include/sync_with_master_gtid.inc
66+
67+
--source include/rpl_end.inc

sql/mysqld.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5405,6 +5405,7 @@ static int init_server_components()
54055405
unireg_abort(1);
54065406
}
54075407

5408+
start_handle_manager();
54085409
if (opt_bin_log)
54095410
{
54105411
int error;
@@ -5864,7 +5865,6 @@ int mysqld_main(int argc, char **argv)
58645865
}
58655866

58665867
create_shutdown_event();
5867-
start_handle_manager();
58685868

58695869
/* Copy default global rpl_filter to global_rpl_filter */
58705870
copy_filter_setting(global_rpl_filter, get_or_create_rpl_filter("", 0));

sql/sql_manager.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ void start_handle_manager()
133133
{
134134
pthread_t hThread;
135135
int err;
136+
DBUG_EXECUTE_IF("delay_start_handle_manager", my_sleep(1000););
136137
manager_thread_in_use = 1;
137138
mysql_cond_init(key_COND_manager, &COND_manager,NULL);
138139
mysql_mutex_init(key_LOCK_manager, &LOCK_manager, NULL);

0 commit comments

Comments
 (0)