Skip to content

Commit f19f101

Browse files
authored
hooks: reporting GH_OST_ETA_SECONDS. ETA as part of migration context (#936)
* v1.1.0 * WIP: copying AUTO_INCREMENT value to ghost table Initial commit: towards setting up a test suite Signed-off-by: Shlomi Noach <[email protected]> * greping for 'expect_table_structure' content * Adding simple test for 'expect_table_structure' scenario * adding tests for AUTO_INCREMENT value after row deletes. Should initially fail * clear event beforehand * parsing AUTO_INCREMENT from alter query, reading AUTO_INCREMENT from original table, applying AUTO_INCREMENT value onto ghost table if applicable and user has not specified AUTO_INCREMENT in alter statement * support GetUint64 Signed-off-by: Shlomi Noach <[email protected]> * minor update to test Signed-off-by: Shlomi Noach <[email protected]> * adding test for user defined AUTO_INCREMENT statement * Generated column as part of UNIQUE (or PRIMARY) KEY Signed-off-by: Shlomi Noach <[email protected]> * skip analysis of generated column data type in unique key Signed-off-by: Shlomi Noach <[email protected]> * All MySQL DBs limited to max 3 concurrent/idle connections Signed-off-by: Shlomi Noach <[email protected]> * hooks: reporting GH_OST_ETA_SECONDS. ETA stored as part of migration context Signed-off-by: Shlomi Noach <[email protected]> * GH_OST_ETA_NANOSECONDS Signed-off-by: Shlomi Noach <[email protected]> * N/A denoted by negative value Signed-off-by: Shlomi Noach <[email protected]> * ETAUnknown constant Signed-off-by: Shlomi Noach <[email protected]>
1 parent c41823e commit f19f101

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

go/base/context.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ const (
5252
const (
5353
HTTPStatusOK = 200
5454
MaxEventsBatchSize = 1000
55+
ETAUnknown = math.MinInt64
5556
)
5657

5758
var (
@@ -182,6 +183,7 @@ type MigrationContext struct {
182183
lastHeartbeatOnChangelogMutex *sync.Mutex
183184
CurrentLag int64
184185
currentProgress uint64
186+
etaNanoseonds int64
185187
ThrottleHTTPStatusCode int64
186188
controlReplicasLagResult mysql.ReplicationLagResult
187189
TotalRowsCopied int64
@@ -267,6 +269,7 @@ func NewMigrationContext() *MigrationContext {
267269
MaxLagMillisecondsThrottleThreshold: 1500,
268270
CutOverLockTimeoutSeconds: 3,
269271
DMLBatchSize: 10,
272+
etaNanoseonds: ETAUnknown,
270273
maxLoad: NewLoadMap(),
271274
criticalLoad: NewLoadMap(),
272275
throttleMutex: &sync.Mutex{},
@@ -474,6 +477,22 @@ func (this *MigrationContext) SetProgressPct(progressPct float64) {
474477
atomic.StoreUint64(&this.currentProgress, math.Float64bits(progressPct))
475478
}
476479

480+
func (this *MigrationContext) GetETADuration() time.Duration {
481+
return time.Duration(atomic.LoadInt64(&this.etaNanoseonds))
482+
}
483+
484+
func (this *MigrationContext) SetETADuration(etaDuration time.Duration) {
485+
atomic.StoreInt64(&this.etaNanoseonds, etaDuration.Nanoseconds())
486+
}
487+
488+
func (this *MigrationContext) GetETASeconds() int64 {
489+
nano := atomic.LoadInt64(&this.etaNanoseonds)
490+
if nano < 0 {
491+
return ETAUnknown
492+
}
493+
return nano / int64(time.Second)
494+
}
495+
477496
// math.Float64bits([f=0..100])
478497

479498
// GetTotalRowsCopied returns the accurate number of rows being copied (affected)

go/logic/hooks.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ func (this *HooksExecutor) applyEnvironmentVariables(extraVariables ...string) [
6666
env = append(env, fmt.Sprintf("GH_OST_INSPECTED_LAG=%f", this.migrationContext.GetCurrentLagDuration().Seconds()))
6767
env = append(env, fmt.Sprintf("GH_OST_HEARTBEAT_LAG=%f", this.migrationContext.TimeSinceLastHeartbeatOnChangelog().Seconds()))
6868
env = append(env, fmt.Sprintf("GH_OST_PROGRESS=%f", this.migrationContext.GetProgressPct()))
69+
env = append(env, fmt.Sprintf("GH_OST_ETA_SECONDS=%d", this.migrationContext.GetETASeconds()))
6970
env = append(env, fmt.Sprintf("GH_OST_HOOKS_HINT=%s", this.migrationContext.HooksHintMessage))
7071
env = append(env, fmt.Sprintf("GH_OST_HOOKS_HINT_OWNER=%s", this.migrationContext.HooksHintOwner))
7172
env = append(env, fmt.Sprintf("GH_OST_HOOKS_HINT_TOKEN=%s", this.migrationContext.HooksHintToken))

go/logic/migrator.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -939,20 +939,29 @@ func (this *Migrator) printStatus(rule PrintStatusRule, writers ...io.Writer) {
939939
}
940940

941941
var etaSeconds float64 = math.MaxFloat64
942-
eta := "N/A"
942+
var etaDuration = time.Duration(base.ETAUnknown)
943943
if progressPct >= 100.0 {
944-
eta = "due"
944+
etaDuration = 0
945945
} else if progressPct >= 0.1 {
946946
elapsedRowCopySeconds := this.migrationContext.ElapsedRowCopyTime().Seconds()
947947
totalExpectedSeconds := elapsedRowCopySeconds * float64(rowsEstimate) / float64(totalRowsCopied)
948948
etaSeconds = totalExpectedSeconds - elapsedRowCopySeconds
949949
if etaSeconds >= 0 {
950-
etaDuration := time.Duration(etaSeconds) * time.Second
951-
eta = base.PrettifyDurationOutput(etaDuration)
950+
etaDuration = time.Duration(etaSeconds) * time.Second
952951
} else {
953-
eta = "due"
952+
etaDuration = 0
954953
}
955954
}
955+
this.migrationContext.SetETADuration(etaDuration)
956+
var eta string
957+
switch etaDuration {
958+
case 0:
959+
eta = "due"
960+
case time.Duration(base.ETAUnknown):
961+
eta = "N/A"
962+
default:
963+
eta = base.PrettifyDurationOutput(etaDuration)
964+
}
956965

957966
state := "migrating"
958967
if atomic.LoadInt64(&this.migrationContext.CountingRowsFlag) > 0 && !this.migrationContext.ConcurrentCountTableRows {

0 commit comments

Comments
 (0)