Skip to content

Commit 9e8e82c

Browse files
committed
MDEV-25669: SST scripts should check all server groups in config files
1) This commit implements reading all sections from configuration files while looking for the current value of any server variable, which were previously only read from the [mysqld.suffix] group and from [mysqld], but not from other groups such as [mariadb.suffix], [mariadb] or, for example, [server]. 2) This commit also fixes misrecognition of some parameters when parsing a command line containing a special marker for the end of the list of options ("--") or when short option names (such as "-s", "-a" and "-h arg") chained together (like a "-sah arg"). Such parameters can be passed to the SST script in the list of arguments after "--mysqld-args" if the server is started with a complex set of options - this was revealed during manual testing of changes to read configuration files. 3) The server-side preparation code for the "--mysqld-args" option list has also been simplified to make it easier to change in the future (if needed), and has been improved to properly handle the special backquote ("`") character in the argument values.
1 parent 69feb04 commit 9e8e82c

File tree

4 files changed

+201
-191
lines changed

4 files changed

+201
-191
lines changed

scripts/wsrep_sst_common.sh

100644100755
Lines changed: 109 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -240,44 +240,108 @@ case "$1" in
240240
original_cmd=""
241241
shift
242242
while [ $# -gt 0 ]; do
243-
# check if the argument is the short option
244-
# (starting with "-" instead of "--"):
245-
if [ "${1#--}" = "$1" -a "${1#-}" != "$1" ]; then
246-
option="${1#-}"
247-
value=""
248-
# check that the option value follows the name,
249-
# without a space:
250-
if [ ${#option} -gt 1 ]; then
251-
# let's separate the first character as the option name,
252-
# and the subsequent characters consider its value:
253-
value="${1#-?}"
254-
option="${1%$value}"
255-
# check that the option name consists of one letter
256-
# and there are the following arguments:
257-
elif [ ${#option} -eq 1 -a $# -gt 1 ]; then
258-
# if the next argument does not start with a "-" character,
259-
# then this is the value of the current option:
260-
if [ "${2#-}" = "$2" ]; then
261-
value="$2"
243+
lname="${1#--}"
244+
# "--" is interpreted as the end of the list of options:
245+
if [ -z "$lname" ]; then
246+
shift
247+
if [ $# -gt 0 ]; then
248+
# copy "--" to the output string:
249+
original_cmd="$original_cmd --"
250+
# All other arguments must be copied unchanged:
251+
while [ $# -gt 0 ]; do
252+
original_cmd="$original_cmd '$1'"
262253
shift
263-
fi
254+
done
264255
fi
265-
shift
266-
if [ "$option" = 'h' ]; then
267-
if [ -z "$WSREP_SST_OPT_DATA" ]; then
268-
MYSQLD_OPT_DATADIR="${value%/}"
269-
fi
270-
elif [ "$option" != 'u' -a \
271-
"$option" != 'P' ]; then
272-
if [ -z "$original_cmd" ]; then
273-
original_cmd="'-$option$value'"
274-
else
275-
original_cmd="$original_cmd '-$option$value'"
256+
break;
257+
fi
258+
# Make sure the argument does not start with "--", otherwise it
259+
# is a long option, which is processed after this "if":
260+
if [ "$lname" = "$1" ]; then
261+
# Check if the argument is the short option or the short
262+
# options list, starting with "-":
263+
options="${1#-}"
264+
if [ "$options" != "$1" -a -n "$options" ]; then
265+
slist=""
266+
while [ -n "$options" ]; do
267+
# Let's separate the first character as the current
268+
# option name:
269+
if [ -n "$BASH_VERSION" ]; then
270+
option="${options:0:1}"
271+
else
272+
# If it's not bash, then we need to use slow
273+
# external utilities:
274+
option=$(echo "$options" | cut -c1-1)
275+
fi
276+
# And the subsequent characters consider option value:
277+
value=""
278+
if [ ${#options} -gt 0 ]; then
279+
value="${options#?}"
280+
fi
281+
# Check for options without argument:
282+
if [ "$option" != '?' -a \
283+
"$option" != 'a' -a \
284+
"$option" != 's' -a \
285+
"$option" != 'v' ]
286+
then
287+
# If the option value is absent, then check
288+
# the following argument:
289+
if [ -z "$value" -a $# -gt 1 ]; then
290+
# if the next argument does not start with
291+
# the "-" character, then next argument is
292+
# the current option value:
293+
if [ "${2#-}" = "$2" ]; then
294+
shift
295+
value="$1"
296+
fi
297+
fi
298+
if [ $option == 'h' ]; then
299+
if [ -z "$WSREP_SST_OPT_DATA" ]; then
300+
MYSQLD_OPT_DATADIR="${value%/}"
301+
fi
302+
elif [ $option != 'u' -a \
303+
$option != 'P' ]
304+
then
305+
if [ -z "$value" ]; then
306+
slist="$slist$option"
307+
elif [ -z "$slist" ]; then
308+
slist="$option '$value'"
309+
else
310+
slist="$slist -$option '$value'"
311+
fi
312+
fi
313+
break
314+
315+
else
316+
slist="$slist$option"
317+
fi
318+
options="$value"
319+
done
320+
if [ -n "$slist" ]; then
321+
original_cmd="$original_cmd -$slist"
276322
fi
323+
elif [ -z "$options" ]; then
324+
# We found an equal sign without any characters after it:
325+
original_cmd="$original_cmd -"
326+
else
327+
# We found a value that does not start with a minus -
328+
# it is a positional argument or the value of previous
329+
# option. Copy it to output string (as is):
330+
original_cmd="$original_cmd '$1'"
277331
fi
332+
shift
278333
continue;
279334
fi
335+
# Now we are sure that we are working with an option
336+
# that has a "long" name, so remove all characters after
337+
# the first equal sign:
280338
option="${1%%=*}"
339+
# The "--loose-" prefix should not affect the recognition
340+
# of the option name:
341+
if [ "${option#--loose-}" != "$option" ]; then
342+
option="--${option#--loose-}"
343+
fi
344+
# Some options just need to be removed from the list:
281345
if [ "$option" != '--defaults-file' -a \
282346
"$option" != '--defaults-extra-file' -a \
283347
"$option" != '--defaults-group-suffix' -a \
@@ -340,22 +404,17 @@ case "$1" in
340404
;;
341405
esac
342406
if [ $skip_mysqld_arg -eq 0 ]; then
343-
if [ -z "$original_cmd" ]; then
344-
original_cmd="'$1'"
345-
else
346-
original_cmd="$original_cmd '$1'"
347-
fi
407+
original_cmd="$original_cmd '$1'"
348408
fi
349-
fi
350-
shift
409+
fi
410+
shift
351411
done
352-
WSREP_SST_OPT_MYSQLD="$original_cmd"
412+
WSREP_SST_OPT_MYSQLD="${original_cmd# *}"
353413
break
354414
;;
355-
*) # must be command
356-
# usage
357-
# exit 1
358-
;;
415+
*) # Must be command usage
416+
# exit 1
417+
;;
359418
esac
360419
shift
361420
done
@@ -601,9 +660,9 @@ parse_cnf()
601660
# of the groups list (as if it were a prefix):
602661
groups="${groups#$group}"
603662
groups="${groups#\|}"
604-
# if the group name is the same as the "[--]mysqld", then
605-
# try to use it together with the group suffix:
606-
if [ "${group#--}" = 'mysqld' -a -n "$WSREP_SST_OPT_SUFFIX_VALUE" ]; then
663+
# If the group name is the same as the "mysqld" without "--" prefix,
664+
# then try to use it together with the group suffix:
665+
if [ "$group" = 'mysqld' -a -n "$WSREP_SST_OPT_SUFFIX_VALUE" ]; then
607666
reval=$($MY_PRINT_DEFAULTS "mysqld$WSREP_SST_OPT_SUFFIX_VALUE" | awk "$pattern")
608667
if [ -n "$reval" ]; then
609668
break
@@ -616,7 +675,7 @@ parse_cnf()
616675
fi
617676
done
618677

619-
# use default if we haven't found a value:
678+
# Use default if we haven't found a value:
620679
if [ -z "$reval" ]; then
621680
[ -n "${3:-}" ] && reval="$3"
622681
fi
@@ -648,9 +707,9 @@ in_config()
648707
# of the groups list (as if it were a prefix):
649708
groups="${groups#$group}"
650709
groups="${groups#\|}"
651-
# if the group name is the same as the "[--]mysqld", then
652-
# try to use it together with the group suffix:
653-
if [ "${group#--}" = 'mysqld' -a -n "$WSREP_SST_OPT_SUFFIX_VALUE" ]; then
710+
# If the group name is the same as the "mysqld" without "--" prefix,
711+
# then try to use it together with the group suffix:
712+
if [ "$group" = 'mysqld' -a -n "$WSREP_SST_OPT_SUFFIX_VALUE" ]; then
654713
found=$($MY_PRINT_DEFAULTS "mysqld$WSREP_SST_OPT_SUFFIX_VALUE" | awk "$pattern")
655714
if [ $found -ne 0 ]; then
656715
break

scripts/wsrep_sst_mariabackup.sh

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,6 @@ read_cnf()
404404
# avoid CA verification if not set explicitly:
405405
# nodes may happen to have different CA if self-generated
406406
# zeroing up tcert does the trick
407-
local mode=$(parse_cnf 'sst' 'ssl-mode')
408407
[ "${tmode#VERIFY}" != "$tmode" ] || tcert=""
409408
fi
410409
fi
@@ -421,8 +420,9 @@ read_cnf()
421420
sockopt=$(parse_cnf sst sockopt "")
422421
progress=$(parse_cnf sst progress "")
423422
ttime=$(parse_cnf sst time 0)
424-
cpat=$(parse_cnf sst cpat '.*galera\.cache$\|.*sst_in_progress$\|.*\.sst$\|.*gvwstate\.dat$\|.*grastate\.dat$\|.*\.err$\|.*\.log$\|.*RPM_UPGRADE_MARKER$\|.*RPM_UPGRADE_HISTORY$')
425-
[ $OS = 'FreeBSD' ] && cpat=$(parse_cnf sst cpat '.*galera\.cache$|.*sst_in_progress$|.*\.sst$|.*gvwstate\.dat$|.*grastate\.dat$|.*\.err$|.*\.log$|.*RPM_UPGRADE_MARKER$|.*RPM_UPGRADE_HISTORY$')
423+
cpat='.*galera\.cache$\|.*sst_in_progress$\|.*\.sst$\|.*gvwstate\.dat$\|.*grastate\.dat$\|.*\.err$\|.*\.log$\|.*RPM_UPGRADE_MARKER$\|.*RPM_UPGRADE_HISTORY$'
424+
[ "$OS" = 'FreeBSD' ] && cpat=$(echo "$cpat" | sed 's/\\|/|/g')
425+
cpat=$(parse_cnf sst cpat "$cpat")
426426
scomp=$(parse_cnf sst compressor "")
427427
sdecomp=$(parse_cnf sst decompressor "")
428428

@@ -445,9 +445,7 @@ read_cnf()
445445
fi
446446

447447
if [ $ssyslog -ne -1 ]; then
448-
if $MY_PRINT_DEFAULTS mysqld_safe | grep -q -- "--syslog"; then
449-
ssyslog=1
450-
fi
448+
ssyslog=$(in_config 'mysqld_safe' 'syslog')
451449
fi
452450
}
453451

@@ -771,7 +769,7 @@ monitor_process()
771769

772770
while true ; do
773771
if ! ps -p "$WSREP_SST_OPT_PARENT" &>/dev/null; then
774-
wsrep_log_error "Parent mysqld process (PID:${WSREP_SST_OPT_PARENT}) terminated unexpectedly."
772+
wsrep_log_error "Parent mysqld process (PID: $WSREP_SST_OPT_PARENT) terminated unexpectedly."
775773
exit 32
776774
fi
777775
if ! ps -p "$sst_stream_pid" &>/dev/null; then
@@ -1139,7 +1137,7 @@ then
11391137

11401138
if ! ps -p "$WSREP_SST_OPT_PARENT" &>/dev/null
11411139
then
1142-
wsrep_log_error "Parent mysqld process (PID:${WSREP_SST_OPT_PARENT}) terminated unexpectedly."
1140+
wsrep_log_error "Parent mysqld process (PID: $WSREP_SST_OPT_PARENT) terminated unexpectedly."
11431141
exit 32
11441142
fi
11451143

scripts/wsrep_sst_rsync.sh

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -218,23 +218,21 @@ SSTKEY=$(parse_cnf 'sst' 'tkey')
218218
SSTCERT=$(parse_cnf 'sst' 'tcert')
219219
SSTCA=$(parse_cnf 'sst' 'tca')
220220

221+
SST_SECTIONS="--mysqld|sst"
222+
221223
check_server_ssl_config()
222224
{
223-
local section="$1"
224-
SSTKEY=$(parse_cnf "$section" 'ssl-key')
225-
SSTCERT=$(parse_cnf "$section" 'ssl-cert')
226-
SSTCA=$(parse_cnf "$section" 'ssl-ca')
225+
SSTKEY=$(parse_cnf "$SST_SECTIONS" 'ssl-key')
226+
SSTCERT=$(parse_cnf "$SST_SECTIONS" 'ssl-cert')
227+
SSTCA=$(parse_cnf "$SST_SECTIONS" 'ssl-ca')
227228
}
228229

229-
SSLMODE=$(parse_cnf 'sst' 'ssl-mode' | tr [:lower:] [:upper:])
230+
SSLMODE=$(parse_cnf "$SST_SECTIONS" 'ssl-mode' | tr [:lower:] [:upper:])
230231

232+
# no old-style SSL config in [sst], check for new one:
231233
if [ -z "$SSTKEY" -a -z "$SSTCERT" -a -z "$SSTCA" ]
232234
then
233-
# no old-style SSL config in [sst], check for new one
234-
check_server_ssl_config 'sst'
235-
if [ -z "$SSTKEY" -a -z "$SSTCERT" -a -z "$SSTCA" ]; then
236-
check_server_ssl_config '--mysqld'
237-
fi
235+
check_server_ssl_config
238236
fi
239237

240238
if [ -z "$SSLMODE" ]; then
@@ -602,7 +600,7 @@ EOF
602600
if ! ps -p $MYSQLD_PID >/dev/null
603601
then
604602
wsrep_log_error \
605-
"Parent mysqld process (PID:$MYSQLD_PID) terminated unexpectedly."
603+
"Parent mysqld process (PID: $MYSQLD_PID) terminated unexpectedly."
606604
kill -- -$MYSQLD_PID
607605
sleep 1
608606
exit 32

0 commit comments

Comments
 (0)