-
Notifications
You must be signed in to change notification settings - Fork 481
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PS-9453: percona_telemetry causes a long wait on COND_thd_list due to…
… the absence of the root user https://perconadev.atlassian.net/browse/PS-9453 Problem: If there is no 'root' user (it was renamed) and Percona Telemetry is disabled, server shutdown stuck. Additionally SHOW PROCESSLIST reports increasing number of processes with root user in state 'login'. Cause: Percona Telemetry component used hard codded 'root' user used for querying the server for metrics. If the user is not present, mysql_command_factory service connect() method fails, however it leaves opened/orphaned internal MYSQL_SESSION. It is because after opening MYSQL_SESSION we check if the user exists. It doesn't exist, so the method returns with STATE_MACHINE_FAILED error. Caller does not know anything about underlying session, does cleanup, frees memory. Moreover, the same problem potentially exists even if the user exists, but cssm_begin_connect() exits with error for any reason. Creation of session registers THD object in Global_THD_manager. That's why increasing number of processes is visible in SHOW PROCESSLIST. Why it hangs during shutdown: During shutdown, the server waits for signal handler thread (signal_hand()) to join the main thread. Then the component infrastructure is deinitialized. At the same time signal_hand() waits for all threads to finish Global_THD_manager::wait_till_no_thd(). The above described bug related to orphaned mysql sessions cause that there are orphaned THDs that never end. This causes server to wait infinitively. Solution: 1. Handle the error in cssm_begin_connect() and close opened MYSQL_SESSION. This part fixes hangs caused by nonexistent user. 2. Percona Telemetry Component uses mysql.session user. When Percona Telemetry Component is enabled, the user is granted a few more permissions during the server startup. Note that even without this permissions, the component is able to work, but not able to report some metrics. Additionally fixed potential memory leak if connection setup in Percona Telemetry Component fails.
- Loading branch information
1 parent
a634d87
commit a7179a8
Showing
6 changed files
with
167 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
mysql-test/suite/component_percona_telemetry/r/no_user.result
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
SELECT * FROM information_schema.table_privileges WHERE grantee = "'mysql.session'@'localhost'" ORDER BY table_schema, table_name; | ||
GRANTEE TABLE_CATALOG TABLE_SCHEMA TABLE_NAME PRIVILEGE_TYPE IS_GRANTABLE | ||
'mysql.session'@'localhost' def mysql component SELECT NO | ||
'mysql.session'@'localhost' def mysql user SELECT NO | ||
'mysql.session'@'localhost' def performance_schema replication_group_members SELECT NO | ||
SHOW GRANTS FOR 'mysql.session'@'localhost'; | ||
Grants for mysql.session@localhost | ||
GRANT SHUTDOWN, SUPER, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO `mysql.session`@`localhost` | ||
GRANT AUDIT_ABORT_EXEMPT,AUTHENTICATION_POLICY_ADMIN,BACKUP_ADMIN,CLONE_ADMIN,CONNECTION_ADMIN,FIREWALL_EXEMPT,PERSIST_RO_VARIABLES_ADMIN,SESSION_VARIABLES_ADMIN,SYSTEM_USER,SYSTEM_VARIABLES_ADMIN ON *.* TO `mysql.session`@`localhost` | ||
GRANT SELECT ON `performance_schema`.* TO `mysql.session`@`localhost` | ||
GRANT SELECT ON `mysql`.`component` TO `mysql.session`@`localhost` | ||
GRANT SELECT ON `mysql`.`user` TO `mysql.session`@`localhost` | ||
GRANT SELECT ON `performance_schema`.`replication_group_members` TO `mysql.session`@`localhost` | ||
# restart:--percona_telemetry.grace_interval=30 --percona_telemetry.scrape_interval=30 --percona_telemetry.telemetry_root_dir=<telemetry_root_dir> | ||
RENAME USER 'root'@'localhost' to 'root.tmp'@'localhost'; | ||
Warnings: | ||
Warning 4005 User 'root'@'localhost' is referenced as a definer account in a stored routine. | ||
Warning 4005 User 'root'@'localhost' is referenced as a definer account in a trigger. | ||
'root' user used by component's 1st verison does not exist. Telemetry dir should contain 1 file. | ||
1 | ||
RENAME USER 'root.tmp'@'localhost' to 'root'@'localhost'; | ||
Warnings: | ||
Warning 4005 User 'root'@'localhost' is referenced as a definer account in a stored routine. | ||
Warning 4005 User 'root'@'localhost' is referenced as a definer account in a trigger. | ||
# restart:--percona_telemetry.grace_interval=30 --percona_telemetry.scrape_interval=30 --percona_telemetry.telemetry_root_dir=<telemetry_root_dir> | ||
RENAME USER 'mysql.session'@'localhost' to 'mysql.session.tmp'@'localhost'; | ||
include/assert.inc [No orphaned sessions expected in processlist] | ||
'mysql.session' user used by component does not exist. Telemetry dir should still contain 1 file. | ||
1 | ||
RENAME USER 'mysql.session.tmp'@'localhost' to 'mysql.session'@'localhost'; | ||
# restart:--percona_telemetry.grace_interval=30 --percona_telemetry.scrape_interval=30 --percona_telemetry.telemetry_root_dir=<telemetry_root_dir> |
70 changes: 70 additions & 0 deletions
70
mysql-test/suite/component_percona_telemetry/t/no_user.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Test that lack of the user used by Percona Telemetry Component | ||
# doesn't cause hangs during server restart and no orphaned sessions are created. | ||
|
||
--source include/have_percona_telemetry.inc | ||
|
||
--let $telemetry_root_dir = $MYSQL_TMP_DIR/telemetry_dir | ||
--let $grace_interval = 30 | ||
--let $scrape_interval = 30 | ||
|
||
--mkdir $telemetry_root_dir | ||
|
||
# Record mysql.session user privileges | ||
SELECT * FROM information_schema.table_privileges WHERE grantee = "'mysql.session'@'localhost'" ORDER BY table_schema, table_name; | ||
SHOW GRANTS FOR 'mysql.session'@'localhost'; | ||
|
||
# restart the server with custom telemetry file path and timeouts | ||
--let $restart_parameters = "restart:--percona_telemetry.grace_interval=$grace_interval --percona_telemetry.scrape_interval=$scrape_interval --percona_telemetry.telemetry_root_dir=$telemetry_root_dir" | ||
--replace_regex /telemetry_root_dir=.*telemetry_dir/telemetry_root_dir=<telemetry_root_dir>/ | ||
--source include/restart_mysqld.inc | ||
|
||
# Rename 'root' user (1st version of Percona Telemetry Component used 'root' user) | ||
# 1st version will not collect any data and will not create telemetry file and the restart will hang. | ||
# Fixed version will work properly as it doesn't use 'root' user. | ||
RENAME USER 'root'@'localhost' to 'root.tmp'@'localhost'; | ||
|
||
# sleep more than grace_interval and check that telemetry file was created | ||
--let $timeout = `select $grace_interval + 10` | ||
--sleep $timeout | ||
|
||
--echo 'root' user used by component's 1st verison does not exist. Telemetry dir should contain 1 file. | ||
--exec ls -1 $telemetry_root_dir | wc -l | ||
|
||
# | ||
# It should be possible to restart the server. | ||
# | ||
RENAME USER 'root.tmp'@'localhost' to 'root'@'localhost'; | ||
--let $restart_parameters = "restart:--percona_telemetry.grace_interval=$grace_interval --percona_telemetry.scrape_interval=$scrape_interval --percona_telemetry.telemetry_root_dir=$telemetry_root_dir" | ||
--replace_regex /telemetry_root_dir=.*telemetry_dir/telemetry_root_dir=<telemetry_root_dir>/ | ||
--source include/restart_mysqld.inc | ||
|
||
|
||
# | ||
# Now rename the user used by component | ||
# | ||
RENAME USER 'mysql.session'@'localhost' to 'mysql.session.tmp'@'localhost'; | ||
|
||
# Wait a few cycles and ensure that SHOW PROCESSLIST does not contain rows related to orphaned sessions. | ||
--let $timeout = `select $grace_interval + 3 * $scrape_interval` | ||
--sleep $timeout | ||
|
||
--let $assert_text = No orphaned sessions expected in processlist | ||
--let $assert_cond = [SELECT COUNT(*) as Result FROM performance_schema.processlist WHERE user = "mysql.session";, Result, 1] = 0 | ||
--source include/assert.inc | ||
|
||
# Hheck that no new telemetry file was created | ||
--echo 'mysql.session' user used by component does not exist. Telemetry dir should still contain 1 file. | ||
--exec ls -1 $telemetry_root_dir | wc -l | ||
|
||
|
||
# | ||
# It should be still possible to restart the server. | ||
# | ||
RENAME USER 'mysql.session.tmp'@'localhost' to 'mysql.session'@'localhost'; | ||
--let $restart_parameters = "restart:--percona_telemetry.grace_interval=$grace_interval --percona_telemetry.scrape_interval=$scrape_interval --percona_telemetry.telemetry_root_dir=$telemetry_root_dir" | ||
--replace_regex /telemetry_root_dir=.*telemetry_dir/telemetry_root_dir=<telemetry_root_dir>/ | ||
--source include/restart_mysqld.inc | ||
|
||
# cleanup | ||
--force-rmdir $telemetry_root_dir | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters