From 503b7b0d6cff548669a143f579255b9c1e2ca3af Mon Sep 17 00:00:00 2001 From: Cathal Coffey Date: Sun, 7 Feb 2021 13:52:59 +0000 Subject: [PATCH] Consolidate the two sleepWhileTrue loops --- go/logic/migrator.go | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/go/logic/migrator.go b/go/logic/migrator.go index f866cfc..c64b8be 100644 --- a/go/logic/migrator.go +++ b/go/logic/migrator.go @@ -496,6 +496,12 @@ func (this *Migrator) cutOver() (err error) { this.migrationContext.Log.Debugf("checking for cut-over postpone") this.sleepWhileTrue( func() (bool, error) { + heartbeatLag := this.migrationContext.TimeSinceLastHeartbeatOnChangelog() + maxLagMillisecondsThrottleThreshold := atomic.LoadInt64(&this.migrationContext.MaxLagMillisecondsThrottleThreshold) + if heartbeatLag > time.Duration(maxLagMillisecondsThrottleThreshold)*time.Millisecond { + 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()) + return true, nil + } if this.migrationContext.PostponeCutOverFlagFile == "" { return false, nil } @@ -520,22 +526,6 @@ func (this *Migrator) cutOver() (err error) { this.migrationContext.MarkPointOfInterest() this.migrationContext.Log.Debugf("checking for cut-over postpone: complete") - this.migrationContext.Log.Infof("Waiting for heartbeat lag to be low enough to proceed") - this.sleepWhileTrue( - func() (bool, error) { - heartbeatLag := this.migrationContext.TimeSinceLastHeartbeatOnChangelog() - maxLagMillisecondsThrottleThreshold := atomic.LoadInt64(&this.migrationContext.MaxLagMillisecondsThrottleThreshold) - if heartbeatLag > time.Duration(maxLagMillisecondsThrottleThreshold)*time.Millisecond { - 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()) - return true, nil - } else { - return false, nil - } - }, - ) - this.migrationContext.MarkPointOfInterest() - this.migrationContext.Log.Infof("Heartbeat lag is low enough, proceeding") - if this.migrationContext.TestOnReplica { // With `--test-on-replica` we stop replication thread, and then proceed to use // the same cut-over phase as the master would use. That means we take locks