diff options
| author | Julius Goryavsky <julius.goryavsky@mariadb.com> | 2022-05-17 23:49:13 +0200 |
|---|---|---|
| committer | Julius Goryavsky <julius.goryavsky@mariadb.com> | 2022-05-17 23:49:13 +0200 |
| commit | 00b2b78fd12164a914117bf45d972dc1062bd9d6 (patch) | |
| tree | 8f9546020e21a0e8f5ff45730ba9e4377c4d8cb6 /scripts/wsrep_sst_mariabackup.sh | |
| parent | f8a3e9994d2348a5d5a44240f8bd469c97ecbcda (diff) | |
| download | mariadb-git-bb-10.9-MDEV-28583.tar.gz | |
MDEV-28583: Galera: binlogs disappear after rsync ISTbb-10.9-MDEV-28583
This commit sends a flag indicating the presence of the "--bypass"
option from the donor node to the joiner nodes during rsync IST,
because without such a flag it is impossible to distinguish IST
from the SST on the joiner nodes (in IST/SST scripts, because the
"--bypass" option is still not passed to scripts from server code).
Specifically, this fixes an issue with binary logs disappearing
after IST (via rsync). There are also changes to diagnostic messages
here that will make it easier to diagnose script-related problems
in the future when debugging and when checking the logs. This commit
also adds more robust signal handlers - to handle exceptions during
script execution. These handlers won't mask some crashes and it
also unifies exit codes between different scripts. These changes
have already been helpful to debugging "bypass" flag handling.
Diffstat (limited to 'scripts/wsrep_sst_mariabackup.sh')
| -rw-r--r-- | scripts/wsrep_sst_mariabackup.sh | 120 |
1 files changed, 53 insertions, 67 deletions
diff --git a/scripts/wsrep_sst_mariabackup.sh b/scripts/wsrep_sst_mariabackup.sh index 08582e1f671..66b23922f9b 100644 --- a/scripts/wsrep_sst_mariabackup.sh +++ b/scripts/wsrep_sst_mariabackup.sh @@ -87,6 +87,7 @@ encrypt_chunk="" readonly SECRET_TAG='secret' readonly TOTAL_TAG='total' +readonly TOTAL_TAG_SST="$SECRET_TAG /$TOTAL_TAG" # Required for backup locks # For backup locks it is 1 sent by joiner @@ -163,12 +164,10 @@ get_keys() exit 3 fi - if [ -z "$ekey" ]; then - if [ ! -r "$ekeyfile" ]; then - wsrep_log_error "FATAL: Either key must be specified" \ - "or keyfile must be readable" - exit 3 - fi + if [ -z "$ekey" -a ! -r "$ekeyfile" ]; then + wsrep_log_error "FATAL: Either key must be specified" \ + "or keyfile must be readable" + exit 3 fi if [ "$eformat" = 'openssl' ]; then @@ -215,9 +214,7 @@ get_keys() exit 2 fi - if [ "$WSREP_SST_OPT_ROLE" = 'joiner' ]; then - ecmd="$ecmd -d" - fi + [ "$WSREP_SST_OPT_ROLE" = 'joiner' ] && ecmd="$ecmd -d" stagemsg="$stagemsg-XB-Encrypted" } @@ -468,11 +465,10 @@ adjust_progress() return fi + rlimitopts="" if [ -n "$rlimit" -a "$WSREP_SST_OPT_ROLE" = 'donor' ]; then wsrep_log_info "Rate-limiting SST to $rlimit" rlimitopts=" -L $rlimit" - else - rlimitopts="" fi if [ -n "$progress" ]; then @@ -495,7 +491,7 @@ adjust_progress() fi fi - rcmd=":" + rcmd=':' else # Default progress output parseable by parent pvopts="-f -i 1 -n -b" @@ -639,18 +635,6 @@ get_stream() wsrep_log_info "Streaming with $sfmt" } -sig_joiner_cleanup() -{ - local estatus=$? - if [ $estatus -ne 0 ]; then - wsrep_log_error "Cleanup after exit with status: $estatus" - fi - wsrep_log_error "Removing $MAGIC_FILE file due to signal" - [ "$(pwd)" != "$OLD_PWD" ] && cd "$OLD_PWD" - [ -f "$MAGIC_FILE" ] && rm -f "$MAGIC_FILE" - exit $estatus -} - cleanup_at_exit() { # Since this is invoked just after exit NNN @@ -661,6 +645,11 @@ cleanup_at_exit() [ "$(pwd)" != "$OLD_PWD" ] && cd "$OLD_PWD" + if [ $estatus -ne 0 ]; then + wsrep_log_error "Removing $MAGIC_FILE file due to signal" + [ -f "$MAGIC_FILE" ] && rm -f "$MAGIC_FILE" || : + fi + if [ "$WSREP_SST_OPT_ROLE" = 'joiner' ]; then wsrep_log_info "Removing the sst_in_progress file" wsrep_cleanup_progress_file @@ -690,7 +679,7 @@ cleanup_at_exit() fi # Final cleanup - pgid=$(ps -o pgid= $$ 2>/dev/null | grep -o -E '[0-9]*' || :) + pgid=$(ps -o pgid= $$ 2>/dev/null | grep -o -E '[0-9]+' || :) # This means no setsid done in mysqld. # We don't want to kill mysqld here otherwise. @@ -786,17 +775,15 @@ recv_joiner() fi fi - pushd "$dir" 1>/dev/null - set +e - if [ $wait -ne 0 ]; then wait_for_listen & fi + cd "$dir" + set +e timeit "$msg" "$ltcmd | $strmcmd; RC=( "\${PIPESTATUS[@]}" )" - set -e - popd 1>/dev/null + cd "$OLD_PWD" if [ ${RC[0]} -eq 124 ]; then wsrep_log_error "Possible timeout in receiving first data from" \ @@ -822,8 +809,13 @@ recv_joiner() exit 32 fi - # check donor supplied secret - SECRET=$(grep -m1 -E "^$SECRET_TAG[[:space:]]" -- "$MAGIC_FILE" || :) + # Select the "secret" tag whose value does not start + # with a slash symbol. All new tags must to start with + # the space and the slash symbol after the word "secret" - + # to be removed by older versions of the SST scripts: + SECRET=$(grep -m1 -E "^$SECRET_TAG[[:space:]]+[^/]" \ + -- "$MAGIC_FILE" || :) + # Check donor supplied secret: SECRET=$(trim_string "${SECRET#$SECRET_TAG}") if [ "$SECRET" != "$MY_SECRET" ]; then wsrep_log_error "Donor does not know my secret!" @@ -832,16 +824,13 @@ recv_joiner() fi # check total SST footprint - total=$(grep -m1 -E "^$TOTAL_TAG[[:space:]]" -- "$MAGIC_FILE" || :) - total=$(trim_string "${total#$TOTAL_TAG}") + total=$(grep -m1 -E "^$TOTAL_TAG_SST[[:space:]]" \ + -- "$MAGIC_FILE" || :) + total=$(trim_string "${total#$TOTAL_TAG_SST}") if [ $total -ge 0 ]; then # report to parent echo "$TOTAL_TAG $total" fi - - grep -v -E "^($SECRET_TAG|$TOTAL_TAG)[[:space:]]" -- \ - "$MAGIC_FILE" > "$MAGIC_FILE.new" - mv "$MAGIC_FILE.new" "$MAGIC_FILE" fi } @@ -850,11 +839,11 @@ send_donor() local dir="$1" local msg="$2" - pushd "$dir" 1>/dev/null + cd "$dir" set +e timeit "$msg" "$strmcmd | $tcmd; RC=( "\${PIPESTATUS[@]}" )" set -e - popd 1>/dev/null + cd "$OLD_PWD" for ecode in "${RC[@]}"; do if [ $ecode -ne 0 ]; then @@ -869,7 +858,7 @@ monitor_process() { local sst_stream_pid=$1 - while true ; do + while :; do if ! ps -p "$WSREP_SST_OPT_PARENT" >/dev/null 2>&1; then wsrep_log_error \ "Parent mysqld process (PID: $WSREP_SST_OPT_PARENT)" \ @@ -886,13 +875,6 @@ monitor_process() [ -f "$MAGIC_FILE" ] && rm -f "$MAGIC_FILE" -if [ "$WSREP_SST_OPT_ROLE" != 'joiner' -a \ - "$WSREP_SST_OPT_ROLE" != 'donor' ] -then - wsrep_log_error "Invalid role '$WSREP_SST_OPT_ROLE'" - exit 22 -fi - read_cnf setup_ports @@ -1009,8 +991,8 @@ setup_commands() get_stream get_transfer -if [ "$WSREP_SST_OPT_ROLE" = 'donor' ] -then +if [ "$WSREP_SST_OPT_ROLE" = 'donor' ]; then + trap cleanup_at_exit EXIT if [ $WSREP_SST_OPT_BYPASS -eq 0 ] @@ -1062,7 +1044,7 @@ then echo "$WSREP_SST_OPT_GTID $WSREP_SST_OPT_GTID_DOMAIN_ID" > "$MAGIC_FILE" # Tell joiner what to expect: - echo "$TOTAL_TAG $payload" >> "$MAGIC_FILE" + echo "$TOTAL_TAG_SST $payload" >> "$MAGIC_FILE" if [ -n "$WSREP_SST_OPT_REMOTE_PSWD" ]; then # Let joiner know that we know its secret @@ -1086,7 +1068,7 @@ then tcmd="$ttcmd" if [ -n "$pcmd" ]; then - if [ "$rcmd" != ":" ]; then + if [ "$rcmd" != ':' ]; then # redirect pv stderr to rcmd for tagging and output to parent tcmd="{ $pcmd 2>&3 | $tcmd; } 3>&1 | $rcmd" else @@ -1140,6 +1122,7 @@ then fi setup_commands + set +e timeit "$stagemsg-SST" "$INNOBACKUP | $tcmd; RC=( "\${PIPESTATUS[@]}" )" set -e @@ -1183,10 +1166,9 @@ then echo "done $WSREP_SST_OPT_GTID" wsrep_log_info "Total time on donor: $totime seconds" - wsrep_log_info "mariabackup SST/IST completed on donor" -elif [ "$WSREP_SST_OPT_ROLE" = 'joiner' ] -then +else # joiner + [ -e "$SST_PROGRESS_FILE" ] && \ wsrep_log_info "Stale sst_in_progress file: $SST_PROGRESS_FILE" [ -n "$SST_PROGRESS_FILE" ] && touch "$SST_PROGRESS_FILE" @@ -1257,6 +1239,7 @@ then sleep 1 done + trap simple_cleanup EXIT echo $$ > "$SST_PID" stagemsg='Joiner-Recv' @@ -1266,7 +1249,7 @@ then [ -f "$DATA/$IST_FILE" ] && rm -f "$DATA/$IST_FILE" # May need xtrabackup_checkpoints later on - [ -f "$DATA/xtrabackup_binary" ] && rm -f "$DATA/xtrabackup_binary" + [ -f "$DATA/xtrabackup_binary" ] && rm -f "$DATA/xtrabackup_binary" [ -f "$DATA/xtrabackup_galera_info" ] && rm -f "$DATA/xtrabackup_galera_info" ADDR="$WSREP_SST_OPT_HOST" @@ -1293,7 +1276,6 @@ then MY_SECRET="" # for check down in recv_joiner() fi - trap sig_joiner_cleanup HUP PIPE INT TERM trap cleanup_at_exit EXIT get_keys @@ -1351,13 +1333,13 @@ then cd "$DATA" wsrep_log_info "Cleaning the old binary logs" # If there is a file with binlogs state, delete it: - [ -f "$binlog_base.state" ] && rm -fv "$binlog_base.state" 1>&2 + [ -f "$binlog_base.state" ] && rm -f "$binlog_base.state" >&2 # Clean up the old binlog files and index: if [ -f "$binlog_index" ]; then while read bin_file || [ -n "$bin_file" ]; do - rm -fv "$bin_file" 1>&2 || : + rm -f "$bin_file" >&2 || : done < "$binlog_index" - rm -fv "$binlog_index" 1>&2 + rm -f "$binlog_index" >&2 fi if [ -n "$binlog_dir" -a "$binlog_dir" != '.' -a \ -d "$binlog_dir" ] @@ -1368,7 +1350,7 @@ then "Cleaning the binlog directory '$binlog_dir' as well" fi fi - rm -fv "$binlog_base".[0-9]* 1>&2 || : + rm -f "$binlog_base".[0-9]* >&2 || : cd "$OLD_PWD" fi @@ -1379,13 +1361,13 @@ then ${ib_undo_dir:+"$ib_undo_dir"} \ ${ib_log_dir:+"$ib_log_dir"} \ "$DATA" -mindepth 1 -prune -regex "$cpat" \ - -o -exec rm -rfv {} 1>&2 \+ + -o -exec rm -rf {} >&2 \+ else find ${ib_home_dir:+"$ib_home_dir"} \ ${ib_undo_dir:+"$ib_undo_dir"} \ ${ib_log_dir:+"$ib_log_dir"} \ "$DATA" -mindepth 1 -prune -regex "$cpat" \ - -o -exec rm -rfv {} 1>&2 \+ + -o -exec rm -rf {} >&2 \+ fi TDATA="$DATA" @@ -1457,7 +1439,6 @@ then wsrep_log_info "Preparing the backup at $DATA" setup_commands timeit 'mariabackup prepare stage' "$INNOAPPLY" - if [ $? -ne 0 ]; then wsrep_log_error "mariabackup apply finished with errors." \ "Check syslog or '$INNOAPPLYLOG' for details." @@ -1514,6 +1495,10 @@ then else wsrep_log_info "'$IST_FILE' received from donor: Running IST" + if [ $WSREP_SST_OPT_BYPASS -eq 0 ]; then + readonly WSREP_SST_OPT_BYPASS=1 + readonly WSREP_TRANSFER_TYPE='IST' + fi fi @@ -1522,12 +1507,13 @@ then exit 2 fi - coords=$(cat "$MAGIC_FILE") + # Remove special tags from the magic file, and from the output: + coords=$(grep -v -E "^$SECRET_TAG[[:space:]]" -- "$MAGIC_FILE") wsrep_log_info "Galera co-ords from recovery: $coords" - cat "$MAGIC_FILE" # Output : UUID:seqno wsrep_gtid_domain_id + echo "$coords" # Output : UUID:seqno wsrep_gtid_domain_id wsrep_log_info "Total time on joiner: $totime seconds" - wsrep_log_info "mariabackup SST/IST completed on joiner" fi +wsrep_log_info "$WSREP_METHOD $WSREP_TRANSFER_TYPE completed on $WSREP_SST_OPT_ROLE" exit 0 |
