perf(nodes): target orphan recovery during client reconciliation (#7240)

Every node snapshot merge ran a clear-orphan-marks UPDATE over the whole clients table, marked rows or not. On a PostgreSQL master with thousands of clients that was a full scan every five seconds per node, inside the single serialized writer.

A merge now clears marks only for the clients it reconciled, and an unchanged snapshot issues no orphan statement at all. Marks left on still-attached clients by older builds, restores or imports are repaired by the existing five-minute reaper, in the same transaction that decides what to delete, and a client that loses its last link has its stale mark cleared first so the reaper cannot delete it without a grace period.

Verified on SQLite and PostgreSQL 18: the previous code repairs an unrelated mark on every merge and reaps a legacy-marked client right after it is detached.

Fixes #7231
This commit is contained in:
Hamed
2026-11-29 17:55:47 +03:30
committed by GitHub
parent 4954b032f1
commit b1cec64b18
5 changed files with 184 additions and 27 deletions
+10
View File
@@ -94,6 +94,16 @@ jobs:
exit 1
fi
- name: PostgreSQL sync orphan recovery
run: |
set -o pipefail
go test ./internal/web/service -run '^Test(SyncOrphanRecoveryScope|LegacySyncOrphanMarksAcrossLinkChanges)Postgres$' -count=1 -v | tee /tmp/postgres-sync-orphans.log
passed=$(grep -c -- '^--- PASS' /tmp/postgres-sync-orphans.log || true)
if [ "$passed" -ne 2 ]; then
echo "expected both PostgreSQL sync orphan recovery tests to pass, got $passed" >&2
exit 1
fi
- name: PostgreSQL client traffic lifecycle edits
run: |
set -o pipefail