From 9a4763ceee77b4a8541a518ab23bdb982b7f137e Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Wed, 1 Jan 2020 15:45:55 +0100 Subject: [PATCH] client/status: notify user if size estimation is imprecise There's plenty of room for improvement here. For example, detect if we're past the last step without size estimation and compute the remaining sum of bytes to be replicated from there on. --- client/status.go | 19 ++++++++++++++++--- replication/report/replication_report.go | 10 ++++++---- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/client/status.go b/client/status.go index 75ef3f1..2811f34 100644 --- a/client/status.go +++ b/client/status.go @@ -461,7 +461,7 @@ func (t *tui) renderReplicationReport(rep *report.Report, history *bytesProgress if latest.State != report.AttemptPlanning && latest.State != report.AttemptPlanningError { // Draw global progress bar // Progress: [---------------] - expected, replicated := latest.BytesSum() + expected, replicated, containsInvalidSizeEstimates := latest.BytesSum() rate, changeCount := history.Update(replicated) eta := time.Duration(0) if rate > 0 { @@ -474,6 +474,10 @@ func (t *tui) renderReplicationReport(rep *report.Report, history *bytesProgress t.write(fmt.Sprintf(" (%s remaining)", humanizeDuration(eta))) } t.newline() + if containsInvalidSizeEstimates { + t.write("NOTE: not all steps could be size-estimated, total estimate is likely imprecise!") + t.newline() + } var maxFSLen int for _, fs := range latest.Filesystems { @@ -714,11 +718,20 @@ func (t *tui) drawBar(length int, bytes, totalBytes int64, changeCount int) { func (t *tui) printFilesystemStatus(rep *report.FilesystemReport, active bool, maxFS int) { - expected, replicated := rep.BytesSum() - status := fmt.Sprintf("%s (step %d/%d, %s/%s)", + expected, replicated, containsInvalidSizeEstimates := rep.BytesSum() + sizeEstimationImpreciseNotice := "" + if containsInvalidSizeEstimates { + sizeEstimationImpreciseNotice = " (some steps lack size estimation)" + } + if rep.CurrentStep < len(rep.Steps) && rep.Steps[rep.CurrentStep].Info.BytesExpected == 0 { + sizeEstimationImpreciseNotice = " (step lacks size estimation)" + } + + status := fmt.Sprintf("%s (step %d/%d, %s/%s)%s", strings.ToUpper(string(rep.State)), rep.CurrentStep, len(rep.Steps), ByteCountBinary(replicated), ByteCountBinary(expected), + sizeEstimationImpreciseNotice, ) activeIndicator := " " diff --git a/replication/report/replication_report.go b/replication/report/replication_report.go index 7f8f605..17f507b 100644 --- a/replication/report/replication_report.go +++ b/replication/report/replication_report.go @@ -91,19 +91,21 @@ type StepInfo struct { BytesReplicated int64 } -func (a *AttemptReport) BytesSum() (expected, replicated int64) { +func (a *AttemptReport) BytesSum() (expected, replicated int64, containsInvalidSizeEstimates bool) { for _, fs := range a.Filesystems { - e, r := fs.BytesSum() + e, r, fsContainsInvalidEstimate := fs.BytesSum() + containsInvalidSizeEstimates = containsInvalidSizeEstimates || fsContainsInvalidEstimate expected += e replicated += r } - return expected, replicated + return expected, replicated, containsInvalidSizeEstimates } -func (f *FilesystemReport) BytesSum() (expected, replicated int64) { +func (f *FilesystemReport) BytesSum() (expected, replicated int64, containsInvalidSizeEstimates bool) { for _, step := range f.Steps { expected += step.Info.BytesExpected replicated += step.Info.BytesReplicated + containsInvalidSizeEstimates = containsInvalidSizeEstimates || step.Info.BytesExpected == 0 } return }