Skip to content

Commit 49f128f

Browse files
george-reynyainikep
authored andcommitted
[thread_pool] Add max_db_connections for thread_pool plugin
Summary: 1. Add `change_db_callback` that is called to notify that session db is being changed, and when db is dropped. 2. Add a few `thd_*` functions to fill missing functionality. 3. Add `thread_pool` suite with copies of existing `max_db_connections` and `max_db_connections_stress` tests. Reviewed By: lth Differential Revision: D27209327
1 parent 97b07a1 commit 49f128f

10 files changed

+737
-18
lines changed

include/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ IF (INSTALL_EXTRA_HEADERS)
219219
../sql/sql_bitmap.h
220220
../sql/sql_cmd.h
221221
../sql/sql_const.h
222+
../sql/sql_db.h
222223
../sql/sql_error.h
223224
../sql/sql_list.h
224225
../sql/sql_plist.h
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
disable_query_log;
2+
3+
--let $thread_pool_plugin_installed= `SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.PLUGINS WHERE PLUGIN_NAME = 'THREAD_POOL'`
4+
if (!$thread_pool_plugin_installed)
5+
{
6+
--skip Use --thread-pool to run this test
7+
}
8+
9+
enable_query_log;
Lines changed: 306 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,306 @@
1+
== Setup
2+
create database test_db;
3+
create user test_user@localhost;
4+
grant all on test.* to test_user@localhost;
5+
grant all on test_db.* to test_user@localhost;
6+
use test_db;
7+
create user super_user@localhost;
8+
grant all on *.* to super_user@localhost with grant option;
9+
SET @start_value = @@global.thread_pool_max_db_connections;
10+
SET @@global.thread_pool_max_db_connections = 10;
11+
SELECT @@global.thread_pool_max_db_connections;
12+
@@global.thread_pool_max_db_connections
13+
10
14+
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' and connections <> 0 order by schema_name;
15+
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS
16+
connection default;
17+
== Fill up thread_pool_max_db_connections
18+
connect con$i, localhost, test_user,,test;
19+
connect con$i, localhost, test_user,,test;
20+
connect con$i, localhost, test_user,,test;
21+
connect con$i, localhost, test_user,,test;
22+
connect con$i, localhost, test_user,,test;
23+
connect con$i, localhost, test_user,,test;
24+
connect con$i, localhost, test_user,,test;
25+
connect con$i, localhost, test_user,,test;
26+
connect con$i, localhost, test_user,,test;
27+
connect con$i, localhost, test_user,,test;
28+
== New non-admin connection will be rejected
29+
ERROR HY000: Maximum connections reached for `test on localhost`
30+
== Existing connection can switch to same db, another db or empty db
31+
connection con10;
32+
use test_db;
33+
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name;
34+
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS
35+
test 0 0 0 0 9 1
36+
test_db 0 0 0 0 1 0
37+
use test;
38+
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name;
39+
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS
40+
test 0 0 0 0 10 1
41+
test_db 0 0 0 0 0 0
42+
use test;
43+
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name;
44+
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS
45+
test 0 0 0 0 10 1
46+
test_db 0 0 0 0 0 0
47+
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name;
48+
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS
49+
test 0 0 0 0 9 1
50+
test_db 0 0 0 0 1 0
51+
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name;
52+
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS
53+
test 0 0 0 0 10 1
54+
test_db 0 0 0 0 0 0
55+
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name;
56+
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS
57+
test 0 0 0 0 9 1
58+
test_db 0 0 0 0 0 0
59+
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name;
60+
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS
61+
test 0 0 0 0 9 1
62+
test_db 0 0 0 0 0 0
63+
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name;
64+
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS
65+
test 0 0 0 0 10 1
66+
test_db 0 0 0 0 0 0
67+
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name;
68+
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS
69+
test 0 0 0 0 10 1
70+
test_db 0 0 0 0 0 0
71+
== Admin user connection is not limited by thread_pool_max_db_connections
72+
connect con_root, localhost, root,,test;
73+
connection con_root;
74+
SELECT @@global.thread_pool_max_db_connections;
75+
@@global.thread_pool_max_db_connections
76+
10
77+
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name;
78+
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS
79+
test 0 0 0 0 10 1
80+
test_db 0 0 0 0 0 0
81+
disconnect con_root;
82+
connection default;
83+
== Test another admin super_user
84+
connect con_super, localhost, super_user,,test;
85+
connection con_super;
86+
SELECT @@global.thread_pool_max_db_connections;
87+
@@global.thread_pool_max_db_connections
88+
10
89+
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name;
90+
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS
91+
test 0 0 0 0 10 1
92+
test_db 0 0 0 0 0 0
93+
== Change admin user to regular user on new connection will fail
94+
== because thread_pool_max_db_connections is already reached
95+
mysqltest: At line 1: Query 'change_user test_user,,test' failed.
96+
ERROR 50039 (HY000): Maximum connections reached for `test on localhost`
97+
== Change user to root is OK
98+
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name;
99+
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS
100+
test 0 0 0 0 10 2
101+
test_db 0 0 0 0 0 0
102+
disconnect con_super;
103+
== Change regular user to root will free up a connection
104+
== so we will be able to connect another regular user
105+
connection con10;
106+
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name;
107+
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS
108+
test 0 0 0 0 9 2
109+
test_db 0 0 0 0 0 0
110+
connect con11, localhost, test_user,,test;
111+
disconnect con11;
112+
== Change con10 back to regular user
113+
connection con10;
114+
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name;
115+
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS
116+
test 0 0 0 0 10 2
117+
test_db 0 0 0 0 0 0
118+
== No new regular connection can be accepted
119+
ERROR HY000: Maximum connections reached for `test on localhost`
120+
== Connections to test_db independently can reach thread_pool_max_db_connections
121+
connect con2_$i, localhost, test_user,,test_db;
122+
connect con2_$i, localhost, test_user,,test_db;
123+
connect con2_$i, localhost, test_user,,test_db;
124+
connect con2_$i, localhost, test_user,,test_db;
125+
connect con2_$i, localhost, test_user,,test_db;
126+
connect con2_$i, localhost, test_user,,test_db;
127+
connect con2_$i, localhost, test_user,,test_db;
128+
connect con2_$i, localhost, test_user,,test_db;
129+
connect con2_$i, localhost, test_user,,test_db;
130+
connect con2_$i, localhost, test_user,,test_db;
131+
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name;
132+
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS
133+
test 0 0 0 0 10 3
134+
test_db 0 0 0 0 10 0
135+
== New non-admin connection to test_db will be rejected
136+
ERROR HY000: Maximum connections reached for `test_db on localhost`
137+
== Use test_db that reached limit should fail
138+
connection con10;
139+
use test_db;
140+
ERROR HY000: Maximum connections reached for `test_db on localhost`
141+
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name;
142+
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS
143+
test 0 0 0 0 10 3
144+
test_db 0 0 0 0 10 2
145+
== Change_user to test_db that reached limit should fail
146+
connection default;
147+
disconnect con10;
148+
mysqltest: At line 1: Query 'change_user test_user,,test_db' failed.
149+
ERROR 50039 (HY000): Maximum connections reached for `test_db on localhost`
150+
connect con10, localhost, test_user,,test;
151+
== Connections with no db are not limited by thread_pool_max_db_connections
152+
connection default;
153+
connect con3_$i, localhost, test_user,,*NO-ONE*;
154+
connect con3_$i, localhost, test_user,,*NO-ONE*;
155+
connect con3_$i, localhost, test_user,,*NO-ONE*;
156+
connect con3_$i, localhost, test_user,,*NO-ONE*;
157+
connect con3_$i, localhost, test_user,,*NO-ONE*;
158+
connect con3_$i, localhost, test_user,,*NO-ONE*;
159+
connect con3_$i, localhost, test_user,,*NO-ONE*;
160+
connect con3_$i, localhost, test_user,,*NO-ONE*;
161+
connect con3_$i, localhost, test_user,,*NO-ONE*;
162+
connect con3_$i, localhost, test_user,,*NO-ONE*;
163+
connect con3_$i, localhost, test_user,,*NO-ONE*;
164+
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name;
165+
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS
166+
test 0 0 0 0 10 3
167+
test_db 0 0 0 0 10 3
168+
disconnect con3_11;
169+
== Decrement user connection counts
170+
connection default;
171+
disconnect con10;
172+
disconnect con2_10;
173+
disconnect con3_10;
174+
disconnect con9;
175+
disconnect con2_9;
176+
disconnect con3_9;
177+
disconnect con8;
178+
disconnect con2_8;
179+
disconnect con3_8;
180+
disconnect con7;
181+
disconnect con2_7;
182+
disconnect con3_7;
183+
disconnect con6;
184+
disconnect con2_6;
185+
disconnect con3_6;
186+
disconnect con5;
187+
disconnect con2_5;
188+
disconnect con3_5;
189+
disconnect con4;
190+
disconnect con2_4;
191+
disconnect con3_4;
192+
disconnect con3;
193+
disconnect con2_3;
194+
disconnect con3_3;
195+
disconnect con2;
196+
disconnect con2_2;
197+
disconnect con3_2;
198+
disconnect con1;
199+
disconnect con2_1;
200+
disconnect con3_1;
201+
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name;
202+
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS
203+
test 0 0 0 0 0 3
204+
test_db 0 0 0 0 0 3
205+
== Verify that counter is not affected when db doesn't exist or access is denied
206+
ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'bogus_db'
207+
ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'bogus_db'
208+
ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'bogus_db'
209+
ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'bogus_db'
210+
ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'bogus_db'
211+
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name;
212+
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS
213+
test 0 0 0 0 0 3
214+
test_db 0 0 0 0 0 3
215+
== Able to refill up thread_pool_max_db_connections
216+
connection default;
217+
connect con$i, localhost, test_user,,test;
218+
connect con$i, localhost, test_user,,test;
219+
connect con$i, localhost, test_user,,test;
220+
connect con$i, localhost, test_user,,test;
221+
connect con$i, localhost, test_user,,test;
222+
connect con$i, localhost, test_user,,test;
223+
connect con$i, localhost, test_user,,test;
224+
connect con$i, localhost, test_user,,test;
225+
connect con$i, localhost, test_user,,test;
226+
connect con$i, localhost, test_user,,test;
227+
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name;
228+
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS
229+
test 0 0 0 0 10 3
230+
test_db 0 0 0 0 0 3
231+
ERROR HY000: Maximum connections reached for `test on localhost`
232+
== Increase thread_pool_max_db_connections
233+
connection default;
234+
SET @@global.thread_pool_max_db_connections = 15;
235+
SELECT @@global.thread_pool_max_db_connections;
236+
@@global.thread_pool_max_db_connections
237+
15
238+
connect con$i, localhost, test_user,,test;
239+
connect con$i, localhost, test_user,,test;
240+
connect con$i, localhost, test_user,,test;
241+
connect con$i, localhost, test_user,,test;
242+
connect con$i, localhost, test_user,,test;
243+
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name;
244+
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS
245+
test 0 0 0 0 15 4
246+
test_db 0 0 0 0 0 3
247+
ERROR HY000: Maximum connections reached for `test on localhost`
248+
== Decrease thread_pool_max_db_connections
249+
connection default;
250+
SET @@global.thread_pool_max_db_connections = 5;
251+
SELECT @@global.thread_pool_max_db_connections;
252+
@@global.thread_pool_max_db_connections
253+
5
254+
disconnect con15;
255+
disconnect con14;
256+
disconnect con13;
257+
disconnect con12;
258+
disconnect con11;
259+
disconnect con10;
260+
disconnect con9;
261+
disconnect con8;
262+
disconnect con7;
263+
disconnect con6;
264+
disconnect con5;
265+
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name;
266+
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS
267+
test 0 0 0 0 4 5
268+
test_db 0 0 0 0 0 3
269+
connect con5, localhost, test_user,,test;
270+
ERROR HY000: Maximum connections reached for `test on localhost`
271+
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name;
272+
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS
273+
test 0 0 0 0 5 6
274+
test_db 0 0 0 0 0 3
275+
connection default;
276+
disconnect con5;
277+
== Drop database with connections
278+
connect con2_1, localhost, test_user,,test_db;
279+
connect con2_2, localhost, test_user,,test_db;
280+
drop database test_db;
281+
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name;
282+
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS
283+
test 0 0 0 0 4 6
284+
use test;
285+
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name;
286+
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS
287+
test 0 0 0 0 5 6
288+
connection default;
289+
disconnect con2_1;
290+
disconnect con2_2;
291+
== Cleanup
292+
connection default;
293+
SET @@global.thread_pool_max_db_connections = @start_value;
294+
SELECT @@global.thread_pool_max_db_connections;
295+
@@global.thread_pool_max_db_connections
296+
0
297+
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name;
298+
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS
299+
test 0 0 0 0 4 6
300+
rejected_connections = 9
301+
drop user test_user@localhost;
302+
drop user super_user@localhost;
303+
disconnect con4;
304+
disconnect con3;
305+
disconnect con2;
306+
disconnect con1;
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
create user test_user@localhost identified with 'mysql_native_password' BY '';
2+
grant all on test.* to test_user@localhost;
3+
create database test_db10;
4+
grant all on test_db10.* to test_user@localhost;
5+
use test_db10;
6+
create database test_db9;
7+
grant all on test_db9.* to test_user@localhost;
8+
use test_db9;
9+
create database test_db8;
10+
grant all on test_db8.* to test_user@localhost;
11+
use test_db8;
12+
create database test_db7;
13+
grant all on test_db7.* to test_user@localhost;
14+
use test_db7;
15+
create database test_db6;
16+
grant all on test_db6.* to test_user@localhost;
17+
use test_db6;
18+
create database test_db5;
19+
grant all on test_db5.* to test_user@localhost;
20+
use test_db5;
21+
create database test_db4;
22+
grant all on test_db4.* to test_user@localhost;
23+
use test_db4;
24+
create database test_db3;
25+
grant all on test_db3.* to test_user@localhost;
26+
use test_db3;
27+
create database test_db2;
28+
grant all on test_db2.* to test_user@localhost;
29+
use test_db2;
30+
create database test_db1;
31+
grant all on test_db1.* to test_user@localhost;
32+
use test_db1;
33+
drop database test_db10;
34+
drop database test_db9;
35+
drop database test_db8;
36+
drop database test_db7;
37+
drop database test_db6;
38+
drop database test_db5;
39+
drop database test_db4;
40+
drop database test_db3;
41+
drop database test_db2;
42+
drop database test_db1;
43+
drop user test_user@localhost;
44+
errors present
45+
1

0 commit comments

Comments
 (0)