@@ -14,7 +14,7 @@ import (
1414 "github.com/0chain/blobber/code/go/0chain.net/core/common"
1515 "github.com/0chain/blobber/code/go/0chain.net/core/logging"
1616 "github.com/0chain/gosdk/constants"
17- "github.com/remeh/sizedwaitgroup "
17+ "golang.org/x/sync/errgroup "
1818
1919 "go.uber.org/zap"
2020 "gorm.io/gorm"
@@ -236,35 +236,19 @@ func (cc *AllocationChangeCollector) ApplyChanges(ctx context.Context, allocatio
236236}
237237
238238func (a * AllocationChangeCollector ) CommitToFileStore (ctx context.Context ) error {
239- commitCtx , cancel := context .WithCancel (ctx )
240- defer cancel ()
241- // Can be configured at runtime, this number will depend on the number of active allocations
242- swg := sizedwaitgroup .New (5 )
239+ // Limit can be configured at runtime, this number will depend on the number of active allocations
240+ eg , _ := errgroup .WithContext (ctx )
241+ eg .SetLimit (5 )
243242 mut := & sync.Mutex {}
244- var (
245- commitError error
246- errorMutex sync.Mutex
247- )
248243 for _ , change := range a .AllocationChanges {
249- select {
250- case <- commitCtx .Done ():
251- return fmt .Errorf ("commit to filestore failed: %s" , commitError .Error ())
252- default :
253- }
254- swg .Add ()
255- go func (change AllocationChangeProcessor ) {
256- err := change .CommitToFileStore (ctx , mut )
257- if err != nil && ! errors .Is (common .ErrFileWasDeleted , err ) {
258- cancel ()
259- errorMutex .Lock ()
260- commitError = err
261- errorMutex .Unlock ()
262- }
263- swg .Done ()
264- }(change )
244+ allocChange := change
245+ eg .Go (func () error {
246+ return allocChange .CommitToFileStore (ctx , mut )
247+ })
265248 }
266- swg .Wait ()
267- return commitError
249+ logging .Logger .Info ("Waiting for commit to filestore" , zap .String ("allocation_id" , a .AllocationID ))
250+
251+ return eg .Wait ()
268252}
269253
270254func (a * AllocationChangeCollector ) DeleteChanges (ctx context.Context ) {
0 commit comments