Skip to content

Commit 503b7b0

Browse files
committed
Consolidate the two sleepWhileTrue loops
1 parent d5c2414 commit 503b7b0

File tree

1 file changed

+6
-16
lines changed

1 file changed

+6
-16
lines changed

go/logic/migrator.go

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,12 @@ func (this *Migrator) cutOver() (err error) {
496496
this.migrationContext.Log.Debugf("checking for cut-over postpone")
497497
this.sleepWhileTrue(
498498
func() (bool, error) {
499+
heartbeatLag := this.migrationContext.TimeSinceLastHeartbeatOnChangelog()
500+
maxLagMillisecondsThrottleThreshold := atomic.LoadInt64(&this.migrationContext.MaxLagMillisecondsThrottleThreshold)
501+
if heartbeatLag > time.Duration(maxLagMillisecondsThrottleThreshold)*time.Millisecond {
502+
this.migrationContext.Log.Debugf("current HeartbeatLag (%.2fs) is too high, it needs to be less than --max-lag-millis (%.2fs) to continue", heartbeatLag.Seconds(), (time.Duration(maxLagMillisecondsThrottleThreshold) * time.Millisecond).Seconds())
503+
return true, nil
504+
}
499505
if this.migrationContext.PostponeCutOverFlagFile == "" {
500506
return false, nil
501507
}
@@ -520,22 +526,6 @@ func (this *Migrator) cutOver() (err error) {
520526
this.migrationContext.MarkPointOfInterest()
521527
this.migrationContext.Log.Debugf("checking for cut-over postpone: complete")
522528

523-
this.migrationContext.Log.Infof("Waiting for heartbeat lag to be low enough to proceed")
524-
this.sleepWhileTrue(
525-
func() (bool, error) {
526-
heartbeatLag := this.migrationContext.TimeSinceLastHeartbeatOnChangelog()
527-
maxLagMillisecondsThrottleThreshold := atomic.LoadInt64(&this.migrationContext.MaxLagMillisecondsThrottleThreshold)
528-
if heartbeatLag > time.Duration(maxLagMillisecondsThrottleThreshold)*time.Millisecond {
529-
this.migrationContext.Log.Debugf("current HeartbeatLag (%.2fs) is too high, it needs to be less than --max-lag-millis (%.2fs) to continue", heartbeatLag.Seconds(), (time.Duration(maxLagMillisecondsThrottleThreshold) * time.Millisecond).Seconds())
530-
return true, nil
531-
} else {
532-
return false, nil
533-
}
534-
},
535-
)
536-
this.migrationContext.MarkPointOfInterest()
537-
this.migrationContext.Log.Infof("Heartbeat lag is low enough, proceeding")
538-
539529
if this.migrationContext.TestOnReplica {
540530
// With `--test-on-replica` we stop replication thread, and then proceed to use
541531
// the same cut-over phase as the master would use. That means we take locks

0 commit comments

Comments
 (0)