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
|
--echo
--echo ## Test the Performance Schema Notification service WL#8881
--echo ##
--echo ## 1. Install component to register callbacks for each API
--echo ## 2. Launch multiple sessions to trigger callback events, log the events to file
--echo ## 3. Import log file into a table
--echo ## 4. Verify the contents of the table
--source include/have_debug.inc
--disable_ps_protocol
--echo ## Disable resource groups for this test.
SET DEBUG='+d, disable_rg_pfs_notifications';
--echo
--echo ## Install test component
INSTALL COMPONENT "file://component_test_pfs_notification";
--echo
--echo ## Create 2 users to control the test mode, and 3 users for testing
CREATE USER PFS_MTR_MODE_ENABLE;
CREATE USER PFS_MTR_MODE_DISABLE;
CREATE USER PFS_MTR_REGISTER_INTERNAL;
CREATE USER PFS_MTR_UNREGISTER_INTERNAL;
CREATE USER PFS_MTR_NEGATIVE_TEST_CASES;
CREATE USER PFS_USER1;
CREATE USER PFS_USER2;
CREATE USER PFS_USER3;
GRANT ALL ON *.* TO PFS_MTR_MODE_ENABLE;
GRANT ALL ON *.* TO PFS_MTR_MODE_DISABLE;
GRANT ALL ON *.* TO PFS_MTR_REGISTER_INTERNAL;
GRANT ALL ON *.* TO PFS_MTR_UNREGISTER_INTERNAL;
GRANT ALL ON *.* TO PFS_MTR_NEGATIVE_TEST_CASES;
GRANT ALL ON *.* TO PFS_USER1;
GRANT ALL ON *.* TO PFS_USER2;
GRANT ALL ON *.* TO PFS_USER3;
# The test component has two modes: MTR and RQG.
# The MTR mode verifies the correct operation of the Notification API, and is
# intended for MTR use only. In this mode, the test component registers 3
# callback functions for each of the five events that change the resource group
# name multiple times per connection and write status messages to both stderr
# and an external log file. The MTR mode uses the log file to capture and verify
# results.
#
# The RQG mode is intended for RQG and performance runs with many concurrent
# connections. This mode stresses the callback registry and provides an
# empirical assessment of performance overhead by registering three lightweight
# callbacks per event. The resource group name is set only once per connection
# in order to provide verifiable evidence of its operation.
#
# The RQG mode does not write to stderr or to external log files.
#
# Until system variables for server components is supported (WL#9424), the test
# mode is controlled by the client username. The test component defaults to RQG
# mode, and MTR mode is activated when a client connects with the username
# PFS_MTR_MODE_ENABLE.
--echo
--echo ## Enable MTR mode by connecting with a pre-defined username.
--echo
connect (con_pfs, localhost, PFS_MTR_MODE_ENABLE, , test);
--echo
--echo ## Test internal registration
--echo
connect (con_reg, localhost, PFS_MTR_REGISTER_INTERNAL, , test);
--echo
--echo ## Test negative test cases
--echo
connect (con_neg, localhost, PFS_MTR_NEGATIVE_TEST_CASES, , test);
--echo
--echo ## Test unregister internal
--echo
connect (con_unreg, localhost, PFS_MTR_UNREGISTER_INTERNAL, , test);
--echo
--echo ## Clean up special test cases
--echo ## Disconnect internal registration user
--connection con_reg
--disconnect con_reg
--source include/wait_until_disconnected.inc
--echo ## Disconnect internal unregistration user
--connection con_unreg
--disconnect con_unreg
--source include/wait_until_disconnected.inc
--echo ## Disconnect negative test case user
--connection con_neg
--disconnect con_neg
--source include/wait_until_disconnected.inc
--echo
--echo ## Start 2 sessions to generate thread_create and session_connect events.
--echo ## The session_connect callback assigns a resource group name for each user.
--echo
--echo ## Session 1
connect (con1, localhost, PFS_USER1, , test);
--echo
--echo ## Verify PFS_USER1 resource group in PERFORMANCE_SCHEMA.THREADS
SELECT name, type, processlist_user, processlist_host, processlist_db, resource_group
FROM performance_schema.threads
WHERE resource_group = 'RESOURCE_GROUP_3_2_1' AND processlist_user = 'PFS_USER1';
--echo
--echo ## Start session 2
--echo connect (con2, localhost, PFS_USER2, , test)
connect (con2, localhost, PFS_USER2, , test);
--echo
--echo ## Verify PFS_USER2 in PERFORMANCE_SCHEMA.THREADS
SELECT name, type, processlist_user, processlist_host, processlist_db, resource_group
FROM performance_schema.threads
WHERE resource_group = 'RESOURCE_GROUP_3_2_1' AND processlist_user = 'PFS_USER2';
--echo
--echo ## Change user from PFS_USER2 to PFS_USER3
--change_user PFS_USER3,,test
--echo
--echo ## Disconnect 2 sessions to generate session_disconnect and thread_destroy events.
--echo
--echo ## Disconnect session 1
--connection con1
--disconnect con1
--source include/wait_until_disconnected.inc
--echo ## Disconnect session 2
--connection con2
--disconnect con2
--source include/wait_until_disconnected.inc
--echo ## Disconnect primary control session
--connection con_pfs
--disconnect con_pfs
--source include/wait_until_disconnected.inc
--echo
--echo ## Disable MTR mode and activate RQG mode by connecting with a pre-defined username.
--echo
connect (con_pfs1, localhost, PFS_MTR_MODE_DISABLE, , test);
--echo ## Verify mode change
--echo
SELECT name, type, processlist_user, processlist_host, processlist_db, resource_group
FROM performance_schema.threads WHERE processlist_user = 'PFS_MTR_MODE_DISABLE';
--echo ## Disconnect second control session
--connection con_pfs1
--disconnect con_pfs1
--source include/wait_until_disconnected.inc
connection default;
--echo
--echo ## Uninstall component
--echo
UNINSTALL COMPONENT 'file://component_test_pfs_notification';
let $wait_condition=SELECT count(*)=0 FROM mysql.component WHERE component_urn like '%component_test_pfs_notification';
--source include/wait_condition.inc
--echo
--echo ## Create results table
--echo
CREATE TABLE test.callback_events (callback TEXT, handle INT, ret_code INT,
thread_id BIGINT UNSIGNED, plist_id BIGINT UNSIGNED, os_thread BIGINT UNSIGNED,
resource_group TEXT, user TEXT, host TEXT, vcpu TEXT, priority TEXT);
--echo
--echo ## Import log file
--echo
let $MYSQLD_DATADIR= `select @@datadir`;
#cat_file $MYSQLD_DATADIR/test_pfs_notification.log;
--replace_result $MYSQLD_DATADIR MYSQLD_DATADIR
--disable_warnings
eval
LOAD DATA LOCAL INFILE '$MYSQLD_DATADIR/test_pfs_notification.log' INTO TABLE test.callback_events
FIELDS TERMINATED BY ' ' LINES TERMINATED BY '\n' STARTING BY '*** '
(@label, callback, @label, handle, @label, ret_code, @label, thread_id, @label, plist_id,
@label, os_thread, @label, resource_group, @label, user, @label, host, @label, vcpu, @label, priority);
--echo
--echo ## Verify results
--echo
--enable_warnings
let $column_list =
rpad(callback, 35, ' ') as "callback ",
rpad(handle, 10, ' ') as "handle ",
rpad(ret_code, 10, ' ') as "ret_code ",
rpad(thread_id, 10, ' ') as "thread_id ",
rpad(plist_id, 10, ' ') as "plist_id ",
rpad(os_thread, 10, ' ') as "os_thread ",
rpad(resource_group, 20, ' ') as "resource_group ",
rpad(user, 30, ' ') as "user ",
rpad(host, 10, ' ') as "host ";
--echo SELECT * FROM test.callback_events WHERE callback = "session_change_user";
--replace_column 2 " ... " 4 " ... " 5 " ... " 6 " ... "
--disable_query_log
eval SELECT $column_list FROM callback_events
WHERE callback = 'session_change_user' AND resource_group = 'RESOURCE_GROUP_3_2_1'
ORDER BY callback, resource_group, user LIMIT 1;
# Each session connect callback changes the group name e.g. RESOURCE_GROUP_1,
# RESOURCE_GROUP_2, ..., etc. However, callbacks are invoked in reverse order of
# registration, so on disconnect each session should be RESOURCE_GROUP_1.
--echo
--echo SELECT * FROM test.callback_events WHERE callback = "session_connect;
--replace_column 2 " ... " 4 " ... " 5 " ... " 6 " ... "
eval SELECT $column_list FROM callback_events
WHERE callback = 'session_connect' AND resource_group = 'RESOURCE_GROUP_3_2_1'
ORDER BY callback, resource_group, user LIMIT 1;
--echo
--echo SELECT * FROM test.callback_events WHERE callback = "session_disconnect";
--replace_column 2 " ... " 4 " ... " 5 " ... " 6 " ... "
eval SELECT $column_list FROM callback_events
WHERE callback = 'session_disconnect' AND resource_group = 'RESOURCE_GROUP_3_2_1'
ORDER BY callback, resource_group, user LIMIT 1;
--echo
--echo SELECT * FROM test.callback_events WHERE callback = "thread_create";
--replace_column 2 " ... " 4 " ... " 5 " ... " 6 " ... "
eval SELECT $column_list FROM callback_events
WHERE callback = 'thread_create' AND resource_group = 'RESOURCE_GROUP_3_2_1'
ORDER BY callback, resource_group, user LIMIT 1;
--echo
--echo SELECT * FROM test.callback_events WHERE callback = "thread_destroy";
--replace_column 2 " ... " 4 " ... " 5 " ... " 6 " ... "
eval SELECT $column_list FROM callback_events
WHERE callback = 'thread_destroy' AND resource_group = 'RESOURCE_GROUP_3_2_1'
ORDER BY callback, resource_group, user LIMIT 1;
--echo
--echo SELECT * FROM test.callback_events WHERE callback = "register_notification_internal";
--replace_column 3 " ... " 4 " ... " 5 " ... " 6 " ... "
eval SELECT $column_list FROM callback_events
WHERE callback = 'register_notification_internal'
ORDER BY callback, resource_group, user LIMIT 1;
--echo
--echo SELECT * FROM test.callback_events WHERE callback LIKE "unregister_notification_internal";
--replace_column 4 " ... " 5 " ... " 6 " ... "
eval SELECT $column_list FROM callback_events
WHERE callback LIKE 'unregister_notification_internal'
ORDER BY callback, resource_group, user LIMIT 1;
--echo
--echo SELECT * FROM test.callback_events WHERE callback = "register_notification(bad_cb)";
--replace_column 4 " ... " 5 " ... " 6 " ... "
eval SELECT $column_list FROM callback_events
WHERE callback = 'register_notification(bad_cb)'
ORDER BY callback, resource_group, user LIMIT 1;
--echo
--echo SELECT * FROM test.callback_events WHERE callback = "register_notification(nullptr)";
--replace_column 4 " ... " 5 " ... " 6 " ... "
eval SELECT $column_list FROM callback_events
WHERE callback = 'register_notification(nullptr)'
ORDER BY callback, resource_group, user LIMIT 1;
--echo
--echo SELECT * FROM test.callback_events WHERE callback = "unregister_notification(bad_handle)";
--replace_column 4 " ... " 5 " ... " 6 " ... "
eval SELECT $column_list FROM callback_events
WHERE callback = 'unregister_notification(bad_handle)'
ORDER BY callback, resource_group, user LIMIT 1;
--enable_query_log
--echo
--echo ## Clean up
--echo
DROP USER PFS_MTR_MODE_ENABLE;
DROP USER PFS_MTR_MODE_DISABLE;
DROP USER PFS_MTR_REGISTER_INTERNAL;
DROP USER PFS_MTR_UNREGISTER_INTERNAL;
DROP USER PFS_MTR_NEGATIVE_TEST_CASES;
DROP USER PFS_USER1;
DROP USER PFS_USER2;
DROP USER PFS_USER3;
DROP TABLE test.callback_events;
remove_file $MYSQLD_DATADIR/test_pfs_notification.log;
SET DEBUG='-d,disable_rg_pfs_notifications';
--enable_ps_protocol
|