mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-04 16:34:52 +03:00
12e0b076a8
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.
25 lines
598 B
Go
25 lines
598 B
Go
package database
|
|
|
|
import (
|
|
"errors"
|
|
"os"
|
|
|
|
"golang.org/x/sys/windows"
|
|
)
|
|
|
|
func tryMaintenanceFileLock(file *os.File, exclusive bool) (bool, error) {
|
|
flags := uint32(windows.LOCKFILE_FAIL_IMMEDIATELY)
|
|
if exclusive {
|
|
flags |= windows.LOCKFILE_EXCLUSIVE_LOCK
|
|
}
|
|
err := windows.LockFileEx(windows.Handle(file.Fd()), flags, 0, 1, 0, &windows.Overlapped{})
|
|
if errors.Is(err, windows.ERROR_LOCK_VIOLATION) {
|
|
return false, nil
|
|
}
|
|
return err == nil, err
|
|
}
|
|
|
|
func unlockMaintenanceFile(file *os.File) error {
|
|
return windows.UnlockFileEx(windows.Handle(file.Fd()), 0, 1, 0, &windows.Overlapped{})
|
|
}
|