diff --git a/go/base/context.go b/go/base/context.go index 6142f9c..7b196af 100644 --- a/go/base/context.go +++ b/go/base/context.go @@ -559,7 +559,11 @@ func (this *MigrationContext) GetControlReplicasLagResult() mysql.ReplicationLag func (this *MigrationContext) SetControlReplicasLagResult(lagResult *mysql.ReplicationLagResult) { this.throttleMutex.Lock() defer this.throttleMutex.Unlock() - this.controlReplicasLagResult = *lagResult + if lagResult == nil { + this.controlReplicasLagResult = *mysql.NewNoReplicationLagResult() + } else { + this.controlReplicasLagResult = *lagResult + } } func (this *MigrationContext) GetThrottleControlReplicaKeys() *mysql.InstanceKeyMap { diff --git a/go/logic/throttler.go b/go/logic/throttler.go index 1635b5e..beb4f47 100644 --- a/go/logic/throttler.go +++ b/go/logic/throttler.go @@ -158,9 +158,7 @@ func (this *Throttler) collectControlReplicasLag() { // No need to read lag return } - if result := readControlReplicasLag(); result != nil { - this.migrationContext.SetControlReplicasLagResult(result) - } + this.migrationContext.SetControlReplicasLagResult(readControlReplicasLag()) } aggressiveTicker := time.Tick(100 * time.Millisecond) relaxedFactor := 10 diff --git a/go/mysql/utils.go b/go/mysql/utils.go index bfd3c24..fb70dc9 100644 --- a/go/mysql/utils.go +++ b/go/mysql/utils.go @@ -22,6 +22,14 @@ type ReplicationLagResult struct { Err error } +func NewNoReplicationLagResult() *ReplicationLagResult { + return &ReplicationLagResult{Lag: 0, Err: nil} +} + +func (this *ReplicationLagResult) HasLag() bool { + return this.Lag > 0 +} + // GetReplicationLag returns replication lag for a given connection config; either by explicit query // or via SHOW SLAVE STATUS func GetReplicationLag(connectionConfig *ConnectionConfig) (replicationLag time.Duration, err error) {