nixbot

builds

failed treefmt-check checks.x86_64-linux.treefmt · build #596 · raw

1treefmt v2.4.0traversed 937 files2emitted 234 files for processing3formatted 234 files (4 changed) in 588ms4 M ansible/files/admin_api_scripts/pg_upgrade_scripts/common.sh5 M ansible/files/admin_api_scripts/pg_upgrade_scripts/initiate.sh6 M ansible/files/admin_api_scripts/pg_upgrade_scripts/prepare.sh7 M ansible/files/admin_api_scripts/pg_upgrade_scripts/start_guard.sh8diff --git a/ansible/files/admin_api_scripts/pg_upgrade_scripts/common.sh b/ansible/files/admin_api_scripts/pg_upgrade_scripts/common.sh9index 671c392..1cbe9f2 10075510--- a/ansible/files/admin_api_scripts/pg_upgrade_scripts/common.sh11+++ b/ansible/files/admin_api_scripts/pg_upgrade_scripts/common.sh12@@ -1,6 +1,6 @@13 #! /usr/bin/env bash14 15-# Common functions and variables used by 16+# Common functions and variables used by17 # prepare.sh, initiate.sh and complete.sh18 19 #staging/prod20diff --git a/ansible/files/admin_api_scripts/pg_upgrade_scripts/initiate.sh b/ansible/files/admin_api_scripts/pg_upgrade_scripts/initiate.sh21index bd01384..ca09fcb 10075522--- a/ansible/files/admin_api_scripts/pg_upgrade_scripts/initiate.sh23+++ b/ansible/files/admin_api_scripts/pg_upgrade_scripts/initiate.sh24@@ -133,11 +133,11 @@ cleanup() {25 # can fail under set -e, or the restart below would be refused.26 unblock_postgres_start || log "WARNING: failed to lift the postgres start block; check /run/systemd/system/postgresql.service.d"27 28- # jparem : $LOG_FILE exists, even if directory29- # ${MOUNT_POINT}/pgdata/pg_upgrade_output.d/ does not!30- # so removing the ship-ing of the log here rather than the conditional block31- # down there..32- # https://linear.app/supabase/issue/MPG-1531/initiatesh-call-ship-logs-no-matter-what33+ # jparem : $LOG_FILE exists, even if directory34+ # ${MOUNT_POINT}/pgdata/pg_upgrade_output.d/ does not!35+ # so removing the ship-ing of the log here rather than the conditional block36+ # down there..37+ # https://linear.app/supabase/issue/MPG-1531/initiatesh-call-ship-logs-no-matter-what38 ship_logs "$LOG_FILE" || true39 40 if [ -d "${MOUNT_POINT}/pgdata/pg_upgrade_output.d/" ]; then41@@ -661,71 +661,71 @@ EOF42 CI_stop_postgres43 fi44 45- #CHECKSUM_FLAG="--data-checksums" if the SOURCE cluster has checksums46- #CHECKSUM_FLAG="" if the SOURCE doesn't have them (yet)47- # in this case the following code adds them48+ #CHECKSUM_FLAG="--data-checksums" if the SOURCE cluster has checksums49+ #CHECKSUM_FLAG="" if the SOURCE doesn't have them (yet)50+ # in this case the following code adds them51 52- if [[ "$CHECKSUM_FLAG" == "" ]]; then53+ if [[ $CHECKSUM_FLAG == "" ]]; then54 55- # old db hasn't got checksum, we will enable it its overall size 56- # (${PGDATAOLD}) is <= 20 Gb57+ # old db hasn't got checksum, we will enable it its overall size58+ # (${PGDATAOLD}) is <= 20 Gb59 60- # 20 gb = 20 x 1024 x 1024 = 20971520 61- MAX_SIZE=2097152062- 63- PGDATAOLD_SIZE=$(du -sk "${PGDATAOLD}" | cut -f1)64+ # 20 gb = 20 x 1024 x 1024 = 2097152065+ MAX_SIZE=2097152066 67- if [[ "$PGDATAOLD_SIZE" -le "$MAX_SIZE" ]]; then68+ PGDATAOLD_SIZE=$(du -sk "${PGDATAOLD}" | cut -f1)69 70- log "9.1 adding checksums to SOURCE PG (<20 Gb)"71+ if [[ $PGDATAOLD_SIZE -le $MAX_SIZE ]]; then72 73- # we're adding a timer: the "pg_checksum -e" operation on ${PGDATAOLD} must74- # not run for more than 10 minutes otherwise we exist this code on error75- # ofc, if the pg_checksums detects a physical corruption, we have to exit76- # the program with a consistent message explaining the corruption77- 78- MAX_DURATION="10m"79- KILL_AFTER="15s"80+ log "9.1 adding checksums to SOURCE PG (<20 Gb)"81 82- timeout -k "${KILL_AFTER}" "${MAX_DURATION}" ${PGBINOLD}/pg_checksums -e "${PGDATAOLD}" || STATUS=$?83+ # we're adding a timer: the "pg_checksum -e" operation on ${PGDATAOLD} must84+ # not run for more than 10 minutes otherwise we exist this code on error85+ # ofc, if the pg_checksums detects a physical corruption, we have to exit86+ # the program with a consistent message explaining the corruption87 88- # if everything is fine, $STATUS hasn't been defined, 89- # so we initialize it with 0 because it's a success 90- STATUS=${STATUS:-0}91+ MAX_DURATION="10m"92+ KILL_AFTER="15s"93+94+ timeout -k "${KILL_AFTER}" "${MAX_DURATION}" ${PGBINOLD}/pg_checksums -e "${PGDATAOLD}" || STATUS=$?95+96+ # if everything is fine, $STATUS hasn't been defined,97+ # so we initialize it with 0 because it's a success98+ STATUS=${STATUS:-0}99 100 # we'll manage ERROR codes down there, to actually log anything101 # properly, for later diagnostic reading the $LOG_FILE into project102 # where it has been shipped ship_logs() in common.sh103 104- case $STATUS in105- 0) 106- log "adding checksums SUCCEEDED."107- ;;108- 124|137) 109- log "adding checksums FAILED. Max time (${MAX_DURATION}) reached! Process killed."110- exit 124111- ;;112- *)113- log "adding checksum FAILED with Error code ${STATUS}"114- exit "$STATUS"115- ;;116- esac117-118- # we're here if everything went well with STATUS=0119- # so now, checksums are enabled on the SOURCE! 120- CHECKSUM_FLAG="--data-checksums"121- 122- else123-124- log "9.1 did *not* add checksum to SOURCE PG: size $PGDATAOLD_SIZE > 20 Gb!"125-126- fi127-128- else129- 130- log "9.1 checksums already present on SOURCE"131-132- fi133+ case $STATUS in134+ 0)135+ log "adding checksums SUCCEEDED."136+ ;;137+ 124 | 137)138+ log "adding checksums FAILED. Max time (${MAX_DURATION}) reached! Process killed."139+ exit 124140+ ;;141+ *)142+ log "adding checksum FAILED with Error code ${STATUS}"143+ exit "$STATUS"144+ ;;145+ esac146+147+ # we're here if everything went well with STATUS=0148+ # so now, checksums are enabled on the SOURCE!149+ CHECKSUM_FLAG="--data-checksums"150+151+ else152+153+ log "9.1 did *not* add checksum to SOURCE PG: size $PGDATAOLD_SIZE > 20 Gb!"154+155+ fi156+157+ else158+159+ log "9.1 checksums already present on SOURCE"160+161+ fi162 163 log "10. Creating new data directory, initializing database"164 chown -R postgres:postgres "$MOUNT_POINT/"165diff --git a/ansible/files/admin_api_scripts/pg_upgrade_scripts/prepare.sh b/ansible/files/admin_api_scripts/pg_upgrade_scripts/prepare.sh166index 9b6e6a9..1598aaf 100755167--- a/ansible/files/admin_api_scripts/pg_upgrade_scripts/prepare.sh168+++ b/ansible/files/admin_api_scripts/pg_upgrade_scripts/prepare.sh169@@ -26,7 +26,7 @@ chmod 640 "$LOG_FILE"170 # file, a previous attempt has run and failed.171 RETRY=0172 if grep -qF "prepare.sh started" "$LOG_FILE"; then173- RETRY=1174+ RETRY=1175 fi176 177 # From here on, everything written to stdout/stderr (log messages, but also178@@ -44,8 +44,8 @@ trap 'log "prepare.sh FAILED at line $LINENO: \"$BASH_COMMAND\" (exit code $?)"'179 # Source the shared helpers (log and ship_logs functions)180 # shellcheck disable=SC1091181 source "$SCRIPT_DIR/common.sh" || {182- log "cannot source $SCRIPT_DIR/common.sh"183- exit 1184+ log "cannot source $SCRIPT_DIR/common.sh"185+ exit 1186 }187 188 # ship_logs reads these variables, and "set -u" would abort the script on an189@@ -61,23 +61,23 @@ source "$SCRIPT_DIR/common.sh" || {190 # retry, so the caller handles the "gave up" case.191 # The script's exit code is always preserved for the caller.192 on_exit() {193- local rc=$?194- trap - EXIT ERR # avoid re-entering the traps from inside this handler195-196- if [ "$rc" -eq 0 ]; then197- if [ "$RETRY" -eq 0 ]; then198- log "prepare.sh ended with no errors."199- else200- log "prepare.sh finally ended without error this time."201- fi202- # Single upload of the log file; never fatal203- if declare -F ship_logs >/dev/null; then204- ship_logs "$LOG_FILE" || log "Log upload failed (non-blocking)."205- else206- log "ship_logs is not available, log upload skipped."207- fi208- fi209- exit "$rc"210+ local rc=$?211+ trap - EXIT ERR # avoid re-entering the traps from inside this handler212+213+ if [ "$rc" -eq 0 ]; then214+ if [ "$RETRY" -eq 0 ]; then215+ log "prepare.sh ended with no errors."216+ else217+ log "prepare.sh finally ended without error this time."218+ fi219+ # Single upload of the log file; never fatal220+ if declare -F ship_logs >/dev/null; then221+ ship_logs "$LOG_FILE" || log "Log upload failed (non-blocking)."222+ else223+ log "ship_logs is not available, log upload skipped."224+ fi225+ fi226+ exit "$rc"227 }228 trap on_exit EXIT229 230@@ -86,7 +86,10 @@ trap on_exit EXIT231 log "prepare.sh started."232 233 # check that /data is actually mounted234-mountpoint -q /data || { log "/data is not mounted"; exit 1; }235+mountpoint -q /data || {236+ log "/data is not mounted"237+ exit 1238+}239 240 # stop postgresql: "systemctl stop blocks until the unit has fully stopped"241 # https://linear.app/supabase/issue/MPG-1283/harden-a-bit-preparesh#comment-cea7446f242@@ -95,17 +98,19 @@ systemctl stop postgresql243 244 # ...but let's still verify that the service is explicitly stopped245 if systemctl is-active --quiet postgresql; then246- log "postgresql service is still active!"; exit 1247+ log "postgresql service is still active!"248+ exit 1249 fi250 251 # ...and that there are no remaining postgres processes252 if pgrep -x postgres >/dev/null; then253- log "postgres processes are still alive!"; exit 1254+ log "postgres processes are still alive!"255+ exit 1256 fi257 258 # copy the pgsodium root key with proper owner and permissions259 install -m 600 -o postgres -g postgres \260- /etc/postgresql-custom/pgsodium_root.key /data/pgsodium_root.key261+ /etc/postgresql-custom/pgsodium_root.key /data/pgsodium_root.key262 263 # flush cached writes to persistent storage264 sync265@@ -113,12 +118,12 @@ sync266 # Unmount /data. Capture the native umount error message and route it through267 # "log" so that it is timestamped like the rest of the log entries.268 if ! umount_out=$(umount /data 2>&1); then269- log "Unable to unmount /data: $umount_out"270- # List the processes still using /data ("|| true" so a fuser failure271- # does not trigger the ERR trap and mask the real cause)272- log "Processes using /data:"273- log "$(ls -l /proc/* 2>/dev/null | grep "data" || true)"274- exit 1275+ log "Unable to unmount /data: $umount_out"276+ # List the processes still using /data ("|| true" so a fuser failure277+ # does not trigger the ERR trap and mask the real cause)278+ log "Processes using /data:"279+ log "$(ls -l /proc/* 2>/dev/null | grep "data" || true)"280+ exit 1281 fi282 283 # Reaching this point means success: the final message and the log upload284diff --git a/ansible/files/admin_api_scripts/pg_upgrade_scripts/start_guard.sh b/ansible/files/admin_api_scripts/pg_upgrade_scripts/start_guard.sh285index c40fe69..1537a5c 100755286--- a/ansible/files/admin_api_scripts/pg_upgrade_scripts/start_guard.sh287+++ b/ansible/files/admin_api_scripts/pg_upgrade_scripts/start_guard.sh288@@ -4,9 +4,9 @@289 # file copy. Sourced by initiate.sh and tests/pg_upgrade/test-start-guard.sh.290 # Expects log, IS_CI, PGDATAOLD and PGDATANEW from the caller.291 292-# From step 9 until cleanup, nothing may start the source postgres: 293-# 294-# If it has to run, "pg_checksums -e" will operate on the source postgres, and 295+# From step 9 until cleanup, nothing may start the source postgres:296+#297+# If it has to run, "pg_checksums -e" will operate on the source postgres, and298 # this one has to stay stopped during the whole operation299 #300 # pg_upgrade copies the data files without a postmaster holding the directory,