2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-22 19:08:55 +00:00

Merge pull request #3748 from greatroar/runworkers

repository: Remove RunWorkers, report ctx.Err()
This commit is contained in:
MichaelEischer 2022-05-11 19:38:46 +02:00 committed by GitHub
commit df554e5f69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 31 deletions

View File

@ -37,7 +37,7 @@ func ForAllIndexes(ctx context.Context, repo restic.Repository,
return repo.List(ctx, restic.IndexFile, func(id restic.ID, size int64) error {
select {
case <-ctx.Done():
return nil
return ctx.Err()
case ch <- FileInfo{id, size}:
}
return nil
@ -69,9 +69,9 @@ func ForAllIndexes(ctx context.Context, repo restic.Repository,
}
// run workers on ch
wg.Go(func() error {
return RunWorkers(loadIndexParallelism, worker)
})
for i := 0; i < loadIndexParallelism; i++ {
wg.Go(worker)
}
return wg.Wait()
}

View File

@ -365,7 +365,7 @@ func (mi *MasterIndex) Save(ctx context.Context, repo restic.Repository, packBla
select {
case ch <- newIndex:
case <-ctx.Done():
return nil
return ctx.Err()
}
newIndex = NewIndex()
}
@ -397,10 +397,9 @@ func (mi *MasterIndex) Save(ctx context.Context, repo restic.Repository, packBla
}
// run workers on ch
wg.Go(func() error {
return RunWorkers(saveIndexParallelism, worker)
})
for i := 0; i < saveIndexParallelism; i++ {
wg.Go(worker)
}
err = wg.Wait()
return obsolete, err

View File

@ -679,7 +679,7 @@ func (r *Repository) CreateIndexFromPacks(ctx context.Context, packsize map[rest
for id, size := range packsize {
select {
case <-ctx.Done():
return nil
return ctx.Err()
case ch <- FileInfo{id, size}:
}
}
@ -705,9 +705,9 @@ func (r *Repository) CreateIndexFromPacks(ctx context.Context, packsize map[rest
}
// run workers on ch
wg.Go(func() error {
return RunWorkers(listPackParallelism, worker)
})
for i := 0; i < listPackParallelism; i++ {
wg.Go(worker)
}
err = wg.Wait()
if err != nil {

View File

@ -1,18 +0,0 @@
package repository
import (
"golang.org/x/sync/errgroup"
)
// RunWorkers runs count instances of workerFunc using an errgroup.Group.
// If an error occurs in one of the workers, it is returned.
func RunWorkers(count int, workerFunc func() error) error {
var wg errgroup.Group
// run workers
for i := 0; i < count; i++ {
wg.Go(workerFunc)
}
return wg.Wait()
}