@@ -819,11 +819,18 @@ func (this *Migrator) initiateStatus() {
819
819
this .printStatus (ForcePrintStatusAndHintRule )
820
820
ticker := time .NewTicker (time .Second )
821
821
defer ticker .Stop ()
822
+ var previousCount int64
822
823
for range ticker .C {
823
824
if atomic .LoadInt64 (& this .finishedMigrating ) > 0 {
824
825
return
825
826
}
826
827
go this .printStatus (HeuristicPrintStatusRule )
828
+ totalCopied := atomic .LoadInt64 (& this .migrationContext .TotalRowsCopied )
829
+ if previousCount > 0 {
830
+ copiedThisLoop := totalCopied - previousCount
831
+ atomic .StoreInt64 (& this .migrationContext .EtaRowsPerSecond , copiedThisLoop )
832
+ }
833
+ previousCount = totalCopied
827
834
}
828
835
}
829
836
@@ -925,9 +932,20 @@ func (this *Migrator) getMigrationETA(rowsEstimate int64) (eta string, duration
925
932
duration = 0
926
933
} else if progressPct >= 0.1 {
927
934
totalRowsCopied := this .migrationContext .GetTotalRowsCopied ()
928
- elapsedRowCopySeconds := this .migrationContext .ElapsedRowCopyTime ().Seconds ()
929
- totalExpectedSeconds := elapsedRowCopySeconds * float64 (rowsEstimate ) / float64 (totalRowsCopied )
930
- etaSeconds := totalExpectedSeconds - elapsedRowCopySeconds
935
+ etaRowsPerSecond := atomic .LoadInt64 (& this .migrationContext .EtaRowsPerSecond )
936
+ var etaSeconds float64
937
+ // If there is data available on our current row-copies-per-second rate, use it.
938
+ // Otherwise we can fallback to the total elapsed time and extrapolate.
939
+ // This is going to be less accurate on a longer copy as the insert rate
940
+ // will tend to slow down.
941
+ if etaRowsPerSecond > 0 {
942
+ remainingRows := float64 (rowsEstimate ) - float64 (totalRowsCopied )
943
+ etaSeconds = remainingRows / float64 (etaRowsPerSecond )
944
+ } else {
945
+ elapsedRowCopySeconds := this .migrationContext .ElapsedRowCopyTime ().Seconds ()
946
+ totalExpectedSeconds := elapsedRowCopySeconds * float64 (rowsEstimate ) / float64 (totalRowsCopied )
947
+ etaSeconds = totalExpectedSeconds - elapsedRowCopySeconds
948
+ }
931
949
if etaSeconds >= 0 {
932
950
duration = time .Duration (etaSeconds ) * time .Second
933
951
} else {
0 commit comments