forked from facebook/mysql-5.6
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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
- Loading branch information
1 parent
8078ba2
commit 620c6a6
Showing
10 changed files
with
737 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
disable_query_log; | ||
|
||
--let $thread_pool_plugin_installed= `SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.PLUGINS WHERE PLUGIN_NAME = 'THREAD_POOL'` | ||
if (!$thread_pool_plugin_installed) | ||
{ | ||
--skip Use --thread-pool to run this test | ||
} | ||
|
||
enable_query_log; |
306 changes: 306 additions & 0 deletions
306
mysql-test/suite/thread_pool/r/max_db_connections.result
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,306 @@ | ||
== Setup | ||
create database test_db; | ||
create user test_user@localhost; | ||
grant all on test.* to test_user@localhost; | ||
grant all on test_db.* to test_user@localhost; | ||
use test_db; | ||
create user super_user@localhost; | ||
grant all on *.* to super_user@localhost with grant option; | ||
SET @start_value = @@global.thread_pool_max_db_connections; | ||
SET @@global.thread_pool_max_db_connections = 10; | ||
SELECT @@global.thread_pool_max_db_connections; | ||
@@global.thread_pool_max_db_connections | ||
10 | ||
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' and connections <> 0 order by schema_name; | ||
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS | ||
connection default; | ||
== Fill up thread_pool_max_db_connections | ||
connect con$i, localhost, test_user,,test; | ||
connect con$i, localhost, test_user,,test; | ||
connect con$i, localhost, test_user,,test; | ||
connect con$i, localhost, test_user,,test; | ||
connect con$i, localhost, test_user,,test; | ||
connect con$i, localhost, test_user,,test; | ||
connect con$i, localhost, test_user,,test; | ||
connect con$i, localhost, test_user,,test; | ||
connect con$i, localhost, test_user,,test; | ||
connect con$i, localhost, test_user,,test; | ||
== New non-admin connection will be rejected | ||
ERROR HY000: Maximum connections reached for `test on localhost` | ||
== Existing connection can switch to same db, another db or empty db | ||
connection con10; | ||
use test_db; | ||
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name; | ||
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS | ||
test 0 0 0 0 9 1 | ||
test_db 0 0 0 0 1 0 | ||
use test; | ||
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name; | ||
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS | ||
test 0 0 0 0 10 1 | ||
test_db 0 0 0 0 0 0 | ||
use test; | ||
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name; | ||
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS | ||
test 0 0 0 0 10 1 | ||
test_db 0 0 0 0 0 0 | ||
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name; | ||
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS | ||
test 0 0 0 0 9 1 | ||
test_db 0 0 0 0 1 0 | ||
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name; | ||
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS | ||
test 0 0 0 0 10 1 | ||
test_db 0 0 0 0 0 0 | ||
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name; | ||
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS | ||
test 0 0 0 0 9 1 | ||
test_db 0 0 0 0 0 0 | ||
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name; | ||
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS | ||
test 0 0 0 0 9 1 | ||
test_db 0 0 0 0 0 0 | ||
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name; | ||
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS | ||
test 0 0 0 0 10 1 | ||
test_db 0 0 0 0 0 0 | ||
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name; | ||
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS | ||
test 0 0 0 0 10 1 | ||
test_db 0 0 0 0 0 0 | ||
== Admin user connection is not limited by thread_pool_max_db_connections | ||
connect con_root, localhost, root,,test; | ||
connection con_root; | ||
SELECT @@global.thread_pool_max_db_connections; | ||
@@global.thread_pool_max_db_connections | ||
10 | ||
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name; | ||
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS | ||
test 0 0 0 0 10 1 | ||
test_db 0 0 0 0 0 0 | ||
disconnect con_root; | ||
connection default; | ||
== Test another admin super_user | ||
connect con_super, localhost, super_user,,test; | ||
connection con_super; | ||
SELECT @@global.thread_pool_max_db_connections; | ||
@@global.thread_pool_max_db_connections | ||
10 | ||
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name; | ||
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS | ||
test 0 0 0 0 10 1 | ||
test_db 0 0 0 0 0 0 | ||
== Change admin user to regular user on new connection will fail | ||
== because thread_pool_max_db_connections is already reached | ||
mysqltest: At line 1: Query 'change_user test_user,,test' failed. | ||
ERROR 50039 (HY000): Maximum connections reached for `test on localhost` | ||
== Change user to root is OK | ||
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name; | ||
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS | ||
test 0 0 0 0 10 2 | ||
test_db 0 0 0 0 0 0 | ||
disconnect con_super; | ||
== Change regular user to root will free up a connection | ||
== so we will be able to connect another regular user | ||
connection con10; | ||
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name; | ||
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS | ||
test 0 0 0 0 9 2 | ||
test_db 0 0 0 0 0 0 | ||
connect con11, localhost, test_user,,test; | ||
disconnect con11; | ||
== Change con10 back to regular user | ||
connection con10; | ||
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name; | ||
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS | ||
test 0 0 0 0 10 2 | ||
test_db 0 0 0 0 0 0 | ||
== No new regular connection can be accepted | ||
ERROR HY000: Maximum connections reached for `test on localhost` | ||
== Connections to test_db independently can reach thread_pool_max_db_connections | ||
connect con2_$i, localhost, test_user,,test_db; | ||
connect con2_$i, localhost, test_user,,test_db; | ||
connect con2_$i, localhost, test_user,,test_db; | ||
connect con2_$i, localhost, test_user,,test_db; | ||
connect con2_$i, localhost, test_user,,test_db; | ||
connect con2_$i, localhost, test_user,,test_db; | ||
connect con2_$i, localhost, test_user,,test_db; | ||
connect con2_$i, localhost, test_user,,test_db; | ||
connect con2_$i, localhost, test_user,,test_db; | ||
connect con2_$i, localhost, test_user,,test_db; | ||
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name; | ||
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS | ||
test 0 0 0 0 10 3 | ||
test_db 0 0 0 0 10 0 | ||
== New non-admin connection to test_db will be rejected | ||
ERROR HY000: Maximum connections reached for `test_db on localhost` | ||
== Use test_db that reached limit should fail | ||
connection con10; | ||
use test_db; | ||
ERROR HY000: Maximum connections reached for `test_db on localhost` | ||
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name; | ||
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS | ||
test 0 0 0 0 10 3 | ||
test_db 0 0 0 0 10 2 | ||
== Change_user to test_db that reached limit should fail | ||
connection default; | ||
disconnect con10; | ||
mysqltest: At line 1: Query 'change_user test_user,,test_db' failed. | ||
ERROR 50039 (HY000): Maximum connections reached for `test_db on localhost` | ||
connect con10, localhost, test_user,,test; | ||
== Connections with no db are not limited by thread_pool_max_db_connections | ||
connection default; | ||
connect con3_$i, localhost, test_user,,*NO-ONE*; | ||
connect con3_$i, localhost, test_user,,*NO-ONE*; | ||
connect con3_$i, localhost, test_user,,*NO-ONE*; | ||
connect con3_$i, localhost, test_user,,*NO-ONE*; | ||
connect con3_$i, localhost, test_user,,*NO-ONE*; | ||
connect con3_$i, localhost, test_user,,*NO-ONE*; | ||
connect con3_$i, localhost, test_user,,*NO-ONE*; | ||
connect con3_$i, localhost, test_user,,*NO-ONE*; | ||
connect con3_$i, localhost, test_user,,*NO-ONE*; | ||
connect con3_$i, localhost, test_user,,*NO-ONE*; | ||
connect con3_$i, localhost, test_user,,*NO-ONE*; | ||
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name; | ||
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS | ||
test 0 0 0 0 10 3 | ||
test_db 0 0 0 0 10 3 | ||
disconnect con3_11; | ||
== Decrement user connection counts | ||
connection default; | ||
disconnect con10; | ||
disconnect con2_10; | ||
disconnect con3_10; | ||
disconnect con9; | ||
disconnect con2_9; | ||
disconnect con3_9; | ||
disconnect con8; | ||
disconnect con2_8; | ||
disconnect con3_8; | ||
disconnect con7; | ||
disconnect con2_7; | ||
disconnect con3_7; | ||
disconnect con6; | ||
disconnect con2_6; | ||
disconnect con3_6; | ||
disconnect con5; | ||
disconnect con2_5; | ||
disconnect con3_5; | ||
disconnect con4; | ||
disconnect con2_4; | ||
disconnect con3_4; | ||
disconnect con3; | ||
disconnect con2_3; | ||
disconnect con3_3; | ||
disconnect con2; | ||
disconnect con2_2; | ||
disconnect con3_2; | ||
disconnect con1; | ||
disconnect con2_1; | ||
disconnect con3_1; | ||
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name; | ||
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS | ||
test 0 0 0 0 0 3 | ||
test_db 0 0 0 0 0 3 | ||
== Verify that counter is not affected when db doesn't exist or access is denied | ||
ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'bogus_db' | ||
ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'bogus_db' | ||
ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'bogus_db' | ||
ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'bogus_db' | ||
ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'bogus_db' | ||
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name; | ||
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS | ||
test 0 0 0 0 0 3 | ||
test_db 0 0 0 0 0 3 | ||
== Able to refill up thread_pool_max_db_connections | ||
connection default; | ||
connect con$i, localhost, test_user,,test; | ||
connect con$i, localhost, test_user,,test; | ||
connect con$i, localhost, test_user,,test; | ||
connect con$i, localhost, test_user,,test; | ||
connect con$i, localhost, test_user,,test; | ||
connect con$i, localhost, test_user,,test; | ||
connect con$i, localhost, test_user,,test; | ||
connect con$i, localhost, test_user,,test; | ||
connect con$i, localhost, test_user,,test; | ||
connect con$i, localhost, test_user,,test; | ||
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name; | ||
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS | ||
test 0 0 0 0 10 3 | ||
test_db 0 0 0 0 0 3 | ||
ERROR HY000: Maximum connections reached for `test on localhost` | ||
== Increase thread_pool_max_db_connections | ||
connection default; | ||
SET @@global.thread_pool_max_db_connections = 15; | ||
SELECT @@global.thread_pool_max_db_connections; | ||
@@global.thread_pool_max_db_connections | ||
15 | ||
connect con$i, localhost, test_user,,test; | ||
connect con$i, localhost, test_user,,test; | ||
connect con$i, localhost, test_user,,test; | ||
connect con$i, localhost, test_user,,test; | ||
connect con$i, localhost, test_user,,test; | ||
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name; | ||
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS | ||
test 0 0 0 0 15 4 | ||
test_db 0 0 0 0 0 3 | ||
ERROR HY000: Maximum connections reached for `test on localhost` | ||
== Decrease thread_pool_max_db_connections | ||
connection default; | ||
SET @@global.thread_pool_max_db_connections = 5; | ||
SELECT @@global.thread_pool_max_db_connections; | ||
@@global.thread_pool_max_db_connections | ||
5 | ||
disconnect con15; | ||
disconnect con14; | ||
disconnect con13; | ||
disconnect con12; | ||
disconnect con11; | ||
disconnect con10; | ||
disconnect con9; | ||
disconnect con8; | ||
disconnect con7; | ||
disconnect con6; | ||
disconnect con5; | ||
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name; | ||
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS | ||
test 0 0 0 0 4 5 | ||
test_db 0 0 0 0 0 3 | ||
connect con5, localhost, test_user,,test; | ||
ERROR HY000: Maximum connections reached for `test on localhost` | ||
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name; | ||
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS | ||
test 0 0 0 0 5 6 | ||
test_db 0 0 0 0 0 3 | ||
connection default; | ||
disconnect con5; | ||
== Drop database with connections | ||
connect con2_1, localhost, test_user,,test_db; | ||
connect con2_2, localhost, test_user,,test_db; | ||
drop database test_db; | ||
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name; | ||
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS | ||
test 0 0 0 0 4 6 | ||
use test; | ||
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name; | ||
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS | ||
test 0 0 0 0 5 6 | ||
connection default; | ||
disconnect con2_1; | ||
disconnect con2_2; | ||
== Cleanup | ||
connection default; | ||
SET @@global.thread_pool_max_db_connections = @start_value; | ||
SELECT @@global.thread_pool_max_db_connections; | ||
@@global.thread_pool_max_db_connections | ||
0 | ||
select * from information_schema.tp_admission_control_entities where schema_name like 'test%' order by schema_name; | ||
SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS | ||
test 0 0 0 0 4 6 | ||
rejected_connections = 9 | ||
drop user test_user@localhost; | ||
drop user super_user@localhost; | ||
disconnect con4; | ||
disconnect con3; | ||
disconnect con2; | ||
disconnect con1; |
45 changes: 45 additions & 0 deletions
45
mysql-test/suite/thread_pool/r/max_db_connections_stress.result
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
create user test_user@localhost identified with 'mysql_native_password' BY ''; | ||
grant all on test.* to test_user@localhost; | ||
create database test_db10; | ||
grant all on test_db10.* to test_user@localhost; | ||
use test_db10; | ||
create database test_db9; | ||
grant all on test_db9.* to test_user@localhost; | ||
use test_db9; | ||
create database test_db8; | ||
grant all on test_db8.* to test_user@localhost; | ||
use test_db8; | ||
create database test_db7; | ||
grant all on test_db7.* to test_user@localhost; | ||
use test_db7; | ||
create database test_db6; | ||
grant all on test_db6.* to test_user@localhost; | ||
use test_db6; | ||
create database test_db5; | ||
grant all on test_db5.* to test_user@localhost; | ||
use test_db5; | ||
create database test_db4; | ||
grant all on test_db4.* to test_user@localhost; | ||
use test_db4; | ||
create database test_db3; | ||
grant all on test_db3.* to test_user@localhost; | ||
use test_db3; | ||
create database test_db2; | ||
grant all on test_db2.* to test_user@localhost; | ||
use test_db2; | ||
create database test_db1; | ||
grant all on test_db1.* to test_user@localhost; | ||
use test_db1; | ||
drop database test_db10; | ||
drop database test_db9; | ||
drop database test_db8; | ||
drop database test_db7; | ||
drop database test_db6; | ||
drop database test_db5; | ||
drop database test_db4; | ||
drop database test_db3; | ||
drop database test_db2; | ||
drop database test_db1; | ||
drop user test_user@localhost; | ||
errors present | ||
1 |
Oops, something went wrong.