fix(nodes): shorten the traffic merge lock window (#7315)

Stage existing client traffic updates in snapshot order and flush them after client reconciliation to shorten PostgreSQL row-lock lifetime. Keep configuration, traffic counters, renewals and baselines atomic in the same serialized transaction, preserve concurrent last_sub_fetch updates, and retain rollback and idempotent replay semantics.

Batch baseline upserts by (node_id, email) within SQLite parameter limits. Decode snapshot claims before opening the transaction while retaining transactional ownership checks. Add debug metrics for queue wait, writer execution and transaction duration.

Validation: all 12 GitHub CI jobs passed on reviewed head 6dc504b675, including race, PostgreSQL, node and Xray E2E. PostgreSQL CI logs explicitly confirm both contention and baseline batching regressions. The author reports PostgreSQL 16/18 validation, rollback/replay coverage and a reduction from 4,187 baseline upserts to 28 in a local fixture.

Scope: this resolves the reproduced subscription row-lock window, not the full serialized writer hold, shared-client cache restriction, historical 41-second SQL tail or cross-process migration/restore deadlock. These require follow-up. No independent production measurements or successful CI run on the exact latest combined revision were verified before merge.

Refs #7305
This commit is contained in:
Hamed
2026-12-02 13:02:15 +03:30
committed by GitHub
parent 9f483d9465
commit bdddb08249
4 changed files with 299 additions and 66 deletions
+10
View File
@@ -214,6 +214,16 @@ jobs:
exit 1
fi
- name: PostgreSQL node merge contention
run: |
set -o pipefail
go test ./internal/web/service -run '^TestNodeMerge(LetsSubscriptionTouchDuringClientReconciliationPostgres|BatchesBaselinesForActiveClients)$' -count=1 -v | tee /tmp/postgres-node-merge-contention.log
passed=$(grep -c -- '^--- PASS' /tmp/postgres-node-merge-contention.log || true)
if [ "$passed" -ne 2 ]; then
echo "expected both PostgreSQL node merge contention tests to pass, got $passed" >&2
exit 1
fi
- name: PostgreSQL schema and migration tests
run: |
set -o pipefail