From 4eed8a05d7080cf846aef24507d68b3a882cd999 Mon Sep 17 00:00:00 2001 From: yahavi Date: Tue, 17 Oct 2023 15:51:29 +0300 Subject: [PATCH 1/3] Revert "Transfer - Fix some issues in the progressbar (#997)" This reverts commit 9b64c74d7c9426c8b610e05c8655dd515a7a22d3. --- utils/progressbar/progressbarmng.go | 39 ++++++++----------- .../progressbar/transferprogressbarmanager.go | 12 ++---- 2 files changed, 20 insertions(+), 31 deletions(-) diff --git a/utils/progressbar/progressbarmng.go b/utils/progressbar/progressbarmng.go index d9e7ff010..bb7cb26f6 100644 --- a/utils/progressbar/progressbarmng.go +++ b/utils/progressbar/progressbarmng.go @@ -95,18 +95,17 @@ func (bm *ProgressBarMng) newDoubleValueProgressBar(getVal func() (firstNumerato if err != nil { log.Error(err) } - numeratorString := artifactoryutils.ConvertIntToStorageSizeString(getProgressNumerator(statistics, *firstNumerator, *firstDenominator)) - denominatorString := artifactoryutils.ConvertIntToStorageSizeString(*firstDenominator) - return color.Green.Render(numeratorString + "/" + denominatorString) - }), - decor.Name(" "+secondValueLine+": "), decor.Any(func(statistics decor.Statistics) string { + s1 := artifactoryutils.ConvertIntToStorageSizeString(*firstNumerator) + s2 := artifactoryutils.ConvertIntToStorageSizeString(*firstDenominator) + return color.Green.Render(s1 + "/" + s2) + }), decor.Name(" "+secondValueLine+": "), decor.Any(func(statistics decor.Statistics) string { _, _, secondNumerator, secondDenominator, err := getVal() if err != nil { log.Error(err) } - numeratorString := strconv.FormatInt(getProgressNumerator(statistics, *secondNumerator, *secondDenominator), 10) - denominatorString := strconv.Itoa(int(*secondDenominator)) - return color.Green.Render(numeratorString + "/" + denominatorString) + s1 := strconv.Itoa(int(*secondNumerator)) + s2 := strconv.Itoa(int(*secondDenominator)) + return color.Green.Render(s1 + "/" + s2) }), ), ) @@ -189,9 +188,7 @@ func (bm *ProgressBarMng) NewHeadlineBar(msg string) *mpb.Bar { func (bm *ProgressBarMng) Increment(prog *TasksWithHeadlineProg) { bm.barsRWMutex.RLock() defer bm.barsRWMutex.RUnlock() - if prog.tasksProgressBar.bar.Current() < math.MaxInt64 { - prog.tasksProgressBar.bar.Increment() - } + prog.tasksProgressBar.bar.Increment() prog.tasksProgressBar.tasksCount++ } @@ -199,9 +196,7 @@ func (bm *ProgressBarMng) Increment(prog *TasksWithHeadlineProg) { func (bm *ProgressBarMng) IncBy(n int, prog *TasksWithHeadlineProg) { bm.barsRWMutex.RLock() defer bm.barsRWMutex.RUnlock() - if prog.tasksProgressBar.bar.Current() < math.MaxInt64 { - prog.tasksProgressBar.bar.IncrBy(n) - } + prog.tasksProgressBar.bar.IncrBy(n) prog.tasksProgressBar.tasksCount += int64(n) } @@ -209,7 +204,12 @@ func (bm *ProgressBarMng) IncBy(n int, prog *TasksWithHeadlineProg) { func (bm *ProgressBarMng) DoneTask(prog *TasksWithHeadlineProg) { bm.barsRWMutex.RLock() defer bm.barsRWMutex.RUnlock() - prog.tasksProgressBar.bar.SetCurrent(math.MaxInt64) + diff := prog.tasksProgressBar.total - prog.tasksProgressBar.tasksCount + // Handle large number of total tasks + for ; diff > math.MaxInt; diff -= math.MaxInt { + prog.tasksProgressBar.bar.IncrBy(math.MaxInt) + } + prog.tasksProgressBar.bar.IncrBy(int(diff)) } func (bm *ProgressBarMng) NewTasksProgressBar(totalTasks int64, windows bool, taskType string) *TasksProgressBar { @@ -240,7 +240,7 @@ func (bm *ProgressBarMng) newTasksProgressBar(getVal func() (numerator, denomina mpb.AppendDecorators( decor.Name(" "+headLine+": "), decor.Any(func(statistics decor.Statistics) string { - numeratorString := strconv.FormatInt(getProgressNumerator(statistics, *numerator, *denominator), 10) + numeratorString := strconv.Itoa(int(*numerator)) denominatorString := strconv.Itoa(int(*denominator)) return color.Green.Render(numeratorString + "/" + denominatorString) }), @@ -353,10 +353,3 @@ func setTerminalWidthVar() error { } return err } - -func getProgressNumerator(statistics decor.Statistics, numerator, denominator int64) int64 { - if statistics.Current == math.MaxInt64 { - return denominator - } - return numerator -} diff --git a/utils/progressbar/transferprogressbarmanager.go b/utils/progressbar/transferprogressbarmanager.go index 840ccd02d..a9bae5f56 100644 --- a/utils/progressbar/transferprogressbarmanager.go +++ b/utils/progressbar/transferprogressbarmanager.go @@ -1,7 +1,6 @@ package progressbar import ( - "math" "sync" "time" @@ -15,7 +14,6 @@ import ( const ( phase1HeadLine = "Phase 1: Transferring all files in the repository" phase2HeadLine = "Phase 2: Transferring newly created and modified files" - phase3HeadLine = "Phase 3: Retrying transfer failures" DelayedFilesContentNote = "Files to be transferred last, after all other files" RetryFailureContentNote = "In Phase 3 and in subsequent executions, we'll retry transferring the failed files" ) @@ -118,7 +116,7 @@ func (tpm *TransferProgressMng) NewPhase1ProgressBar() *TasksWithHeadlineProg { if tpm.currentRepoShouldStop { return } - transferredStorage, totalStorage, _, _, err := getVals() + ptr1, ptr2, _, _, err := getVals() if err != nil { log.Error("Error: Couldn't get needed information about transfer status from state") } @@ -127,10 +125,8 @@ func (tpm *TransferProgressMng) NewPhase1ProgressBar() *TasksWithHeadlineProg { return } if pb.GetTasksProgressBar() != nil { - pb.GetTasksProgressBar().SetGeneralProgressTotal(*totalStorage) - if pb.GetTasksProgressBar().GetBar().Current() < math.MaxInt64 { - pb.GetTasksProgressBar().GetBar().SetCurrent(*transferredStorage) - } + pb.GetTasksProgressBar().SetGeneralProgressTotal(*ptr2) + pb.GetTasksProgressBar().GetBar().SetCurrent(*ptr1) } time.Sleep(1 * time.Second) } @@ -187,7 +183,7 @@ func (tpm *TransferProgressMng) NewPhase3ProgressBar() *TasksWithHeadlineProg { }) return transferredStorage, totalStorage, transferredFiles, totalFiles, err } - pb := tpm.barMng.newDoubleHeadLineProgressBar(phase3HeadLine, tpm.transferLabels.Storage, tpm.transferLabels.Files, getVals) + pb := tpm.barMng.newDoubleHeadLineProgressBar(phase2HeadLine, tpm.transferLabels.Storage, tpm.transferLabels.Files, getVals) tpm.wg.Add(1) go func() { From 44c6479faca2c4365b1201f2066edd4e9f5c99b4 Mon Sep 17 00:00:00 2001 From: yahavi Date: Tue, 17 Oct 2023 16:25:56 +0300 Subject: [PATCH 2/3] Fix phase 3 label --- utils/progressbar/transferprogressbarmanager.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/utils/progressbar/transferprogressbarmanager.go b/utils/progressbar/transferprogressbarmanager.go index a9bae5f56..4219c20d0 100644 --- a/utils/progressbar/transferprogressbarmanager.go +++ b/utils/progressbar/transferprogressbarmanager.go @@ -14,6 +14,7 @@ import ( const ( phase1HeadLine = "Phase 1: Transferring all files in the repository" phase2HeadLine = "Phase 2: Transferring newly created and modified files" + phase3HeadLine = "Phase 3: Retrying transfer failures" DelayedFilesContentNote = "Files to be transferred last, after all other files" RetryFailureContentNote = "In Phase 3 and in subsequent executions, we'll retry transferring the failed files" ) @@ -183,7 +184,7 @@ func (tpm *TransferProgressMng) NewPhase3ProgressBar() *TasksWithHeadlineProg { }) return transferredStorage, totalStorage, transferredFiles, totalFiles, err } - pb := tpm.barMng.newDoubleHeadLineProgressBar(phase2HeadLine, tpm.transferLabels.Storage, tpm.transferLabels.Files, getVals) + pb := tpm.barMng.newDoubleHeadLineProgressBar(phase3HeadLine, tpm.transferLabels.Storage, tpm.transferLabels.Files, getVals) tpm.wg.Add(1) go func() { From e692622faac752bf2cb78f2ff45ed9d645d9e542 Mon Sep 17 00:00:00 2001 From: yahavi Date: Wed, 18 Oct 2023 10:18:05 +0300 Subject: [PATCH 3/3] CR --- utils/progressbar/progressbarmng.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/progressbar/progressbarmng.go b/utils/progressbar/progressbarmng.go index bb7cb26f6..2c9dce525 100644 --- a/utils/progressbar/progressbarmng.go +++ b/utils/progressbar/progressbarmng.go @@ -205,7 +205,7 @@ func (bm *ProgressBarMng) DoneTask(prog *TasksWithHeadlineProg) { bm.barsRWMutex.RLock() defer bm.barsRWMutex.RUnlock() diff := prog.tasksProgressBar.total - prog.tasksProgressBar.tasksCount - // Handle large number of total tasks + // diff is int64, but we can increase the progress up to math.MaxInt in a time for ; diff > math.MaxInt; diff -= math.MaxInt { prog.tasksProgressBar.bar.IncrBy(math.MaxInt) }