Skip to content

Commit baee4f6

Browse files
author
Shlomi Noach
committed
fixing phantom throttle-control-replicas lag result
1 parent 5af7026 commit baee4f6

3 files changed

Lines changed: 14 additions & 4 deletions

File tree

go/base/context.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,11 @@ func (this *MigrationContext) GetControlReplicasLagResult() mysql.ReplicationLag
559559
func (this *MigrationContext) SetControlReplicasLagResult(lagResult *mysql.ReplicationLagResult) {
560560
this.throttleMutex.Lock()
561561
defer this.throttleMutex.Unlock()
562-
this.controlReplicasLagResult = *lagResult
562+
if lagResult == nil {
563+
this.controlReplicasLagResult = *mysql.NewNoReplicationLagResult()
564+
} else {
565+
this.controlReplicasLagResult = *lagResult
566+
}
563567
}
564568

565569
func (this *MigrationContext) GetThrottleControlReplicaKeys() *mysql.InstanceKeyMap {

go/logic/throttler.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,7 @@ func (this *Throttler) collectControlReplicasLag() {
158158
// No need to read lag
159159
return
160160
}
161-
if result := readControlReplicasLag(); result != nil {
162-
this.migrationContext.SetControlReplicasLagResult(result)
163-
}
161+
this.migrationContext.SetControlReplicasLagResult(readControlReplicasLag())
164162
}
165163
aggressiveTicker := time.Tick(100 * time.Millisecond)
166164
relaxedFactor := 10

go/mysql/utils.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ type ReplicationLagResult struct {
2222
Err error
2323
}
2424

25+
func NewNoReplicationLagResult() *ReplicationLagResult {
26+
return &ReplicationLagResult{Lag: 0, Err: nil}
27+
}
28+
29+
func (this *ReplicationLagResult) HasLag() bool {
30+
return this.Lag > 0
31+
}
32+
2533
// GetReplicationLag returns replication lag for a given connection config; either by explicit query
2634
// or via SHOW SLAVE STATUS
2735
func GetReplicationLag(connectionConfig *ConnectionConfig) (replicationLag time.Duration, err error) {

0 commit comments

Comments
 (0)