From 321e5847bae200ed9bd60542dc61e1b791887ec4 Mon Sep 17 00:00:00 2001 From: lmtwga Date: Fri, 16 Sep 2022 17:49:09 +0800 Subject: [PATCH] fix: because lock is not release, drop cutover sentry table is hanged --- go/logic/applier.go | 14 ++++++-------- go/logic/migrator.go | 7 +------ 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/go/logic/applier.go b/go/logic/applier.go index 89e1995..8eafc17 100644 --- a/go/logic/applier.go +++ b/go/logic/applier.go @@ -9,7 +9,6 @@ import ( gosql "database/sql" "fmt" "strings" - "sync" "sync/atomic" "time" @@ -904,7 +903,7 @@ func (this *Applier) CreateAtomicCutOverSentryTable() error { } // AtomicCutOverMagicLock -func (this *Applier) AtomicCutOverMagicLock(sessionIdChan chan int64, tableLocked chan<- error, okToUnlockTable <-chan bool, tableUnlocked chan<- error, dropCutOverSentryTableOnce *sync.Once) error { +func (this *Applier) AtomicCutOverMagicLock(sessionIdChan chan int64, tableLocked chan<- error, okToUnlockTable <-chan bool, tableUnlocked chan<- error) error { tx, err := this.db.Begin() if err != nil { tableLocked <- err @@ -915,6 +914,7 @@ func (this *Applier) AtomicCutOverMagicLock(sessionIdChan chan int64, tableLocke tableLocked <- fmt.Errorf("Unexpected error in AtomicCutOverMagicLock(), injected to release blocking channel reads") tableUnlocked <- fmt.Errorf("Unexpected error in AtomicCutOverMagicLock(), injected to release blocking channel reads") tx.Rollback() + this.DropAtomicCutOverSentryTableIfExists() }() var sessionId int64 @@ -983,12 +983,10 @@ func (this *Applier) AtomicCutOverMagicLock(sessionIdChan chan int64, tableLocke sql.EscapeName(this.migrationContext.GetOldTableName()), ) - dropCutOverSentryTableOnce.Do(func() { - if _, err := tx.Exec(query); err != nil { - this.migrationContext.Log.Errore(err) - // We DO NOT return here because we must `UNLOCK TABLES`! - } - }) + if _, err := tx.Exec(query); err != nil { + this.migrationContext.Log.Errore(err) + // We DO NOT return here because we must `UNLOCK TABLES`! + } // Tables still locked this.migrationContext.Log.Infof("Releasing lock from %s.%s, %s.%s", diff --git a/go/logic/migrator.go b/go/logic/migrator.go index 865814d..6fb57ba 100644 --- a/go/logic/migrator.go +++ b/go/logic/migrator.go @@ -13,7 +13,6 @@ import ( "math" "os" "strings" - "sync" "sync/atomic" "time" @@ -639,12 +638,8 @@ func (this *Migrator) atomicCutOver() (err error) { defer atomic.StoreInt64(&this.migrationContext.InCutOverCriticalSectionFlag, 0) okToUnlockTable := make(chan bool, 4) - var dropCutOverSentryTableOnce sync.Once defer func() { okToUnlockTable <- true - dropCutOverSentryTableOnce.Do(func() { - this.applier.DropAtomicCutOverSentryTableIfExists() - }) }() atomic.StoreInt64(&this.migrationContext.AllEventsUpToLockProcessedInjectedFlag, 0) @@ -653,7 +648,7 @@ func (this *Migrator) atomicCutOver() (err error) { tableLocked := make(chan error, 2) tableUnlocked := make(chan error, 2) go func() { - if err := this.applier.AtomicCutOverMagicLock(lockOriginalSessionIdChan, tableLocked, okToUnlockTable, tableUnlocked, &dropCutOverSentryTableOnce); err != nil { + if err := this.applier.AtomicCutOverMagicLock(lockOriginalSessionIdChan, tableLocked, okToUnlockTable, tableUnlocked); err != nil { this.migrationContext.Log.Errore(err) } }()