nixbot

builds

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

1treefmt v2.4.0traversed 940 files2emitted 234 files for processing3formatted 234 files (4 changed) in 604ms4 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 e31a74a..ecea3de 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@@ -657,71 +657,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 12c8e19..2583295 100755167--- a/ansible/files/admin_api_scripts/pg_upgrade_scripts/prepare.sh168+++ b/ansible/files/admin_api_scripts/pg_upgrade_scripts/prepare.sh169@@ -22,7 +22,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@@ -40,8 +40,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@@ -57,16 +57,16 @@ 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- log "prepare.sh ended with no errors."198- ship_logs "$LOG_FILE" completion || log "Log upload failed (non-blocking)."199- else200- ship_logs "$LOG_FILE" prepare-failed || log "Log upload failed (non-blocking)."201- fi202- exit "$rc"203+ local rc=$?204+ trap - EXIT ERR # avoid re-entering the traps from inside this handler205+206+ if [ "$rc" -eq 0 ]; then207+ log "prepare.sh ended with no errors."208+ ship_logs "$LOG_FILE" completion || log "Log upload failed (non-blocking)."209+ else210+ ship_logs "$LOG_FILE" prepare-failed || log "Log upload failed (non-blocking)."211+ fi212+ exit "$rc"213 }214 trap on_exit EXIT215 216@@ -75,7 +75,10 @@ trap on_exit EXIT217 log "prepare.sh started."218 219 # check that /data is actually mounted220-mountpoint -q /data || { log "/data is not mounted"; exit 1; }221+mountpoint -q /data || {222+ log "/data is not mounted"223+ exit 1224+}225 226 # stop postgresql: "systemctl stop blocks until the unit has fully stopped"227 # https://linear.app/supabase/issue/MPG-1283/harden-a-bit-preparesh#comment-cea7446f228@@ -84,17 +87,19 @@ systemctl stop postgresql229 230 # ...but let's still verify that the service is explicitly stopped231 if systemctl is-active --quiet postgresql; then232- log "postgresql service is still active!"; exit 1233+ log "postgresql service is still active!"234+ exit 1235 fi236 237 # ...and that there are no remaining postgres processes238 if pgrep -x postgres >/dev/null; then239- log "postgres processes are still alive!"; exit 1240+ log "postgres processes are still alive!"241+ exit 1242 fi243 244 # copy the pgsodium root key with proper owner and permissions245 install -m 600 -o postgres -g postgres \246- /etc/postgresql-custom/pgsodium_root.key /data/pgsodium_root.key247+ /etc/postgresql-custom/pgsodium_root.key /data/pgsodium_root.key248 249 # flush cached writes to persistent storage250 sync251@@ -102,12 +107,12 @@ sync252 # Unmount /data. Capture the native umount error message and route it through253 # "log" so that it is timestamped like the rest of the log entries.254 if ! umount_out=$(umount /data 2>&1); then255- log "Unable to unmount /data: $umount_out"256- # List the processes still using /data ("|| true" so a fuser failure257- # does not trigger the ERR trap and mask the real cause)258- log "Processes using /data:"259- log "$(ls -l /proc/*/fd /proc/*/cwd 2>/dev/null | grep ' /data' || true)"260- exit 1261+ log "Unable to unmount /data: $umount_out"262+ # List the processes still using /data ("|| true" so a fuser failure263+ # does not trigger the ERR trap and mask the real cause)264+ log "Processes using /data:"265+ log "$(ls -l /proc/*/fd /proc/*/cwd 2>/dev/null | grep ' /data' || true)"266+ exit 1267 fi268 269 # Reaching this point means success: the final message and the log upload270diff --git a/ansible/files/admin_api_scripts/pg_upgrade_scripts/start_guard.sh b/ansible/files/admin_api_scripts/pg_upgrade_scripts/start_guard.sh271index c40fe69..1537a5c 100755272--- a/ansible/files/admin_api_scripts/pg_upgrade_scripts/start_guard.sh273+++ b/ansible/files/admin_api_scripts/pg_upgrade_scripts/start_guard.sh274@@ -4,9 +4,9 @@275 # file copy. Sourced by initiate.sh and tests/pg_upgrade/test-start-guard.sh.276 # Expects log, IS_CI, PGDATAOLD and PGDATANEW from the caller.277 278-# From step 9 until cleanup, nothing may start the source postgres: 279-# 280-# If it has to run, "pg_checksums -e" will operate on the source postgres, and 281+# From step 9 until cleanup, nothing may start the source postgres:282+#283+# If it has to run, "pg_checksums -e" will operate on the source postgres, and284 # this one has to stay stopped during the whole operation285 #286 # pg_upgrade copies the data files without a postmaster holding the directory,