Skip to content

Commit e723909

Browse files
author
Shlomi Noach
committed
Merge pull request #45 from github/print-status-point-of-interest
support for marking point-of-interest in migration
2 parents 6d9a8ba + 20f0008 commit e723909

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

go/base/context.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ type MigrationContext struct {
7979
LockTablesStartTime time.Time
8080
RenameTablesStartTime time.Time
8181
RenameTablesEndTime time.Time
82+
pointOfInterestTime time.Time
83+
pointOfInterestTimeMutex *sync.Mutex
8284
CurrentLag int64
8385
TotalRowsCopied int64
8486
TotalDMLEventsApplied int64
@@ -131,6 +133,7 @@ func newMigrationContext() *MigrationContext {
131133
throttleMutex: &sync.Mutex{},
132134
ThrottleControlReplicaKeys: mysql.NewInstanceKeyMap(),
133135
configMutex: &sync.Mutex{},
136+
pointOfInterestTimeMutex: &sync.Mutex{},
134137
}
135138
}
136139

@@ -216,16 +219,31 @@ func (this *MigrationContext) GetIteration() int64 {
216219
return atomic.LoadInt64(&this.Iteration)
217220
}
218221

222+
func (this *MigrationContext) MarkPointOfInterest() int64 {
223+
this.pointOfInterestTimeMutex.Lock()
224+
defer this.pointOfInterestTimeMutex.Unlock()
225+
226+
this.pointOfInterestTime = time.Now()
227+
return atomic.LoadInt64(&this.Iteration)
228+
}
229+
230+
func (this *MigrationContext) TimeSincePointOfInterest() time.Duration {
231+
this.pointOfInterestTimeMutex.Lock()
232+
defer this.pointOfInterestTimeMutex.Unlock()
233+
234+
return time.Now().Sub(this.pointOfInterestTime)
235+
}
236+
219237
func (this *MigrationContext) SetThrottled(throttle bool, reason string) {
220238
this.throttleMutex.Lock()
221-
defer func() { this.throttleMutex.Unlock() }()
239+
defer this.throttleMutex.Unlock()
222240
this.isThrottled = throttle
223241
this.throttleReason = reason
224242
}
225243

226244
func (this *MigrationContext) IsThrottled() (bool, string) {
227245
this.throttleMutex.Lock()
228-
defer func() { this.throttleMutex.Unlock() }()
246+
defer this.throttleMutex.Unlock()
229247
return this.isThrottled, this.throttleReason
230248
}
231249

go/logic/migrator.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,8 @@ func (this *Migrator) printStatus() {
606606
shouldPrintStatus = (elapsedSeconds%5 == 0)
607607
} else if elapsedSeconds <= 180 {
608608
shouldPrintStatus = (elapsedSeconds%5 == 0)
609+
} else if this.migrationContext.TimeSincePointOfInterest() <= 60 {
610+
shouldPrintStatus = (elapsedSeconds%5 == 0)
609611
} else {
610612
shouldPrintStatus = (elapsedSeconds%30 == 0)
611613
}

0 commit comments

Comments
 (0)