From 4e2ecc4587f421763c527459861c67b39c68c3f3 Mon Sep 17 00:00:00 2001 From: Valentin Kuznetsov Date: Tue, 20 Sep 2022 07:33:10 -0400 Subject: [PATCH] Add solution to resolve stale QUEUED migration requests --- dbs/migration_server.go | 9 ++++++++- static/sql/migration_requests.sql | 5 ++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/dbs/migration_server.go b/dbs/migration_server.go index 29877107..a3488f07 100644 --- a/dbs/migration_server.go +++ b/dbs/migration_server.go @@ -82,7 +82,14 @@ func MigrationServer(interval, timeout int, ch <-chan bool) { api.Params = params time0 := time.Now() atomic.AddUint64(&TotalMigrationRequests, 1) - api.ProcessMigration() + if r.MIGRATION_STATUS == QUEUED { + // asynchronously start migration request + // the StartMigrationRequest relies on MigrationAsyncTimeout (in sec) + // context timeout + go StartMigrationRequest(r) + } else { + api.ProcessMigration() + } log.Printf("migration process %+v finished in %v", params, time.Since(time0)) } } diff --git a/static/sql/migration_requests.sql b/static/sql/migration_requests.sql index 2eb6bd81..54a98181 100644 --- a/static/sql/migration_requests.sql +++ b/static/sql/migration_requests.sql @@ -9,10 +9,9 @@ JOIN {{.Owner}}.MIGRATION_BLOCKS MB ON MB.MIGRATION_REQUEST_ID=MR.MIGRATION_REQU {{if .Oldest}} WHERE MR.MIGRATION_STATUS=0 +or MR.MIGRATION_STATUS=1 or (MR.migration_status=3 and MR.retry_count=0 and MR.last_modification_date <= {{.Date1}}) or (MR.migration_status=3 and MR.retry_count=1 and MR.last_modification_date <= {{.Date2}}) or (MR.migration_status=3 and MR.retry_count=2 and MR.last_modification_date <= {{.Date3}}) ---or (MR.migration_status=0 and MR.retry_count=0 and MR.last_modification_date <= {{.PendingDate}}) ---or (MR.migration_status=1 and MR.retry_count=0 and MR.last_modification_date <= {{.ProgressDate}}) -or MR.MIGRATION_STATUS=1 +or (MR.migration_status=5 and MR.retry_count=0 and MR.last_modification_date <= {{.Date1}}) {{end}}