@@ -14,7 +14,7 @@ import (
14
14
"github.com/0chain/blobber/code/go/0chain.net/core/common"
15
15
"github.com/0chain/blobber/code/go/0chain.net/core/logging"
16
16
"github.com/0chain/gosdk/constants"
17
- "github.com/remeh/sizedwaitgroup "
17
+ "golang.org/x/sync/errgroup "
18
18
19
19
"go.uber.org/zap"
20
20
"gorm.io/gorm"
@@ -236,35 +236,19 @@ func (cc *AllocationChangeCollector) ApplyChanges(ctx context.Context, allocatio
236
236
}
237
237
238
238
func (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 )
243
242
mut := & sync.Mutex {}
244
- var (
245
- commitError error
246
- errorMutex sync.Mutex
247
- )
248
243
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
+ })
265
248
}
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 ()
268
252
}
269
253
270
254
func (a * AllocationChangeCollector ) DeleteChanges (ctx context.Context ) {
0 commit comments