Debian Codegraph @

mysql-test/suite/rpl/t/rpl_4threads_deadlock.test

raw
1 ###############################################################################
2 # Bug#17283409 4-WAY DEADLOCK: ZOMBIES, PURGING BINLOGS, SHOW PROCESSLIST,
3 # SHOW BINLOGS
4 # Problem: A deadlock was occurring when 4 threads were involved in acquiring
5 # locks
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 allow any threads to execute
26 # its '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
34
35 connect(master2,127.0.0.1,root,,test,$MASTER_MYPORT,);
36 connect(master3,127.0.0.1,root,,test,$MASTER_MYPORT,);
37 --connection master
38 SET @save_debug=@@global.debug;
39 SET GLOBAL DEBUG='+d,before_dump_thread_acquires_current_mutex,processlist_acquiring_dump_threads_LOCK_thd_data';
40
41 # Iteration 1 with "SHOW PROCESSLIST command"
42 # Iteration 2 with "SELECT * FROM information_schema.processlist"
43 --let $iter=2
44 while ($iter)
45 {
46 # Create atleast one binary log, otherwise purge logs command, show binary
47 # logs command do not hit the DEBUG_SYNC points.
48 FLUSH LOGS;
49 --connection slave
50 --source include/stop_slave.inc
51 --source include/start_slave.inc
52 # Thread 1
53 --connection master
54 --echo "Wait_for dump_thread_signal"
55 SET DEBUG_SYNC='now WAIT_FOR dump_thread_signal';
56
57 # Thread 2
58 --connection master1
59 SET DEBUG_SYNC='show_binlogs_after_lock_log_before_lock_index SIGNAL parked1 WAIT_FOR go_parked1';
60 --send SHOW BINARY LOGS
61
62 --connection master
63 echo "Wait_for parked1";
64 SET DEBUG_SYNC='now WAIT_FOR parked1';
65
66 # Thread 3
67 --connection master2
68 SET DEBUG_SYNC='purge_logs_after_lock_index_before_thread_count SIGNAL parked2 WAIT_FOR go_parked2';
69 --send PURGE BINARY LOGS BEFORE '2038-01-19'
70
71 --connection master
72 echo "Wait_for parked2";
73 SET DEBUG_SYNC='now WAIT_FOR parked2';
74
75 # Thread 4
76 --connection master3
77 SET DEBUG_SYNC='processlist_after_LOCK_thd_list_before_LOCK_thd_data SIGNAL parked3 WAIT_FOR go_parked3';
78 if ($iter == 1)
79 {
80 --let $query=SHOW PROCESSLIST
81 }
82 if ($iter == 2)
83 {
84 --let $query=SELECT * FROM information_schema.processlist
85 }
86 --send_eval $query
87
88 --connection master
89 echo "Wait_for parked3";
90 SET DEBUG_SYNC='now WAIT_FOR parked3';
91
92 echo "now signal go to all 4 waiting threads";
93 SET DEBUG_SYNC='now SIGNAL go_dump_thread';
94 SET DEBUG_SYNC='now SIGNAL go_parked1';
95 SET DEBUG_SYNC='now SIGNAL go_parked2';
96 SET DEBUG_SYNC='now SIGNAL go_parked3';
97
98 # Output of each command vary depends on other tests ran in suite(output vary
99 # in Pb2 runs), so lets ignore output. Anyways, we are interested in seeing
100 # that there is no deadlock.
101 --disable_result_log
102 --connection master1
103 --reap
104 --connection master2
105 --reap
106 --connection master3
107 --reap
108 --enable_result_log
109
110 --dec $iter
111 }
112
113 --echo "Cleanup"
114 --disconnect master2
115 --disconnect master3
116
117 --connection master
118 SET DEBUG_SYNC='RESET';
119 SET GLOBAL DEBUG=@save_debug;
120 source include/rpl_end.inc;