Debian Codegraph @

mysql-test/suite/perfschema/t/hostcache_ipv4_max_con.test

raw
1
2 #
3 # Tests for the performance_schema host_cache.
4 #
5 # Simulate failures from per user quotas:
6 # - reported in COUNT_MAX_USER_CONNECTION_ERRORS
7 # - reported in COUNT_MAX_USER_CONNECTION_PER_HOUR_ERRORS
8 # Simulate failures from server quotas:
9 # - reported in COUNT_MAX_CONNECTION_ERRORS
10
11 --source include/not_embedded.inc
12 --source include/have_debug.inc
13 --source include/have_perfschema.inc
14 --source include/have_hostname_cache.inc
15
16 # Enforce a clean state
17 --source ../include/wait_for_pfs_thread_count.inc
18 --source ../include/hostcache_set_state.inc
19
20 --disable_cursor_protocol
21 select @@global.max_connections into @saved_max_connections;
22 select @@global.max_user_connections into @saved_max_user_connections;
23 --enable_cursor_protocol
24
25 create user 'quota'@'santa.claus.ipv4.example.com';
26 grant select on test.* to 'quota'@'santa.claus.ipv4.example.com';
27 grant usage on *.* to 'quota'@'santa.claus.ipv4.example.com'
28 with max_connections_per_hour 3;
29
30 connect (con1,"127.0.0.1",root,,test,$MASTER_MYPORT,);
31 select "Con1 is alive";
32 select current_user();
33 disconnect con1;
34
35 --connection default
36 SET @saved_dbug = @@GLOBAL.debug_dbug;
37 set global debug_dbug= "+d,vio_peer_addr_fake_ipv4,getnameinfo_fake_ipv4,getaddrinfo_fake_good_ipv4";
38
39 connect (con2a,"127.0.0.1",quota,,test,$MASTER_MYPORT,);
40 select "Con2a is alive";
41 select current_user();
42 disconnect con2a;
43
44 --connection default
45 --source ../include/hostcache_dump.inc
46
47 connect (con2b,"127.0.0.1",quota,,test,$MASTER_MYPORT,);
48 select "Con2b is alive";
49 select current_user();
50 disconnect con2b;
51
52 --connection default
53 --source ../include/hostcache_dump.inc
54
55 connect (con2c,"127.0.0.1",quota,,test,$MASTER_MYPORT,);
56 select "Con2c is alive";
57 select current_user();
58 disconnect con2c;
59
60 --connection default
61 --source ../include/hostcache_dump.inc
62
63 --disable_query_log
64 --error ER_USER_LIMIT_REACHED
65 connect (con2d,"127.0.0.1",quota,,test,$MASTER_MYPORT,);
66 --enable_query_log
67
68 --connection default
69 --source ../include/hostcache_dump.inc
70
71 --disable_query_log
72 --error ER_USER_LIMIT_REACHED
73 connect (con2e,"127.0.0.1",quota,,test,$MASTER_MYPORT,);
74 --enable_query_log
75
76 --connection default
77 --source ../include/hostcache_dump.inc
78
79 # Wait for all disconnects
80 --source ../include/wait_for_pfs_thread_count.inc
81
82 grant usage on *.* to 'quota'@'santa.claus.ipv4.example.com'
83 with max_connections_per_hour 0;
84 grant usage on *.* to 'quota'@'santa.claus.ipv4.example.com'
85 with max_user_connections 3;
86 flush user_resources;
87
88 connect (con3a,"127.0.0.1",quota,,test,$MASTER_MYPORT,);
89 select "Con7 is alive";
90 select current_user();
91
92 --connection default
93 --source ../include/hostcache_dump.inc
94
95 connect (con3b,"127.0.0.1",quota,,test,$MASTER_MYPORT,);
96 select "Con3b is alive";
97 select current_user();
98
99 --connection default
100 --source ../include/hostcache_dump.inc
101
102 connect (con3c,"127.0.0.1",quota,,test,$MASTER_MYPORT,);
103 select "Con3c is alive";
104 select current_user();
105
106 --connection default
107 --source ../include/hostcache_dump.inc
108
109 --disable_query_log
110 --error ER_USER_LIMIT_REACHED
111 connect (con3d,"127.0.0.1",quota,,test,$MASTER_MYPORT,);
112 --enable_query_log
113
114 --connection default
115 --source ../include/hostcache_dump.inc
116
117 --disable_query_log
118 --error ER_USER_LIMIT_REACHED
119 connect (con3e,"127.0.0.1",quota,,test,$MASTER_MYPORT,);
120 --enable_query_log
121
122 --connection default
123 --source ../include/hostcache_dump.inc
124
125 disconnect con3a;
126 disconnect con3b;
127 disconnect con3c;
128
129 # Wait for all disconnects
130 --source ../include/wait_for_pfs_thread_count.inc
131
132 grant usage on *.* to 'quota'@'santa.claus.ipv4.example.com'
133 with max_user_connections 0;
134 flush user_resources;
135
136 set global max_user_connections = 3;
137
138 connect (con4a,"127.0.0.1",quota,,test,$MASTER_MYPORT,);
139 select "Con4a is alive";
140 select current_user();
141
142 --connection default
143 --source ../include/hostcache_dump.inc
144
145 connect (con4b,"127.0.0.1",quota,,test,$MASTER_MYPORT,);
146 select "Con4b is alive";
147 select current_user();
148
149 --connection default
150 --source ../include/hostcache_dump.inc
151
152 connect (con4c,"127.0.0.1",quota,,test,$MASTER_MYPORT,);
153 select "Con4c is alive";
154 select current_user();
155
156 --connection default
157 --source ../include/hostcache_dump.inc
158
159 --disable_query_log
160 --error ER_TOO_MANY_USER_CONNECTIONS
161 connect (con4d,"127.0.0.1",quota,,test,$MASTER_MYPORT,);
162 --enable_query_log
163
164 --connection default
165 --source ../include/hostcache_dump.inc
166
167 --disable_query_log
168 --error ER_TOO_MANY_USER_CONNECTIONS
169 connect (con4e,"127.0.0.1",quota,,test,$MASTER_MYPORT,);
170 --enable_query_log
171
172 --connection default
173 --source ../include/hostcache_dump.inc
174
175 disconnect con4a;
176 disconnect con4b;
177 disconnect con4c;
178
179 # Wait for all disconnects
180 --source ../include/wait_for_pfs_thread_count.inc
181
182 set global max_user_connections = 0;
183 set global max_connections = 10;
184 flush user_resources;
185
186 connect (tmp_con1,"127.0.0.1",quota,,test,$MASTER_MYPORT,);
187 connect (tmp_con2,"127.0.0.1",quota,,test,$MASTER_MYPORT,);
188 connect (tmp_con3,"127.0.0.1",quota,,test,$MASTER_MYPORT,);
189 connect (tmp_con4,"127.0.0.1",quota,,test,$MASTER_MYPORT,);
190 connect (tmp_con5,"127.0.0.1",quota,,test,$MASTER_MYPORT,);
191 connect (tmp_con6,"127.0.0.1",quota,,test,$MASTER_MYPORT,);
192 connect (tmp_con7,"127.0.0.1",quota,,test,$MASTER_MYPORT,);
193
194 connect (con5a,"127.0.0.1",quota,,test,$MASTER_MYPORT,);
195 select "Con4a is alive";
196 select current_user();
197
198 --connection default
199 --source ../include/hostcache_dump.inc
200
201 connect (con5b,"127.0.0.1",quota,,test,$MASTER_MYPORT,);
202 select "Con5b is alive";
203 select current_user();
204
205 --connection default
206 --source ../include/hostcache_dump.inc
207
208 # About error ER_CON_COUNT_ERROR:
209 # - this error is associated with SQLSTATE 08004,
210 # and returned from 2 places in the server code.
211 # - which path returns the error is not predictable,
212 # as it depends on the server load and thread scheduling
213 # - one path returns a SQLSTATE of 08004
214 # - another path returns no SQLSTATE at all,
215 # and then the client sets a default value of HY000 for SQLSTATE
216 #
217 # Testing for error ER_CON_COUNT_ERROR alone causes this to
218 # be printed in the result file:
219 # - ERROR 08004: Too many connections
220 # which in turn causes spurious test failures.
221 #
222 # To work around this, this scripts expect to see either
223 # the error number ER_CON_COUNT_ERROR (it always does)
224 # or the error number 9999 (it never does, this error does not exist).
225 # The exact error number and SQLSTATE is not printed in the result file,
226 # makig this test robust for both cases:
227 # - ERROR 08004: Too many connections
228 # - ERROR HY000: Too many connections
229
230 --disable_query_log
231 --error ER_CON_COUNT_ERROR, 9999
232 connect (con5c,"127.0.0.1",quota,,test,$MASTER_MYPORT,);
233 --enable_query_log
234
235 --connection default
236 --source ../include/hostcache_dump.inc
237
238 --disable_query_log
239 --error ER_CON_COUNT_ERROR, 9999
240 connect (con5d,"127.0.0.1",quota,,test,$MASTER_MYPORT,);
241 --enable_query_log
242
243 --connection default
244 --source ../include/hostcache_dump.inc
245
246 disconnect con5a;
247 disconnect con5b;
248 --disconnect tmp_con1
249 --disconnect tmp_con2
250 --disconnect tmp_con3
251 --disconnect tmp_con4
252 --disconnect tmp_con5
253 --disconnect tmp_con6
254 --disconnect tmp_con7
255
256 # Wait for all disconnects
257 --source ../include/wait_for_pfs_thread_count.inc
258
259 set global max_connections = @saved_max_connections;
260 set global max_user_connections = @saved_max_user_connections;
261
262 # revoke all privileges on test.* from 'quota'@'santa.claus.ipv4.example.com';
263 drop user 'quota'@'santa.claus.ipv4.example.com';
264
265 SET @@GLOBAL.debug_dbug = @saved_dbug;
266