Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transfer - Progress should only represent successful storage transfer #1000

Merged
merged 4 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 16 additions & 23 deletions utils/progressbar/progressbarmng.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}),
),
)
Expand Down Expand Up @@ -189,27 +188,28 @@ 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++
}

// Increment increments completed tasks count by n.
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)
}

// DoneTask increase tasks counter to the number of totalTasks.
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
// 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)
}
prog.tasksProgressBar.bar.IncrBy(int(diff))
}

func (bm *ProgressBarMng) NewTasksProgressBar(totalTasks int64, windows bool, taskType string) *TasksProgressBar {
Expand Down Expand Up @@ -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)
}),
Expand Down Expand Up @@ -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
}
9 changes: 3 additions & 6 deletions utils/progressbar/transferprogressbarmanager.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package progressbar

import (
"math"
"sync"
"time"

Expand Down Expand Up @@ -118,7 +117,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")
}
Expand All @@ -127,10 +126,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)
}
Expand Down
Loading