Skip to content

Commit 271c727

Browse files
author
Shlomi Noach
committed
refactor progressPct into migrationContext
1 parent 8893b22 commit 271c727

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

go/base/context.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package base
77

88
import (
99
"fmt"
10+
"math"
1011
"os"
1112
"regexp"
1213
"strings"
@@ -174,7 +175,7 @@ type MigrationContext struct {
174175
pointOfInterestTime time.Time
175176
pointOfInterestTimeMutex *sync.Mutex
176177
CurrentLag int64
177-
CurrentProgress uint64 // math.Float64bits([f=0..100])
178+
currentProgress uint64
178179
ThrottleHTTPStatusCode int64
179180
controlReplicasLagResult mysql.ReplicationLagResult
180181
TotalRowsCopied int64
@@ -433,6 +434,16 @@ func (this *MigrationContext) GetCurrentLagDuration() time.Duration {
433434
return time.Duration(atomic.LoadInt64(&this.CurrentLag))
434435
}
435436

437+
func (this *MigrationContext) GetProgressPct() float64 {
438+
return math.Float64frombits(atomic.LoadUint64(&this.currentProgress))
439+
}
440+
441+
func (this *MigrationContext) SetProgressPct(progressPct float64) {
442+
atomic.StoreUint64(&this.currentProgress, math.Float64bits(progressPct))
443+
}
444+
445+
// math.Float64bits([f=0..100])
446+
436447
// GetTotalRowsCopied returns the accurate number of rows being copied (affected)
437448
// This is not exactly the same as the rows being iterated via chunks, but potentially close enough
438449
func (this *MigrationContext) GetTotalRowsCopied() int64 {

go/logic/hooks.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ package logic
88

99
import (
1010
"fmt"
11-
"math"
1211
"os"
1312
"os/exec"
1413
"path/filepath"
@@ -65,7 +64,7 @@ func (this *HooksExecutor) applyEnvironmentVariables(extraVariables ...string) [
6564
env = append(env, fmt.Sprintf("GH_OST_INSPECTED_HOST=%s", this.migrationContext.GetInspectorHostname()))
6665
env = append(env, fmt.Sprintf("GH_OST_EXECUTING_HOST=%s", this.migrationContext.Hostname))
6766
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))))
67+
env = append(env, fmt.Sprintf("GH_OST_PROGRESS=%f", this.migrationContext.GetProgressPct()))
6968
env = append(env, fmt.Sprintf("GH_OST_HOOKS_HINT=%s", this.migrationContext.HooksHintMessage))
7069
env = append(env, fmt.Sprintf("GH_OST_HOOKS_HINT_OWNER=%s", this.migrationContext.HooksHintOwner))
7170
env = append(env, fmt.Sprintf("GH_OST_HOOKS_HINT_TOKEN=%s", this.migrationContext.HooksHintToken))

go/logic/migrator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ func (this *Migrator) printStatus(rule PrintStatusRule, writers ...io.Writer) {
896896
progressPct = 100.0 * float64(totalRowsCopied) / float64(rowsEstimate)
897897
}
898898
// we take the opportunity to update migration context with progressPct
899-
atomic.StoreUint64(&this.migrationContext.CurrentProgress, math.Float64bits(progressPct))
899+
this.migrationContext.SetProgressPct(progressPct)
900900
// Before status, let's see if we should print a nice reminder for what exactly we're doing here.
901901
shouldPrintMigrationStatusHint := (elapsedSeconds%600 == 0)
902902
if rule == ForcePrintStatusAndHintRule {

0 commit comments

Comments
 (0)