1
###############################################################################
2
# Bug#17283409 4-WAY DEADLOCK: ZOMBIES, PURGING BINLOGS, SHOW PROCESSLIST,
4
# Problem: A deadlock was occuring when 4 threads were involved in acquiring
6
# Thread 1: Dump thread ( Slave is reconnecting, so on Master, a new dump
7
# thread is trying kill zombie dump threads. It acquired
8
# thread's LOCK_thd_data and it is about to acquire
9
# mysys_var->current_mutex ( which LOCK_log)
10
# Thread 2: Application thread is executing show binlogs and acquired
11
# LOCK_log and it is about to acquire LOCK_index.
12
# Thread 3: Applicaiton thread is executing Purge binary logs and acquired
13
# LOCK_index and it is about to acquire LOCK_thread_count.
14
# Thread 4: Application thread is executing show processlist and acquired
15
# LOCK_thread_count and it is about to acquire zombie dump
16
# thread's LOCK_thd_data.
17
# Deadlock : Thread 1 -> Thread 2 -> Thread 3-> Thread 4 -> Thread 1
18
# The same above deadlock was observed when thread 4 is replaced with another
19
# thread which is executing 'SELECT * FROM information_schema.processlist'
20
# command and acquired LOCK_thread_count and it is about to acquire zombie
21
# dump thread's LOCK_thd_data.
22
# Fix: Introuced a new lock (Lock_thread_remove) which will guard the thread
23
# deletion (exit process) and the same lock is used in show processlist
24
# execution instead of LOCK_thread_count. i.e., After the patch, Server allows
25
# new threads to join the system but it will not any threads to execute its
26
# 'cleanup' process. Now the new lock order is: LOCK_thread_remove ->
27
# LOCK_thd_data -> LOCK_log -> LOCK_index -> LOCK_thread_count Both the above
28
# scenarios are tested with the below test code and it proves that there is no
29
# deadlock after the fix.
30
###############################################################################
31
--source include/have_debug_sync.inc
32
--source include/have_binlog_format_statement.inc
33
--source include/master-slave.inc
35
connect(master2,127.0.0.1,root,,test,$MASTER_MYPORT,);
36
connect(master3,127.0.0.1,root,,test,$MASTER_MYPORT,);
38
# Create atleast one binary log, otherwise purge logs command, show binary
39
# logs command do not hit the DEBUG_SYNC points.
41
SET @save_debug=@@global.debug;
42
SET GLOBAL DEBUG='+d,before_dump_thread_acquires_current_mutex,processlist_acquiring_dump_threads_LOCK_thd_data';
44
# Iteration 1 with "SHOW PROCESSLIST command"
45
# Iteration 2 with "SELECT * FROM information_schema.processlist"
50
--source include/stop_slave.inc
51
--source include/start_slave.inc
54
--echo "Wait_for dump_thread_signal"
55
SET DEBUG_SYNC='now WAIT_FOR dump_thread_signal';
59
SET DEBUG_SYNC='show_binlogs_after_lock_log_before_lock_index SIGNAL parked1 WAIT_FOR go';
60
--send SHOW BINARY LOGS
63
echo "Wait_for parked1";
64
SET DEBUG_SYNC='now WAIT_FOR parked1';
68
SET DEBUG_SYNC='purge_logs_after_lock_index_before_thread_count SIGNAL parked2 WAIT_FOR go';
69
--send PURGE BINARY LOGS BEFORE '9999-12-31'
72
echo "Wait_for parked2";
73
SET DEBUG_SYNC='now WAIT_FOR parked2';
77
SET DEBUG_SYNC='processlist_after_LOCK_thd_count_before_LOCK_thd_data SIGNAL parked3 WAIT_FOR go';
80
--let $query=SHOW PROCESSLIST
84
--let $query=SELECT * FROM information_schema.processlist
89
echo "Wait_for parked3";
90
SET DEBUG_SYNC='now WAIT_FOR parked3';
93
SET DEBUG_SYNC='now SIGNAL go';
95
# Output of each command vary depends on other tests ran in suite(output vary
96
# in Pb2 runs), so lets ignore output. Anyways, we are interested in seeing
97
# that there is no deadlock.
115
SET DEBUG_SYNC='RESET';
116
SET GLOBAL DEBUG=@save_debug;
117
source include/rpl_end.inc;