Skip to content

Commit 406e4ea

Browse files
committed
remove lock
1 parent 29b4523 commit 406e4ea

File tree

1 file changed

+23
-28
lines changed

1 file changed

+23
-28
lines changed

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

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1972,46 +1972,41 @@ func (fsh *StorageHandler) Rollback(ctx context.Context, r *http.Request) (*blob
19721972
writemarkerEntity.ClientPublicKey = clientKey
19731973
Logger.Info("rollback_writemarker", zap.Any("writemarker", writemarkerEntity.WM))
19741974

1975-
alloc, err := allocation.Repo.GetByIdAndLock(c, allocationID)
1976-
Logger.Info("[rollback]Lock Allocation", zap.Bool("is_redeem_required", alloc.IsRedeemRequired), zap.String("allocation_root", alloc.AllocationRoot), zap.String("latest_wm_redeemed", alloc.LatestRedeemedWM))
1977-
if err != nil {
1978-
txn.Rollback()
1979-
return &result, common.NewError("allocation_read_error", "Error reading the allocation object")
1980-
}
1975+
Logger.Info("[rollback]Lock Allocation", zap.Bool("is_redeem_required", allocationObj.IsRedeemRequired), zap.String("allocation_root", allocationObj.AllocationRoot), zap.String("latest_wm_redeemed", allocationObj.LatestRedeemedWM))
19811976

1982-
alloc.BlobberSizeUsed -= latestWriteMarkerEntity.WM.Size
1983-
alloc.UsedSize -= latestWriteMarkerEntity.WM.Size
1984-
alloc.AllocationRoot = allocationRoot
1985-
alloc.FileMetaRoot = fileMetaRoot
1986-
alloc.IsRedeemRequired = false
1987-
alloc.NumObjects = alloc.PrevNumObjects
1988-
alloc.NumBlocks = alloc.PrevNumBlocks
1977+
allocationObj.BlobberSizeUsed -= latestWriteMarkerEntity.WM.Size
1978+
allocationObj.UsedSize -= latestWriteMarkerEntity.WM.Size
1979+
allocationObj.AllocationRoot = allocationRoot
1980+
allocationObj.FileMetaRoot = fileMetaRoot
1981+
allocationObj.IsRedeemRequired = false
1982+
allocationObj.NumObjects = allocationObj.PrevNumObjects
1983+
allocationObj.NumBlocks = allocationObj.PrevNumBlocks
19891984
updateMap := map[string]interface{}{
1990-
"blobber_size_used": alloc.BlobberSizeUsed,
1991-
"used_size": alloc.UsedSize,
1992-
"allocation_root": alloc.AllocationRoot,
1993-
"file_meta_root": alloc.FileMetaRoot,
1985+
"blobber_size_used": allocationObj.BlobberSizeUsed,
1986+
"used_size": allocationObj.UsedSize,
1987+
"allocation_root": allocationObj.AllocationRoot,
1988+
"file_meta_root": allocationObj.FileMetaRoot,
19941989
"is_redeem_required": false,
1995-
"num_objects": alloc.NumObjects,
1996-
"num_blocks": alloc.NumBlocks,
1990+
"num_objects": allocationObj.NumObjects,
1991+
"num_blocks": allocationObj.NumBlocks,
19971992
}
19981993

19991994
updateOption := func(a *allocation.Allocation) {
2000-
a.BlobberSizeUsed = alloc.BlobberSizeUsed
2001-
a.UsedSize = alloc.UsedSize
2002-
a.AllocationRoot = alloc.AllocationRoot
2003-
a.FileMetaRoot = alloc.FileMetaRoot
2004-
a.IsRedeemRequired = alloc.IsRedeemRequired
2005-
a.NumObjects = alloc.NumObjects
2006-
a.NumBlocks = alloc.NumBlocks
1995+
a.BlobberSizeUsed = allocationObj.BlobberSizeUsed
1996+
a.UsedSize = allocationObj.UsedSize
1997+
a.AllocationRoot = allocationObj.AllocationRoot
1998+
a.FileMetaRoot = allocationObj.FileMetaRoot
1999+
a.IsRedeemRequired = allocationObj.IsRedeemRequired
2000+
a.NumObjects = allocationObj.NumObjects
2001+
a.NumBlocks = allocationObj.NumBlocks
20072002
}
20082003
writemarkerEntity.Latest = true
20092004
err = txn.Create(writemarkerEntity).Error
20102005
if err != nil {
20112006
txn.Rollback()
20122007
return &result, common.NewError("write_marker_error", "Error persisting the write marker "+err.Error())
20132008
}
2014-
if err = allocation.Repo.UpdateAllocation(c, alloc, updateMap, updateOption); err != nil {
2009+
if err = allocation.Repo.UpdateAllocation(c, allocationObj, updateMap, updateOption); err != nil {
20152010
txn.Rollback()
20162011
return &result, common.NewError("allocation_write_error", "Error persisting the allocation object "+err.Error())
20172012
}
@@ -2024,7 +2019,7 @@ func (fsh *StorageHandler) Rollback(ctx context.Context, r *http.Request) (*blob
20242019
var node wmpt.Node
20252020
if len(fileMetaRoot) > 0 {
20262021
decodedRoot, _ := hex.DecodeString(fileMetaRoot)
2027-
node = wmpt.NewHashNode(decodedRoot, alloc.NumBlocks)
2022+
node = wmpt.NewHashNode(decodedRoot, allocationObj.NumBlocks)
20282023
}
20292024
trie.RollbackTrie(node)
20302025
}

0 commit comments

Comments
 (0)