|
| 1 | +create database test_db; |
| 2 | +create database test_db2; |
| 3 | +create user 'test_user'@'localhost'; |
| 4 | +grant all on test_db.* to 'test_user'@'localhost'; |
| 5 | +grant all on test_db2.* to 'test_user'@'localhost'; |
| 6 | +grant all on test.* to 'test_user'@'localhost'; |
| 7 | +use test_db2; |
| 8 | +use test_db; |
| 9 | +set @start_max_running_queries= @@global.thread_pool_max_running_queries; |
| 10 | +set @start_max_waiting_queries= @@global.thread_pool_max_waiting_queries; |
| 11 | +set @@global.thread_pool_max_running_queries=10; |
| 12 | +set @@global.thread_pool_max_waiting_queries=5; |
| 13 | +create table t1(a int) engine=InnoDB; |
| 14 | +lock table t1 write; |
| 15 | +Threads waiting for admission will have appropriate state set in processlist. |
| 16 | +Super user is exempted from admission control checks. |
| 17 | +select * from t1; |
| 18 | +a |
| 19 | +set @@global.thread_pool_admission_control_filter = 'USE'; |
| 20 | +select @@global.thread_pool_admission_control_filter; |
| 21 | +@@global.thread_pool_admission_control_filter |
| 22 | +USE |
| 23 | +Maximum waiting queries reached. So this would hit an error. |
| 24 | +use test_db; |
| 25 | +select * from t1|||| |
| 26 | +ERROR HY000: Maximum waiting queries 5 reached for database `test_db` |
| 27 | +Maximum waiting queries reached. So this would hit an error. |
| 28 | +use test_db2; |
| 29 | +create table t1_test(aaa int); |
| 30 | +insert into t1_test values (1); |
| 31 | +select aaa from t1_test; |
| 32 | +drop table t1_test; |
| 33 | +use test_db; |
| 34 | +select * from t1|||| |
| 35 | +aaa |
| 36 | +1 |
| 37 | +ERROR HY000: Maximum waiting queries 5 reached for database `test_db` |
| 38 | +use test_db; |
| 39 | +select * from t1; |
| 40 | +ERROR HY000: Maximum waiting queries 5 reached for database `test_db` |
| 41 | +set @@global.thread_pool_admission_control_filter = ''; |
| 42 | +select @@global.thread_pool_admission_control_filter; |
| 43 | +@@global.thread_pool_admission_control_filter |
| 44 | + |
| 45 | +Check status variables |
| 46 | +aborted_queries = 3 |
| 47 | +running_queries = 10 |
| 48 | +waiting_queries = 5 |
| 49 | +select * from information_schema.tp_admission_control_entities where schema_name like 'test_db%' order by schema_name; |
| 50 | +SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS |
| 51 | +test_db 5 10 3 0 15 0 |
| 52 | +test_db2 0 0 0 0 0 0 |
| 53 | +Filled up queues on one db doesn't affect queries on other db. |
| 54 | +use test_db2; |
| 55 | +select * from information_schema.tp_admission_control_entities where schema_name like 'test_db%' order by schema_name; |
| 56 | +SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS |
| 57 | +test_db 5 10 3 0 15 0 |
| 58 | +test_db2 0 1 0 0 1 0 |
| 59 | +set @@global.thread_pool_max_waiting_queries=6; |
| 60 | +Kill a thread that is waiting for admission. |
| 61 | +select count(*) from t1; |
| 62 | +kill ID; |
| 63 | +use test_db; |
| 64 | +unlock tables; |
| 65 | +Verify the waiting queries received wakeup signal. |
| 66 | +select count(*) from t1; |
| 67 | +count(*) |
| 68 | +15 |
| 69 | +set @save_admission_control_by_trx = @@global.thread_pool_admission_control_by_trx; |
| 70 | +select @save_admission_control_by_trx; |
| 71 | +@save_admission_control_by_trx |
| 72 | +0 |
| 73 | +set @@global.thread_pool_max_running_queries=5; |
| 74 | +set @@global.thread_pool_max_waiting_queries=10; |
| 75 | +# By default, open transaction has no effect on running queries |
| 76 | +select count(*) from t1; |
| 77 | +count(*) |
| 78 | +15 |
| 79 | +# Test: open transactions will take slots in running queries, |
| 80 | +# and will not be blocked |
| 81 | +set @@global.thread_pool_admission_control_filter = 'BEGIN,COMMIT,ROLLBACK'; |
| 82 | +select @@global.thread_pool_admission_control_filter; |
| 83 | +@@global.thread_pool_admission_control_filter |
| 84 | +BEGIN,COMMIT,ROLLBACK |
| 85 | +set @@global.thread_pool_admission_control_by_trx = true; |
| 86 | +SELECT @@global.thread_pool_admission_control_by_trx; |
| 87 | +@@global.thread_pool_admission_control_by_trx |
| 88 | +1 |
| 89 | +Open transaction is able to continue running queries |
| 90 | +connection con_max_wait; |
| 91 | +New queries will be rejected (waiting queue is full) |
| 92 | +select * from t1; |
| 93 | +ERROR HY000: Maximum waiting queries 10 reached for database `test_db` |
| 94 | +New transactions will be rejected (waiting queue is full) |
| 95 | +begin; |
| 96 | +select * from t1; |
| 97 | +ERROR HY000: Maximum waiting queries 10 reached for database `test_db` |
| 98 | +aborted_queries will increase by 2 |
| 99 | +Committing a transaction will free up the running query slots |
| 100 | +The waiting queries will be unblocked |
| 101 | +Check status variables |
| 102 | +include/assert.inc [DB Admission control waiting queries should be zero] |
| 103 | +include/assert.inc [DB Admission control running queries should be zero] |
| 104 | +include/assert.inc [DB Admission control aborted queries should be five] |
| 105 | +select * from information_schema.tp_admission_control_entities where schema_name like 'test_db%' order by schema_name; |
| 106 | +SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS |
| 107 | +test_db 0 0 5 0 13 0 |
| 108 | +test_db2 0 0 0 0 0 0 |
| 109 | +set @@global.thread_pool_admission_control_by_trx = @save_admission_control_by_trx; |
| 110 | +select @@global.thread_pool_admission_control_by_trx; |
| 111 | +@@global.thread_pool_admission_control_by_trx |
| 112 | +0 |
| 113 | +set @@global.thread_pool_admission_control_filter = ''; |
| 114 | +select @@global.thread_pool_admission_control_filter; |
| 115 | +@@global.thread_pool_admission_control_filter |
| 116 | + |
| 117 | +# End of open transaction test |
| 118 | +# Test admission_control_queue_timeout |
| 119 | +use test_db; |
| 120 | +set @@global.thread_pool_max_running_queries=1; |
| 121 | +set @@global.thread_pool_max_waiting_queries=5; |
| 122 | +set @save_admission_control_filter = @@global.thread_pool_admission_control_filter; |
| 123 | +set @save_admission_control_queue_timeout = @@global.thread_pool_admission_control_queue_timeout; |
| 124 | +set @@global.thread_pool_admission_control_queue_timeout = 100; |
| 125 | +set @@global.thread_pool_admission_control_filter = 'BEGIN,COMMIT,ROLLBACK'; |
| 126 | +create table t2(a int primary key) engine=InnoDB; |
| 127 | +begin; |
| 128 | +insert into t2 values (1); |
| 129 | +begin; |
| 130 | +insert into t2 values (1); |
| 131 | +insert into t2 values (2); |
| 132 | +ERROR HY000: Got timeout while waiting on admission control queue for database `test_db` |
| 133 | +rollback; |
| 134 | +rollback; |
| 135 | +drop table t2; |
| 136 | +set @@global.thread_pool_admission_control_filter = @save_admission_control_filter; |
| 137 | +set @@global.thread_pool_admission_control_queue_timeout = @save_admission_control_queue_timeout; |
| 138 | +timeout_queries should be 1 |
| 139 | +timeout_queries = 1 |
| 140 | +waiting_queries should be 0 |
| 141 | +waiting_queries = 0 |
| 142 | +select * from information_schema.tp_admission_control_entities where schema_name like 'test_db%' order by schema_name; |
| 143 | +SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS |
| 144 | +test_db 0 0 5 1 15 0 |
| 145 | +test_db2 0 0 0 0 0 0 |
| 146 | +reset global.thread_pool_max_running_queries and global.thread_pool_max_waiting_queries |
| 147 | +set @@global.thread_pool_max_running_queries=10; |
| 148 | +set @@global.thread_pool_max_waiting_queries=5; |
| 149 | +Run parallel load and drop the database. |
| 150 | +set @@global.thread_pool_max_waiting_queries=0; |
| 151 | +Cleanup. |
| 152 | +Verify there are no waiting threads. |
| 153 | +select count(*) from information_schema.processlist where state='waiting for admission'; |
| 154 | +count(*) |
| 155 | +0 |
| 156 | +select * from information_schema.tp_admission_control_entities where schema_name like 'test_db%' order by schema_name; |
| 157 | +SCHEMA_NAME WAITING_QUERIES RUNNING_QUERIES ABORTED_QUERIES TIMEOUT_QUERIES CONNECTIONS REJECTED_CONNECTIONS |
| 158 | +set @@global.thread_pool_max_running_queries=@start_max_running_queries; |
| 159 | +set @@global.thread_pool_max_waiting_queries=@start_max_waiting_queries; |
| 160 | +drop user test_user@localhost; |
0 commit comments