summaryrefslogtreecommitdiff
path: root/mysql-test/suite/perfschema/t/show_plugin.test
blob: 047caf71a4b06a9a7e3d9a4cb50dbe493048022d (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
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
################# suite/perfschema/t/show_plugin.test ##########################
#                                                                              #
# MySQL plugins can define their own status variables and system variables.    #
# This test exercises SHOW STATUS, SHOW VARIABLES and the status and system    #
# variable tables while the EXAMPLE plugin is loaded and unloaded.             #
#                                                                              #
# The EXAMPLE plugin defines the following system and status variables:        #
# Global system variables:                                                     # 
#   example_double_thdvar                                                      #
#   example_double_var                                                         #
#   example_enum_var                                                           #
#   example_ulong_var                                                          #
#                                                                              #
# Session variables:                                                           #
#   example_double_thdvar - Local and/or global                                #
#                                                                              #
# Global status:                                                               #
#   example_func_example  - Status function                                    #
#                                                                              #
################################################################################

--source include/have_perfschema.inc
--source include/not_embedded.inc
--source include/not_windows_embedded.inc
--source include/have_example_plugin.inc
--source include/have_debug_sync.inc

--enable_connect_log

--echo
--echo ================================================================================
--echo SETUP
--echo ================================================================================
--echo # Save the initial number of concurrent sessions
--source include/count_sessions.inc
--echo
--echo # Save current SHOW_COMPATIBILITY_56 setting
SELECT @@global.show_compatibility_56 INTO @show_compatibility_56_save;
--echo #
--echo # SET COMPATIBILITY MODE = OFF
--echo #
SET @@global.show_compatibility_56 = OFF;
--echo
--echo # Verify EXAMPLE plugin is not loaded
SELECT COUNT(*) = 0 AS "Expect 1" FROM information_schema.plugins WHERE plugin_name = "EXAMPLE";
--echo
--echo # Create one session to force local and global system variables;
connect(con0, localhost, root,,);
--connection default
--echo
--echo ================================================================================
--echo TEST 1- NO PLUGIN VARS
--echo ================================================================================
--source ../include/show_plugin_verifier.inc
--echo

--echo ================================================================================
--echo TEST 2 - PLUGIN LOAD, UNLOAD, RELOAD
--echo ================================================================================
--echo ================================================================================
--echo 2.1 - INSTALL PLUGIN
--echo ================================================================================
--replace_regex /\.dll/.so/
eval INSTALL PLUGIN example SONAME '$EXAMPLE_PLUGIN';

--echo
--echo ================================================================================
--echo 2.1a - FORCE SYNC OF LOCAL AND GLOBAL SYSTEM VARS
--echo ================================================================================
--source ../include/show_plugin_verifier.inc

--disconnect con0

--echo
--echo ================================================================================
--echo 2.2 - SET PLUGIN VARS
--echo ================================================================================
--echo # GLOBAL
SET GLOBAL example_ulong_var = 100;
SET GLOBAL example_enum_var = e1;
SET GLOBAL example_double_var = 100.9990;
SET GLOBAL example_double_thdvar = 101.9991;
--echo # SESSION
SET SESSION example_double_thdvar = 102.9992;

--echo
--echo ================================================================================
--echo 2.3 - VERIFY UPDATED PLUGIN VARS
--echo ================================================================================
--source ../include/show_plugin_verifier.inc

--echo
--echo ================================================================================
--echo 2.4 - UNINSTALL PLUGIN
--echo ================================================================================
UNINSTALL PLUGIN example;

--echo
--echo ================================================================================
--echo 2.5 - VERIFY NO PLUGIN VARS
--echo ================================================================================
--source ../include/show_plugin_verifier.inc

--echo
--echo ================================================================================
--echo 2.6 - REINSTALL PLUGIN
--echo ================================================================================
--echo # Reinstall EXAMPLE plugin
--replace_regex /\.dll/.so/
eval INSTALL PLUGIN example SONAME '$EXAMPLE_PLUGIN';

--echo
--echo ================================================================================
--echo 2.7 - SET PLUGIN VARS AGAIN
--echo ================================================================================
--echo # GLOBAL
SET GLOBAL example_ulong_var = 200;
SET GLOBAL example_enum_var = e2;
SET GLOBAL example_double_var = 200.8880;
SET GLOBAL example_double_thdvar = 201.8881;
--echo # SESSION
SET SESSION example_double_thdvar = 202.8882;

--echo
--echo ================================================================================
--echo 2.8 - VERIFY PLUGIN VARS
--echo ================================================================================
--source ../include/show_plugin_verifier.inc

--echo
--echo ================================================================================
--echo 2.9 - UNINSTALL PLUGIN
--echo ================================================================================
UNINSTALL PLUGIN example;

--echo
--echo ================================================================================
--echo 2.10 - VERIFY NO PLUGIN VARS
--echo ================================================================================
--source ../include/show_plugin_verifier.inc

--echo
--echo ================================================================================
--echo TEST 3 - SESSION PLUGIN VARS ON MULTIPLE CONNECTIONS
--echo ================================================================================
--echo
--echo ================================================================================
--echo 3.1 - INSTALL PLUGIN
--echo ================================================================================
--replace_regex /\.dll/.so/
eval INSTALL PLUGIN example SONAME '$EXAMPLE_PLUGIN';

--echo
--echo ================================================================================
--echo 3.2 - SET GLOBAL AND DEFAULT CONNECTION VARS
--echo ================================================================================
--connection default
SET GLOBAL example_ulong_var = 300;
SET GLOBAL example_enum_var = e1;
SET GLOBAL example_double_var = 301.0000;
SET GLOBAL example_double_thdvar = 302.0000;
SET SESSION example_double_thdvar = 300.0000;

--echo
--echo ================================================================================
--echo 3.3 - CONNECT 3 CLIENTS, SET LOCAL PLUGIN VARS
--echo ================================================================================
connect(con1, localhost, root,,);
SET SESSION example_double_thdvar = 300.1111;
--echo
connect(con2, localhost, root,,);
SET SESSION example_double_thdvar = 300.2222;
--echo
connect(con3, localhost, root,,);
SET SESSION example_double_thdvar = 300.3333;
--echo
--connection default

--echo
--echo ================================================================================
--echo 3.4 - VERIFY GLOBAL AND SESSION PLUGIN VARS
--echo ================================================================================
--source ../include/show_plugin_verifier.inc
--echo
--echo # Variables by thread
SELECT variable_name, variable_value FROM performance_schema.variables_by_thread
WHERE variable_name LIKE "example_%" ORDER BY variable_value;

--echo
--echo ================================================================================
--echo 3.5 - DISCONNECT CLIENTS
--echo ================================================================================
--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

--echo
--echo ================================================================================
--echo 3.6 - VERIFY SESSION VARS ARE REMOVED
--echo ================================================================================
--source ../include/show_plugin_verifier.inc
--echo
--echo # Variables by thread
SELECT variable_name, variable_value FROM performance_schema.variables_by_thread
WHERE variable_name LIKE "example_%" ORDER BY variable_value;

--echo
--echo ================================================================================
--echo 3.7 - RECONNECT 3 CLIENTS, SET SESSION VARS FOR EACH
--echo ================================================================================
connect(con1, localhost, root,,);
SET SESSION example_double_thdvar = 311.1111;
--echo
connect(con2, localhost, root,,);
SET SESSION example_double_thdvar = 322.2222;
--echo
connect(con3, localhost, root,,);
SET SESSION example_double_thdvar = 333.3333;
--echo
--connection default

--echo
--echo ================================================================================
--echo 3.8 - VERIFY GLOBAL AND SESSION VARS
--echo ================================================================================
--source ../include/show_plugin_verifier.inc
--echo
--echo # Variables by thread
SELECT variable_name, variable_value FROM performance_schema.variables_by_thread
WHERE variable_name LIKE "example_%" ORDER BY variable_value;

--echo
--echo ================================================================================
--echo 3.9 - UNINSTALL PLUGIN, LEAVE CLIENTS CONNECTED
--echo ================================================================================
UNINSTALL PLUGIN example;

--echo
--echo ================================================================================
--echo 3.10 - VERIFY SESSION VARS ARE REMOVED
--echo ================================================================================
--source ../include/show_plugin_verifier.inc
--echo
--echo # VARIABLES BY THREAD
SELECT variable_name, variable_value FROM performance_schema.variables_by_thread
WHERE variable_name LIKE "example_%" ORDER BY variable_value;

--echo
--echo ================================================================================
--echo 3.11 - DISCONNECT CLIENTS
--echo ================================================================================
--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

--echo
--echo ================================================================================
--echo 3.12 - VERIFY CLIENTS ARE REMOVED
--echo ================================================================================
--source ../include/show_plugin_verifier.inc
--echo
--echo # VARIABLES BY THREAD
SELECT variable_name, variable_value FROM performance_schema.variables_by_thread
WHERE variable_name LIKE "example_%" ORDER BY variable_value;

--echo
--echo ================================================================================
--echo TEST 4 - BUG#18008907: DEADLOCK WITH CHANGE_USER, SHOW VARIABLES, INSTALL PLUGIN
--echo ================================================================================
--echo
--disable_result_log
DELIMITER |;

CREATE PROCEDURE install_no_such_plugin()
BEGIN
  INSTALL PLUGIN no_such_plugin SONAME 'no_such_object';
END|
--echo
CREATE PROCEDURE show_vars()
BEGIN
  -- select on information_schema.global_variables
  -- will fail, still need to cover execution of the code
  -- to verify potential dead locks.
  declare continue handler for sqlexception
  begin
  end;

  SELECT COUNT(*) FROM information_schema.global_variables;
  SELECT COUNT(*) FROM performance_schema.global_variables;
END|

DELIMITER ;|
--enable_result_log

--echo
--echo ================================================================================
--echo 4.1 - DEADLOCK SCENARIO 1:
--echo       con1 - has LOCK_system_variables_hash and waits on LOCK_plugin AND
--echo       default - has LOCK_plugin and waits on LOCK_system_variables_hash
--echo ================================================================================
connect(con1, localhost, root,,);
SET DEBUG_SYNC='acquired_LOCK_system_variables_hash SIGNAL install_plugin WAIT_FOR cont_show_vars';
--send call show_vars();
--connection default
SET DEBUG_SYNC='now WAIT_FOR install_plugin';
SET DEBUG_SYNC='acquired_LOCK_plugin SIGNAL cont_show_vars';
--send call install_no_such_plugin();
--connection con1

--echo
--echo # Without fix, reap will hang.
--disable_warnings
--replace_column 1 #
--reap;
--enable_warnings
SET DEBUG_SYNC='RESET';

--connection default
--replace_regex /(Can\'t open shared library).*$/\1/
--error ER_CANT_OPEN_LIBRARY
--reap;
--echo
SET DEBUG_SYNC='RESET';

--echo
--echo ================================================================================
--echo 4.2 - DEADLOCK SCENARIO 2:
--echo       default - has LOCK_system_variables_hash, waits on LOCK_global_system_variables
--echo       con1 - has LOCK_plugin, waits on LOCK_system_variables_hash AND
--echo       con2 - has LOCK_global_system_variables, waits on LOCK_plugin
--echo ================================================================================
SET DEBUG_SYNC='acquired_LOCK_system_variables_hash SIGNAL install_plugin WAIT_FOR nothing TIMEOUT 10';
--send call show_vars();
--connection con1
SET DEBUG_SYNC='now WAIT_FOR install_plugin';
SET DEBUG_SYNC='acquired_LOCK_plugin SIGNAL create_connection WAIT_FOR nothing TIMEOUT 10';
--send call install_no_such_plugin();
connect(con2, localhost, root,,);
SET DEBUG_SYNC='now WAIT_FOR create_connection';

--echo
--echo # Without fix, deadlock situation will occur on timeout of debug_syncs in
--echo # default and con1.  Because of this, change_user operation hangs.
--echo change_user
change_user;
--connection con1
--replace_regex /(Can\'t open shared library).*$/\1/
--error ER_CANT_OPEN_LIBRARY
--reap;

--echo
--connection default
--replace_column 1 #
--disable_warnings
--reap;
--enable_warnings

--echo
--disconnect con2

--echo
--echo ================================================================================
--echo 4.3 - DEADLOCK SCENARIO 3: CONCURRENT SHOW VARIABLES AND UNINSTALL PLUGIN
--echo ================================================================================
--echo #
--echo # INSTALL PLUGIN
--echo #
--replace_regex /\.dll/.so/
eval INSTALL PLUGIN example SONAME '$EXAMPLE_PLUGIN';
--connection con1

--echo
--echo # Acquiring LOCK_system_variables_hash and LOCK_plugin_delete
SET DEBUG_SYNC='acquired_LOCK_system_variables_hash SIGNAL uninstall_plugin WAIT_FOR go';

--send call show_vars();
connect(con2, localhost, root,,);

--echo #
--echo # UNINSTALL PLUGIN
--echo #
SET DEBUG_SYNC='now WAIT_FOR uninstall_plugin';
--send UNINSTALL PLUGIN example;
--connection default

--echo
--echo # Uninstall will wait until SHOW VARIABLES releases LOCK_plugin_delete.
let $wait_condition= SELECT count(*) = 1 FROM INFORMATION_SCHEMA.PROCESSLIST
                     WHERE INFO='UNINSTALL PLUGIN example' and
                     STATE='System lock';
--source include/wait_condition.inc
SET DEBUG_SYNC='now SIGNAL go';
--echo # Connect con1 - reap
--connection con1
--replace_column 1 #
--disable_warnings
--reap
--enable_warnings
--echo # Connect con2 - reap
--connection con2
--disable_warnings
--reap
--enable_warnings

--echo
--echo ================================================================================
--echo TEST 5 - BUG#22225549 MYSQL_CHANGE_USER/MYSQL_RESET_CONNECTION + SET INNODB...
--echo          Update to plugin-defined session variable triggers resync with global
--echo          variables and deadlocks on THD::LOCK_thd_sysvar.
--echo ================================================================================
#
# THD:LOCK_thd_sysvar is only used when SHOW_COMPATIBILITY_56 = OFF
#
SELECT @@global.show_compatibility_56;
#
# The deadlock occurs when plugin-defined session variables are resynced with the global
# variables. To force a resync, change the user and update a session variable from a
# plugin, in this case InnoDB.
#
select @@session.innodb_strict_mode;
let $innodb_strict_mode_save = `select @@session.innodb_strict_mode`;
select user(), current_user();
--echo change_user root
--change_user root
--echo #
--echo # Trigger a resync of session variables with global variables.
--echo #
set @@session.innodb_strict_mode=off;

--echo
--echo # Restore
--echo
eval set @@session.innodb_strict_mode=$innodb_strict_mode_save;
select @@session.innodb_strict_mode;

--echo
--echo ================================================================================
--echo CLEAN UP
--echo ================================================================================
--connection default
--echo
DROP PROCEDURE show_vars;
DROP PROCEDURE install_no_such_plugin;
SET DEBUG_SYNC='RESET';

--echo
--disconnect con1
--disconnect con2
--disable_connect_log

--echo
--echo # Restore SHOW_COMPATIBILITY_56 setting
SET @@global.show_compatibility_56 = @show_compatibility_56_save;

--echo
--echo # Wait till we reached the initial number of concurrent sessions
--source include/wait_until_count_sessions.inc