| 1 |
--echo |
| 2 |
--echo ## Test the Performance Schema Notification service WL#8881 |
| 3 |
--echo ## |
| 4 |
--echo ## 1. Install component to register callbacks for each API |
| 5 |
--echo ## 2. Launch multiple sessions to trigger callback events, log the events to file |
| 6 |
--echo ## 3. Import log file into a table |
| 7 |
--echo ## 4. Verify the contents of the table |
| 8 |
|
| 9 |
--source include/have_debug.inc |
| 10 |
|
| 11 |
--disable_ps_protocol |
| 12 |
|
| 13 |
--echo ## Disable resource groups for this test. |
| 14 |
SET DEBUG='+d, disable_rg_pfs_notifications'; |
| 15 |
|
| 16 |
--echo |
| 17 |
--echo ## Install test component |
| 18 |
INSTALL COMPONENT "file://component_test_pfs_notification"; |
| 19 |
|
| 20 |
--echo |
| 21 |
--echo ## Create 2 users to control the test mode, and 3 users for testing |
| 22 |
CREATE USER PFS_MTR_MODE_ENABLE; |
| 23 |
CREATE USER PFS_MTR_MODE_DISABLE; |
| 24 |
CREATE USER PFS_MTR_REGISTER_INTERNAL; |
| 25 |
CREATE USER PFS_MTR_UNREGISTER_INTERNAL; |
| 26 |
CREATE USER PFS_MTR_NEGATIVE_TEST_CASES; |
| 27 |
CREATE USER PFS_USER1; |
| 28 |
CREATE USER PFS_USER2; |
| 29 |
CREATE USER PFS_USER3; |
| 30 |
GRANT ALL ON *.* TO PFS_MTR_MODE_ENABLE; |
| 31 |
GRANT ALL ON *.* TO PFS_MTR_MODE_DISABLE; |
| 32 |
GRANT ALL ON *.* TO PFS_MTR_REGISTER_INTERNAL; |
| 33 |
GRANT ALL ON *.* TO PFS_MTR_UNREGISTER_INTERNAL; |
| 34 |
GRANT ALL ON *.* TO PFS_MTR_NEGATIVE_TEST_CASES; |
| 35 |
GRANT ALL ON *.* TO PFS_USER1; |
| 36 |
GRANT ALL ON *.* TO PFS_USER2; |
| 37 |
GRANT ALL ON *.* TO PFS_USER3; |
| 38 |
|
| 39 |
# The test component has two modes: MTR and RQG. |
| 40 |
# The MTR mode verifies the correct operation of the Notification API, and is |
| 41 |
# intended for MTR use only. In this mode, the test component registers 3 |
| 42 |
# callback functions for each of the five events that change the resource group |
| 43 |
# name multiple times per connection and write status messages to both stderr |
| 44 |
# and an external log file. The MTR mode uses the log file to capture and verify |
| 45 |
# results. |
| 46 |
# |
| 47 |
# The RQG mode is intended for RQG and performance runs with many concurrent |
| 48 |
# connections. This mode stresses the callback registry and provides an |
| 49 |
# empirical assessment of performance overhead by registering three lightweight |
| 50 |
# callbacks per event. The resource group name is set only once per connection |
| 51 |
# in order to provide verifiable evidence of its operation. |
| 52 |
# |
| 53 |
# The RQG mode does not write to stderr or to external log files. |
| 54 |
# |
| 55 |
# Until system variables for server components is supported (WL#9424), the test |
| 56 |
# mode is controlled by the client username. The test component defaults to RQG |
| 57 |
# mode, and MTR mode is activated when a client connects with the username |
| 58 |
# PFS_MTR_MODE_ENABLE. |
| 59 |
|
| 60 |
--echo |
| 61 |
--echo ## Enable MTR mode by connecting with a pre-defined username. |
| 62 |
--echo |
| 63 |
connect (con_pfs, localhost, PFS_MTR_MODE_ENABLE, , test); |
| 64 |
|
| 65 |
--echo |
| 66 |
--echo ## Test internal registration |
| 67 |
--echo |
| 68 |
connect (con_reg, localhost, PFS_MTR_REGISTER_INTERNAL, , test); |
| 69 |
|
| 70 |
--echo |
| 71 |
--echo ## Test negative test cases |
| 72 |
--echo |
| 73 |
connect (con_neg, localhost, PFS_MTR_NEGATIVE_TEST_CASES, , test); |
| 74 |
|
| 75 |
--echo |
| 76 |
--echo ## Test unregister internal |
| 77 |
--echo |
| 78 |
connect (con_unreg, localhost, PFS_MTR_UNREGISTER_INTERNAL, , test); |
| 79 |
|
| 80 |
--echo |
| 81 |
--echo ## Clean up special test cases |
| 82 |
--echo ## Disconnect internal registration user |
| 83 |
--connection con_reg |
| 84 |
--disconnect con_reg |
| 85 |
--source include/wait_until_disconnected.inc |
| 86 |
--echo ## Disconnect internal unregistration user |
| 87 |
--connection con_unreg |
| 88 |
--disconnect con_unreg |
| 89 |
--source include/wait_until_disconnected.inc |
| 90 |
--echo ## Disconnect negative test case user |
| 91 |
--connection con_neg |
| 92 |
--disconnect con_neg |
| 93 |
--source include/wait_until_disconnected.inc |
| 94 |
|
| 95 |
--echo |
| 96 |
--echo ## Start 2 sessions to generate thread_create and session_connect events. |
| 97 |
--echo ## The session_connect callback assigns a resource group name for each user. |
| 98 |
--echo |
| 99 |
--echo ## Session 1 |
| 100 |
connect (con1, localhost, PFS_USER1, , test); |
| 101 |
|
| 102 |
--echo |
| 103 |
--echo ## Verify PFS_USER1 resource group in PERFORMANCE_SCHEMA.THREADS |
| 104 |
SELECT name, type, processlist_user, processlist_host, processlist_db, resource_group |
| 105 |
FROM performance_schema.threads |
| 106 |
WHERE resource_group = 'RESOURCE_GROUP_3_2_1' AND processlist_user = 'PFS_USER1'; |
| 107 |
|
| 108 |
--echo |
| 109 |
--echo ## Start session 2 |
| 110 |
--echo connect (con2, localhost, PFS_USER2, , test) |
| 111 |
connect (con2, localhost, PFS_USER2, , test); |
| 112 |
|
| 113 |
--echo |
| 114 |
--echo ## Verify PFS_USER2 in PERFORMANCE_SCHEMA.THREADS |
| 115 |
SELECT name, type, processlist_user, processlist_host, processlist_db, resource_group |
| 116 |
FROM performance_schema.threads |
| 117 |
WHERE resource_group = 'RESOURCE_GROUP_3_2_1' AND processlist_user = 'PFS_USER2'; |
| 118 |
|
| 119 |
--echo |
| 120 |
--echo ## Change user from PFS_USER2 to PFS_USER3 |
| 121 |
--change_user PFS_USER3,,test |
| 122 |
|
| 123 |
--echo |
| 124 |
--echo ## Disconnect 2 sessions to generate session_disconnect and thread_destroy events. |
| 125 |
--echo |
| 126 |
--echo ## Disconnect session 1 |
| 127 |
--connection con1 |
| 128 |
--disconnect con1 |
| 129 |
--source include/wait_until_disconnected.inc |
| 130 |
|
| 131 |
--echo ## Disconnect session 2 |
| 132 |
--connection con2 |
| 133 |
--disconnect con2 |
| 134 |
--source include/wait_until_disconnected.inc |
| 135 |
|
| 136 |
--echo ## Disconnect primary control session |
| 137 |
--connection con_pfs |
| 138 |
--disconnect con_pfs |
| 139 |
--source include/wait_until_disconnected.inc |
| 140 |
|
| 141 |
--echo |
| 142 |
--echo ## Disable MTR mode and activate RQG mode by connecting with a pre-defined username. |
| 143 |
--echo |
| 144 |
connect (con_pfs1, localhost, PFS_MTR_MODE_DISABLE, , test); |
| 145 |
|
| 146 |
--echo ## Verify mode change |
| 147 |
--echo |
| 148 |
SELECT name, type, processlist_user, processlist_host, processlist_db, resource_group |
| 149 |
FROM performance_schema.threads WHERE processlist_user = 'PFS_MTR_MODE_DISABLE'; |
| 150 |
|
| 151 |
--echo ## Disconnect second control session |
| 152 |
--connection con_pfs1 |
| 153 |
--disconnect con_pfs1 |
| 154 |
--source include/wait_until_disconnected.inc |
| 155 |
|
| 156 |
connection default; |
| 157 |
|
| 158 |
--echo |
| 159 |
--echo ## Uninstall component |
| 160 |
--echo |
| 161 |
UNINSTALL COMPONENT 'file://component_test_pfs_notification'; |
| 162 |
let $wait_condition=SELECT count(*)=0 FROM mysql.component WHERE component_urn like '%component_test_pfs_notification'; |
| 163 |
--source include/wait_condition.inc |
| 164 |
|
| 165 |
--echo |
| 166 |
--echo ## Create results table |
| 167 |
--echo |
| 168 |
CREATE TABLE test.callback_events (callback TEXT, handle INT, ret_code INT, |
| 169 |
thread_id BIGINT UNSIGNED, plist_id BIGINT UNSIGNED, os_thread BIGINT UNSIGNED, |
| 170 |
resource_group TEXT, user TEXT, host TEXT, vcpu TEXT, priority TEXT); |
| 171 |
|
| 172 |
--echo |
| 173 |
--echo ## Import log file |
| 174 |
--echo |
| 175 |
let $MYSQLD_DATADIR= `select @@datadir`; |
| 176 |
#cat_file $MYSQLD_DATADIR/test_pfs_notification.log; |
| 177 |
--replace_result $MYSQLD_DATADIR MYSQLD_DATADIR |
| 178 |
--disable_warnings |
| 179 |
eval |
| 180 |
LOAD DATA LOCAL INFILE '$MYSQLD_DATADIR/test_pfs_notification.log' INTO TABLE test.callback_events |
| 181 |
FIELDS TERMINATED BY ' ' LINES TERMINATED BY '\n' STARTING BY '*** ' |
| 182 |
(@label, callback, @label, handle, @label, ret_code, @label, thread_id, @label, plist_id, |
| 183 |
@label, os_thread, @label, resource_group, @label, user, @label, host, @label, vcpu, @label, priority); |
| 184 |
|
| 185 |
--echo |
| 186 |
--echo ## Verify results |
| 187 |
--echo |
| 188 |
--enable_warnings |
| 189 |
|
| 190 |
let $column_list = |
| 191 |
rpad(callback, 35, ' ') as "callback ", |
| 192 |
rpad(handle, 10, ' ') as "handle ", |
| 193 |
rpad(ret_code, 10, ' ') as "ret_code ", |
| 194 |
rpad(thread_id, 10, ' ') as "thread_id ", |
| 195 |
rpad(plist_id, 10, ' ') as "plist_id ", |
| 196 |
rpad(os_thread, 10, ' ') as "os_thread ", |
| 197 |
rpad(resource_group, 20, ' ') as "resource_group ", |
| 198 |
rpad(user, 30, ' ') as "user ", |
| 199 |
rpad(host, 10, ' ') as "host "; |
| 200 |
|
| 201 |
--echo SELECT * FROM test.callback_events WHERE callback = "session_change_user"; |
| 202 |
--replace_column 2 " ... " 4 " ... " 5 " ... " 6 " ... " |
| 203 |
--disable_query_log |
| 204 |
eval SELECT $column_list FROM callback_events |
| 205 |
WHERE callback = 'session_change_user' AND resource_group = 'RESOURCE_GROUP_3_2_1' |
| 206 |
ORDER BY callback, resource_group, user LIMIT 1; |
| 207 |
|
| 208 |
# Each session connect callback changes the group name e.g. RESOURCE_GROUP_1, |
| 209 |
# RESOURCE_GROUP_2, ..., etc. However, callbacks are invoked in reverse order of |
| 210 |
# registration, so on disconnect each session should be RESOURCE_GROUP_1. |
| 211 |
|
| 212 |
--echo |
| 213 |
--echo SELECT * FROM test.callback_events WHERE callback = "session_connect; |
| 214 |
--replace_column 2 " ... " 4 " ... " 5 " ... " 6 " ... " |
| 215 |
eval SELECT $column_list FROM callback_events |
| 216 |
WHERE callback = 'session_connect' AND resource_group = 'RESOURCE_GROUP_3_2_1' |
| 217 |
ORDER BY callback, resource_group, user LIMIT 1; |
| 218 |
|
| 219 |
--echo |
| 220 |
--echo SELECT * FROM test.callback_events WHERE callback = "session_disconnect"; |
| 221 |
--replace_column 2 " ... " 4 " ... " 5 " ... " 6 " ... " |
| 222 |
eval SELECT $column_list FROM callback_events |
| 223 |
WHERE callback = 'session_disconnect' AND resource_group = 'RESOURCE_GROUP_3_2_1' |
| 224 |
ORDER BY callback, resource_group, user LIMIT 1; |
| 225 |
|
| 226 |
--echo |
| 227 |
--echo SELECT * FROM test.callback_events WHERE callback = "thread_create"; |
| 228 |
--replace_column 2 " ... " 4 " ... " 5 " ... " 6 " ... " |
| 229 |
eval SELECT $column_list FROM callback_events |
| 230 |
WHERE callback = 'thread_create' AND resource_group = 'RESOURCE_GROUP_3_2_1' |
| 231 |
ORDER BY callback, resource_group, user LIMIT 1; |
| 232 |
|
| 233 |
--echo |
| 234 |
--echo SELECT * FROM test.callback_events WHERE callback = "thread_destroy"; |
| 235 |
--replace_column 2 " ... " 4 " ... " 5 " ... " 6 " ... " |
| 236 |
eval SELECT $column_list FROM callback_events |
| 237 |
WHERE callback = 'thread_destroy' AND resource_group = 'RESOURCE_GROUP_3_2_1' |
| 238 |
ORDER BY callback, resource_group, user LIMIT 1; |
| 239 |
|
| 240 |
--echo |
| 241 |
--echo SELECT * FROM test.callback_events WHERE callback = "register_notification_internal"; |
| 242 |
--replace_column 3 " ... " 4 " ... " 5 " ... " 6 " ... " |
| 243 |
eval SELECT $column_list FROM callback_events |
| 244 |
WHERE callback = 'register_notification_internal' |
| 245 |
ORDER BY callback, resource_group, user LIMIT 1; |
| 246 |
|
| 247 |
--echo |
| 248 |
--echo SELECT * FROM test.callback_events WHERE callback LIKE "unregister_notification_internal"; |
| 249 |
--replace_column 4 " ... " 5 " ... " 6 " ... " |
| 250 |
eval SELECT $column_list FROM callback_events |
| 251 |
WHERE callback LIKE 'unregister_notification_internal' |
| 252 |
ORDER BY callback, resource_group, user LIMIT 1; |
| 253 |
|
| 254 |
--echo |
| 255 |
--echo SELECT * FROM test.callback_events WHERE callback = "register_notification(bad_cb)"; |
| 256 |
--replace_column 4 " ... " 5 " ... " 6 " ... " |
| 257 |
eval SELECT $column_list FROM callback_events |
| 258 |
WHERE callback = 'register_notification(bad_cb)' |
| 259 |
ORDER BY callback, resource_group, user LIMIT 1; |
| 260 |
|
| 261 |
--echo |
| 262 |
--echo SELECT * FROM test.callback_events WHERE callback = "register_notification(nullptr)"; |
| 263 |
--replace_column 4 " ... " 5 " ... " 6 " ... " |
| 264 |
eval SELECT $column_list FROM callback_events |
| 265 |
WHERE callback = 'register_notification(nullptr)' |
| 266 |
ORDER BY callback, resource_group, user LIMIT 1; |
| 267 |
|
| 268 |
--echo |
| 269 |
--echo SELECT * FROM test.callback_events WHERE callback = "unregister_notification(bad_handle)"; |
| 270 |
--replace_column 4 " ... " 5 " ... " 6 " ... " |
| 271 |
eval SELECT $column_list FROM callback_events |
| 272 |
WHERE callback = 'unregister_notification(bad_handle)' |
| 273 |
ORDER BY callback, resource_group, user LIMIT 1; |
| 274 |
|
| 275 |
--enable_query_log |
| 276 |
|
| 277 |
--echo |
| 278 |
--echo ## Clean up |
| 279 |
--echo |
| 280 |
DROP USER PFS_MTR_MODE_ENABLE; |
| 281 |
DROP USER PFS_MTR_MODE_DISABLE; |
| 282 |
DROP USER PFS_MTR_REGISTER_INTERNAL; |
| 283 |
DROP USER PFS_MTR_UNREGISTER_INTERNAL; |
| 284 |
DROP USER PFS_MTR_NEGATIVE_TEST_CASES; |
| 285 |
DROP USER PFS_USER1; |
| 286 |
DROP USER PFS_USER2; |
| 287 |
DROP USER PFS_USER3; |
| 288 |
DROP TABLE test.callback_events; |
| 289 |
|
| 290 |
remove_file $MYSQLD_DATADIR/test_pfs_notification.log; |
| 291 |
SET DEBUG='-d,disable_rg_pfs_notifications'; |
| 292 |
--enable_ps_protocol |