From b068d59e5f23827e9faf00933f88faaa6bd38d33 Mon Sep 17 00:00:00 2001 From: Brad Seiler Date: Fri, 6 Nov 2026 18:19:06 -0500 Subject: [PATCH] fix(db): make invite repair run budget configurable Retain the finite default and explain timeout recovery across committed batches so large repairs can finish with a reviewed invocation budget. Co-authored-by: Honor Signed-off-by: Brad Seiler --- TESTING.md | 6 ++++++ scripts/maintenance/backfill_invite_revocations.sql | 12 +++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/TESTING.md b/TESTING.md index fa3a9a3a82..b97b18d363 100644 --- a/TESTING.md +++ b/TESTING.md @@ -231,6 +231,12 @@ psql -X -v ON_ERROR_STOP=1 -f scripts/maintenance/backfill_invite_revocations.sq Run it as a top-level script, outside any caller transaction. The final query must report `0` unrepaired invites in active communities. Run it twice; the second run must keep zero and leave revocation timestamps and markers unchanged. +The default two-minute statement timeout covers the entire repair invocation, +not each batch. A timeout preserves committed batches, rolls back the current +batch and skips the final query; it is not a successful zero check. Keep the +same writer controls in place and rerun. If scanning already repaired rows +exhausts that budget, pass a larger finite budget, for example +`psql -X -v ON_ERROR_STOP=1 -v invite_repair_timeout=10min -f scripts/maintenance/backfill_invite_revocations.sql`. Review fenced communities separately and keep their admission closed until they can be repaired under the same controls. diff --git a/scripts/maintenance/backfill_invite_revocations.sql b/scripts/maintenance/backfill_invite_revocations.sql index 286da2578b..3d42bd7ae0 100644 --- a/scripts/maintenance/backfill_invite_revocations.sql +++ b/scripts/maintenance/backfill_invite_revocations.sql @@ -12,9 +12,19 @@ -- before clearing legacy_admission on every invite row. Skipped communities -- retain the marker and remain fail-closed until a later run. The script is -- idempotent; rerun it after a failure. +-- statement_timeout bounds the entire DO invocation, including all batches; +-- COMMIT does not restart it. On timeout, committed batches remain repaired, +-- the current batch rolls back, and ON_ERROR_STOP skips the final zero check. +-- Keep admission closed and rerun. If scanning the repaired prefix consumes +-- the budget, choose a larger finite invocation budget with psql's +-- -v invite_repair_timeout=10min (the default is 2min). \set ON_ERROR_STOP on +\if :{?invite_repair_timeout} +\else +\set invite_repair_timeout 2min +\endif SET lock_timeout = '5s'; -SET statement_timeout = '2min'; +SET statement_timeout = :'invite_repair_timeout'; DO $$ DECLARE