Skip to content

Commit 40c979b

Browse files
committed
readonly in commit write
1 parent ed1e03f commit 40c979b

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func FetchAllocationFromEventsDB(ctx context.Context, allocationID string, alloc
113113
a.StartTime = sa.StartTime
114114
a.StorageVersion = uint8(sa.StorageVersion)
115115
a.OwnerSigningPublicKey = sa.OwnerSigningPublicKey
116-
logging.Logger.Info("OwnerSigningPublicKey", zap.String("OwnerSigningPublicKey", a.OwnerSigningPublicKey), zap.String("allocation_id", a.ID))
116+
logging.Logger.Info("OwnerSigningPublicKey", zap.String("OwnerSigningPublicKey", a.OwnerSigningPublicKey), zap.String("allocation_id", a.ID), zap.String("allocation_tx", a.Tx))
117117

118118
m := map[string]interface{}{
119119
"allocation_id": a.ID,
@@ -141,7 +141,7 @@ func FetchAllocationFromEventsDB(ctx context.Context, allocationID string, alloc
141141
return a, nil
142142
}
143143

144-
logging.Logger.Info("Saving the allocation to DB", zap.String("allocation_id", a.ID))
144+
logging.Logger.Info("Saving the allocation to DB", zap.String("allocation_id", a.ID), zap.String("allocation_tx", a.Tx))
145145

146146
if !isExist {
147147
err = Repo.Save(ctx, a)

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import (
44
"context"
55
"errors"
66
"fmt"
7-
"github.com/0chain/gosdk/core/client"
87
"net/http"
98
"time"
109

10+
"github.com/0chain/gosdk/core/client"
11+
1112
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/allocation"
1213
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/blobberhttp"
1314
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/writemarker"
@@ -142,12 +143,12 @@ func WithStatusConnectionForWM(handler common.StatusCodeResponderF) common.Statu
142143

143144
mutex := lock.GetMutex(allocation.Allocation{}.TableName(), allocationID)
144145
Logger.Info("Locking allocation", zap.String("allocation_id", allocationID))
146+
mutex.Lock()
147+
defer mutex.Unlock()
145148
wmSet := writemarker.SetCommittingMarker(allocationID, true)
146149
if !wmSet {
147150
return nil, http.StatusBadRequest, common.NewError("pending_markers", "Committing marker set failed")
148151
}
149-
mutex.Lock()
150-
defer mutex.Unlock()
151152
ctx = GetMetaDataStore().CreateTransaction(ctx)
152153
tx := GetMetaDataStore().GetTransaction(ctx)
153154
resp, statusCode, err = handler(ctx, r)
@@ -161,6 +162,7 @@ func WithStatusConnectionForWM(handler common.StatusCodeResponderF) common.Statu
161162
}
162163
writemarker.SetCommittingMarker(allocationID, false)
163164
}
165+
Logger.Debug("Unlocking allocation", zap.String("allocation_id", allocationID))
164166
}()
165167

166168
if err != nil {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ func (fsh *StorageHandler) CommitWrite(ctx context.Context, r *http.Request) (*b
622622
return nil, common.NewError("blacklisted_client", "Client is blacklisted: "+clientID)
623623
}
624624

625-
allocationObj, err := fsh.verifyAllocation(ctx, allocationId, allocationTx, false)
625+
allocationObj, err := fsh.verifyAllocation(ctx, allocationId, allocationTx, true)
626626
if err != nil {
627627
return nil, common.NewError("invalid_parameters", "Invalid allocation id passed."+err.Error())
628628
}

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,16 @@ func SetupWorkers(ctx context.Context) {
115115
}
116116

117117
func redeemWriteMarker(md *markerData) error {
118-
ctx := datastore.GetStore().CreateTransaction(context.TODO())
118+
timeoutCtx, cancel := context.WithTimeout(context.Background(), 180*time.Second)
119+
defer cancel()
120+
ctx := datastore.GetStore().CreateTransaction(timeoutCtx)
119121
db := datastore.GetStore().GetTransaction(ctx)
120122
allocationID := md.allocationID
121123
shouldRollback := false
122124
start := time.Now()
123125
logging.Logger.Info("redeeming_write_marker", zap.String("allocationID", allocationID))
124126
allocMu := lock.GetMutex(allocation.Allocation{}.TableName(), allocationID)
125127
allocMu.RLock()
126-
defer allocMu.RUnlock()
127128
defer func() {
128129
if shouldRollback {
129130
if rollbackErr := db.Rollback().Error; rollbackErr != nil {
@@ -135,8 +136,9 @@ func redeemWriteMarker(md *markerData) error {
135136
} else {
136137
deleteMarkerData(allocationID)
137138
}
139+
allocMu.RUnlock()
138140
}()
139-
141+
logging.Logger.Debug("getAllocation", zap.Any("allocation", allocationID))
140142
alloc, err := allocation.Repo.GetAllocationFromDB(ctx, allocationID)
141143
if err != nil {
142144
logging.Logger.Error("Error redeeming the write marker.", zap.Any("allocation", allocationID), zap.Any("wm", allocationID), zap.Any("error", err))
@@ -153,7 +155,7 @@ func redeemWriteMarker(md *markerData) error {
153155
shouldRollback = true
154156
return nil
155157
}
156-
158+
logging.Logger.Debug("getWritemarker", zap.Any("allocation", allocationID))
157159
wm, err := GetWriteMarkerEntity(ctx, alloc.ID, alloc.AllocationRoot)
158160
if err != nil {
159161
logging.Logger.Error("Error redeeming the write marker.", zap.Any("allocation", allocationID), zap.Any("wm", alloc.AllocationRoot), zap.Any("error", err))
@@ -163,7 +165,7 @@ func redeemWriteMarker(md *markerData) error {
163165
shouldRollback = true
164166
return err
165167
}
166-
168+
logging.Logger.Debug("RedeemMarker", zap.Any("allocation", allocationID), zap.Any("wm", wm.WM.AllocationRoot), zap.Any("txn", wm.CloseTxnID))
167169
err = wm.RedeemMarker(ctx, alloc.LastRedeemedSeq+1)
168170
if err != nil {
169171
elapsedTime := time.Since(start)
@@ -178,7 +180,7 @@ func redeemWriteMarker(md *markerData) error {
178180
shouldRollback = true
179181
return err
180182
}
181-
183+
logging.Logger.Debug("UpdateAllocationRedeem", zap.Any("allocation", allocationID), zap.Any("wm", wm.WM.AllocationRoot), zap.Any("txn", wm.CloseTxnID))
182184
err = allocation.Repo.UpdateAllocationRedeem(ctx, allocationID, wm.WM.AllocationRoot, alloc, wm.Sequence)
183185
if err != nil {
184186
logging.Logger.Error("Error redeeming the write marker. Allocation latest wm redeemed update failed",
@@ -188,7 +190,7 @@ func redeemWriteMarker(md *markerData) error {
188190
go tryAgain(md)
189191
return err
190192
}
191-
193+
logging.Logger.Debug("RedeemMarker", zap.Any("allocation", allocationID), zap.Any("wm", wm.WM.AllocationRoot), zap.Any("txn", wm.CloseTxnID))
192194
err = db.Commit().Error
193195
if err != nil {
194196
logging.Logger.Error("Error committing the writemarker redeem",

0 commit comments

Comments
 (0)