salvage 2026-11-06: uncommitted work from scratch/darkwing-scratch/r181/wt (disk cleanup #824)
This commit is contained in:
1 parent
a757f8fe64
commit
f803aaece7
3 files changed
+129
-16
No files matched your search
+31
-12
@@ -36,6 +36,8 @@ usage: stack-release.sh adopt BUSINESS
|
||||
stack-release.sh rollback BUSINESS [--restore ACTIVATION [--events N]] [--timeout S] [--plan]
|
||||
stack-release.sh status BUSINESS
|
||||
common options: --copies DIR, --bin DIR
|
||||
--events N is the total of the per-table counts the post-backup-events refusal prints: events and
|
||||
every table in COUNTED.
|
||||
USAGE
|
||||
exit "${1:-4}"
|
||||
}
|
||||
@@ -288,16 +290,32 @@ plugin_checks() {
|
||||
|
||||
# --- The store ---
|
||||
|
||||
# Row 181: the tables a bus writer fills without an event in the same transaction, in schema
|
||||
# order. A restore drops their rows after STAMP as it drops events, so the guard counts them too.
|
||||
# BUILD.md for row 181 names each writer; the T46 guard classifies every table in the schema.
|
||||
COUNTED="role_claims thread_claims decision_events messages deliveries task_snapshots projects threads thread_opens instance_names usage_records"
|
||||
|
||||
STORE_JS='
|
||||
const {DatabaseSync}=require("node:sqlite");const {pathToFileURL}=require("node:url");
|
||||
const [mode,file,stamp]=process.argv.slice(1);
|
||||
const [mode,file,stamp,tables=""]=process.argv.slice(1);
|
||||
// immutable=1 on a stopped store with no -wal or -shm: it creates no file and leaves the main
|
||||
// file mtime and sha256 as they were (the row 162 probe). A plain readOnly open of a stopped
|
||||
// WAL store creates -shm and -wal, so it is used only on a store the running bus holds.
|
||||
const db=mode.startsWith("held")?new DatabaseSync(file,{readOnly:true}):new DatabaseSync(pathToFileURL(file).href+"?immutable=1",{readOnly:true});
|
||||
try{
|
||||
if(mode.endsWith("version"))process.stdout.write(db.prepare("SELECT value FROM meta WHERE key=?").get("schema_version").value+"\n");
|
||||
else process.stdout.write(db.prepare("SELECT count(*) AS n FROM events WHERE at > ?").get(stamp).n+"\n");
|
||||
else{
|
||||
// "TOTAL<tab>TEXT": events, then each listed table with rows after STAMP, in list order. A
|
||||
// listed table the store lacks counts 0 (no instance_names before 3g, no usage_records before
|
||||
// 3h). One that is there but cannot be read throws, as a failed events count does.
|
||||
const ev=db.prepare("SELECT count(*) AS n FROM events WHERE at > ?").get(stamp).n;let total=ev,text=ev+" event(s)";
|
||||
for(const t of tables.split(" ").filter(Boolean)){
|
||||
if(!db.prepare("SELECT 1 FROM sqlite_master WHERE type=? AND name=?").get("table",t))continue;
|
||||
const n=db.prepare("SELECT count(*) AS n FROM "+t+" WHERE at > ?").get(stamp).n;
|
||||
if(n){total+=n;text+=", "+n+" "+t+" row(s)"}
|
||||
}
|
||||
process.stdout.write(total+"\t"+text+"\n");
|
||||
}
|
||||
}finally{db.close()}'
|
||||
|
||||
# Sets UNCLEAN and returns 0 when a -wal or -shm sits beside the store. An immutable read would
|
||||
@@ -310,8 +328,8 @@ store_unclean() {
|
||||
done
|
||||
return 1
|
||||
}
|
||||
# A read of the stopped store: version, or count STAMP. Call store_unclean first.
|
||||
store_read() { node -e "$STORE_JS" -- "$1" "$STORE" "${2:-}"; }
|
||||
# A read of the stopped store: version, or count STAMP TABLES. Call store_unclean first.
|
||||
store_read() { node -e "$STORE_JS" -- "$1" "$STORE" "${2:-}" "${3:-}"; }
|
||||
|
||||
# No writer.lock, and no process with a file open under <dataRoot>/bus/ (stopped-check.sh's
|
||||
# test). One find over the /proc fd links, not a readlink per link: this host has about 16,000.
|
||||
@@ -824,8 +842,8 @@ run_steps() {
|
||||
[ "$STORE_SCHEMA" = "$P_SCHEMA" ] || rollback_in_run store-differs
|
||||
if [ -n "$RESTORE" ]; then
|
||||
local n
|
||||
n="$(store_read count "$(cat "$DATA/backups/stack/$RESTORE/STAMP")")" || rollback_in_run schema-unreadable
|
||||
[ "$n" = "$COUNT" ] || rollback_in_run post-backup-events
|
||||
n="$(store_read count "$(cat "$DATA/backups/stack/$RESTORE/STAMP")" "$COUNTED")" || rollback_in_run schema-unreadable
|
||||
[ "${n%%$'\t'*}" = "$COUNT" ] || rollback_in_run post-backup-events
|
||||
restore_store "$RESTORE" || after_fail restore
|
||||
fi
|
||||
fi
|
||||
@@ -880,22 +898,23 @@ do_rollback() {
|
||||
[ "$P_SCHEMA" = "$T_SCHEMA" ] || [ -n "$RESTORE" ] || refuse schema-differs "the store is at $P_SCHEMA and $TO expects $T_SCHEMA; pass --restore ACTIVATION"
|
||||
new_activation
|
||||
if [ -n "$RESTORE" ]; then
|
||||
local o="$DATA/backups/stack/$RESTORE" rc=0
|
||||
local o="$DATA/backups/stack/$RESTORE" rc=0 c="" text
|
||||
[ -f "$o/SHA256SUMS" ] && [ "$(cat "$o/DATA_ROOT" 2>/dev/null)" = "$DATA" ] && [ "$(cat "$o/SCHEMA" 2>/dev/null)" = "$T_SCHEMA" ] && [ -f "$o/STAMP" ] \
|
||||
|| refuse restore-mismatch "$o is not a backup of this root at $T_SCHEMA"
|
||||
# Before anything stops. A store the running bus holds is read with readOnly, which adds
|
||||
# no file (the probe); a stopped one falls under the store_unclean rule.
|
||||
if systemctl --user is-active --quiet "$BUS_UNIT"; then
|
||||
COUNT="$(node -e "$STORE_JS" -- heldcount "$STORE" "$(cat "$o/STAMP")")" || rc=1
|
||||
c="$(node -e "$STORE_JS" -- heldcount "$STORE" "$(cat "$o/STAMP")" "$COUNTED")" || rc=1
|
||||
# plan_store's recheck (row 166 item 2), before anything stops.
|
||||
systemctl --user is-active --quiet "$BUS_UNIT" || refuse restore-mismatch "the bus stopped while the events after $(cat "$o/STAMP") were counted, so the store state changed; nothing was stopped"
|
||||
else
|
||||
! store_unclean || refuse store-unclean "$UNCLEAN is present; the bus did not close the store cleanly"
|
||||
COUNT="$(store_read count "$(cat "$o/STAMP")")" || rc=1
|
||||
c="$(store_read count "$(cat "$o/STAMP")" "$COUNTED")" || rc=1
|
||||
fi
|
||||
[ "$rc" = 0 ] || refuse restore-mismatch "cannot count the events after $(cat "$o/STAMP")"
|
||||
echo "restore: $o; the store now in place moves to $POST and is kept; $COUNT event(s) were written after the backup"
|
||||
[ "$COUNT" = 0 ] || [ "$EVENTS" = "$COUNT" ] || refuse post-backup-events "$COUNT event(s) were written after the backup; Jason decides, then --events $COUNT"
|
||||
[ "$rc" = 0 ] || refuse restore-mismatch "cannot count the rows after $(cat "$o/STAMP")"
|
||||
COUNT="${c%%$'\t'*}" text="${c#*$'\t'}"
|
||||
echo "restore: $o; the store now in place moves to $POST and is kept; $text were written after the backup"
|
||||
[ "$COUNT" = 0 ] || [ "$EVENTS" = "$COUNT" ] || refuse post-backup-events "$text were written after the backup; Jason decides, then --events $COUNT"
|
||||
BACKUP="$RESTORE"
|
||||
fi
|
||||
run_steps restore
|
||||
|
||||
Reference in new issue
Block a user