Skip to content

Commit 0e2d33a

Browse files
Merge in #755
1 parent ce03757 commit 0e2d33a

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

go/logic/applier.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/github/gh-ost/go/sql"
1818

1919
"github.com/outbrain/golib/sqlutils"
20+
"sync"
2021
)
2122

2223
const (
@@ -787,7 +788,7 @@ func (this *Applier) CreateAtomicCutOverSentryTable() error {
787788
}
788789

789790
// AtomicCutOverMagicLock
790-
func (this *Applier) AtomicCutOverMagicLock(sessionIdChan chan int64, tableLocked chan<- error, okToUnlockTable <-chan bool, tableUnlocked chan<- error) error {
791+
func (this *Applier) AtomicCutOverMagicLock(sessionIdChan chan int64, tableLocked chan<- error, okToUnlockTable <-chan bool, tableUnlocked chan<- error, dropCutOverSentryTableOnce *sync.Once) error {
791792
tx, err := this.db.Begin()
792793
if err != nil {
793794
tableLocked <- err
@@ -865,10 +866,13 @@ func (this *Applier) AtomicCutOverMagicLock(sessionIdChan chan int64, tableLocke
865866
sql.EscapeName(this.migrationContext.DatabaseName),
866867
sql.EscapeName(this.migrationContext.GetOldTableName()),
867868
)
868-
if _, err := tx.Exec(query); err != nil {
869-
this.migrationContext.Log.Errore(err)
870-
// We DO NOT return here because we must `UNLOCK TABLES`!
871-
}
869+
870+
dropCutOverSentryTableOnce.Do(func() {
871+
if _, err := tx.Exec(query); err != nil {
872+
this.migrationContext.Log.Errore(err)
873+
// We DO NOT return here because we must `UNLOCK TABLES`!
874+
}
875+
})
872876

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

go/logic/migrator.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"math"
1212
"os"
1313
"strings"
14+
"sync"
1415
"sync/atomic"
1516
"time"
1617

@@ -606,9 +607,12 @@ func (this *Migrator) atomicCutOver() (err error) {
606607
defer atomic.StoreInt64(&this.migrationContext.InCutOverCriticalSectionFlag, 0)
607608

608609
okToUnlockTable := make(chan bool, 4)
610+
var dropCutOverSentryTableOnce sync.Once
609611
defer func() {
610612
okToUnlockTable <- true
611-
this.applier.DropAtomicCutOverSentryTableIfExists()
613+
dropCutOverSentryTableOnce.Do(func() {
614+
this.applier.DropAtomicCutOverSentryTableIfExists()
615+
})
612616
}()
613617

614618
atomic.StoreInt64(&this.migrationContext.AllEventsUpToLockProcessedInjectedFlag, 0)
@@ -617,7 +621,7 @@ func (this *Migrator) atomicCutOver() (err error) {
617621
tableLocked := make(chan error, 2)
618622
tableUnlocked := make(chan error, 2)
619623
go func() {
620-
if err := this.applier.AtomicCutOverMagicLock(lockOriginalSessionIdChan, tableLocked, okToUnlockTable, tableUnlocked); err != nil {
624+
if err := this.applier.AtomicCutOverMagicLock(lockOriginalSessionIdChan, tableLocked, okToUnlockTable, tableUnlocked, &dropCutOverSentryTableOnce); err != nil {
621625
this.migrationContext.Log.Errore(err)
622626
}
623627
}()

0 commit comments

Comments
 (0)