summaryrefslogtreecommitdiff
path: root/mysql-test/suite/perfschema/t/socket_instances_func.test
blob: 7e8dfe51d2fc75e44e64a5f24ccb26ca9f0e2343 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
#
# Some functional checks for the content of performance_schema.socket_instances.
#

--source include/not_embedded.inc
--source include/not_windows.inc
--source include/have_perfschema.inc

# Set this to enable debugging output
let $my_socket_debug_dbug= 0;

#
# Set IP address defaults with respect to IPV6 support
#

# Determine if IPV6 supported
let $check_ipv6_just_check= 1;
--source include/check_ipv6.inc

# Determine if IPV4 mapped to IPV6 supported
let $check_ipv4_mapped_just_check= 1;
--source include/have_ipv4_mapped.inc

let $my_localhost= 127.0.0.1;

if($check_ipv6_supported)
{
  let $my_localhost= ::1;
}

if($check_ipv4_mapped_supported)
{
  let $my_localhost= ::ffff:127.0.0.1;
}

if($my_socket_debug)
{
  --echo IPV6=$check_ipv6_supported, IPV4_MAPPED=$check_ipv4_mapped_supported, LOCALHOST=$my_localhost
}

# This test only runs when IPv6 is supported (see include/check_ipv6.inc), so
# the server will listen on both IPv4 and IPv6 wildcard addresses. That's why
# the expected number of TCP/IP listeners is always 2.

#
# Preserve the current state of SOCKET_INSTANCES
#

--echo # Take a snapshot of SOCKET_INSTANCES
CREATE TEMPORARY TABLE my_socket_instances AS
SELECT * FROM performance_schema.socket_instances;

--echo # Get thread id of the default connection
SELECT THREAD_ID INTO @thread_id
FROM performance_schema.threads
WHERE PROCESSLIST_ID = CONNECTION_ID();

let $con0_thread_id= `SELECT @thread_id`;

#
# ESTABLISH TCP/IP CONNECTION 1
#
# Start connection with IP = localhost (127.0.0.1 or ::1)

--connect (con1,$my_localhost,root,,test,,$MASTER_MYPORT)

if($my_socket_debug)
{
#  --replace_result '::ffff:127.0.0.1' <LOCALHOST> '127.0.0.1' <LOCALHOST> '::1' <LOCALHOST> '::' <BINDADDR> '0.0.0.0' <BINDADDR>
  SELECT * FROM performance_schema.socket_instances;
}

--echo # Store the thread id of connection 1 (tcp/ip)
SELECT THREAD_ID INTO @thread_id
FROM performance_schema.threads
WHERE PROCESSLIST_ID = CONNECTION_ID();

--echo # Store the port of connection 1 (tcp/ip)
eval SELECT PORT INTO @port
FROM performance_schema.socket_instances
WHERE THREAD_ID = @thread_id;

let $con1_thread_id= `SELECT @thread_id`;
let $con1_port= `SELECT @port`;

--connection default

#
# ESTABLISH TCP/IP CONNECTION 2
#
# Start a second connection with IP = localhost (127.0.0.1 or ::1)

--connect (con2,$my_localhost,root,,test,,$MASTER_MYPORT)

if($my_socket_debug)
{
#  --replace_result '::ffff:127.0.0.1' <LOCALHOST> '127.0.0.1' <LOCALHOST> '::1' <LOCALHOST> '::' <BINDADDR> '0.0.0.0' <BINDADDR>
  SELECT * FROM performance_schema.socket_instances;
}

--echo # Store the thread_id of connection 2 (tcp/ip)
SELECT THREAD_ID INTO @thread_id
FROM performance_schema.threads
WHERE PROCESSLIST_ID = CONNECTION_ID();

--echo # Store the port of connection 2 (tcp/ip)
eval SELECT PORT INTO @port
FROM performance_schema.socket_instances
WHERE THREAD_ID = @thread_id;

let $con2_thread_id= `SELECT @thread_id`;
let $con2_port= `SELECT @port`;

--connection default

#
# ESTABLISH LOCAL UNIX DOMAIN CONNECTION
#
# Connect via mysql sock file

--connect(con3,localhost,root,,test,,)

if($my_socket_debug)
{
#  --replace_result '::ffff:127.0.0.1' <LOCALHOST> '127.0.0.1' <LOCALHOST> '::1' <LOCALHOST> '::' <BINDADDR> '0.0.0.0' <BINDADDR>
  SELECT * FROM performance_schema.socket_instances;
}

--echo # Store the thread id of connection 3 (unix domain)
SELECT THREAD_ID INTO @thread_id
FROM performance_schema.threads
WHERE PROCESSLIST_ID = CONNECTION_ID();

--echo # Store the port of connection 3 (unix domain)
eval SELECT PORT INTO @port
FROM performance_schema.socket_instances
WHERE THREAD_ID = @thread_id;

let $con3_port= `SELECT @port`;
let $con3_thread_id= `SELECT @thread_id`;

--connection default

#
# VERIFY EVENT NAMES
#

--echo # EVENT_NAME is the "wait/io/socket/*" instrument identifier.

SELECT COUNT(*) = 0 AS "Expect 1"
FROM performance_schema.socket_instances
WHERE EVENT_NAME NOT LIKE 'wait/io/socket/%';

#
# VERIFY UNIQUE EVENT IDs
#

--echo # OBJECT_INSTANCE_BEGIN is an arbitrary identifier, guaranteed to be unique.

SELECT COUNT(*) = COUNT(DISTINCT OBJECT_INSTANCE_BEGIN) AS "Expect 1"
FROM performance_schema.socket_instances;

#
# VERIFY UNIQUE SOCKET ID
#

--echo # SOCKET_ID is the internal file handle assigned to the socket.

SELECT COUNT(*) = COUNT(DISTINCT SOCKET_ID) AS "Expect 1"
FROM performance_schema.socket_instances;

#
# VERIFY UNIQUE THREAD IDs
#

--echo # Characteristics per our thread
--echo #    There must be only one entry with our thread_id

--disable_query_log ONCE
eval SET @thread_id= $con0_thread_id;

eval SELECT COUNT(*) = 1 AS 'Expect 1'
FROM performance_schema.socket_instances
WHERE THREAD_ID = @thread_id;

#
# VERIFY UNIQUE PORT NUMBERS FOR TCP/IP CLIENTS
#

--echo # TCP/IP connections should have a unique port number
--disable_query_log ONCE
eval SET @port= $con1_port;

--echo # Connection 1 (tcp/ip)
eval SELECT COUNT(*) = 1 AS 'Expect 1'
FROM performance_schema.socket_instances
WHERE PORT = @port;

--disable_query_log ONCE
eval SET @port= $con2_port;

--echo # Connection 2 (tcp/ip)
eval SELECT COUNT(*) = 1 AS 'Expect 1'
FROM performance_schema.socket_instances
WHERE PORT = @port;

#
# VERIFY CONNECTION DETAILS FOR THE DEFAULT CONNECTION
#

--echo #    Check the content for the default connection (unix domain)
# EVENT_NAME                           OBJECT_INSTANCE_BEGIN  THREAD_ID  SOCKET_ID  IP  PORT    STATE
# wait/io/socket/sql/client_connection       139799531958280         16         37         0    ACTIVE

--disable_query_log ONCE
eval SET @thread_id = $con0_thread_id;

SELECT COUNT(*) = 1 as 'Expect 1'
FROM performance_schema.socket_instances
WHERE EVENT_NAME = 'wait/io/socket/sql/client_connection'
AND PORT = 0 AND THREAD_ID = @thread_id;

#
# VERIFY SERVER LISTENING SOCKET, TCP/IP
#

--echo # Characteristics of 'server_tcpip_socket' entry
--echo #    Server listening socket, TCP/IP
--echo #    There are two entries with 'wait/io/socket/sql/server_tcpip_socket',
--echo #    for [::] and for 0.0.0.0.
--echo #    They share the same thread id with 'wait/io/socket/sql/server_unix_socket'.

SELECT COUNT(*) = 2 AS 'Expect 2'
FROM performance_schema.socket_instances
WHERE EVENT_NAME = 'wait/io/socket/sql/server_tcpip_socket';

# Store the thread id of server_tcpip_socket
--echo # Get the 'server_tcpip_socket' thread id

SELECT DISTINCT THREAD_ID INTO @thread_id
FROM performance_schema.socket_instances
WHERE EVENT_NAME = 'wait/io/socket/sql/server_tcpip_socket';

let $server_tcpip_thread_id= `SELECT @thread_id`;

--echo #    Check the content.
--disable_query_log ONCE
eval SET @port = $MASTER_MYPORT;

eval SELECT THREAD_ID = @thread_id
     AND (IP = '0.0.0.0' OR IP = '::')
     AND PORT = @port
     AND STATE = 'ACTIVE' AS 'Expect 1'
FROM performance_schema.socket_instances
WHERE EVENT_NAME = 'wait/io/socket/sql/server_tcpip_socket';

#
# VERIFY SERVER LISTENING SOCKET, UNIX DOMAIN
#

--echo # Characteristics of 'server_unix_socket' entry
--echo #    Server listening socket, unix domain (socket file)
--echo #    There is only one entry with 'wait/io/socket/sql/server_unix_socket'.
--echo #    It shares the same thread id as 'wait/io/socket/sql/server_tcpip_socket'.

SELECT COUNT(*) = 1 AS 'Expect 1'
FROM performance_schema.socket_instances
WHERE EVENT_NAME = 'wait/io/socket/sql/server_unix_socket';

# Store the thread id of 'server_unix_socket'
--echo # Get the 'server_unix_socket' thread id

SELECT THREAD_ID INTO @thread_id
FROM performance_schema.socket_instances
WHERE EVENT_NAME = 'wait/io/socket/sql/server_unix_socket';

let $server_unix_thread_id= `SELECT @thread_id`;

--echo #    Check the content.
eval SELECT THREAD_ID = @thread_id
     AND IP = ''
     AND PORT = 0
     AND STATE = 'ACTIVE' AS 'Expect 1'
FROM performance_schema.socket_instances
WHERE EVENT_NAME = 'wait/io/socket/sql/server_unix_socket';

#
# VERIFY SERVER LISTENING SOCKET THREAD IDs
#

--echo # Server listening sockets (TCP and Unix) are handled on the same thread

--disable_query_log ONCE
eval SET @thread_id = $server_tcpip_thread_id;

eval SELECT COUNT(*) = 3 AS 'Expect 3'
FROM performance_schema.socket_instances
WHERE THREAD_ID = @thread_id;

--disable_query_log ONCE
eval SET @thread_id = $server_unix_thread_id;

eval SELECT COUNT(*) = 3 AS 'Expect 3'
FROM performance_schema.socket_instances
WHERE THREAD_ID = @thread_id;

--echo #Compare server listener socket thread ids
--disable_query_log ONCE
eval SELECT ($server_tcpip_thread_id = $server_unix_thread_id) into @match_thread_id;

select @match_thread_id;

#
# VERIFY TCP/IP CLIENT CONNECTION 1
#

# EVENT_NAME                           OBJECT_INSTANCE_BEGIN  THREAD_ID  SOCKET_ID   IP           PORT  STATE
# wait/io/socket/sql/client_connection       140707865187120         18         59   127.0.0.1   59298   IDLE or ACTIVE

--echo #    Check content for client connection 1 (tcpip)

--disable_query_log
eval SET @port = $con1_port;
eval SET @thread_id = $con1_thread_id;
eval SET @addr = '$my_localhost';
--enable_query_log

eval SELECT EVENT_NAME = 'wait/io/socket/sql/client_connection'
        AND (IP LIKE '%127.0.0.1' OR IP = '::1')
        AND PORT = @port
AS 'Expect 1'
FROM performance_schema.socket_instances
WHERE THREAD_ID = @thread_id;

--echo # Characteristics of entries with THREAD_ID of con1
--echo #    There is only one entry with this id.

eval SELECT COUNT(*) = 1 AS 'Expect 1'
FROM performance_schema.socket_instances
WHERE THREAD_ID = @thread_id;

#
# VERIFY TCP/IP CLIENT CONNECTION 2
#

# EVENT_NAME                           OBJECT_INSTANCE_BEGIN  THREAD_ID  SOCKET_ID   IP           PORT  STATE
# wait/io/socket/sql/client_connection       140707865187120         18         59   127.0.0.1   59298   IDLE or ACTIVE

--echo #    Check content for client connection 2 (tcpip)

--disable_query_log
eval SET @port = $con2_port;
eval SET @thread_id = $con2_thread_id;
eval SET @addr = '$my_localhost';
--enable_query_log

eval SELECT EVENT_NAME = 'wait/io/socket/sql/client_connection'
        AND (IP LIKE '%127.0.0.1' OR IP = '::1')
        AND PORT = @port
AS 'Expect 1'
FROM performance_schema.socket_instances
WHERE THREAD_ID = @thread_id;

--echo # Characteristics of entries with THREAD_ID of con2
--echo #    There is only one entry with this id.

eval SELECT COUNT(*) = 1 AS 'Expect 1'
FROM performance_schema.socket_instances
WHERE THREAD_ID = @thread_id;

#
# VERIFY LOCAL CONNECTION, UNIX DOMAIN
#

# EVENT_NAME                           OBJECT_INSTANCE_BEGIN  THREAD_ID  SOCKET_ID  IP  PORT  STATE
# wait/io/socket/sql/client_connection       139799531958280         16         37         0   IDLE or ACTIVE

--echo #    Check the content for client connection 3 (unix domain).

--disable_query_log ONCE
eval SET @thread_id = $con3_thread_id;

eval SELECT EVENT_NAME = 'wait/io/socket/sql/client_connection'
     AND IP = ''
     AND PORT = 0
AS 'Expect 1'
FROM performance_schema.socket_instances
WHERE THREAD_ID = @thread_id;

--echo # Characteristics of entries with THREAD_ID of con3
--echo #    There is only one entry with this id.

eval SELECT COUNT(*) = 1 AS 'Expect 1'
FROM performance_schema.socket_instances
WHERE THREAD_ID = @thread_id;

#
# LIST CLIENT CONNECTIONS
#

--echo # Show differences to socket_instances before con1, con2 and con3 connecting
let $part=
FROM performance_schema.socket_instances
WHERE (EVENT_NAME,OBJECT_INSTANCE_BEGIN,THREAD_ID,SOCKET_ID,IP,PORT,STATE)
NOT IN (SELECT EVENT_NAME,OBJECT_INSTANCE_BEGIN,THREAD_ID,SOCKET_ID,IP,PORT,STATE
        FROM my_socket_instances)
ORDER BY THREAD_ID;
--replace_result '::ffff:127.0.0.1' <LOCALHOST> '127.0.0.1' <LOCALHOST> '::1' <LOCALHOST> '::' <BINDADDR> '0.0.0.0' <BINDADDR>
eval
SELECT EVENT_NAME, IP
$part;

--connection default

#
# DROP CLIENT CONNECTIONS
#

--connection con1
--disconnect con1
--source include/wait_until_disconnected.inc
--connection con2
--disconnect con2
--source include/wait_until_disconnected.inc
--connection con3
--disconnect con3
--source include/wait_until_disconnected.inc
--connection default

#
# VERIFY CONNECTIONS DROPPED
#

--echo # After waiting a bit we should have no differences to socket_instances
--echo # before con1, con2, con3 connecting.
let $wait_timeout= 10;
let $wait_condition= SELECT COUNT(*) = 0 $part;
--source include/wait_condition.inc
#
eval
SELECT *
$part;