Debian Codegraph @

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

raw
1 #
2 # Some functional checks for the content of performance_schema.socket_instances.
3 #
4
5 --source include/not_embedded.inc
6 --source include/not_windows.inc
7 --source include/have_perfschema.inc
8
9 # Set this to enable debugging output
10 let $my_socket_debug_dbug= 0;
11
12 #
13 # Set IP address defaults with respect to IPV6 support
14 #
15
16 # Determine if IPV6 supported
17 let $check_ipv6_just_check= 1;
18 --source include/check_ipv6.inc
19
20 # Determine if IPV4 mapped to IPV6 supported
21 let $check_ipv4_mapped_just_check= 1;
22 --source include/have_ipv4_mapped.inc
23
24 let $my_localhost= 127.0.0.1;
25
26 if($check_ipv6_supported)
27 {
28 let $my_localhost= ::1;
29 }
30
31 if($check_ipv4_mapped_supported)
32 {
33 let $my_localhost= ::ffff:127.0.0.1;
34 }
35
36 if($my_socket_debug)
37 {
38 --echo IPV6=$check_ipv6_supported, IPV4_MAPPED=$check_ipv4_mapped_supported, LOCALHOST=$my_localhost
39 }
40
41 # This test only runs when IPv6 is supported (see include/check_ipv6.inc), so
42 # the server will listen on both IPv4 and IPv6 wildcard addresses. That's why
43 # the expected number of TCP/IP listeners is always 2.
44
45 #
46 # Preserve the current state of SOCKET_INSTANCES
47 #
48
49 --echo # Take a snapshot of SOCKET_INSTANCES
50 CREATE TEMPORARY TABLE my_socket_instances AS
51 SELECT * FROM performance_schema.socket_instances;
52
53 --echo # Get thread id of the default connection
54 --disable_cursor_protocol
55 SELECT THREAD_ID INTO @thread_id
56 FROM performance_schema.threads
57 WHERE PROCESSLIST_ID = CONNECTION_ID();
58 --enable_cursor_protocol
59
60 let $con0_thread_id= `SELECT @thread_id`;
61
62 #
63 # ESTABLISH TCP/IP CONNECTION 1
64 #
65 # Start connection with IP = localhost (127.0.0.1 or ::1)
66
67 --connect (con1,$my_localhost,root,,test,,$MASTER_MYPORT)
68
69 if($my_socket_debug)
70 {
71 # --replace_result '::ffff:127.0.0.1' <LOCALHOST> '127.0.0.1' <LOCALHOST> '::1' <LOCALHOST> '::' <BINDADDR> '0.0.0.0' <BINDADDR>
72 SELECT * FROM performance_schema.socket_instances;
73 }
74
75 --echo # Store the thread id of connection 1 (tcp/ip)
76 --disable_cursor_protocol
77 SELECT THREAD_ID INTO @thread_id
78 FROM performance_schema.threads
79 WHERE PROCESSLIST_ID = CONNECTION_ID();
80 --enable_cursor_protocol
81
82 --echo # Store the port of connection 1 (tcp/ip)
83 --disable_cursor_protocol
84 eval SELECT PORT INTO @port
85 FROM performance_schema.socket_instances
86 WHERE THREAD_ID = @thread_id;
87 --enable_cursor_protocol
88
89 let $con1_thread_id= `SELECT @thread_id`;
90 let $con1_port= `SELECT @port`;
91
92 --connection default
93
94 #
95 # ESTABLISH TCP/IP CONNECTION 2
96 #
97 # Start a second connection with IP = localhost (127.0.0.1 or ::1)
98
99 --connect (con2,$my_localhost,root,,test,,$MASTER_MYPORT)
100
101 if($my_socket_debug)
102 {
103 # --replace_result '::ffff:127.0.0.1' <LOCALHOST> '127.0.0.1' <LOCALHOST> '::1' <LOCALHOST> '::' <BINDADDR> '0.0.0.0' <BINDADDR>
104 SELECT * FROM performance_schema.socket_instances;
105 }
106
107 --echo # Store the thread_id of connection 2 (tcp/ip)
108 --disable_cursor_protocol
109 SELECT THREAD_ID INTO @thread_id
110 FROM performance_schema.threads
111 WHERE PROCESSLIST_ID = CONNECTION_ID();
112 --enable_cursor_protocol
113
114 --echo # Store the port of connection 2 (tcp/ip)
115 --disable_cursor_protocol
116 eval SELECT PORT INTO @port
117 FROM performance_schema.socket_instances
118 WHERE THREAD_ID = @thread_id;
119 --enable_cursor_protocol
120
121 let $con2_thread_id= `SELECT @thread_id`;
122 let $con2_port= `SELECT @port`;
123
124 --connection default
125
126 #
127 # ESTABLISH LOCAL UNIX DOMAIN CONNECTION
128 #
129 # Connect via mysql sock file
130
131 --connect(con3,localhost,root,,test,,)
132
133 if($my_socket_debug)
134 {
135 # --replace_result '::ffff:127.0.0.1' <LOCALHOST> '127.0.0.1' <LOCALHOST> '::1' <LOCALHOST> '::' <BINDADDR> '0.0.0.0' <BINDADDR>
136 SELECT * FROM performance_schema.socket_instances;
137 }
138
139 --echo # Store the thread id of connection 3 (unix domain)
140 --disable_cursor_protocol
141 SELECT THREAD_ID INTO @thread_id
142 FROM performance_schema.threads
143 WHERE PROCESSLIST_ID = CONNECTION_ID();
144 --enable_cursor_protocol
145
146 --echo # Store the port of connection 3 (unix domain)
147 --disable_cursor_protocol
148 eval SELECT PORT INTO @port
149 FROM performance_schema.socket_instances
150 WHERE THREAD_ID = @thread_id;
151 --enable_cursor_protocol
152
153 let $con3_port= `SELECT @port`;
154 let $con3_thread_id= `SELECT @thread_id`;
155
156 --connection default
157
158 #
159 # VERIFY EVENT NAMES
160 #
161
162 --echo # EVENT_NAME is the "wait/io/socket/*" instrument identifier.
163
164 SELECT COUNT(*) = 0 AS "Expect 1"
165 FROM performance_schema.socket_instances
166 WHERE EVENT_NAME NOT LIKE 'wait/io/socket/%';
167
168 #
169 # VERIFY UNIQUE EVENT IDs
170 #
171
172 --echo # OBJECT_INSTANCE_BEGIN is an arbitrary identifier, guaranteed to be unique.
173
174 SELECT COUNT(*) = COUNT(DISTINCT OBJECT_INSTANCE_BEGIN) AS "Expect 1"
175 FROM performance_schema.socket_instances;
176
177 #
178 # VERIFY UNIQUE SOCKET ID
179 #
180
181 --echo # SOCKET_ID is the internal file handle assigned to the socket.
182
183 SELECT COUNT(*) = COUNT(DISTINCT SOCKET_ID) AS "Expect 1"
184 FROM performance_schema.socket_instances;
185
186 #
187 # VERIFY UNIQUE THREAD IDs
188 #
189
190 --echo # Characteristics per our thread
191 --echo # There must be only one entry with our thread_id
192
193 --disable_query_log ONCE
194 eval SET @thread_id= $con0_thread_id;
195
196 eval SELECT COUNT(*) = 1 AS 'Expect 1'
197 FROM performance_schema.socket_instances
198 WHERE THREAD_ID = @thread_id;
199
200 #
201 # VERIFY UNIQUE PORT NUMBERS FOR TCP/IP CLIENTS
202 #
203
204 --echo # TCP/IP connections should have a unique port number
205 --disable_query_log ONCE
206 eval SET @port= $con1_port;
207
208 --echo # Connection 1 (tcp/ip)
209 eval SELECT COUNT(*) = 1 AS 'Expect 1'
210 FROM performance_schema.socket_instances
211 WHERE PORT = @port;
212
213 --disable_query_log ONCE
214 eval SET @port= $con2_port;
215
216 --echo # Connection 2 (tcp/ip)
217 eval SELECT COUNT(*) = 1 AS 'Expect 1'
218 FROM performance_schema.socket_instances
219 WHERE PORT = @port;
220
221 #
222 # VERIFY CONNECTION DETAILS FOR THE DEFAULT CONNECTION
223 #
224
225 --echo # Check the content for the default connection (unix domain)
226 # EVENT_NAME OBJECT_INSTANCE_BEGIN THREAD_ID SOCKET_ID IP PORT STATE
227 # wait/io/socket/sql/client_connection 139799531958280 16 37 0 ACTIVE
228
229 --disable_query_log ONCE
230 eval SET @thread_id = $con0_thread_id;
231
232 SELECT COUNT(*) = 1 as 'Expect 1'
233 FROM performance_schema.socket_instances
234 WHERE EVENT_NAME = 'wait/io/socket/sql/client_connection'
235 AND PORT = 0 AND THREAD_ID = @thread_id;
236
237 #
238 # VERIFY SERVER LISTENING SOCKET, TCP/IP
239 #
240
241 --echo # Characteristics of 'server_tcpip_socket' entry
242 --echo # Server listening socket, TCP/IP
243 --echo # There are two entries with 'wait/io/socket/sql/server_tcpip_socket',
244 --echo # for [::] and for 0.0.0.0.
245 --echo # They share the same thread id with 'wait/io/socket/sql/server_unix_socket'.
246
247 SELECT COUNT(*) = 2 AS 'Expect 2'
248 FROM performance_schema.socket_instances
249 WHERE EVENT_NAME = 'wait/io/socket/sql/server_tcpip_socket';
250
251 # Store the thread id of server_tcpip_socket
252 --echo # Get the 'server_tcpip_socket' thread id
253
254 --disable_cursor_protocol
255 SELECT DISTINCT THREAD_ID INTO @thread_id
256 FROM performance_schema.socket_instances
257 WHERE EVENT_NAME = 'wait/io/socket/sql/server_tcpip_socket';
258 --enable_cursor_protocol
259
260 let $server_tcpip_thread_id= `SELECT @thread_id`;
261
262 --echo # Check the content.
263 --disable_query_log ONCE
264 eval SET @port = $MASTER_MYPORT;
265
266 eval SELECT THREAD_ID = @thread_id
267 AND (IP = '0.0.0.0' OR IP = '::')
268 AND PORT = @port
269 AND STATE = 'ACTIVE' AS 'Expect 1'
270 FROM performance_schema.socket_instances
271 WHERE EVENT_NAME = 'wait/io/socket/sql/server_tcpip_socket';
272
273 #
274 # VERIFY SERVER LISTENING SOCKET, UNIX DOMAIN
275 #
276
277 --echo # Characteristics of 'server_unix_socket' entry
278 --echo # Server listening socket, unix domain (socket file)
279 --echo # There is only one entry with 'wait/io/socket/sql/server_unix_socket'.
280 --echo # It shares the same thread id as 'wait/io/socket/sql/server_tcpip_socket'.
281
282 SELECT COUNT(*) = 1 AS 'Expect 1'
283 FROM performance_schema.socket_instances
284 WHERE EVENT_NAME = 'wait/io/socket/sql/server_unix_socket';
285
286 # Store the thread id of 'server_unix_socket'
287 --echo # Get the 'server_unix_socket' thread id
288
289 --disable_cursor_protocol
290 SELECT THREAD_ID INTO @thread_id
291 FROM performance_schema.socket_instances
292 WHERE EVENT_NAME = 'wait/io/socket/sql/server_unix_socket';
293 --enable_cursor_protocol
294
295 let $server_unix_thread_id= `SELECT @thread_id`;
296
297 --echo # Check the content.
298 eval SELECT THREAD_ID = @thread_id
299 AND IP = ''
300 AND PORT = 0
301 AND STATE = 'ACTIVE' AS 'Expect 1'
302 FROM performance_schema.socket_instances
303 WHERE EVENT_NAME = 'wait/io/socket/sql/server_unix_socket';
304
305 #
306 # VERIFY SERVER LISTENING SOCKET THREAD IDs
307 #
308
309 --echo # Server listening sockets (TCP and Unix) are handled on the same thread
310
311 --disable_query_log ONCE
312 eval SET @thread_id = $server_tcpip_thread_id;
313
314 eval SELECT COUNT(*) = 3 AS 'Expect 3'
315 FROM performance_schema.socket_instances
316 WHERE THREAD_ID = @thread_id;
317
318 --disable_query_log ONCE
319 eval SET @thread_id = $server_unix_thread_id;
320
321 eval SELECT COUNT(*) = 3 AS 'Expect 3'
322 FROM performance_schema.socket_instances
323 WHERE THREAD_ID = @thread_id;
324
325 --echo #Compare server listener socket thread ids
326 --disable_query_log ONCE
327 --disable_cursor_protocol
328 eval SELECT ($server_tcpip_thread_id = $server_unix_thread_id) into @match_thread_id;
329 --disable_cursor_protocol
330
331 select @match_thread_id;
332
333 #
334 # VERIFY TCP/IP CLIENT CONNECTION 1
335 #
336
337 # EVENT_NAME OBJECT_INSTANCE_BEGIN THREAD_ID SOCKET_ID IP PORT STATE
338 # wait/io/socket/sql/client_connection 140707865187120 18 59 127.0.0.1 59298 IDLE or ACTIVE
339
340 --echo # Check content for client connection 1 (tcpip)
341
342 --disable_query_log
343 eval SET @port = $con1_port;
344 eval SET @thread_id = $con1_thread_id;
345 eval SET @addr = '$my_localhost';
346 --enable_query_log
347
348 eval SELECT EVENT_NAME = 'wait/io/socket/sql/client_connection'
349 AND (IP LIKE '%127.0.0.1' OR IP = '::1')
350 AND PORT = @port
351 AS 'Expect 1'
352 FROM performance_schema.socket_instances
353 WHERE THREAD_ID = @thread_id;
354
355 --echo # Characteristics of entries with THREAD_ID of con1
356 --echo # There is only one entry with this id.
357
358 eval SELECT COUNT(*) = 1 AS 'Expect 1'
359 FROM performance_schema.socket_instances
360 WHERE THREAD_ID = @thread_id;
361
362 #
363 # VERIFY TCP/IP CLIENT CONNECTION 2
364 #
365
366 # EVENT_NAME OBJECT_INSTANCE_BEGIN THREAD_ID SOCKET_ID IP PORT STATE
367 # wait/io/socket/sql/client_connection 140707865187120 18 59 127.0.0.1 59298 IDLE or ACTIVE
368
369 --echo # Check content for client connection 2 (tcpip)
370
371 --disable_query_log
372 eval SET @port = $con2_port;
373 eval SET @thread_id = $con2_thread_id;
374 eval SET @addr = '$my_localhost';
375 --enable_query_log
376
377 eval SELECT EVENT_NAME = 'wait/io/socket/sql/client_connection'
378 AND (IP LIKE '%127.0.0.1' OR IP = '::1')
379 AND PORT = @port
380 AS 'Expect 1'
381 FROM performance_schema.socket_instances
382 WHERE THREAD_ID = @thread_id;
383
384 --echo # Characteristics of entries with THREAD_ID of con2
385 --echo # There is only one entry with this id.
386
387 eval SELECT COUNT(*) = 1 AS 'Expect 1'
388 FROM performance_schema.socket_instances
389 WHERE THREAD_ID = @thread_id;
390
391 #
392 # VERIFY LOCAL CONNECTION, UNIX DOMAIN
393 #
394
395 # EVENT_NAME OBJECT_INSTANCE_BEGIN THREAD_ID SOCKET_ID IP PORT STATE
396 # wait/io/socket/sql/client_connection 139799531958280 16 37 0 IDLE or ACTIVE
397
398 --echo # Check the content for client connection 3 (unix domain).
399
400 --disable_query_log ONCE
401 eval SET @thread_id = $con3_thread_id;
402
403 eval SELECT EVENT_NAME = 'wait/io/socket/sql/client_connection'
404 AND IP = ''
405 AND PORT = 0
406 AS 'Expect 1'
407 FROM performance_schema.socket_instances
408 WHERE THREAD_ID = @thread_id;
409
410 --echo # Characteristics of entries with THREAD_ID of con3
411 --echo # There is only one entry with this id.
412
413 eval SELECT COUNT(*) = 1 AS 'Expect 1'
414 FROM performance_schema.socket_instances
415 WHERE THREAD_ID = @thread_id;
416
417 #
418 # LIST CLIENT CONNECTIONS
419 #
420
421 --echo # Show differences to socket_instances before con1, con2 and con3 connecting
422 let $part=
423 FROM performance_schema.socket_instances
424 WHERE (EVENT_NAME,OBJECT_INSTANCE_BEGIN,THREAD_ID,SOCKET_ID,IP,PORT,STATE)
425 NOT IN (SELECT EVENT_NAME,OBJECT_INSTANCE_BEGIN,THREAD_ID,SOCKET_ID,IP,PORT,STATE
426 FROM my_socket_instances)
427 ORDER BY THREAD_ID;
428 --replace_result '::ffff:127.0.0.1' <LOCALHOST> '127.0.0.1' <LOCALHOST> '::1' <LOCALHOST> '::' <BINDADDR> '0.0.0.0' <BINDADDR>
429 eval
430 SELECT EVENT_NAME, IP
431 $part;
432
433 --connection default
434
435 #
436 # DROP CLIENT CONNECTIONS
437 #
438
439 --connection con1
440 --disconnect con1
441 --source include/wait_until_disconnected.inc
442 --connection con2
443 --disconnect con2
444 --source include/wait_until_disconnected.inc
445 --connection con3
446 --disconnect con3
447 --source include/wait_until_disconnected.inc
448 --connection default
449
450 #
451 # VERIFY CONNECTIONS DROPPED
452 #
453
454 --echo # After waiting a bit we should have no differences to socket_instances
455 --echo # before con1, con2, con3 connecting.
456 let $wait_timeout= 10;
457 let $wait_condition= SELECT COUNT(*) = 0 $part;
458 --source include/wait_condition.inc
459 #
460 eval
461 SELECT *
462 $part;
463