Skip to content

Commit f4229fc

Browse files
committed
Bug#23074173 - NUMBER OF WORKER THREADS GOES UNDER MYSQLX_MIN_WORKER_THREADS
Description: There was a race-condition in scheduler.cc, comparation and decrementation of variable holding number of active workers was done in two instructions without any mutex guarding the access to it. Solution: Access to m_workers_count is now guarded by m_thread_worker_pending_mutex. Reviewed-by: Andrzej Religa <[email protected]> Reviewed-by: Grzegorz Szwarc <[email protected]> RB: 12370
1 parent d385aaa commit f4229fc

File tree

11 files changed

+317
-53
lines changed

11 files changed

+317
-53
lines changed
Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
install plugin mysqlx soname "mysqlx.so";
2+
call mtr.add_suppression("Plugin mysqlx reported: .Failed at SSL configuration: .SSL context is not usable without certificate and private key..");
3+
call mtr.add_suppression("Plugin mysqlx reported: .SSL_CTX_load_verify_locations failed.");
4+
SET GLOBAL Mysqlx_min_worker_threads=50;
5+
SET GLOBAL Mysqlx_max_connections = 200;
6+
SET GLOBAL Mysqlx_idle_worker_thread_timeout=2;
7+
connecting...
8+
active session is now 'con 0'
9+
connecting...
10+
active session is now 'con 1'
11+
connecting...
12+
active session is now 'con 2'
13+
connecting...
14+
active session is now 'con 3'
15+
connecting...
16+
active session is now 'con 4'
17+
connecting...
18+
active session is now 'con 5'
19+
connecting...
20+
active session is now 'con 6'
21+
connecting...
22+
active session is now 'con 7'
23+
connecting...
24+
active session is now 'con 8'
25+
connecting...
26+
active session is now 'con 9'
27+
connecting...
28+
active session is now 'con 10'
29+
connecting...
30+
active session is now 'con 11'
31+
connecting...
32+
active session is now 'con 12'
33+
connecting...
34+
active session is now 'con 13'
35+
connecting...
36+
active session is now 'con 14'
37+
connecting...
38+
active session is now 'con 15'
39+
connecting...
40+
active session is now 'con 16'
41+
connecting...
42+
active session is now 'con 17'
43+
connecting...
44+
active session is now 'con 18'
45+
connecting...
46+
active session is now 'con 19'
47+
connecting...
48+
active session is now 'con 20'
49+
connecting...
50+
active session is now 'con 21'
51+
connecting...
52+
active session is now 'con 22'
53+
connecting...
54+
active session is now 'con 23'
55+
connecting...
56+
active session is now 'con 24'
57+
connecting...
58+
active session is now 'con 25'
59+
connecting...
60+
active session is now 'con 26'
61+
connecting...
62+
active session is now 'con 27'
63+
connecting...
64+
active session is now 'con 28'
65+
connecting...
66+
active session is now 'con 29'
67+
connecting...
68+
active session is now 'con 30'
69+
connecting...
70+
active session is now 'con 31'
71+
connecting...
72+
active session is now 'con 32'
73+
connecting...
74+
active session is now 'con 33'
75+
connecting...
76+
active session is now 'con 34'
77+
connecting...
78+
active session is now 'con 35'
79+
connecting...
80+
active session is now 'con 36'
81+
connecting...
82+
active session is now 'con 37'
83+
connecting...
84+
active session is now 'con 38'
85+
connecting...
86+
active session is now 'con 39'
87+
connecting...
88+
active session is now 'con 40'
89+
connecting...
90+
active session is now 'con 41'
91+
connecting...
92+
active session is now 'con 42'
93+
connecting...
94+
active session is now 'con 43'
95+
connecting...
96+
active session is now 'con 44'
97+
connecting...
98+
active session is now 'con 45'
99+
connecting...
100+
active session is now 'con 46'
101+
connecting...
102+
active session is now 'con 47'
103+
connecting...
104+
active session is now 'con 48'
105+
connecting...
106+
active session is now 'con 49'
107+
connecting...
108+
active session is now 'con 50'
109+
connecting...
110+
active session is now 'con 51'
111+
connecting...
112+
active session is now 'con 52'
113+
connecting...
114+
active session is now 'con 53'
115+
connecting...
116+
active session is now 'con 54'
117+
connecting...
118+
active session is now 'con 55'
119+
connecting...
120+
active session is now 'con 56'
121+
connecting...
122+
active session is now 'con 57'
123+
connecting...
124+
active session is now 'con 58'
125+
connecting...
126+
active session is now 'con 59'
127+
connecting...
128+
active session is now 'con 60'
129+
connecting...
130+
active session is now 'con 61'
131+
connecting...
132+
active session is now 'con 62'
133+
connecting...
134+
active session is now 'con 63'
135+
connecting...
136+
active session is now 'con 64'
137+
connecting...
138+
active session is now 'con 65'
139+
connecting...
140+
active session is now 'con 66'
141+
connecting...
142+
active session is now 'con 67'
143+
connecting...
144+
active session is now 'con 68'
145+
connecting...
146+
active session is now 'con 69'
147+
connecting...
148+
active session is now 'con 70'
149+
connecting...
150+
active session is now 'con 71'
151+
connecting...
152+
active session is now 'con 72'
153+
connecting...
154+
active session is now 'con 73'
155+
connecting...
156+
active session is now 'con 74'
157+
connecting...
158+
active session is now 'con 75'
159+
connecting...
160+
active session is now 'con 76'
161+
connecting...
162+
active session is now 'con 77'
163+
connecting...
164+
active session is now 'con 78'
165+
connecting...
166+
active session is now 'con 79'
167+
connecting...
168+
active session is now 'con 80'
169+
connecting...
170+
active session is now 'con 81'
171+
connecting...
172+
active session is now 'con 82'
173+
connecting...
174+
active session is now 'con 83'
175+
connecting...
176+
active session is now 'con 84'
177+
connecting...
178+
active session is now 'con 85'
179+
connecting...
180+
active session is now 'con 86'
181+
connecting...
182+
active session is now 'con 87'
183+
connecting...
184+
active session is now 'con 88'
185+
connecting...
186+
active session is now 'con 89'
187+
connecting...
188+
active session is now 'con 90'
189+
connecting...
190+
active session is now 'con 91'
191+
connecting...
192+
active session is now 'con 92'
193+
connecting...
194+
active session is now 'con 93'
195+
connecting...
196+
active session is now 'con 94'
197+
connecting...
198+
active session is now 'con 95'
199+
connecting...
200+
active session is now 'con 96'
201+
connecting...
202+
active session is now 'con 97'
203+
connecting...
204+
active session is now 'con 98'
205+
connecting...
206+
active session is now 'con 99'
207+
SHOW STATUS like 'mysqlx_worker_threads';
208+
Variable_name Value
209+
Mysqlx_worker_threads 50
210+
uninstall plugin mysqlx;

mysql-test/suite/xplugin/r/performance_schema.result

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ install plugin mysqlx soname "mysqlx.so";
22
call mtr.add_suppression("Plugin mysqlx reported: .Failed at SSL configuration: .SSL context is not usable without certificate and private key..");
33
call mtr.add_suppression("Plugin mysqlx reported: .SSL_CTX_load_verify_locations failed.");
44

5-
7 rows affected
6-
Rows matched: 7 Changed: 0 Warnings: 0
5+
6 rows affected
6+
Rows matched: 6 Changed: 0 Warnings: 0
77

88
1 rows affected
99
Rows matched: 1 Changed: 1 Warnings: 0
@@ -26,24 +26,22 @@ thread/mysqlx/worker
2626
0 rows affected
2727
name
2828
wait/synch/mutex/mysqlx/lock_list_access
29-
wait/synch/mutex/mysqlx/scheduler_dynamic_post
30-
wait/synch/mutex/mysqlx/scheduler_dynamic_task_pending
3129
wait/synch/mutex/mysqlx/scheduler_dynamic_thread_exit
30+
wait/synch/mutex/mysqlx/scheduler_dynamic_worker_pending
3231
0 rows affected
3332
name
34-
wait/synch/cond/mysqlx/scheduler_dynamic_task_pending
3533
wait/synch/cond/mysqlx/scheduler_dynamic_thread_exit
34+
wait/synch/cond/mysqlx/scheduler_dynamic_worker_pending
3635
0 rows affected
3736
name
3837
wait/synch/rwlock/mysqlx/client_list_clients
3938
0 rows affected
4039
NAME ENABLED TIMED
4140
wait/synch/mutex/mysqlx/lock_list_access NO NO
42-
wait/synch/mutex/mysqlx/scheduler_dynamic_task_pending NO NO
41+
wait/synch/mutex/mysqlx/scheduler_dynamic_worker_pending NO NO
4342
wait/synch/mutex/mysqlx/scheduler_dynamic_thread_exit YES NO
44-
wait/synch/mutex/mysqlx/scheduler_dynamic_post YES NO
4543
wait/synch/rwlock/mysqlx/client_list_clients YES NO
46-
wait/synch/cond/mysqlx/scheduler_dynamic_task_pending NO NO
44+
wait/synch/cond/mysqlx/scheduler_dynamic_worker_pending NO NO
4745
wait/synch/cond/mysqlx/scheduler_dynamic_thread_exit YES NO
4846
0 rows affected
4947

@@ -175,13 +173,12 @@ thread/mysqlx/worker
175173
command ok
176174
name
177175
wait/synch/mutex/mysqlx/lock_list_access
178-
wait/synch/mutex/mysqlx/scheduler_dynamic_post
179-
wait/synch/mutex/mysqlx/scheduler_dynamic_task_pending
180176
wait/synch/mutex/mysqlx/scheduler_dynamic_thread_exit
177+
wait/synch/mutex/mysqlx/scheduler_dynamic_worker_pending
181178
command ok
182179
name
183-
wait/synch/cond/mysqlx/scheduler_dynamic_task_pending
184180
wait/synch/cond/mysqlx/scheduler_dynamic_thread_exit
181+
wait/synch/cond/mysqlx/scheduler_dynamic_worker_pending
185182
command ok
186183
name
187184
wait/synch/rwlock/mysqlx/client_list_clients
@@ -207,4 +204,4 @@ where EVENT_NAME rlike '^wait/synch/(cond|mutex)/mysqlx/(queue|client_session|ob
207204
EVENT_NAME
208205
UNINSTALL PLUGIN mysqlx;
209206
update performance_schema.setup_instruments set ENABLED='YES'
210-
where NAME rlike '^wait/synch/(cond|mutex)/mysqlx/(lock_list_access|scheduler_dynamic_task_pending)$';
207+
where NAME rlike '^wait/synch/(cond|mutex)/mysqlx/(lock_list_access|scheduler_dynamic_worker_pending)$';
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
--show_compatibility_56=1
2+
--plugin_dir=$MYSQLXPLUGIN_DIR
3+
--performance_schema_events_waits_history_long_size=400000
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
## generated
2+
## Ping
3+
4+
--source suite/xplugin/include/xplugin_preamble.inc
5+
6+
SET GLOBAL Mysqlx_min_worker_threads=50;
7+
SET GLOBAL Mysqlx_max_connections = 200;
8+
SET GLOBAL Mysqlx_idle_worker_thread_timeout=2;
9+
10+
--write_file $MYSQL_TMP_DIR/worker_threads.tmp
11+
12+
-->repeat 100 %I%
13+
-->newsession con %I% root
14+
-->endrepeat
15+
-->abort
16+
EOF
17+
18+
--error 2
19+
--exec $MYSQLXTEST -uroot --password='' --file=$MYSQL_TMP_DIR/worker_threads.tmp 2>&1
20+
21+
let $wait_condition=
22+
SELECT VARIABLE_VALUE <51 FROM information_schema.GLOBAL_STATUS gs where VARIABLE_NAME = 'mysqlx_worker_threads';
23+
--source include/wait_condition.inc
24+
25+
SHOW STATUS like 'mysqlx_worker_threads';
26+
27+
28+
--remove_file $MYSQL_TMP_DIR/worker_threads.tmp
29+
30+
## Postamble
31+
uninstall plugin mysqlx;

mysql-test/suite/xplugin/t/performance_schema.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
update performance_schema.setup_instruments set ENABLED='YES' where NAME like '%mysqlx%';
1414

1515
update performance_schema.setup_instruments set ENABLED='NO' where NAME like 'wait/synch/mutex/mysqlx/lock_list_access';
16-
update performance_schema.setup_instruments set ENABLED='NO' where NAME like 'wait/synch/mutex/mysqlx/scheduler_dynamic_task_pending';
17-
update performance_schema.setup_instruments set ENABLED='NO' where NAME like 'wait/synch/cond/mysqlx/scheduler_dynamic_task_pending';
16+
update performance_schema.setup_instruments set ENABLED='NO' where NAME like 'wait/synch/mutex/mysqlx/scheduler_dynamic_worker_pending';
17+
update performance_schema.setup_instruments set ENABLED='NO' where NAME like 'wait/synch/cond/mysqlx/scheduler_dynamic_worker_pending';
1818

1919
update performance_schema.setup_consumers set ENABLED='YES' where NAME like 'events_waits%';
2020

@@ -505,4 +505,4 @@ where EVENT_NAME rlike '^wait/synch/(cond|mutex)/mysqlx/(queue|client_session|ob
505505
## Postamble
506506
UNINSTALL PLUGIN mysqlx;
507507
update performance_schema.setup_instruments set ENABLED='YES'
508-
where NAME rlike '^wait/synch/(cond|mutex)/mysqlx/(lock_list_access|scheduler_dynamic_task_pending)$';
508+
where NAME rlike '^wait/synch/(cond|mutex)/mysqlx/(lock_list_access|scheduler_dynamic_worker_pending)$';

rapid/plugin/x/mysqlxtest_src/mysqlxtest.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,7 +1539,11 @@ class Command
15391539
{
15401540
std::string s = args;
15411541
std::string user, pass, db, name;
1542+
1543+
replace_variables(s);
1544+
15421545
std::string::size_type p = s.find(CMD_ARG_SEPARATOR);
1546+
15431547
if (p != std::string::npos)
15441548
{
15451549
name = s.substr(0, p);

rapid/plugin/x/ngs/include/ngs/scheduler.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ namespace ngs
6767
bool is_worker_thread(my_thread_t thread_id);
6868
bool is_running();
6969
void join_terminating_workers();
70-
70+
7171
private:
7272
template<typename Element_type>
7373
class lock_list
@@ -138,14 +138,15 @@ namespace ngs
138138
return thread.thread == id;
139139
}
140140

141+
bool wait_if_idle_then_delete_worker();
141142
int32 increase_workers_count();
142143
int32 decrease_workers_count();
143144
int32 increase_tasks_count();
144145
int32 decrease_tasks_count();
145146

146147
const std::string m_name;
147-
Mutex m_task_pending_mutex;
148-
Cond m_task_pending_cond;
148+
Mutex m_worker_pending_mutex;
149+
Cond m_worker_pending_cond;
149150
Mutex m_thread_exit_mutex;
150151
Cond m_thread_exit_cond;
151152
Mutex m_post_mutex;

0 commit comments

Comments
 (0)