|
| 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; |
0 commit comments