Skip to content

Commit 8a26c9e

Browse files
committed
Don't cut-over until it is safe to do so
1 parent a4218cd commit 8a26c9e

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

go/logic/migrator.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,22 @@ func (this *Migrator) cutOver() (err error) {
518518
this.migrationContext.MarkPointOfInterest()
519519
this.migrationContext.Log.Debugf("checking for cut-over postpone: complete")
520520

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

0 commit comments

Comments
 (0)