diff --git a/go/logic/migrator.go b/go/logic/migrator.go index 61f92d9..f36c28a 100644 --- a/go/logic/migrator.go +++ b/go/logic/migrator.go @@ -684,8 +684,9 @@ func (this *Migrator) printMigrationStatusHint(writers ...io.Writer) { *this.inspector.connectionConfig.ImpliedKey, this.migrationContext.Hostname, )) - fmt.Fprintln(w, fmt.Sprintf("# Migration started at %+v", + fmt.Fprintln(w, fmt.Sprintf("# Migration started at %+v; time now is %+v", this.migrationContext.StartTime.Format(time.RubyDate), + time.Now().Format(time.RubyDate), )) maxLoad := this.migrationContext.GetMaxLoad() criticalLoad := this.migrationContext.GetCriticalLoad() @@ -793,7 +794,9 @@ func (this *Migrator) printStatus(rule PrintStatusRule, writers ...io.Writer) { etaDuration := etaTime.Sub(time.Now()) eta = base.PrettifyDurationOutput(etaDuration) etaSeconds = etaDuration.Seconds() + log.Errorf("==== etaTime: %+v, eta=%+v, etaSeonds=%+v", etaTime, eta, etaSeconds) } + log.Errorf("===1 etaTime: %+v, eta=%+v, etaSeonds=%+v", "na", eta, etaSeconds) if etaSeconds < 0 { eta = "due" diff --git a/go/logic/progress.go b/go/logic/progress.go index 2eeaac5..0b95321 100644 --- a/go/logic/progress.go +++ b/go/logic/progress.go @@ -13,7 +13,7 @@ import ( "github.com/github/gh-ost/go/base" ) -const maxHistoryDuration time.Duration = time.Hour +const maxHistoryDuration time.Duration = time.Minute * 61 type ProgressState struct { mark time.Time @@ -50,6 +50,15 @@ func (this *ProgressHistory) oldestState() *ProgressState { return this.history[0] } +func (this *ProgressHistory) firstStateSince(since time.Time) *ProgressState { + for _, state := range this.history { + if !state.mark.Before(since) { + return state + } + } + return nil +} + func (this *ProgressHistory) newestState() *ProgressState { if len(this.history) == 0 { return nil @@ -98,12 +107,12 @@ func (this *ProgressHistory) hasEnoughData() bool { return true } -func (this *ProgressHistory) getETA() (eta time.Time) { +func (this *ProgressHistory) getETABasedOnRange(basedOnRange time.Duration) (eta time.Time) { if !this.hasEnoughData() { return eta } - oldest := this.oldestState() + oldest := this.firstStateSince(time.Now().Add(-basedOnRange)) newest := this.newestState() rowsEstimate := atomic.LoadInt64(&this.migrationContext.RowsEstimate) + atomic.LoadInt64(&this.migrationContext.RowsDeltaEstimate) ratio := float64(rowsEstimate-oldest.rowsCopied) / float64(newest.rowsCopied-oldest.rowsCopied) @@ -113,3 +122,22 @@ func (this *ProgressHistory) getETA() (eta time.Time) { return eta } + +func (this *ProgressHistory) getETA() (eta time.Time) { + if eta = this.getETABasedOnRange(time.Minute * 1); !eta.IsZero() { + return eta + } + if eta = this.getETABasedOnRange(time.Minute * 5); !eta.IsZero() { + return eta + } + if eta = this.getETABasedOnRange(time.Minute * 10); !eta.IsZero() { + return eta + } + if eta = this.getETABasedOnRange(time.Minute * 30); !eta.IsZero() { + return eta + } + if eta = this.getETABasedOnRange(time.Minute * 60); !eta.IsZero() { + return eta + } + return eta +}