Skip to content

Commit

Permalink
Skip cluster/leave task when not a cluster member
Browse files Browse the repository at this point in the history
  • Loading branch information
olliewalsh committed Oct 16, 2024
1 parent 78eb4b2 commit 46e7e81
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
20 changes: 9 additions & 11 deletions templates/ovndbcluster/bin/cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,33 @@ fi
# There is nothing special about -0 pod, except that it's always guaranteed to
# exist, assuming any replicas are ordered.
if [[ "$(hostname)" != "{{ .SERVICE_NAME }}-0" ]]; then

ovs-appctl -t /tmp/ovn${DB_TYPE}_db.ctl cluster/leave ${DB_NAME}

# wait for when the leader confirms we left the cluster
while true; do
# TODO: is there a better way to detect the cluster left state?..
STATUS=$(ovs-appctl -t /tmp/ovn${DB_TYPE}_db.ctl cluster/status ${DB_NAME} | grep Status: | awk -e '{print $2}')
if [ -z "$STATUS" -o "x$STATUS" = "xleft cluster" ]; then
break
if [ -z "$STATUS" -o "x$STATUS" = "xleaving cluster" -o "x$STATUS" = "xcluster member" ]; then
sleep 1
continue
fi
sleep 1
break
done
else
# wait for other members to leave
while true; do
STATUS=$(ovs-appctl -t /tmp/ovn${DB_TYPE}_db.ctl cluster/status ${DB_NAME} | grep Status: | awk -e '{print $2}')
if [ -z "$STATUS" -o "x$STATUS" != "xcluster member" ]; then
break
fi
if SERVER_COUNT=$(ovs-appctl -t /tmp/ovn${DB_TYPE}_db.ctl cluster/status ${DB_NAME} | sed -e '1,/Servers:/d' -e '/^\s*$/d' | wc -l) && [[ $SERVER_COUNT -le 1 ]]; then
break
fi
sleep 1
done
fi

# If replicas are 0 and *all* pods are removed, we still want to retain the
# database with its cid/sid for when the cluster is scaled back to > 0, so
# leaving the database file intact for -0 pod.
if [[ "$(hostname)" != "{{ .SERVICE_NAME }}-0" ]]; then
# now that we left, the database file is no longer valid
cleanup_db_file
fi

# Stop the DB server gracefully; this will also end the pod running script.
# By executing the stop command in the background, we guarantee to exit
# this script and not fail with "FailedPreStopHook", while the database is
Expand Down
2 changes: 1 addition & 1 deletion templates/ovndbcluster/bin/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ set "$@" --ovn-${DB_TYPE}-logfile=/dev/null

# If db file is empty, remove it; otherwise service won't start.
# See https://issues.redhat.com/browse/FDP-689 for more details.
if ! [ -s $DB_FILE ]; then
if ! [ -s $DB_FILE ] || [[ "$(hostname)" != "{{ .SERVICE_NAME }}-0" ]]; then
cleanup_db_file
fi

Expand Down

0 comments on commit 46e7e81

Please sign in to comment.