Skip to content

Commit

Permalink
run delete in same routine
Browse files Browse the repository at this point in the history
  • Loading branch information
Hitenjain14 committed Oct 31, 2024
1 parent 406e4ea commit 72454ce
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions code/go/0chain.net/blobbercore/writemarker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ func redeemWriteMarker(md *markerData) error {
shouldRollback := false
start := time.Now()
logging.Logger.Info("redeeming_write_marker", zap.String("allocationID", allocationID))
allocMu := lock.GetMutex(allocation.Allocation{}.TableName(), allocationID)
allocMu.RLock()
defer allocMu.RUnlock()
defer func() {
if shouldRollback {
if rollbackErr := db.Rollback().Error; rollbackErr != nil {
Expand All @@ -130,14 +133,10 @@ func redeemWriteMarker(md *markerData) error {
}

} else {
go deleteMarkerData(allocationID)
deleteMarkerData(allocationID)
}
}()

allocMu := lock.GetMutex(allocation.Allocation{}.TableName(), allocationID)
allocMu.RLock()
defer allocMu.RUnlock()

alloc, err := allocation.Repo.GetAllocationFromDB(ctx, allocationID)
if err != nil {
logging.Logger.Error("Error redeeming the write marker.", zap.Any("allocation", allocationID), zap.Any("wm", allocationID), zap.Any("error", err))
Expand All @@ -150,7 +149,7 @@ func redeemWriteMarker(md *markerData) error {

if alloc.Finalized {
logging.Logger.Info("Allocation is finalized. Skipping redeeming the write marker.", zap.Any("allocation", allocationID))
go deleteMarkerData(allocationID)
deleteMarkerData(allocationID)
shouldRollback = true
return nil
}
Expand All @@ -174,7 +173,7 @@ func redeemWriteMarker(md *markerData) error {
if retryRedeem(err.Error()) {
go tryAgain(md)
} else {
go deleteMarkerData(allocationID)
deleteMarkerData(allocationID)
}
shouldRollback = true
return err
Expand Down

0 comments on commit 72454ce

Please sign in to comment.