Skip to content

Commit c56d745

Browse files
committed
wsrep_notify: only probe the root credentials when the server is initialized
When a mysql server starts with galera enabled, the galera library performs actions before the InnoDB engine is fully initialized and the server is ready to process SQL commands. Until then, no script should probe the mysql server. Ensure that mysql_wsrep_notify does not probe root credentials before it knows the server mysql server is fully initialized, i.e. when the script knows that the local node is synced (primary partition). In addition, to prevent other scripts from getting stalled while probling the mysql server (e.g. when a remote node cannot be reached), add a timeout period in the credential check logic. Jira: OSPRH-14916
1 parent e669472 commit c56d745

File tree

2 files changed

+27
-15
lines changed

2 files changed

+27
-15
lines changed

templates/galera/bin/mysql_root_auth.sh

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ GALERA_INSTANCE="{{.galeraInstanceName}}"
1717
MY_CNF="$HOME/.my.cnf"
1818
MYSQL_SOCKET=/var/lib/mysql/mysql.sock
1919

20+
CREDENTIALS_CHECK_TIMEOUT=4
21+
2022
# Set up connection parameters based on whether we're connecting remotely or locally
2123
if [ -n "${MYSQL_REMOTE_HOST}" ]; then
2224

@@ -45,22 +47,27 @@ if [ -f "${MY_CNF}" ]; then
4547
SHOULD_VALIDATE=true
4648
fi
4749

48-
if [ "${SHOULD_VALIDATE}" = "true" ] && mysql ${MYSQL_CONN_PARAMS} -uroot -p"${PASSWORD}" -e "SELECT 1;" >/dev/null 2>&1; then
49-
# Credentials are still valid, use cached values
50+
credentials_check=1
51+
if [ "${SHOULD_VALIDATE}" = "true" ]; then
52+
timeout ${CREDENTIALS_CHECK_TIMEOUT} mysql ${MYSQL_CONN_PARAMS} -uroot -p"${PASSWORD}" -e "SELECT 1;" >/dev/null 2>&1
53+
credentials_check=$?
54+
fi
5055

51-
MYSQL_PWD="${PASSWORD}"
52-
DB_ROOT_PASSWORD="${PASSWORD}"
53-
export MYSQL_PWD
54-
export DB_ROOT_PASSWORD
55-
return 0 2>/dev/null || exit 0
56+
if [ "${SHOULD_VALIDATE}" = "true" ] && [ $credentials_check -eq 124 ]; then
57+
# MySQL validation timed out, assume cache is valid and will be validated on next probe
58+
export MYSQL_PWD="${PASSWORD}"
59+
export DB_ROOT_PASSWORD="${PASSWORD}"
60+
return 0
61+
elif [ "${SHOULD_VALIDATE}" = "true" ] && [ $credentials_check -eq 0 ]; then
62+
# Credentials are still valid, use cached values
63+
export MYSQL_PWD="${PASSWORD}"
64+
export DB_ROOT_PASSWORD="${PASSWORD}"
65+
return 0
5666
elif [ "${USE_SOCKET}" = "true" ] && [ ! -S "${MYSQL_SOCKET}" ]; then
5767
# MySQL not running locally, assume cache is valid and will be validated on next probe
58-
59-
MYSQL_PWD="${PASSWORD}"
60-
DB_ROOT_PASSWORD="${PASSWORD}"
61-
export MYSQL_PWD
62-
export DB_ROOT_PASSWORD
63-
return 0 2>/dev/null || exit 0
68+
export MYSQL_PWD="${PASSWORD}"
69+
export DB_ROOT_PASSWORD="${PASSWORD}"
70+
return 0
6471
fi
6572
fi
6673
# If we get here, credentials are invalid, fall through to refresh

templates/galera/bin/mysql_wsrep_notify.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#!/bin/bash
22

3-
source /var/lib/operator-scripts/mysql_root_auth.sh
4-
53
# NOTE(dciabrin) we might use downward API to populate those in the future
64
PODNAME=$HOSTNAME
75
SERVICE=${PODNAME/-galera-[0-9]*/}
@@ -293,6 +291,9 @@ fi
293291

294292
# Contition: ask for a failover. This should be called when mysql is running
295293
if echo "${STATUS}" | grep -i -q -e 'failover'; then
294+
# note: make sure that the root credentials are up to date
295+
# before invoking any mysql command
296+
source /var/lib/operator-scripts/mysql_root_auth.sh
296297
mysql_probe_state
297298
if [ $? != 0 ]; then
298299
log_error "Could not probe missing mysql information. Aborting"
@@ -312,6 +313,10 @@ if echo "${STATUS}" | grep -i -q -v -e 'synced'; then
312313
fi
313314

314315
# At this point mysql is started, query missing arguments
316+
317+
# note: make sure that the root credentials are up to date
318+
# before invoking any mysql command
319+
source /var/lib/operator-scripts/mysql_root_auth.sh
315320
mysql_probe_state
316321
if [ $? != 0 ]; then
317322
log_error "Could not probe missing mysql information. Aborting"

0 commit comments

Comments
 (0)