@calltelemetry/fmix 2.7.26 → 2.7.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/fmix +340 -6
- package/package.json +3 -3
package/bin/fmix
CHANGED
|
@@ -28,7 +28,7 @@ set -uo pipefail
|
|
|
28
28
|
# ---------------------------------------------------------------------------
|
|
29
29
|
# Constants & config
|
|
30
30
|
# ---------------------------------------------------------------------------
|
|
31
|
-
FMIX_VERSION="2.7.
|
|
31
|
+
FMIX_VERSION="2.7.27"
|
|
32
32
|
FMIX_HOME="${FMIX_HOME:-${HOME}/.ct-fmix}"
|
|
33
33
|
FMIX_OS="$(uname -s)"
|
|
34
34
|
FMIX_ARCH="$(uname -m)"
|
|
@@ -62,6 +62,14 @@ FMIX_TELEMETRY_TTL_HOURS="${FMIX_TELEMETRY_TTL_HOURS:-4}"
|
|
|
62
62
|
FMIX_TELEMETRY_TTL_MAX_HOURS="8760"
|
|
63
63
|
FMIX_LOCK_INIT_GRACE="${FMIX_LOCK_INIT_GRACE:-5}"
|
|
64
64
|
FMIX_LOCK_METADATA_TTL_DAYS="${FMIX_LOCK_METADATA_TTL_DAYS:-7}"
|
|
65
|
+
# REL-5395: content-addressed template DBs (ct_fmix_tmpl_*/ct_fmix_snap_*) are
|
|
66
|
+
# superseded by every migration or structure.sql change. Retire the ones unused
|
|
67
|
+
# for this many days, beyond the newest FMIX_TEMPLATE_KEEP per class.
|
|
68
|
+
FMIX_TEMPLATE_PRUNE="${FMIX_TEMPLATE_PRUNE:-1}"
|
|
69
|
+
FMIX_TEMPLATE_RETENTION_DAYS="${FMIX_TEMPLATE_RETENTION_DAYS:-7}"
|
|
70
|
+
FMIX_TEMPLATE_KEEP="${FMIX_TEMPLATE_KEEP:-3}"
|
|
71
|
+
FMIX_TEMPLATE_PRUNE_BATCH="${FMIX_TEMPLATE_PRUNE_BATCH:-8}"
|
|
72
|
+
FMIX_TEMPLATE_RETIRED_RC=201 # internal: a selected template was retired before its clone
|
|
65
73
|
FMIX_WORKTREE_LOCK_TIMEOUT="${FMIX_WORKTREE_LOCK_TIMEOUT:-360}"
|
|
66
74
|
# Session overlays are large (roughly 0.5 GiB each), so four hours is the
|
|
67
75
|
# retention default for both automatic housekeeping and explicit GC. Preserve
|
|
@@ -11210,7 +11218,13 @@ fmix_create_database() {
|
|
|
11210
11218
|
fmix_guard_db_name "$db_name" || return 1
|
|
11211
11219
|
if [[ -n "$template_name" ]]; then
|
|
11212
11220
|
case "$source_kind" in
|
|
11213
|
-
published)
|
|
11221
|
+
published)
|
|
11222
|
+
fmix_guard_template_db_name "$template_name" || return 1
|
|
11223
|
+
# Stamp use BEFORE the host DDL lock: retention re-reads this
|
|
11224
|
+
# stamp under the same lock, so a template a clone is about to
|
|
11225
|
+
# use is never retired out from under it (REL-5395).
|
|
11226
|
+
fmix_record_template_use "$template_name"
|
|
11227
|
+
;;
|
|
11214
11228
|
scratch-publish) fmix_guard_publish_source_db_name "$template_name" || return 1 ;;
|
|
11215
11229
|
*)
|
|
11216
11230
|
fmix_error "SAFETY: unknown CREATE DATABASE source kind '$source_kind'."
|
|
@@ -11253,13 +11267,22 @@ fmix_create_database() {
|
|
|
11253
11267
|
-v ON_ERROR_STOP=1 -c "$sql" 2>&1)"
|
|
11254
11268
|
rc=$?
|
|
11255
11269
|
if (( rc != 0 )); then
|
|
11256
|
-
|
|
11257
|
-
|
|
11270
|
+
local create_fail_rc=1
|
|
11271
|
+
# REL-5395: a published source retired by template retention between
|
|
11272
|
+
# selection and this clone is a reselect, not a failed run.
|
|
11273
|
+
if [[ "$source_kind" == "published" && -n "$template_name" \
|
|
11274
|
+
&& "$out" == *"template database \"${template_name}\" does not exist"* ]]; then
|
|
11275
|
+
fmix_warn "Template $template_name was retired before this clone; reselecting a base."
|
|
11276
|
+
create_fail_rc=$FMIX_TEMPLATE_RETIRED_RC
|
|
11277
|
+
else
|
|
11278
|
+
printf '%s\n' "$out" | tail -8 >&2
|
|
11279
|
+
fmix_error "CREATE DATABASE $db_name failed or exceeded ${timeout}s."
|
|
11280
|
+
fi
|
|
11258
11281
|
if [[ -n "$ddl_lock" ]]; then
|
|
11259
|
-
fmix_command_lock_finish "$ddl_lock"
|
|
11282
|
+
fmix_command_lock_finish "$ddl_lock" "$create_fail_rc"
|
|
11260
11283
|
return $?
|
|
11261
11284
|
fi
|
|
11262
|
-
return
|
|
11285
|
+
return "$create_fail_rc"
|
|
11263
11286
|
fi
|
|
11264
11287
|
if [[ -n "$ddl_lock" ]]; then
|
|
11265
11288
|
fmix_command_lock_finish "$ddl_lock" 0 || return $?
|
|
@@ -11989,10 +12012,232 @@ fmix_publish_hot_base() {
|
|
|
11989
12012
|
fmix_command_lock_finish "$lock" 1
|
|
11990
12013
|
return $?
|
|
11991
12014
|
}
|
|
12015
|
+
fmix_record_template_use "$target"
|
|
11992
12016
|
fmix_command_lock_finish "$lock" 0 || return $?
|
|
11993
12017
|
printf '%s\n' "$target"
|
|
11994
12018
|
}
|
|
11995
12019
|
|
|
12020
|
+
# ---------------------------------------------------------------------------
|
|
12021
|
+
# REL-5395: retired template retention
|
|
12022
|
+
#
|
|
12023
|
+
# Every migration-set change publishes a new ct_fmix_tmpl_<key> and every
|
|
12024
|
+
# structure.sql change builds a new ct_fmix_snap_<hash>. The orphan sweep skips
|
|
12025
|
+
# both prefixes by design (they are shared, not worktree-owned), so before this
|
|
12026
|
+
# nothing ever dropped a superseded template: 343 of them (~40 GiB) accumulated
|
|
12027
|
+
# on one host. Retention retires a published template only when ALL hold:
|
|
12028
|
+
# - its name is exactly ct_fmix_(tmpl|snap)_<16 hex> (nothing else is listed);
|
|
12029
|
+
# - it is not the template this run just published or cloned from;
|
|
12030
|
+
# - it is not among the newest FMIX_TEMPLATE_KEEP of its class by last use;
|
|
12031
|
+
# - it has not been used for FMIX_TEMPLATE_RETENTION_DAYS (rechecked under
|
|
12032
|
+
# the host DDL lock that every fmix CREATE DATABASE also takes);
|
|
12033
|
+
# - it has no live connection in pg_stat_activity, no lock held on it by an
|
|
12034
|
+
# in-flight CREATE DATABASE ... TEMPLATE, and no active CREATE DATABASE
|
|
12035
|
+
# statement naming it.
|
|
12036
|
+
# Retention is best effort: every failure is logged and skipped, and the
|
|
12037
|
+
# callers ignore its status, so a stuck template never fails a run.
|
|
12038
|
+
# ---------------------------------------------------------------------------
|
|
12039
|
+
|
|
12040
|
+
fmix_template_use_dir() {
|
|
12041
|
+
printf '%s/template-use\n' "$FMIX_HOME"
|
|
12042
|
+
}
|
|
12043
|
+
|
|
12044
|
+
fmix_is_retirable_template_name() {
|
|
12045
|
+
[[ "${1:-}" =~ ^ct_fmix_(tmpl|snap)_[0-9a-f]{16}$ ]]
|
|
12046
|
+
}
|
|
12047
|
+
|
|
12048
|
+
fmix_record_template_use() {
|
|
12049
|
+
local name="${1:-}" dir
|
|
12050
|
+
fmix_is_retirable_template_name "$name" || return 0
|
|
12051
|
+
dir="$(fmix_template_use_dir)"
|
|
12052
|
+
mkdir -p "$dir" 2>/dev/null && touch "$dir/$name" 2>/dev/null
|
|
12053
|
+
return 0
|
|
12054
|
+
}
|
|
12055
|
+
|
|
12056
|
+
fmix_template_last_used() {
|
|
12057
|
+
# Latest evidence of use: the use stamp, or for a hot base the publication
|
|
12058
|
+
# time of its db-index record. Prints 0 when neither exists.
|
|
12059
|
+
local name="$1" last=0 file mtime files
|
|
12060
|
+
files="$(fmix_template_use_dir)/$name"
|
|
12061
|
+
if [[ "$name" == ct_fmix_tmpl_* ]]; then
|
|
12062
|
+
files+=$'\n'"$(fmix_db_index_dir "${name#ct_fmix_tmpl_}")/meta.json"
|
|
12063
|
+
fi
|
|
12064
|
+
while IFS= read -r file; do
|
|
12065
|
+
[[ -f "$file" ]] || continue
|
|
12066
|
+
mtime="$(fmix_stat_mtime "$file" 2>/dev/null)"
|
|
12067
|
+
[[ "$mtime" =~ ^[0-9]+$ ]] || continue
|
|
12068
|
+
(( mtime > last )) && last="$mtime"
|
|
12069
|
+
done <<<"$files"
|
|
12070
|
+
printf '%s\n' "$last"
|
|
12071
|
+
}
|
|
12072
|
+
|
|
12073
|
+
fmix_select_retired_templates() {
|
|
12074
|
+
# Reads candidate datnames on stdin; prints the retired ones oldest first.
|
|
12075
|
+
# A template with no use evidence (published before retention existed, or
|
|
12076
|
+
# by another FMIX_HOME) starts its retention clock now instead of being
|
|
12077
|
+
# dropped on first sight.
|
|
12078
|
+
local now="$1" retention_seconds="$2" keep="$3"
|
|
12079
|
+
shift 3
|
|
12080
|
+
local name last protected p rows=""
|
|
12081
|
+
while IFS= read -r name; do
|
|
12082
|
+
name="$(printf '%s' "$name" | tr -d '[:space:]')"
|
|
12083
|
+
fmix_is_retirable_template_name "$name" || continue
|
|
12084
|
+
protected=0
|
|
12085
|
+
for p in "$@"; do
|
|
12086
|
+
[[ "$p" == "$name" ]] && protected=1
|
|
12087
|
+
done
|
|
12088
|
+
last="$(fmix_template_last_used "$name")"
|
|
12089
|
+
if [[ ! "$last" =~ ^[1-9][0-9]*$ ]]; then
|
|
12090
|
+
[[ "${FMIX_TEMPLATE_SELECT_REPORT_ONLY:-0}" == "1" ]] || fmix_record_template_use "$name"
|
|
12091
|
+
last="$now"
|
|
12092
|
+
fi
|
|
12093
|
+
rows+="${name%_*} ${last} ${protected} ${name}"$'\n'
|
|
12094
|
+
done
|
|
12095
|
+
[[ -n "$rows" ]] || return 0
|
|
12096
|
+
printf '%s' "$rows" \
|
|
12097
|
+
| LC_ALL=C sort -k1,1 -k2,2nr -k4,4 \
|
|
12098
|
+
| awk -v now="$now" -v ret="$retention_seconds" -v keep="$keep" '
|
|
12099
|
+
$1 != class { class = $1; rank = 0 }
|
|
12100
|
+
{ rank++ }
|
|
12101
|
+
rank <= keep { next }
|
|
12102
|
+
$3 == 1 { next }
|
|
12103
|
+
now - $2 <= ret { next }
|
|
12104
|
+
{ print $2 " " $4 }' \
|
|
12105
|
+
| LC_ALL=C sort -k1,1n -k2,2 \
|
|
12106
|
+
| cut -d' ' -f2
|
|
12107
|
+
}
|
|
12108
|
+
|
|
12109
|
+
fmix_drop_retired_template() {
|
|
12110
|
+
# Returns 0 dropped, 1 failed (logged), 3 skipped because it is in use or
|
|
12111
|
+
# no longer a published template. Never terminates a backend.
|
|
12112
|
+
local name="$1" state conns locks creates out
|
|
12113
|
+
fmix_is_retirable_template_name "$name" || {
|
|
12114
|
+
fmix_warn "SAFETY: refusing to retire '$name' — not an fmix tmpl/snap template name."
|
|
12115
|
+
return 1
|
|
12116
|
+
}
|
|
12117
|
+
fmix_guard_template_db_name "$name" || return 1
|
|
12118
|
+
state="$(fmix_control_psql 5 -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d postgres -tAc "
|
|
12119
|
+
SELECT (SELECT count(*) FROM pg_stat_activity a
|
|
12120
|
+
WHERE a.datname = d.datname AND a.pid <> pg_backend_pid())
|
|
12121
|
+
|| '|' ||
|
|
12122
|
+
(SELECT count(*) FROM pg_locks l
|
|
12123
|
+
WHERE l.locktype = 'object' AND l.classid = 'pg_database'::regclass
|
|
12124
|
+
AND l.objid = d.oid AND l.pid <> pg_backend_pid())
|
|
12125
|
+
|| '|' ||
|
|
12126
|
+
(SELECT count(*) FROM pg_stat_activity a
|
|
12127
|
+
WHERE a.pid <> pg_backend_pid() AND a.state IS DISTINCT FROM 'idle'
|
|
12128
|
+
AND a.query ~* 'create[[:space:]]+database'
|
|
12129
|
+
AND strpos(a.query, d.datname) > 0)
|
|
12130
|
+
FROM pg_database d
|
|
12131
|
+
WHERE d.datname = '${name}' AND d.datistemplate AND NOT d.datallowconn" \
|
|
12132
|
+
2>/dev/null | tr -d '[:space:]')"
|
|
12133
|
+
if [[ -z "$state" ]]; then
|
|
12134
|
+
return 3
|
|
12135
|
+
fi
|
|
12136
|
+
if [[ ! "$state" =~ ^([0-9]+)\|([0-9]+)\|([0-9]+)$ ]]; then
|
|
12137
|
+
fmix_warn "Template retention could not read activity for $name; keeping it."
|
|
12138
|
+
return 1
|
|
12139
|
+
fi
|
|
12140
|
+
conns="${BASH_REMATCH[1]}" locks="${BASH_REMATCH[2]}" creates="${BASH_REMATCH[3]}"
|
|
12141
|
+
if (( conns > 0 )); then
|
|
12142
|
+
fmix_warn "Keeping retired template $name: $conns live connection(s)."
|
|
12143
|
+
return 3
|
|
12144
|
+
fi
|
|
12145
|
+
if (( locks > 0 || creates > 0 )); then
|
|
12146
|
+
fmix_warn "Keeping retired template $name: an in-flight CREATE DATABASE is using it."
|
|
12147
|
+
return 3
|
|
12148
|
+
fi
|
|
12149
|
+
# PostgreSQL refuses to drop a template database; clear the flag first.
|
|
12150
|
+
# ALLOW_CONNECTIONS stays false, so nobody can connect in between.
|
|
12151
|
+
if ! fmix_control_psql 10 -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d postgres \
|
|
12152
|
+
-v ON_ERROR_STOP=1 -c "ALTER DATABASE \"${name}\" IS_TEMPLATE false" >/dev/null 2>&1; then
|
|
12153
|
+
fmix_warn "Could not unmark retired template $name; keeping it."
|
|
12154
|
+
return 1
|
|
12155
|
+
fi
|
|
12156
|
+
if ! out="$(fmix_control_psql 10 -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d postgres \
|
|
12157
|
+
-v ON_ERROR_STOP=1 -c "DROP DATABASE IF EXISTS \"${name}\"" 2>&1)"; then
|
|
12158
|
+
# Restore the published state so readiness checks keep trusting it.
|
|
12159
|
+
fmix_control_psql 10 -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d postgres \
|
|
12160
|
+
-c "ALTER DATABASE \"${name}\" IS_TEMPLATE true" >/dev/null 2>&1 \
|
|
12161
|
+
|| fmix_warn "Could not restore IS_TEMPLATE on $name after a failed drop."
|
|
12162
|
+
fmix_warn "Could not drop retired template $name; keeping it: $(printf '%s' "$out" | tail -1)"
|
|
12163
|
+
return 1
|
|
12164
|
+
fi
|
|
12165
|
+
rm -f "$(fmix_template_use_dir)/$name" 2>/dev/null
|
|
12166
|
+
if [[ "$name" == ct_fmix_tmpl_* ]]; then
|
|
12167
|
+
local key="${name#ct_fmix_tmpl_}" dir
|
|
12168
|
+
dir="$(fmix_db_index_dir "$key")"
|
|
12169
|
+
if [[ -d "$dir" && "$(fmix_read_db_index_field "$key" base_id)" == "$name" ]] \
|
|
12170
|
+
&& fmix_guard_path "$dir" 2>/dev/null; then
|
|
12171
|
+
rm -rf "$dir" 2>/dev/null \
|
|
12172
|
+
|| fmix_warn "Dropped $name but could not remove its db-index record."
|
|
12173
|
+
fi
|
|
12174
|
+
fi
|
|
12175
|
+
return 0
|
|
12176
|
+
}
|
|
12177
|
+
|
|
12178
|
+
fmix_list_published_templates() {
|
|
12179
|
+
fmix_control_psql 5 -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d postgres -tAc \
|
|
12180
|
+
"SELECT datname FROM pg_database WHERE datistemplate AND NOT datallowconn AND datname ~ '^ct_fmix_(tmpl|snap)_[0-9a-f]{16}\$' ORDER BY datname" \
|
|
12181
|
+
2>/dev/null
|
|
12182
|
+
}
|
|
12183
|
+
|
|
12184
|
+
fmix_prune_retired_template_dbs() {
|
|
12185
|
+
# Usage: fmix_prune_retired_template_dbs <context> <batch|0=all> [protected...]
|
|
12186
|
+
# Best effort by contract: always returns 0.
|
|
12187
|
+
local context="$1" batch="$2"
|
|
12188
|
+
shift 2
|
|
12189
|
+
case "$FMIX_TEMPLATE_PRUNE" in
|
|
12190
|
+
0|false|FALSE|no|NO|off|OFF) return 0 ;;
|
|
12191
|
+
esac
|
|
12192
|
+
local days keep retention_seconds now listing candidates name
|
|
12193
|
+
local dropped=0 kept=0 failed=0 attempted=0 rc ddl_lock="" last
|
|
12194
|
+
days="$(fmix_uint_or_default "$FMIX_TEMPLATE_RETENTION_DAYS" 7 FMIX_TEMPLATE_RETENTION_DAYS)"
|
|
12195
|
+
keep="$(fmix_uint_or_default "$FMIX_TEMPLATE_KEEP" 3 FMIX_TEMPLATE_KEEP)"
|
|
12196
|
+
retention_seconds=$(( days * 86400 ))
|
|
12197
|
+
now="$(fmix_epoch)"
|
|
12198
|
+
listing="$(fmix_list_published_templates)" || {
|
|
12199
|
+
fmix_warn "Template retention ($context): could not list template databases; skipping."
|
|
12200
|
+
return 0
|
|
12201
|
+
}
|
|
12202
|
+
candidates="$(printf '%s\n' "$listing" \
|
|
12203
|
+
| fmix_select_retired_templates "$now" "$retention_seconds" "$keep" "$@")"
|
|
12204
|
+
[[ -n "$candidates" ]] || return 0
|
|
12205
|
+
fmix_host_test_lock_enabled && ddl_lock="$(fmix_host_test_lock_name)"
|
|
12206
|
+
while IFS= read -r name; do
|
|
12207
|
+
[[ -n "$name" ]] || continue
|
|
12208
|
+
if [[ "$batch" =~ ^[1-9][0-9]*$ ]] && (( attempted >= batch )); then
|
|
12209
|
+
break
|
|
12210
|
+
fi
|
|
12211
|
+
attempted=$(( attempted + 1 ))
|
|
12212
|
+
if [[ -n "$ddl_lock" ]] && ! fmix_lock_acquire "$ddl_lock" 5 >/dev/null 2>&1; then
|
|
12213
|
+
fmix_warn "Template retention ($context): host DDL lock is busy; deferring the rest."
|
|
12214
|
+
break
|
|
12215
|
+
fi
|
|
12216
|
+
# A clone stamps use before it waits for this lock; recheck under it.
|
|
12217
|
+
last="$(fmix_template_last_used "$name")"
|
|
12218
|
+
if [[ "$last" =~ ^[0-9]+$ ]] && (( now - last <= retention_seconds )); then
|
|
12219
|
+
rc=3
|
|
12220
|
+
else
|
|
12221
|
+
rc=0
|
|
12222
|
+
fmix_drop_retired_template "$name" || rc=$?
|
|
12223
|
+
fi
|
|
12224
|
+
if [[ -n "$ddl_lock" ]] && ! fmix_lock_release "$ddl_lock" >/dev/null 2>&1; then
|
|
12225
|
+
fmix_warn "Template retention ($context): could not release the host DDL lock; stopping."
|
|
12226
|
+
case "$rc" in 0) dropped=$(( dropped + 1 )) ;; 3) kept=$(( kept + 1 )) ;; *) failed=$(( failed + 1 )) ;; esac
|
|
12227
|
+
break
|
|
12228
|
+
fi
|
|
12229
|
+
case "$rc" in
|
|
12230
|
+
0) dropped=$(( dropped + 1 )); fmix_info "Template retention ($context): dropped retired template $name." ;;
|
|
12231
|
+
3) kept=$(( kept + 1 )) ;;
|
|
12232
|
+
*) failed=$(( failed + 1 )) ;;
|
|
12233
|
+
esac
|
|
12234
|
+
done <<<"$candidates"
|
|
12235
|
+
if (( dropped + kept + failed > 0 )); then
|
|
12236
|
+
fmix_info "Template retention ($context): dropped=$dropped kept_in_use=$kept failed=$failed."
|
|
12237
|
+
fi
|
|
12238
|
+
return 0
|
|
12239
|
+
}
|
|
12240
|
+
|
|
11996
12241
|
fmix_migrate_from_zero() {
|
|
11997
12242
|
# API-2846: bootstrap fallback for when structure.sql is unusable for
|
|
11998
12243
|
# cold bootstrap (missing, or fails fmix_structure_matches_migration_
|
|
@@ -12300,6 +12545,13 @@ fmix_ensure_db() {
|
|
|
12300
12545
|
rc=0
|
|
12301
12546
|
_fmix_ensure_db_impl "$@" || rc=$?
|
|
12302
12547
|
fi
|
|
12548
|
+
if (( rc == FMIX_TEMPLATE_RETIRED_RC )); then
|
|
12549
|
+
# REL-5395: the selected template was retired concurrently and its
|
|
12550
|
+
# db-index record went with it. Nothing was created; select once more.
|
|
12551
|
+
rc=0
|
|
12552
|
+
_fmix_ensure_db_impl "$@" || rc=$?
|
|
12553
|
+
(( rc != FMIX_TEMPLATE_RETIRED_RC )) || rc=1
|
|
12554
|
+
fi
|
|
12303
12555
|
return "$rc"
|
|
12304
12556
|
}
|
|
12305
12557
|
|
|
@@ -12409,6 +12661,7 @@ _fmix_ensure_db_impl() {
|
|
|
12409
12661
|
if [[ -n "$selection" ]]; then
|
|
12410
12662
|
IFS=$'\t' read -r base base_key delta <<<"$selection"
|
|
12411
12663
|
fmix_guard_template_db_name "$base" || return 1
|
|
12664
|
+
fmix_record_template_use "$base"
|
|
12412
12665
|
fmix_info "Selected $base from metadata (schema=$base_key, delta=$delta); performing one clone."
|
|
12413
12666
|
fmix_create_database "$db_name" "$base" || return $?
|
|
12414
12667
|
FMIX_ACTIVE_DB_CLEAN_BOOTSTRAP=1
|
|
@@ -12419,6 +12672,7 @@ _fmix_ensure_db_impl() {
|
|
|
12419
12672
|
local snapshot_rc=1
|
|
12420
12673
|
if [[ "$force_from_zero" != "1" ]]; then
|
|
12421
12674
|
snap="$(fmix_ensure_snapshot_template "$worktree")" && snapshot_rc=0 || snapshot_rc=$?
|
|
12675
|
+
(( snapshot_rc != 0 )) || fmix_record_template_use "$snap"
|
|
12422
12676
|
(( snapshot_rc == 0 || snapshot_rc == 1 )) || return "$snapshot_rc"
|
|
12423
12677
|
fi
|
|
12424
12678
|
if (( snapshot_rc == 0 )); then
|
|
@@ -16231,6 +16485,14 @@ cmd_setup() {
|
|
|
16231
16485
|
fmix_error "Setup completion failed (template access rc=$setup_access_rc, final rc=$setup_finish_rc)."
|
|
16232
16486
|
return "$setup_finish_rc"
|
|
16233
16487
|
fi
|
|
16488
|
+
# REL-5395: a publish supersedes older templates. Retire a bounded batch
|
|
16489
|
+
# now, after the session lock is released; best effort, never fatal.
|
|
16490
|
+
if [[ "${FMIX_ACTIVE_DB_CLEAN_BOOTSTRAP:-0}" == "1" ]]; then
|
|
16491
|
+
# Subshell: lock-keeper state from a failed acquire cannot leak into
|
|
16492
|
+
# this run's exit status.
|
|
16493
|
+
( fmix_prune_retired_template_dbs setup "$FMIX_TEMPLATE_PRUNE_BATCH" \
|
|
16494
|
+
"$published_base" "${FMIX_ACTIVE_DB_BASE_ID:-}" ) || true
|
|
16495
|
+
fi
|
|
16234
16496
|
if [[ "${FMIX_ACTIVE_DB_CLEAN_BOOTSTRAP:-0}" == "1" ]]; then
|
|
16235
16497
|
fmix_info "=== setup complete; hot DB base: $published_base ==="
|
|
16236
16498
|
else
|
|
@@ -18451,6 +18713,39 @@ cmd_runner() {
|
|
|
18451
18713
|
# cmd: fmix task
|
|
18452
18714
|
# ---------------------------------------------------------------------------
|
|
18453
18715
|
|
|
18716
|
+
fmix_task_provision_test_db() {
|
|
18717
|
+
# Artifacts and the scratch DB are separate lifecycles. A session created by
|
|
18718
|
+
# `fmix task` clones artifacts and records db_name in worktree state without
|
|
18719
|
+
# creating ct_fmix_s_<session>, and every later task then matched the warm
|
|
18720
|
+
# artifacts and ran Mix against a missing database. Provision the session DB
|
|
18721
|
+
# through the same fmix_ensure_db path `fmix test` uses, before Mix starts.
|
|
18722
|
+
# An explicit --database name is verified and never created here.
|
|
18723
|
+
local worktree="$1" db_name="$2" task_db_name="$3"
|
|
18724
|
+
if ! fmix_control_psql 5 -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d postgres \
|
|
18725
|
+
-c "SELECT 1" >/dev/null 2>&1; then
|
|
18726
|
+
fmix_error "Postgres at ${DB_HOST}:${DB_PORT} is unreachable; fmix task cannot verify session DB ${task_db_name}."
|
|
18727
|
+
fmix_error "Start the Postgres container (ct-infra-postgres) and retry. Mix was not started."
|
|
18728
|
+
return 1
|
|
18729
|
+
fi
|
|
18730
|
+
if [[ "$task_db_name" != "$db_name" ]]; then
|
|
18731
|
+
if fmix_db_exists "$task_db_name"; then
|
|
18732
|
+
return 0
|
|
18733
|
+
fi
|
|
18734
|
+
fmix_error "Named database ${task_db_name} does not exist. fmix task does not create an explicit --database. Mix was not started."
|
|
18735
|
+
return 1
|
|
18736
|
+
fi
|
|
18737
|
+
if ! fmix_db_exists "$db_name"; then
|
|
18738
|
+
fmix_warn "Session DB ${db_name} is missing; provisioning it as fmix test does."
|
|
18739
|
+
fi
|
|
18740
|
+
fmix_ensure_db "$worktree" "$db_name" 0 0 0 || {
|
|
18741
|
+
local ensure_rc=$?
|
|
18742
|
+
fmix_error "Session DB ${db_name} is missing and could not be provisioned (rc=${ensure_rc}). Mix was not started."
|
|
18743
|
+
fmix_error "Reprovision it with: fmix test --worktree ${worktree} -- <test file>"
|
|
18744
|
+
return "$ensure_rc"
|
|
18745
|
+
}
|
|
18746
|
+
return 0
|
|
18747
|
+
}
|
|
18748
|
+
|
|
18454
18749
|
cmd_task() {
|
|
18455
18750
|
# Run a non-test Mix task against the same exact pinned runtime and
|
|
18456
18751
|
# session-local incremental deps/_build state as fmix setup/test. This is
|
|
@@ -18561,6 +18856,13 @@ cmd_task() {
|
|
|
18561
18856
|
fmix_command_lock_finish "$lock_name" "$task_rc" 1
|
|
18562
18857
|
return $?
|
|
18563
18858
|
}
|
|
18859
|
+
if [[ "$mix_env_arg" == "test" ]]; then
|
|
18860
|
+
fmix_task_provision_test_db "$real_worktree" "$db_name" "$task_db_name" || {
|
|
18861
|
+
task_rc=$?
|
|
18862
|
+
fmix_command_lock_finish "$lock_name" "$task_rc" 1
|
|
18863
|
+
return $?
|
|
18864
|
+
}
|
|
18865
|
+
fi
|
|
18564
18866
|
|
|
18565
18867
|
local -a build_env=()
|
|
18566
18868
|
[[ -n "${MIX_BUILD_PATH:-}" ]] && build_env+=("MIX_BUILD_PATH=$MIX_BUILD_PATH")
|
|
@@ -22420,6 +22722,34 @@ cmd_gc() {
|
|
|
22420
22722
|
done <<<"$all_fmix_dbs"
|
|
22421
22723
|
fi
|
|
22422
22724
|
|
|
22725
|
+
# REL-5395: superseded content-addressed templates. Report the retired set;
|
|
22726
|
+
# --reap drops it through the guarded, best-effort retention path.
|
|
22727
|
+
echo ""
|
|
22728
|
+
echo "--- Retired template DBs (unused > ${FMIX_TEMPLATE_RETENTION_DAYS} days, beyond newest ${FMIX_TEMPLATE_KEEP} per class) ---"
|
|
22729
|
+
local retired_templates retired_days retired_keep
|
|
22730
|
+
retired_days="$(fmix_uint_or_default "$FMIX_TEMPLATE_RETENTION_DAYS" 7 FMIX_TEMPLATE_RETENTION_DAYS)"
|
|
22731
|
+
retired_keep="$(fmix_uint_or_default "$FMIX_TEMPLATE_KEEP" 3 FMIX_TEMPLATE_KEEP)"
|
|
22732
|
+
retired_templates="$(fmix_list_published_templates \
|
|
22733
|
+
| FMIX_TEMPLATE_SELECT_REPORT_ONLY=$(( 1 - do_reap )) fmix_select_retired_templates \
|
|
22734
|
+
"$(fmix_epoch)" "$(( retired_days * 86400 ))" "$retired_keep")"
|
|
22735
|
+
if [[ -n "$retired_templates" ]]; then
|
|
22736
|
+
while IFS= read -r pgdb; do
|
|
22737
|
+
[[ -n "$pgdb" ]] || continue
|
|
22738
|
+
echo " RETIRED-TEMPLATE: $pgdb"
|
|
22739
|
+
actions=$(( actions + 1 ))
|
|
22740
|
+
done <<<"$retired_templates"
|
|
22741
|
+
if (( do_reap == 1 )); then
|
|
22742
|
+
local confirm_rt="y"
|
|
22743
|
+
if (( skip_prompts == 0 )); then
|
|
22744
|
+
printf ' Drop retired templates that are not in use? [y/N] '
|
|
22745
|
+
read -r confirm_rt
|
|
22746
|
+
fi
|
|
22747
|
+
if [[ "$confirm_rt" =~ ^[Yy]$ ]]; then
|
|
22748
|
+
( fmix_prune_retired_template_dbs gc 0 ) || true
|
|
22749
|
+
fi
|
|
22750
|
+
fi
|
|
22751
|
+
fi
|
|
22752
|
+
|
|
22423
22753
|
# Incomplete producer staging can still be a recovery/verifier input.
|
|
22424
22754
|
# Age alone never releases it, including through the legacy mixed GC.
|
|
22425
22755
|
echo ""
|
|
@@ -27738,6 +28068,10 @@ Environment overrides:
|
|
|
27738
28068
|
FMIX_DB_PRESSURE_MIN_AGE Sustained wait age in seconds (default: 10)
|
|
27739
28069
|
FMIX_DB_CREATE_TIMEOUT CREATE DATABASE statement cap in seconds (default: 60)
|
|
27740
28070
|
FMIX_DB_DROP_TIMEOUT DROP DATABASE statement cap in seconds (default: 30)
|
|
28071
|
+
FMIX_TEMPLATE_PRUNE Set to 0 to disable retired template retention (default: 1)
|
|
28072
|
+
FMIX_TEMPLATE_RETENTION_DAYS Retire tmpl/snap templates unused this long (default: 7)
|
|
28073
|
+
FMIX_TEMPLATE_KEEP Newest tmpl/snap templates always kept per class (default: 3)
|
|
28074
|
+
FMIX_TEMPLATE_PRUNE_BATCH Retired templates dropped per setup (default: 8; gc --reap drops all)
|
|
27741
28075
|
FMIX_MIGRATION_DELTA_LIMIT Maximum migrations applied from a selected base (default: 50)
|
|
27742
28076
|
FMIX_COMPILE_HEARTBEAT Silent compile heartbeat seconds (default: 30; 0 disables)
|
|
27743
28077
|
FMIX_COMPILE_TIMEOUT Per-attempt compile cap in seconds (default: 900)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@calltelemetry/fmix",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.27",
|
|
4
4
|
"description": "Verified native FMix runner for CallTelemetry workspaces",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"directory": "packages/npm"
|
|
27
27
|
},
|
|
28
28
|
"fmix": {
|
|
29
|
-
"runnerSha256": "
|
|
30
|
-
"sourceTag": "fmix-v2.7.
|
|
29
|
+
"runnerSha256": "79915aeb7ff03adeb3308c73fa5363b4d6fa59ace54813a607c0e43ec500f028",
|
|
30
|
+
"sourceTag": "fmix-v2.7.27"
|
|
31
31
|
}
|
|
32
32
|
}
|