Skip to content

Commit 067c4df

Browse files
author
Shlomi Noach
authored
Merge pull request #364 from github/fix-reappearing-throttled-reasons
fixing phantom throttle-control-replicas lag result
2 parents 185da16 + b289041 commit 067c4df

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
@@ -561,7 +561,11 @@ func (this *MigrationContext) GetControlReplicasLagResult() mysql.ReplicationLag
561561
func (this *MigrationContext) SetControlReplicasLagResult(lagResult *mysql.ReplicationLagResult) {
562562
this.throttleMutex.Lock()
563563
defer this.throttleMutex.Unlock()
564-
this.controlReplicasLagResult = *lagResult
564+
if lagResult == nil {
565+
this.controlReplicasLagResult = *mysql.NewNoReplicationLagResult()
566+
} else {
567+
this.controlReplicasLagResult = *lagResult
568+
}
565569
}
566570

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

go/logic/throttler.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,7 @@ func (this *Throttler) collectControlReplicasLag() {
176176
// No need to read lag
177177
return
178178
}
179-
if result := readControlReplicasLag(); result != nil {
180-
this.migrationContext.SetControlReplicasLagResult(result)
181-
}
179+
this.migrationContext.SetControlReplicasLagResult(readControlReplicasLag())
182180
}
183181
aggressiveTicker := time.Tick(100 * time.Millisecond)
184182
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)