Skip to content

Commit 7869889

Browse files
author
Shlomi Noach
committed
context, status and hooks: progressPct and CurrentLag
1 parent dcc3e90 commit 7869889

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

go/base/context.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ type MigrationContext struct {
174174
pointOfInterestTime time.Time
175175
pointOfInterestTimeMutex *sync.Mutex
176176
CurrentLag int64
177+
CurrentProgress uint64 // math.Float64bits([f=0..100])
177178
ThrottleHTTPStatusCode int64
178179
controlReplicasLagResult mysql.ReplicationLagResult
179180
TotalRowsCopied int64
@@ -428,6 +429,10 @@ func (this *MigrationContext) MarkRowCopyEndTime() {
428429
this.RowCopyEndTime = time.Now()
429430
}
430431

432+
func (this *MigrationContext) GetCurrentLagDuration() time.Duration {
433+
return time.Duration(atomic.LoadInt64(&this.CurrentLag))
434+
}
435+
431436
// GetTotalRowsCopied returns the accurate number of rows being copied (affected)
432437
// This is not exactly the same as the rows being iterated via chunks, but potentially close enough
433438
func (this *MigrationContext) GetTotalRowsCopied() int64 {

go/logic/hooks.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package logic
88

99
import (
1010
"fmt"
11+
"math"
1112
"os"
1213
"os/exec"
1314
"path/filepath"
@@ -63,6 +64,8 @@ func (this *HooksExecutor) applyEnvironmentVariables(extraVariables ...string) [
6364
env = append(env, fmt.Sprintf("GH_OST_MIGRATED_HOST=%s", this.migrationContext.GetApplierHostname()))
6465
env = append(env, fmt.Sprintf("GH_OST_INSPECTED_HOST=%s", this.migrationContext.GetInspectorHostname()))
6566
env = append(env, fmt.Sprintf("GH_OST_EXECUTING_HOST=%s", this.migrationContext.Hostname))
67+
env = append(env, fmt.Sprintf("GH_OST_INSPECTED_LAG=%f", this.migrationContext.GetCurrentLagDuration().Seconds()))
68+
env = append(env, fmt.Sprintf("GH_OST_PROGRESS=%f", math.Float64frombits(atomic.LoadUint64(&this.migrationContext.CurrentProgress))))
6669
env = append(env, fmt.Sprintf("GH_OST_HOOKS_HINT=%s", this.migrationContext.HooksHintMessage))
6770
env = append(env, fmt.Sprintf("GH_OST_HOOKS_HINT_OWNER=%s", this.migrationContext.HooksHintOwner))
6871
env = append(env, fmt.Sprintf("GH_OST_HOOKS_HINT_TOKEN=%s", this.migrationContext.HooksHintToken))

go/logic/migrator.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,8 @@ func (this *Migrator) printStatus(rule PrintStatusRule, writers ...io.Writer) {
895895
} else {
896896
progressPct = 100.0 * float64(totalRowsCopied) / float64(rowsEstimate)
897897
}
898+
// we take the opportunity to update migration context with progressPct
899+
atomic.StoreUint64(&this.migrationContext.CurrentProgress, math.Float64bits(progressPct))
898900
// Before status, let's see if we should print a nice reminder for what exactly we're doing here.
899901
shouldPrintMigrationStatusHint := (elapsedSeconds%600 == 0)
900902
if rule == ForcePrintStatusAndHintRule {
@@ -911,7 +913,7 @@ func (this *Migrator) printStatus(rule PrintStatusRule, writers ...io.Writer) {
911913
eta := "N/A"
912914
if progressPct >= 100.0 {
913915
eta = "due"
914-
} else if progressPct >= 1.0 {
916+
} else if progressPct >= 0.1 {
915917
elapsedRowCopySeconds := this.migrationContext.ElapsedRowCopyTime().Seconds()
916918
totalExpectedSeconds := elapsedRowCopySeconds * float64(rowsEstimate) / float64(totalRowsCopied)
917919
etaSeconds = totalExpectedSeconds - elapsedRowCopySeconds
@@ -958,12 +960,13 @@ func (this *Migrator) printStatus(rule PrintStatusRule, writers ...io.Writer) {
958960

959961
currentBinlogCoordinates := *this.eventsStreamer.GetCurrentBinlogCoordinates()
960962

961-
status := fmt.Sprintf("Copy: %d/%d %.1f%%; Applied: %d; Backlog: %d/%d; Time: %+v(total), %+v(copy); streamer: %+v; State: %s; ETA: %s",
963+
status := fmt.Sprintf("Copy: %d/%d %.1f%%; Applied: %d; Backlog: %d/%d; Time: %+v(total), %+v(copy); streamer: %+v; Lag: %+v, State: %s; ETA: %s",
962964
totalRowsCopied, rowsEstimate, progressPct,
963965
atomic.LoadInt64(&this.migrationContext.TotalDMLEventsApplied),
964966
len(this.applyEventsQueue), cap(this.applyEventsQueue),
965967
base.PrettifyDurationOutput(elapsedTime), base.PrettifyDurationOutput(this.migrationContext.ElapsedRowCopyTime()),
966968
currentBinlogCoordinates,
969+
this.migrationContext.GetCurrentLagDuration().Seconds(),
967970
state,
968971
eta,
969972
)

0 commit comments

Comments
 (0)