mirror of
https://github.com/Sagit-chu/flvx.git
synced 2026-11-17 01:44:23 +08:00
feat: add optional sequential port allocation with atomic reservations
Adapt the port allocation option from #583 by xigua761 without its commercial licensing changes. Serialize forward, chain, peer runtime, cleanup and import reservations across SQLite/PostgreSQL instances. Co-authored-by: xigua761 <xigua1166@outlook.com>
This commit is contained in:
@@ -18,7 +18,12 @@ var errBackupImportBusy = errors.New("database is busy; retry the backup import"
|
||||
func backupImportTransaction(db *gorm.DB, importRows func(*gorm.DB) error) error {
|
||||
var err error
|
||||
for attempt := 0; attempt < 10; attempt++ {
|
||||
err = db.Transaction(importRows)
|
||||
err = db.Transaction(func(tx *gorm.DB) error {
|
||||
if err := lockPortAllocationTx(tx); err != nil {
|
||||
return err
|
||||
}
|
||||
return importRows(tx)
|
||||
})
|
||||
if !errors.Is(err, errBackupImportBusy) {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user