#!/bin/bash set -eu # shellcheck source=/dev/null source "${BASE}/env_${ENVIRONMENT}" tombstone_msg=$(date +'%Y%m%d_%H%M%S')"_${ENVIRONMENT}" echo "Insert '$tombstone_msg' into tombstone" echo "insert into tombstone(note) values('${tombstone_msg}') returning *" \ | ssh_remote "$AZURE_MASTER" sudo -u gitlab-psql gitlab-psql -v ON_ERROR_STOP=1 -d tombstone # wait until the change is propagated while true do find_new_msg="$(echo "select created_at from tombstone where note = '$tombstone_msg'" \ | ssh_remote "$GCP_MASTER_CANDIDATE" sudo gitlab-psql -v ON_ERROR_STOP=1 -A -t -d tombstone)" if [[ -z "${find_new_msg+x}" ]] || [[ "$find_new_msg" == "" ]] then gcp_cur_rep_delay="$(echo "select round(extract(epoch from (now() - pg_last_xact_replay_timestamp())))" \ | ssh_remote "$GCP_MASTER_CANDIDATE" sudo gitlab-psql -v ON_ERROR_STOP=1 -A -t -d postgres)" echo "New tombstone message is not seen on $GCP_MASTER_CANDIDATE (GCP MASTER CANDIDATE). The replication delay: ${gcp_cur_rep_delay}s. Wait 3 seconds..." sleep 3 else echo "New tombstone message arrived to $GCP_MASTER_CANDIDATE." break fi done