Skip to content

Commit b80032b

Browse files
committed
add logs for commit
1 parent 6fa147c commit b80032b

File tree

3 files changed

+15
-28
lines changed

3 files changed

+15
-28
lines changed

code/go/0chain.net/blobbercore/allocation/allocationchange.go

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -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

238238
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)
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

270254
func (a *AllocationChangeCollector) DeleteChanges(ctx context.Context) {

code/go/0chain.net/blobbercore/handler/object_operation_handler.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,8 @@ func (fsh *StorageHandler) CommitWrite(ctx context.Context, r *http.Request) (*b
502502
clientKey := ctx.Value(constants.ContextKeyClientKey).(string)
503503
clientKeyBytes, _ := hex.DecodeString(clientKey)
504504

505+
logging.Logger.Info("commit_write", zap.String("allocation_id", allocationId))
506+
505507
if clientID == "" || clientKey == "" {
506508
return nil, common.NewError("invalid_parameters", "Please provide clientID and clientKey")
507509
}
@@ -711,7 +713,7 @@ func (fsh *StorageHandler) CommitWrite(ctx context.Context, r *http.Request) (*b
711713
}
712714
}
713715
elapsedCommitStore := time.Since(startTime) - elapsedAllocation - elapsedGetLock - elapsedGetConnObj - elapsedVerifyWM - elapsedWritePreRedeem - elapsedApplyChanges - elapsedSaveAllocation
714-
716+
logging.Logger.Info("commit_filestore", zap.String("allocation_id", allocationId), zap.String("allocation_root", allocationRoot))
715717
connectionObj.DeleteChanges(ctx)
716718

717719
db.Model(connectionObj).Updates(allocation.AllocationChangeCollector{Status: allocation.CommittedConnection})

code/go/0chain.net/blobbercore/handler/worker.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ func CleanupDiskFiles(ctx context.Context) error {
3333

3434
func cleanupAllocationFiles(ctx context.Context, allocationObj allocation.Allocation) {
3535
mutex := lock.GetMutex(allocationObj.TableName(), allocationObj.ID)
36+
logging.Logger.Info("cleanupAllocationLock", zap.Any("allocation_id", allocationObj.ID))
3637
mutex.Lock()
3738
defer mutex.Unlock()
3839
db := datastore.GetStore().GetTransaction(ctx)

0 commit comments

Comments
 (0)