@@ -819,11 +819,18 @@ func (this *Migrator) initiateStatus() {
819819 this .printStatus (ForcePrintStatusAndHintRule )
820820 ticker := time .NewTicker (time .Second )
821821 defer ticker .Stop ()
822+ var previousCount int64
822823 for range ticker .C {
823824 if atomic .LoadInt64 (& this .finishedMigrating ) > 0 {
824825 return
825826 }
826827 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
827834 }
828835}
829836
@@ -925,9 +932,20 @@ func (this *Migrator) getMigrationETA(rowsEstimate int64) (eta string, duration
925932 duration = 0
926933 } else if progressPct >= 0.1 {
927934 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+ }
931949 if etaSeconds >= 0 {
932950 duration = time .Duration (etaSeconds ) * time .Second
933951 } else {
0 commit comments