Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

K8SPXC-1546: Cache binlog->gtid set pairs #1959

Merged
merged 4 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ COPY build/liveness-check.sh /liveness-check.sh
COPY build/readiness-check.sh /readiness-check.sh
COPY build/pmm-prerun.sh /pmm-prerun.sh
COPY build/get-pxc-state /get-pxc-state
COPY build/wsrep_cmd_notify_handler.sh /wsrep_cmd_notify_handler.sh
hors marked this conversation as resolved.
Show resolved Hide resolved

COPY build/haproxy-entrypoint.sh /haproxy-entrypoint.sh
COPY build/haproxy-init-entrypoint.sh /haproxy-init-entrypoint.sh
Expand Down
4 changes: 3 additions & 1 deletion build/pxc-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
elif [ "${!fileVar:-}" ]; then
val="$(<"${!fileVar}")"
elif [ "${3:-}" ] && [ -f "/etc/mysql/mysql-users-secret/$3" ]; then
val="$(</etc/mysql/mysql-users-secret/$3)"

Check notice on line 44 in build/pxc-entrypoint.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] build/pxc-entrypoint.sh#L44 <ShellCheck.SC2086>

Double quote to prevent globbing and word splitting.
Raw output
./build/pxc-entrypoint.sh:44:41: info: Double quote to prevent globbing and word splitting. (ShellCheck.SC2086)
fi
export "$var"="$val"
unset "$fileVar"
Expand All @@ -60,7 +60,7 @@
case "$f" in
*.sh)
echo "$0: running $f"
. "$f"

Check warning on line 63 in build/pxc-entrypoint.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] build/pxc-entrypoint.sh#L63 <ShellCheck.SC1090>

ShellCheck can't follow non-constant source. Use a directive to specify location.
Raw output
./build/pxc-entrypoint.sh:63:5: warning: ShellCheck can't follow non-constant source. Use a directive to specify location. (ShellCheck.SC1090)
;;
*.sql)
echo "$0: running $f"
Expand Down Expand Up @@ -188,10 +188,12 @@
sed -i "/\[mysqld\]/a enforce-gtid-consistency" $CFG
fi

sed -i "/\[mysqld\]/a wsrep_notify_cmd=/var/lib/mysql/wsrep_cmd_notify_handler.sh" $CFG

# add sst.cpat to exclude pxc-entrypoint, unsafe-bootstrap, pxc-configure-pxc from SST cleanup
grep -q "^progress=" $CFG && sed -i "s|^progress=.*|progress=1|" $CFG
grep -q "^\[sst\]" "$CFG" || printf '[sst]\n' >>"$CFG"
grep -q "^cpat=" "$CFG" || sed '/^\[sst\]/a cpat=.*\\.pem$\\|.*init\\.ok$\\|.*galera\\.cache$\\|.*wsrep_recovery_verbose\\.log$\\|.*readiness-check\\.sh$\\|.*liveness-check\\.sh$\\|.*get-pxc-state$\\|.*sst_in_progress$\\|.*sleep-forever$\\|.*pmm-prerun\\.sh$\\|.*sst-xb-tmpdir$\\|.*\\.sst$\\|.*gvwstate\\.dat$\\|.*grastate\\.dat$\\|.*\\.err$\\|.*\\.log$\\|.*RPM_UPGRADE_MARKER$\\|.*RPM_UPGRADE_HISTORY$\\|.*pxc-entrypoint\\.sh$\\|.*unsafe-bootstrap\\.sh$\\|.*pxc-configure-pxc\\.sh\\|.*peer-list$\\|.*auth_plugin$\\|.*version_info$\\|.*mysql-state-monitor$\\|.*mysql-state-monitor\\.log$\\|.*notify\\.sock$\\|.*mysql\\.state$' "$CFG" 1<>"$CFG"
grep -q "^cpat=" "$CFG" || sed '/^\[sst\]/a cpat=.*\\.pem$\\|.*init\\.ok$\\|.*galera\\.cache$\\|.*wsrep_recovery_verbose\\.log$\\|.*readiness-check\\.sh$\\|.*liveness-check\\.sh$\\|.*get-pxc-state$\\|.*sst_in_progress$\\|.*sleep-forever$\\|.*pmm-prerun\\.sh$\\|.*sst-xb-tmpdir$\\|.*\\.sst$\\|.*gvwstate\\.dat$\\|.*grastate\\.dat$\\|.*\\.err$\\|.*\\.log$\\|.*RPM_UPGRADE_MARKER$\\|.*RPM_UPGRADE_HISTORY$\\|.*pxc-entrypoint\\.sh$\\|.*unsafe-bootstrap\\.sh$\\|.*pxc-configure-pxc\\.sh\\|.*peer-list$\\|.*auth_plugin$\\|.*version_info$\\|.*mysql-state-monitor$\\|.*mysql-state-monitor\\.log$\\|.*notify\\.sock$\\|.*mysql\\.state$\\|.*wsrep_cmd_notify_handler\\.sh$' "$CFG" 1<>"$CFG"

if [[ $MYSQL_VERSION == '8.0' && $MYSQL_PATCH_VERSION -ge 26 ]] || [[ $MYSQL_VERSION == '8.4' ]]; then
grep -q "^skip_replica_start=ON" "$CFG" || sed -i "/\[mysqld\]/a skip_replica_start=ON" $CFG
Expand Down Expand Up @@ -251,7 +253,7 @@
i=$(curl "$DISCOVERY_SERVICE/v2/keys/pxc-cluster/queue/$CLUSTER_NAME" | jq -r '.node.nodes[].value')

# this remove my ip from the list
i1="${i[@]//$NODE_IP/}"

Check warning on line 256 in build/pxc-entrypoint.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] build/pxc-entrypoint.sh#L256 <ShellCheck.SC2124>

Assigning an array to a string! Assign as array, or use * instead of @ to concatenate.
Raw output
./build/pxc-entrypoint.sh:256:5: warning: Assigning an array to a string! Assign as array, or use * instead of @ to concatenate. (ShellCheck.SC2124)

# Register the current IP in the discovery service
# key set to expire in 30 sec. There is a cronjob that should update them regularly
Expand All @@ -261,8 +263,8 @@

i=$(curl "$DISCOVERY_SERVICE/v2/keys/pxc-cluster/$CLUSTER_NAME/?quorum=true" | jq -r '.node.nodes[]?.key' | awk -F'/' '{print $(NF)}')
# this remove my ip from the list
i2="${i[@]//$NODE_IP/}"

Check warning on line 266 in build/pxc-entrypoint.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] build/pxc-entrypoint.sh#L266 <ShellCheck.SC2124>

Assigning an array to a string! Assign as array, or use * instead of @ to concatenate.
Raw output
./build/pxc-entrypoint.sh:266:5: warning: Assigning an array to a string! Assign as array, or use * instead of @ to concatenate. (ShellCheck.SC2124)
CLUSTER_JOIN=$(join , $i1 $i2)

Check notice on line 267 in build/pxc-entrypoint.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] build/pxc-entrypoint.sh#L267 <ShellCheck.SC2086>

Double quote to prevent globbing and word splitting.
Raw output
./build/pxc-entrypoint.sh:267:24: info: Double quote to prevent globbing and word splitting. (ShellCheck.SC2086)

Check notice on line 267 in build/pxc-entrypoint.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] build/pxc-entrypoint.sh#L267 <ShellCheck.SC2086>

Double quote to prevent globbing and word splitting.
Raw output
./build/pxc-entrypoint.sh:267:28: info: Double quote to prevent globbing and word splitting. (ShellCheck.SC2086)

sed -r "s|^[#]?wsrep_node_address=.*$|wsrep_node_address=${NODE_IP}|" "${CFG}" 1<>"${CFG}"
sed -r "s|^[#]?wsrep_cluster_name=.*$|wsrep_cluster_name=${CLUSTER_NAME}|" "${CFG}" 1<>"${CFG}"
Expand Down Expand Up @@ -303,7 +305,7 @@

# if we have CLUSTER_JOIN - then we do not need to perform datadir initialize
# the data will be copied from another node
if [ -z "$CLUSTER_JOIN" ] && [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then

Check warning on line 308 in build/pxc-entrypoint.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] build/pxc-entrypoint.sh#L308 <ShellCheck.SC2166>

Prefer [ p ] && [ q ] as [ p -a q ] is not well defined.
Raw output
./build/pxc-entrypoint.sh:308:48: warning: Prefer [ p ] && [ q ] as [ p -a q ] is not well defined. (ShellCheck.SC2166)
# still need to check config, container may have started with --user
_check_config "$@"

Expand All @@ -316,7 +318,7 @@
if [ ! -d "$DATADIR/mysql" ]; then
file_env 'MYSQL_ROOT_PASSWORD' '' 'root'
{ set +x; } 2>/dev/null
if [ -z "$MYSQL_ROOT_PASSWORD" -a -z "$MYSQL_ALLOW_EMPTY_PASSWORD" -a -z "$MYSQL_RANDOM_ROOT_PASSWORD" ]; then

Check warning on line 321 in build/pxc-entrypoint.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] build/pxc-entrypoint.sh#L321 <ShellCheck.SC2166>

Prefer [ p ] && [ q ] as [ p -a q ] is not well defined.
Raw output
./build/pxc-entrypoint.sh:321:34: warning: Prefer [ p ] && [ q ] as [ p -a q ] is not well defined. (ShellCheck.SC2166)

Check warning on line 321 in build/pxc-entrypoint.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] build/pxc-entrypoint.sh#L321 <ShellCheck.SC2166>

Prefer [ p ] && [ q ] as [ p -a q ] is not well defined.
Raw output
./build/pxc-entrypoint.sh:321:70: warning: Prefer [ p ] && [ q ] as [ p -a q ] is not well defined. (ShellCheck.SC2166)
echo >&2 'error: database is uninitialized and password option is not specified '
echo >&2 ' You need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD'
exit 1
Expand Down Expand Up @@ -372,7 +374,7 @@
fi

{ set +x; } 2>/dev/null
if [ ! -z "$MYSQL_RANDOM_ROOT_PASSWORD" ]; then

Check notice on line 377 in build/pxc-entrypoint.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] build/pxc-entrypoint.sh#L377 <ShellCheck.SC2236>

Use -n instead of ! -z.
Raw output
./build/pxc-entrypoint.sh:377:8: info: Use -n instead of ! -z. (ShellCheck.SC2236)
MYSQL_ROOT_PASSWORD="$(pwmake 128)"
echo "GENERATED ROOT PASSWORD: $MYSQL_ROOT_PASSWORD"
fi
Expand All @@ -380,7 +382,7 @@
rootCreate=
# default root to listen for connections from anywhere
file_env 'MYSQL_ROOT_HOST' '%'
if [ ! -z "$MYSQL_ROOT_HOST" -a "$MYSQL_ROOT_HOST" != 'localhost' ]; then

Check notice on line 385 in build/pxc-entrypoint.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] build/pxc-entrypoint.sh#L385 <ShellCheck.SC2236>

Use -n instead of ! -z.
Raw output
./build/pxc-entrypoint.sh:385:8: info: Use -n instead of ! -z. (ShellCheck.SC2236)

Check warning on line 385 in build/pxc-entrypoint.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] build/pxc-entrypoint.sh#L385 <ShellCheck.SC2166>

Prefer [ p ] && [ q ] as [ p -a q ] is not well defined.
Raw output
./build/pxc-entrypoint.sh:385:32: warning: Prefer [ p ] && [ q ] as [ p -a q ] is not well defined. (ShellCheck.SC2166)
# no, we don't care if read finds a terminating character in this heredoc
# https://unix.stackexchange.com/questions/265149/why-is-set-o-errexit-breaking-this-read-heredoc-expression/265151#265151
read -r -d '' rootCreate <<-EOSQL || true
Expand Down Expand Up @@ -437,7 +439,7 @@
EOSQL

{ set +x; } 2>/dev/null
if [ ! -z "$MYSQL_ROOT_PASSWORD" ]; then

Check notice on line 442 in build/pxc-entrypoint.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] build/pxc-entrypoint.sh#L442 <ShellCheck.SC2236>

Use -n instead of ! -z.
Raw output
./build/pxc-entrypoint.sh:442:8: info: Use -n instead of ! -z. (ShellCheck.SC2236)
mysql+=(-p"${MYSQL_ROOT_PASSWORD}")
fi
set -x
Expand All @@ -451,7 +453,7 @@
file_env 'MYSQL_USER'
file_env 'MYSQL_PASSWORD'
{ set +x; } 2>/dev/null
if [ "$MYSQL_USER" -a "$MYSQL_PASSWORD" ]; then

Check warning on line 456 in build/pxc-entrypoint.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] build/pxc-entrypoint.sh#L456 <ShellCheck.SC2166>

Prefer [ p ] && [ q ] as [ p -a q ] is not well defined.
Raw output
./build/pxc-entrypoint.sh:456:22: warning: Prefer [ p ] && [ q ] as [ p -a q ] is not well defined. (ShellCheck.SC2166)
echo "CREATE USER '$MYSQL_USER'@'%' IDENTIFIED BY '$MYSQL_PASSWORD' ;" | "${mysql[@]}"

if [ "$MYSQL_DATABASE" ]; then
Expand All @@ -469,7 +471,7 @@
done

{ set +x; } 2>/dev/null
if [ ! -z "$MYSQL_ONETIME_PASSWORD" ]; then

Check notice on line 474 in build/pxc-entrypoint.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] build/pxc-entrypoint.sh#L474 <ShellCheck.SC2236>

Use -n instead of ! -z.
Raw output
./build/pxc-entrypoint.sh:474:8: info: Use -n instead of ! -z. (ShellCheck.SC2236)
"${mysql[@]}" <<-EOSQL
ALTER USER 'root'@'%' PASSWORD EXPIRE;
EOSQL
Expand All @@ -486,13 +488,13 @@
fi

# exit when MYSQL_INIT_ONLY environment variable is set to avoid starting mysqld
if [ ! -z "$MYSQL_INIT_ONLY" ]; then

Check notice on line 491 in build/pxc-entrypoint.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] build/pxc-entrypoint.sh#L491 <ShellCheck.SC2236>

Use -n instead of ! -z.
Raw output
./build/pxc-entrypoint.sh:491:7: info: Use -n instead of ! -z. (ShellCheck.SC2236)
echo 'Initialization complete, now exiting!'
exit 0
fi
fi

if [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then

Check warning on line 497 in build/pxc-entrypoint.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] build/pxc-entrypoint.sh#L497 <ShellCheck.SC2166>

Prefer [ p ] && [ q ] as [ p -a q ] is not well defined.
Raw output
./build/pxc-entrypoint.sh:497:22: warning: Prefer [ p ] && [ q ] as [ p -a q ] is not well defined. (ShellCheck.SC2166)
# still need to check config, container may have started with --user
_check_config "$@"

Expand All @@ -507,20 +509,20 @@
pxc_version=''
if [ -f "$DATADIR/version_info" ]; then
pxc_version_file="$DATADIR/version_info"
pxc_version=$(cat "$pxc_version_file" | awk '{print $3}')

Check notice on line 512 in build/pxc-entrypoint.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] build/pxc-entrypoint.sh#L512 <ShellCheck.SC2002>

Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.
Raw output
./build/pxc-entrypoint.sh:512:21: info: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead. (ShellCheck.SC2002)
elif [ -f "$DATADIR/xtrabackup_info" ]; then
pxc_version_file="$DATADIR/xtrabackup_info"
pxc_version=$(grep 'server_version' "$pxc_version_file" | awk '{print $3}' | tr -d '\n')
fi

if [[ -f $pxc_version_file && -n $pxc_version && $MYSQL_VERSION == '5.7' ]] && [[ $(cat /tmp/version_info) != $pxc_version ]]; then

Check warning on line 518 in build/pxc-entrypoint.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] build/pxc-entrypoint.sh#L518 <ShellCheck.SC2053>

Quote the right-hand side of != in [[ ]] to prevent glob matching.
Raw output
./build/pxc-entrypoint.sh:518:112: warning: Quote the right-hand side of != in [[ ]] to prevent glob matching. (ShellCheck.SC2053)
SOCKET="$(_get_config 'socket' "$@")"
"$@" --skip-networking --socket="${SOCKET}" --wsrep-provider='none' &
pid="$!"

mysql=(mysql --protocol=socket -uroot -hlocalhost --socket="${SOCKET}" --password="")
{ set +x; } 2>/dev/null
if [ ! -z "$MYSQL_ROOT_PASSWORD" ]; then

Check notice on line 525 in build/pxc-entrypoint.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] build/pxc-entrypoint.sh#L525 <ShellCheck.SC2236>

Use -n instead of ! -z.
Raw output
./build/pxc-entrypoint.sh:525:8: info: Use -n instead of ! -z. (ShellCheck.SC2236)
mysql+=(-p"${MYSQL_ROOT_PASSWORD}")
fi
set -x
Expand Down Expand Up @@ -550,16 +552,16 @@
POD_NAMESPACE=$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace)

wsrep_start_position_opt=""
if [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then

Check warning on line 555 in build/pxc-entrypoint.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] build/pxc-entrypoint.sh#L555 <ShellCheck.SC2166>

Prefer [ p ] && [ q ] as [ p -a q ] is not well defined.
Raw output
./build/pxc-entrypoint.sh:555:22: warning: Prefer [ p ] && [ q ] as [ p -a q ] is not well defined. (ShellCheck.SC2166)
DATADIR="$(_get_config 'datadir' "$@")"
grastate_loc="${DATADIR}/grastate.dat"
wsrep_verbose_logfile="$DATADIR/wsrep_recovery_verbose.log"
if [ -f "$wsrep_verbose_logfile" ]; then
cat "$wsrep_verbose_logfile" | tee -a "$DATADIR/wsrep_recovery_verbose_history.log"

Check notice on line 560 in build/pxc-entrypoint.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] build/pxc-entrypoint.sh#L560 <ShellCheck.SC2002>

Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.
Raw output
./build/pxc-entrypoint.sh:560:7: info: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead. (ShellCheck.SC2002)
rm -f "$wsrep_verbose_logfile"
fi

if [ -s "$grastate_loc" -a -d "$DATADIR/mysql" ]; then

Check warning on line 564 in build/pxc-entrypoint.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] build/pxc-entrypoint.sh#L564 <ShellCheck.SC2166>

Prefer [ p ] && [ q ] as [ p -a q ] is not well defined.
Raw output
./build/pxc-entrypoint.sh:564:26: warning: Prefer [ p ] && [ q ] as [ p -a q ] is not well defined. (ShellCheck.SC2166)
uuid=$(grep 'uuid:' "$grastate_loc" | cut -d: -f2 | tr -d ' ' || :)
seqno=$(grep 'seqno:' "$grastate_loc" | cut -d: -f2 | tr -d ' ' || :)
safe_to_bootstrap=$(grep 'safe_to_bootstrap:' "$grastate_loc" | cut -d: -f2 | tr -d ' ' || :)
Expand All @@ -574,11 +576,11 @@
fi
fi

if [ -z "$wsrep_start_position_opt" -a -d "$DATADIR/mysql" ]; then

Check warning on line 579 in build/pxc-entrypoint.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] build/pxc-entrypoint.sh#L579 <ShellCheck.SC2166>

Prefer [ p ] && [ q ] as [ p -a q ] is not well defined.
Raw output
./build/pxc-entrypoint.sh:579:38: warning: Prefer [ p ] && [ q ] as [ p -a q ] is not well defined. (ShellCheck.SC2166)
"$@" --wsrep_recover --log-error-verbosity=3 --log_error="$wsrep_verbose_logfile"

echo >&2 "WSREP: Print recovery logs: "
cat "$wsrep_verbose_logfile" | tee -a "$DATADIR/wsrep_recovery_verbose_history.log"

Check notice on line 583 in build/pxc-entrypoint.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] build/pxc-entrypoint.sh#L583 <ShellCheck.SC2002>

Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.
Raw output
./build/pxc-entrypoint.sh:583:7: info: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead. (ShellCheck.SC2002)
if grep ' Recovered position:' "$wsrep_verbose_logfile"; then
start_pos="$(
grep ' Recovered position:' "$wsrep_verbose_logfile" |
Expand Down Expand Up @@ -615,7 +617,7 @@
sed -i 's/safe_to_bootstrap: 0/safe_to_bootstrap: 1/g' "$grastate_loc"
fi
echo "Recovery was finished."
exec "$@" $wsrep_start_position_opt

Check notice on line 620 in build/pxc-entrypoint.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] build/pxc-entrypoint.sh#L620 <ShellCheck.SC2086>

Double quote to prevent globbing and word splitting.
Raw output
./build/pxc-entrypoint.sh:620:14: info: Double quote to prevent globbing and word splitting. (ShellCheck.SC2086)
}
function is_manual_recovery() {
set +o xtrace
Expand Down Expand Up @@ -668,7 +670,7 @@
fi
fi

test -e /opt/percona/hookscript/hook.sh && source /opt/percona/hookscript/hook.sh

Check notice on line 673 in build/pxc-entrypoint.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] build/pxc-entrypoint.sh#L673 <ShellCheck.SC1091>

Not following: /opt/percona/hookscript/hook.sh was not specified as input (see shellcheck -x).
Raw output
./build/pxc-entrypoint.sh:673:51: info: Not following: /opt/percona/hookscript/hook.sh was not specified as input (see shellcheck -x). (ShellCheck.SC1091)

init_opt=""
if [[ -f /etc/mysql/init-file/init.sql ]]; then
Expand All @@ -676,4 +678,4 @@
echo "Using init-file: /etc/mysql/init-file/init.sql"
fi

exec "$@" ${wsrep_start_position_opt} ${init_opt}

Check notice on line 681 in build/pxc-entrypoint.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] build/pxc-entrypoint.sh#L681 <ShellCheck.SC2086>

Double quote to prevent globbing and word splitting.
Raw output
./build/pxc-entrypoint.sh:681:11: info: Double quote to prevent globbing and word splitting. (ShellCheck.SC2086)
1 change: 1 addition & 0 deletions build/pxc-init-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ install -o "$(id -u)" -g "$(id -g)" -m 0755 -D /peer-list /var/lib/mysql/peer-li
install -o "$(id -u)" -g "$(id -g)" -m 0755 -D /get-pxc-state /var/lib/mysql/get-pxc-state
install -o "$(id -u)" -g "$(id -g)" -m 0755 -D /pmm-prerun.sh /var/lib/mysql/pmm-prerun.sh
install -o "$(id -u)" -g "$(id -g)" -m 0755 -D /mysql-state-monitor /var/lib/mysql/mysql-state-monitor
install -o "$(id -u)" -g "$(id -g)" -m 0755 -D /wsrep_cmd_notify_handler.sh /var/lib/mysql/wsrep_cmd_notify_handler.sh
42 changes: 42 additions & 0 deletions build/wsrep_cmd_notify_handler.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

set -o errexit

while [ $# -gt 0 ]; do
case $1 in
--status)
STATUS=$2
shift
;;
--uuid)
CLUSTER_UUID=$2

Check warning on line 12 in build/wsrep_cmd_notify_handler.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] build/wsrep_cmd_notify_handler.sh#L12 <ShellCheck.SC2034>

CLUSTER_UUID appears unused. Verify use (or export if used externally).
Raw output
./build/wsrep_cmd_notify_handler.sh:12:2: warning: CLUSTER_UUID appears unused. Verify use (or export if used externally). (ShellCheck.SC2034)
shift
;;
--primary)
[ "$2" = "yes" ] && PRIMARY="1" || PRIMARY="0"

Check warning on line 16 in build/wsrep_cmd_notify_handler.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] build/wsrep_cmd_notify_handler.sh#L16 <ShellCheck.SC2034>

PRIMARY appears unused. Verify use (or export if used externally).
Raw output
./build/wsrep_cmd_notify_handler.sh:16:37: warning: PRIMARY appears unused. Verify use (or export if used externally). (ShellCheck.SC2034)
shift
;;
--index)
INDEX=$2

Check warning on line 20 in build/wsrep_cmd_notify_handler.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] build/wsrep_cmd_notify_handler.sh#L20 <ShellCheck.SC2034>

INDEX appears unused. Verify use (or export if used externally).
Raw output
./build/wsrep_cmd_notify_handler.sh:20:2: warning: INDEX appears unused. Verify use (or export if used externally). (ShellCheck.SC2034)
shift
;;
--members)
MEMBERS=$2

Check warning on line 24 in build/wsrep_cmd_notify_handler.sh

View workflow job for this annotation

GitHub Actions / shellcheck

[shellcheck] build/wsrep_cmd_notify_handler.sh#L24 <ShellCheck.SC2034>

MEMBERS appears unused. Verify use (or export if used externally).
Raw output
./build/wsrep_cmd_notify_handler.sh:24:2: warning: MEMBERS appears unused. Verify use (or export if used externally). (ShellCheck.SC2034)
shift
;;
Comment on lines +7 to +26
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[shfmt] reported by reviewdog 🐶

Suggested change
--status)
STATUS=$2
shift
;;
--uuid)
CLUSTER_UUID=$2
shift
;;
--primary)
[ "$2" = "yes" ] && PRIMARY="1" || PRIMARY="0"
shift
;;
--index)
INDEX=$2
shift
;;
--members)
MEMBERS=$2
shift
;;
--status)
STATUS=$2
shift
;;
--uuid)
CLUSTER_UUID=$2
shift
;;
--primary)
[ "$2" = "yes" ] && PRIMARY="1" || PRIMARY="0"
shift
;;
--index)
INDEX=$2
shift
;;
--members)
MEMBERS=$2
shift
;;

esac

shift
done

CLUSTER_NAME=$(hostname -f | cut -d'-' -f1)
CLUSTER_FQDN=$(hostname -f | cut -d'.' -f3-)

if [[ "$STATUS" == "joiner" ]]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[shfmt] reported by reviewdog 🐶

Suggested change
if [[ "$STATUS" == "joiner" ]]; then
if [[ $STATUS == "joiner" ]]; then

PITR_HOST="${CLUSTER_NAME}-pitr.${CLUSTER_FQDN}"
if getent hosts "${PITR_HOST}" >/dev/null 2>&1; then
curl -d "hostname=$(hostname -f)" "http://${PITR_HOST}:8080/invalidate-cache/"
fi
fi

exit 0
91 changes: 91 additions & 0 deletions cmd/pitr/collector/cache.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package collector

import (
"bytes"
"context"
"encoding/json"
"log"
"time"

"github.com/percona/percona-xtradb-cluster-operator/pkg/pxc/backup/storage"
"github.com/pkg/errors"
)

type BinlogCacheEntry struct {
Binlogs map[string]string `json:"binlogs"` // binlog name -> gtid set
}

type HostBinlogCache struct {
// host -> binlogs. we use pointer here to not copy BinlogCacheEntry
// in case if it grows big and it'll grow big eventually.
Entries map[string]*BinlogCacheEntry `json:"entries"`
Version int `json:"version"`
LastUpdatedAt time.Time `json:"last_updated_at"`
}

func (e *BinlogCacheEntry) Get(key string) (string, bool) {
value, ok := e.Binlogs[key]
return value, ok
}

func (e *BinlogCacheEntry) Set(key, value string) {
e.Binlogs[key] = value
}

func loadCache(ctx context.Context, s storage.Storage, key string) (*HostBinlogCache, error) {
cache := &HostBinlogCache{
Entries: make(map[string]*BinlogCacheEntry),
Version: 1,
}

objReader, err := s.GetObject(ctx, key)
if err != nil {
if errors.Is(err, storage.ErrObjectNotFound) {
log.Printf("WARNING: cache file %s not found", key)
return cache, nil
}
return nil, errors.Wrap(err, "get cache from storage")
}
defer objReader.Close()

if err := json.NewDecoder(objReader).Decode(cache); err != nil {
return nil, errors.Wrap(err, "decode cache")
}

return cache, nil
}

func saveCache(ctx context.Context, s storage.Storage, cache *HostBinlogCache, key string) error {
log.Printf("updating binlog cache")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we going to keep all these logging or do we have them for now only for debugging purposes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i intend to keep these logs, yes

cache.LastUpdatedAt = time.Now()

data, err := json.Marshal(cache)
if err != nil {
return errors.Wrap(err, "marshal cache")
}

err = s.PutObject(ctx, key, bytes.NewReader(data), int64(len(data)))
return errors.Wrap(err, "put cache to s3")
}

func InvalidateCache(ctx context.Context, c *Collector, hostname string) error {
cache, err := loadCache(ctx, c.GetStorage(), c.GetGTIDCacheKey())
if err != nil {
return errors.Wrap(err, "load cache")
}

_, ok := cache.Entries[hostname]
if !ok {
return errors.Errorf("failed to find cache for %s", hostname)
}

log.Printf("invalidating cache for %s", hostname)
delete(cache.Entries, hostname)

err = saveCache(ctx, c.GetStorage(), cache, c.GetGTIDCacheKey())
if err != nil {
return errors.Wrap(err, "save cache")
}

return nil
}
Loading
Loading