Skip to content

Commit 321e584

Browse files
committed
fix: because lock is not release, drop cutover sentry table is hanged
1 parent 1df37c2 commit 321e584

File tree

2 files changed

+7
-14
lines changed

2 files changed

+7
-14
lines changed

go/logic/applier.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
gosql "database/sql"
1010
"fmt"
1111
"strings"
12-
"sync"
1312
"sync/atomic"
1413
"time"
1514

@@ -904,7 +903,7 @@ func (this *Applier) CreateAtomicCutOverSentryTable() error {
904903
}
905904

906905
// AtomicCutOverMagicLock
907-
func (this *Applier) AtomicCutOverMagicLock(sessionIdChan chan int64, tableLocked chan<- error, okToUnlockTable <-chan bool, tableUnlocked chan<- error, dropCutOverSentryTableOnce *sync.Once) error {
906+
func (this *Applier) AtomicCutOverMagicLock(sessionIdChan chan int64, tableLocked chan<- error, okToUnlockTable <-chan bool, tableUnlocked chan<- error) error {
908907
tx, err := this.db.Begin()
909908
if err != nil {
910909
tableLocked <- err
@@ -915,6 +914,7 @@ func (this *Applier) AtomicCutOverMagicLock(sessionIdChan chan int64, tableLocke
915914
tableLocked <- fmt.Errorf("Unexpected error in AtomicCutOverMagicLock(), injected to release blocking channel reads")
916915
tableUnlocked <- fmt.Errorf("Unexpected error in AtomicCutOverMagicLock(), injected to release blocking channel reads")
917916
tx.Rollback()
917+
this.DropAtomicCutOverSentryTableIfExists()
918918
}()
919919

920920
var sessionId int64
@@ -983,12 +983,10 @@ func (this *Applier) AtomicCutOverMagicLock(sessionIdChan chan int64, tableLocke
983983
sql.EscapeName(this.migrationContext.GetOldTableName()),
984984
)
985985

986-
dropCutOverSentryTableOnce.Do(func() {
987-
if _, err := tx.Exec(query); err != nil {
988-
this.migrationContext.Log.Errore(err)
989-
// We DO NOT return here because we must `UNLOCK TABLES`!
990-
}
991-
})
986+
if _, err := tx.Exec(query); err != nil {
987+
this.migrationContext.Log.Errore(err)
988+
// We DO NOT return here because we must `UNLOCK TABLES`!
989+
}
992990

993991
// Tables still locked
994992
this.migrationContext.Log.Infof("Releasing lock from %s.%s, %s.%s",

go/logic/migrator.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"math"
1414
"os"
1515
"strings"
16-
"sync"
1716
"sync/atomic"
1817
"time"
1918

@@ -639,12 +638,8 @@ func (this *Migrator) atomicCutOver() (err error) {
639638
defer atomic.StoreInt64(&this.migrationContext.InCutOverCriticalSectionFlag, 0)
640639

641640
okToUnlockTable := make(chan bool, 4)
642-
var dropCutOverSentryTableOnce sync.Once
643641
defer func() {
644642
okToUnlockTable <- true
645-
dropCutOverSentryTableOnce.Do(func() {
646-
this.applier.DropAtomicCutOverSentryTableIfExists()
647-
})
648643
}()
649644

650645
atomic.StoreInt64(&this.migrationContext.AllEventsUpToLockProcessedInjectedFlag, 0)
@@ -653,7 +648,7 @@ func (this *Migrator) atomicCutOver() (err error) {
653648
tableLocked := make(chan error, 2)
654649
tableUnlocked := make(chan error, 2)
655650
go func() {
656-
if err := this.applier.AtomicCutOverMagicLock(lockOriginalSessionIdChan, tableLocked, okToUnlockTable, tableUnlocked, &dropCutOverSentryTableOnce); err != nil {
651+
if err := this.applier.AtomicCutOverMagicLock(lockOriginalSessionIdChan, tableLocked, okToUnlockTable, tableUnlocked); err != nil {
657652
this.migrationContext.Log.Errore(err)
658653
}
659654
}()

0 commit comments

Comments
 (0)