Skip to content

Commit 5788ab5

Browse files
committed
CR Revisions: Make concurrent operations safe
1 parent a284701 commit 5788ab5

3 files changed

Lines changed: 12 additions & 16 deletions

File tree

go/logic/applier.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ type Applier struct {
3434
db *gosql.DB
3535
singletonDB *gosql.DB
3636
migrationContext *base.MigrationContext
37-
finishedMigrating bool
37+
finishedMigrating int64
3838
}
3939

4040
func NewApplier(migrationContext *base.MigrationContext) *Applier {
4141
return &Applier{
4242
connectionConfig: migrationContext.ApplierConnectionConfig,
4343
migrationContext: migrationContext,
44-
finishedMigrating: false,
44+
finishedMigrating: 0,
4545
}
4646
}
4747

@@ -312,7 +312,7 @@ func (this *Applier) InitiateHeartbeat() {
312312

313313
heartbeatTick := time.Tick(time.Duration(this.migrationContext.HeartbeatIntervalMilliseconds) * time.Millisecond)
314314
for range heartbeatTick {
315-
if this.finishedMigrating {
315+
if atomic.LoadInt64(&this.finishedMigrating) > 0 {
316316
return
317317
}
318318
// Generally speaking, we would issue a goroutine, but I'd actually rather
@@ -1049,5 +1049,5 @@ func (this *Applier) Teardown() {
10491049
log.Debugf("Tearing down...")
10501050
this.db.Close()
10511051
this.singletonDB.Close()
1052-
this.finishedMigrating = true
1052+
atomic.StoreInt64(&this.finishedMigrating, 1)
10531053
}

go/logic/migrator.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ type Migrator struct {
8585

8686
handledChangelogStates map[string]bool
8787

88-
finishedMigrating bool
88+
finishedMigrating int64
8989
}
9090

9191
func NewMigrator(context *base.MigrationContext) *Migrator {
@@ -100,7 +100,7 @@ func NewMigrator(context *base.MigrationContext) *Migrator {
100100
copyRowsQueue: make(chan tableWriteFunc),
101101
applyEventsQueue: make(chan *applyEventStruct, base.MaxEventsBatchSize),
102102
handledChangelogStates: make(map[string]bool),
103-
finishedMigrating: false,
103+
finishedMigrating: 0,
104104
}
105105
return migrator
106106
}
@@ -727,7 +727,7 @@ func (this *Migrator) initiateStatus() error {
727727
this.printStatus(ForcePrintStatusAndHintRule)
728728
statusTick := time.Tick(1 * time.Second)
729729
for range statusTick {
730-
if this.finishedMigrating {
730+
if atomic.LoadInt64(&this.finishedMigrating) > 0 {
731731
return nil
732732
}
733733
go this.printStatus(HeuristicPrintStatusRule)
@@ -954,7 +954,7 @@ func (this *Migrator) initiateStreaming() error {
954954
go func() {
955955
ticker := time.Tick(1 * time.Second)
956956
for range ticker {
957-
if this.finishedMigrating {
957+
if atomic.LoadInt64(&this.finishedMigrating) > 0 {
958958
return
959959
}
960960
this.migrationContext.SetRecentBinlogCoordinates(*this.eventsStreamer.GetCurrentBinlogCoordinates())
@@ -1147,7 +1147,7 @@ func (this *Migrator) executeWriteFuncs() error {
11471147
return nil
11481148
}
11491149
for {
1150-
if this.finishedMigrating {
1150+
if atomic.LoadInt64(&this.finishedMigrating) > 0 {
11511151
return nil
11521152
}
11531153

@@ -1232,7 +1232,7 @@ func (this *Migrator) finalCleanup() error {
12321232
}
12331233

12341234
func (this *Migrator) teardown() {
1235-
this.finishedMigrating = true
1235+
atomic.StoreInt64(&this.finishedMigrating, 1)
12361236

12371237
if this.inspector != nil {
12381238
log.Infof("Tearing down inspector")

vendor/github.com/outbrain/golib/sqlutils/sqlutils.go

Lines changed: 2 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)