Skip to content

Commit fac9224

Browse files
committed
MDEV-27777: Some Galera tests fail on FreeBSD
This commit fixes problems due to bugs and quirks in bsdtar (the FreeBSD version of tar). Separate tests are not required, because without these fixes, many other tests fail when tested in the FreeBSD environment. Also, the grep patterns for reading utility version numbers has been made more robust. The notation of some options of the "cut" utility has been changed.
1 parent 17e0f52 commit fac9224

File tree

4 files changed

+47
-16
lines changed

4 files changed

+47
-16
lines changed

scripts/wsrep_sst_common.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ case "$1" in
336336
else
337337
# If it's not bash, then we need to use slow
338338
# external utilities:
339-
option=$(echo "$options" | cut -c1-1)
339+
option=$(echo "$options" | cut -c1)
340340
fi
341341
# And the subsequent characters consider option value:
342342
value=""

scripts/wsrep_sst_mariabackup.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,8 @@ get_transfer()
323323
if [ "${sockopt#*,dhparam=}" != "$sockopt" ]; then
324324
if [ -z "$ssl_dhparams" ]; then
325325
# Determine the socat version
326-
SOCAT_VERSION=$(socat -V 2>&1 | grep -m1 -oe '[0-9]\.[0-9][\.0-9]*')
326+
SOCAT_VERSION=$(socat -V 2>&1 | \
327+
grep -m1 -owE '[0-9]+(\.[0-9]+)+' | head -n1)
327328
if [ -z "$SOCAT_VERSION" ]; then
328329
wsrep_log_error "******** FATAL ERROR ******************"
329330
wsrep_log_error "* Cannot determine the socat version. *"
@@ -766,7 +767,7 @@ recv_joiner()
766767

767768
# check donor supplied secret
768769
SECRET=$(grep -F -- "$SECRET_TAG " "$MAGIC_FILE" 2>/dev/null | \
769-
cut -d ' ' -f 2)
770+
cut -d ' ' -f2)
770771
if [ "$SECRET" != "$MY_SECRET" ]; then
771772
wsrep_log_error "Donor does not know my secret!"
772773
wsrep_log_info "Donor: '$SECRET', my: '$MY_SECRET'"

scripts/wsrep_sst_rsync.sh

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -435,24 +435,38 @@ EOF
435435
tar_type=0
436436
if tar --help | grep -qw -F -- '--transform'; then
437437
tar_type=1
438-
elif tar --help | grep -qw -E -- '-s[[:space:]]pattern'
439-
then
438+
elif tar --version | grep -q -E '^bsdtar\>'; then
440439
tar_type=2
441440
fi
441+
if [ $tar_type -ne 2 ]; then
442+
if [ -n "$BASH_VERSION" ]; then
443+
printf '%s' "$binlog_files" >&2
444+
else
445+
echo "$binlog_files" >&2
446+
fi
447+
fi
442448
if [ $tar_type -ne 0 ]; then
443449
# Preparing list of the binlog file names:
444450
echo "$binlog_files" | {
445451
binlogs=""
446452
while read bin_file || [ -n "$bin_file" ]; do
447453
[ ! -f "$bin_file" ] && continue
454+
if [ -n "$BASH_VERSION" ]; then
455+
first="${bin_file:0:1}"
456+
else
457+
first=$(echo "$bin_file" | cut -c1)
458+
fi
459+
if [ "$first" = '-' -o "$first" = '@' ]; then
460+
bin_file="./$bin_file"
461+
fi
448462
binlogs="$binlogs${binlogs:+ }'$bin_file'"
449463
done
450464
if [ -n "$binlogs" ]; then
451-
tar_options='/^.*\///g'
452465
if [ $tar_type -eq 1 ]; then
453-
tar_options="--transform='s$tar_options'"
466+
tar_options="--transform='s/^.*\///g'"
454467
else
455-
tar_options="-s '$tar_options'"
468+
# bsdtar handles backslash incorrectly:
469+
tar_options="-s '?^.*/??g'"
456470
fi
457471
eval tar -P $tar_options \
458472
-cvf "'$BINLOG_TAR_FILE'" $binlogs >&2
@@ -465,6 +479,14 @@ EOF
465479
[ ! -f "$bin_file" ] && continue
466480
bin_dir=$(dirname "$bin_file")
467481
bin_base=$(basename "$bin_file")
482+
if [ -n "$BASH_VERSION" ]; then
483+
first="${bin_base:0:1}"
484+
else
485+
first=$(echo "$bin_base" | cut -c1)
486+
fi
487+
if [ "$first" = '-' -o "$first" = '@' ]; then
488+
bin_base="./$bin_base"
489+
fi
468490
if [ -n "$bin_dir" -a "$bin_dir" != '.' ]; then
469491
tar $tar_options "$BINLOG_TAR_FILE" \
470492
-C "$bin_dir" "$bin_base" >&2
@@ -740,7 +762,7 @@ EOF
740762
exit 42
741763
fi
742764
CN=$("$OPENSSL_BINARY" x509 -noout -subject -in "$SSTCERT" | \
743-
tr ',' '\n' | grep -F 'CN =' | cut -d= -f2 | sed s/^\ // | \
765+
tr ',' '\n' | grep -F 'CN =' | cut -d '=' -f2 | sed s/^\ // | \
744766
sed s/\ %//)
745767
fi
746768
MY_SECRET="$(wsrep_gen_secret)"
@@ -781,7 +803,7 @@ EOF
781803
if [ -n "$MY_SECRET" ]; then
782804
# Check donor supplied secret:
783805
SECRET=$(grep -F -- "$SECRET_TAG " "$MAGIC_FILE" 2>/dev/null | \
784-
cut -d ' ' -f 2)
806+
cut -d ' ' -f2)
785807
if [ "$SECRET" != "$MY_SECRET" ]; then
786808
wsrep_log_error "Donor does not know my secret!"
787809
wsrep_log_info "Donor: '$SECRET', my: '$MY_SECRET'"
@@ -840,12 +862,20 @@ EOF
840862
binlog_cd=0
841863
if [ -n "$binlog_dir" -a "$binlog_dir" != '.' ]; then
842864
[ ! -d "$binlog_dir" ] && mkdir -p "$binlog_dir"
843-
cd "$binlog_dir"
844865
binlog_cd=1
866+
cd "$binlog_dir"
845867
fi
846868
# Extracting binlog files:
847869
wsrep_log_info "Extracting binlog files:"
848-
if ! tar -xvf "$BINLOG_TAR_FILE" > "$tmpfile"; then
870+
RC=0
871+
if tar --version | grep -q -E '^bsdtar\>'; then
872+
tar -tf "$BINLOG_TAR_FILE" > "$tmpfile" && \
873+
tar -xvf "$BINLOG_TAR_FILE" > /dev/null || RC=$?
874+
else
875+
tar -xvf "$BINLOG_TAR_FILE" > "$tmpfile" && \
876+
cat "$tmpfile" >&2 || RC=$?
877+
fi
878+
if [ $RC -ne 0 ]; then
849879
rm -f "$tmpfile"
850880
wsrep_log_error "Error unpacking tar file with binlog files"
851881
exit 32

scripts/wsrep_sst_xtrabackup-v2.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,8 @@ get_transfer()
328328
if [ "${sockopt#*,dhparam=}" != "$sockopt" ]; then
329329
if [ -z "$ssl_dhparams" ]; then
330330
# Determine the socat version
331-
SOCAT_VERSION=$(socat -V 2>&1 | grep -m1 -oe '[0-9]\.[0-9][\.0-9]*')
331+
SOCAT_VERSION=$(socat -V 2>&1 | \
332+
grep -m1 -owE '[0-9]+(\.[0-9]+)+' | head -n1)
332333
if [ -z "$SOCAT_VERSION" ]; then
333334
wsrep_log_error "******** FATAL ERROR ******************"
334335
wsrep_log_error "* Cannot determine the socat version. *"
@@ -778,7 +779,7 @@ recv_joiner()
778779

779780
# check donor supplied secret
780781
SECRET=$(grep -F -- "$SECRET_TAG " "$MAGIC_FILE" 2>/dev/null | \
781-
cut -d ' ' -f 2)
782+
cut -d ' ' -f2)
782783
if [ "$SECRET" != "$MY_SECRET" ]; then
783784
wsrep_log_error "Donor does not know my secret!"
784785
wsrep_log_info "Donor: '$SECRET', my: '$MY_SECRET'"
@@ -835,7 +836,7 @@ monitor_process()
835836
XB_REQUIRED_VERSION='2.3.5'
836837

837838
XB_VERSION=$($BACKUP_BIN --version 2>&1 | \
838-
grep -oe '[0-9]\.[0-9][\.0-9]*' | head -n1)
839+
grep -m1 -owE '[0-9]+(\.[0-9]+)+' | head -n1)
839840
if [ -z "$XB_VERSION" ]; then
840841
wsrep_log_error "FATAL: Cannot determine the $BACKUP_BIN version." \
841842
"Needs xtrabackup-$XB_REQUIRED_VERSION or higher to" \
@@ -1212,7 +1213,6 @@ then
12121213
# May need xtrabackup_checkpoints later on
12131214
[ -f "$DATA/xtrabackup_binary" ] && rm -f "$DATA/xtrabackup_binary"
12141215
[ -f "$DATA/xtrabackup_galera_info" ] && rm -f "$DATA/xtrabackup_galera_info"
1215-
[ -f "$DATA/ib_logfile0" ] && rm -f "$DATA/ib_logfile0"
12161216

12171217
ADDR="$WSREP_SST_OPT_ADDR"
12181218

0 commit comments

Comments
 (0)