@@ -18,6 +18,7 @@ import (
18
18
19
19
"github.com/outbrain/golib/log"
20
20
"github.com/outbrain/golib/sqlutils"
21
+ "sync"
21
22
)
22
23
23
24
const (
@@ -52,11 +53,12 @@ func newDmlBuildResultError(err error) *dmlBuildResult {
52
53
// Applier is the one to actually write row data and apply binlog events onto the ghost table.
53
54
// It is where the ghost & changelog tables get created. It is where the cut-over phase happens.
54
55
type Applier struct {
55
- connectionConfig * mysql.ConnectionConfig
56
- db * gosql.DB
57
- singletonDB * gosql.DB
58
- migrationContext * base.MigrationContext
59
- finishedMigrating int64
56
+ connectionConfig * mysql.ConnectionConfig
57
+ db * gosql.DB
58
+ singletonDB * gosql.DB
59
+ migrationContext * base.MigrationContext
60
+ finishedMigrating int64
61
+ dropAtomicCutOverSentryTableMutex sync.Mutex
60
62
}
61
63
62
64
func NewApplier (migrationContext * base.MigrationContext ) * Applier {
@@ -738,6 +740,9 @@ func (this *Applier) ExpectProcess(sessionId int64, stateHint, infoHint string)
738
740
// DropAtomicCutOverSentryTableIfExists checks if the "old" table name
739
741
// happens to be a cut-over magic table; if so, it drops it.
740
742
func (this * Applier ) DropAtomicCutOverSentryTableIfExists () error {
743
+ this .dropAtomicCutOverSentryTableMutex .Lock ()
744
+ defer this .dropAtomicCutOverSentryTableMutex .Unlock ()
745
+
741
746
log .Infof ("Looking for magic cut-over table" )
742
747
tableName := this .migrationContext .GetOldTableName ()
743
748
rowMap := this .showTableStatus (tableName )
@@ -854,6 +859,7 @@ func (this *Applier) AtomicCutOverMagicLock(sessionIdChan chan int64, tableLocke
854
859
855
860
// The magic table is here because we locked it. And we are the only ones allowed to drop it.
856
861
// And in fact, we will:
862
+ this .dropAtomicCutOverSentryTableMutex .Lock ()
857
863
log .Infof ("Dropping magic cut-over table" )
858
864
query = fmt .Sprintf (`drop /* gh-ost */ table if exists %s.%s` ,
859
865
sql .EscapeName (this .migrationContext .DatabaseName ),
@@ -863,6 +869,7 @@ func (this *Applier) AtomicCutOverMagicLock(sessionIdChan chan int64, tableLocke
863
869
log .Errore (err )
864
870
// We DO NOT return here because we must `UNLOCK TABLES`!
865
871
}
872
+ this .dropAtomicCutOverSentryTableMutex .Unlock ()
866
873
867
874
// Tables still locked
868
875
log .Infof ("Releasing lock from %s.%s, %s.%s" ,
0 commit comments