fix(database): coordinate migrations and restores across processes (#7322)

Coordinate database maintenance across panel, CLI, node synchronization, and restore paths.

- Add cross-process PostgreSQL advisory locks and pinned execution fences; cancel CLI work when its lease session is lost.
- Serialize SQLite file replacement with OS-level process locks and stable lock identity.
- Drain traffic writers and node-sync work before restore, then resume after migration and validation.
- Persist PostgreSQL restore-pending state and recover interrupted restores on startup.
- Add regression coverage for concurrent migrations/restores, session-loss fencing, CLI work cancellation, and recovery.

Closes #7318.
This commit is contained in:
Hamed
2026-12-03 12:05:51 +03:30
committed by GitHub
parent d107effd3c
commit 12e0b076a8
31 changed files with 2399 additions and 158 deletions
+20
View File
@@ -85,6 +85,16 @@ jobs:
exit 1
fi
- name: PostgreSQL maintenance fencing and recovery
run: |
set -o pipefail
go test -p=1 . ./internal/database -run '^Test(PostgresCLIWorkFenceSurvivesSessionLoss|PostgresExclusiveRestoreFenceSurvivesSessionLoss|PostgresPendingRestoreRetriesBeforeServing|PostgresRuntimeMaintenanceReacquiresAfterSessionLoss|MaintenanceAcrossProcesses)$' -count=1 -v | tee /tmp/postgres-maintenance.log
passed=$(grep -c -- '^--- PASS' /tmp/postgres-maintenance.log || true)
if [ "$passed" -ne 5 ]; then
echo "expected 5 passing PostgreSQL maintenance tests, got $passed" >&2
exit 1
fi
- name: PostgreSQL inbound add orphan cleanup
run: |
set -o pipefail
@@ -238,6 +248,16 @@ jobs:
exit 1
fi
- name: PostgreSQL database maintenance contention
run: |
set -o pipefail
go test -p=1 . ./internal/database ./internal/web/job -run '^Test(MaintenanceAcrossProcesses|PostgresRuntimeMaintenanceReacquiresAfterSessionLoss|PostgresPendingRestoreRetriesBeforeServing|DatabaseRestoreDrainsAnInFlightNodePoll)$' -count=1 -v | tee /tmp/postgres-maintenance.log
passed=$(grep -c -- '^--- PASS' /tmp/postgres-maintenance.log || true)
if [ "$passed" -ne 4 ]; then
echo "expected 4 passing PostgreSQL database maintenance tests, got $passed" >&2
exit 1
fi
- name: PostgreSQL inbound migration contention
run: |
set -o pipefail