Skip to content

Commit 9e73c33

Browse files
committed
add allocation id filter in get wm
1 parent f2cc842 commit 9e73c33

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ func (fsh *StorageHandler) CommitWrite(ctx context.Context, r *http.Request) (*b
685685
if allocationObj.AllocationRoot == "" {
686686
latestWriteMarkerEntity = nil
687687
} else {
688-
latestWriteMarkerEntity, err = writemarker.GetWriteMarkerEntity(ctx,
688+
latestWriteMarkerEntity, err = writemarker.GetWriteMarkerEntity(ctx, allocationID,
689689
allocationObj.AllocationRoot)
690690
if err != nil {
691691
return nil, common.NewErrorf("latest_write_marker_read_error",
@@ -975,7 +975,7 @@ func (fsh *StorageHandler) CommitWriteV2(ctx context.Context, r *http.Request) (
975975
if allocationObj.AllocationRoot == "" {
976976
latestWriteMarkerEntity = nil
977977
} else {
978-
latestWriteMarkerEntity, err = writemarker.GetWriteMarkerEntity(ctx,
978+
latestWriteMarkerEntity, err = writemarker.GetWriteMarkerEntity(ctx, allocationID,
979979
allocationObj.AllocationRoot)
980980
if err != nil {
981981
return nil, common.NewErrorf("latest_write_marker_read_error",
@@ -1872,7 +1872,7 @@ func (fsh *StorageHandler) Rollback(ctx context.Context, r *http.Request) (*blob
18721872
var result blobberhttp.CommitResult
18731873

18741874
var latestWriteMarkerEntity *writemarker.WriteMarkerEntity
1875-
latestWriteMarkerEntity, err = writemarker.GetWriteMarkerEntity(ctx,
1875+
latestWriteMarkerEntity, err = writemarker.GetWriteMarkerEntity(ctx, allocationID,
18761876
allocationObj.AllocationRoot)
18771877
if err != nil {
18781878
return nil, common.NewErrorf("latest_write_marker_read_error",

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ func (fsh *StorageHandler) GetFileStats(ctx context.Context, r *http.Request) (i
268268
if err != nil {
269269
return nil, common.NewError("bad_db_operation", "Error retrieving file stats. "+err.Error())
270270
}
271-
wm, _ := writemarker.GetWriteMarkerEntity(ctx, fileref.AllocationRoot)
271+
wm, _ := writemarker.GetWriteMarkerEntity(ctx, allocationID, fileref.AllocationRoot)
272272
if wm != nil && fileStats != nil {
273273
fileStats.WriteMarkerRedeemTxn = wm.CloseTxnID
274274
fileStats.OnChain = wm.OnChain()
@@ -529,7 +529,7 @@ func (fsh *StorageHandler) GetLatestWriteMarker(ctx context.Context, r *http.Req
529529
if allocationObj.AllocationRoot == "" {
530530
latestWM = nil
531531
} else {
532-
latestWM, err = writemarker.GetWriteMarkerEntity(ctx, allocationObj.AllocationRoot)
532+
latestWM, err = writemarker.GetWriteMarkerEntity(ctx, allocationId, allocationObj.AllocationRoot)
533533
if err != nil {
534534
logging.Logger.Error("[latest_write_marker]", zap.String("allocation_root", allocationObj.AllocationRoot), zap.String("allocation_id", allocationObj.ID))
535535
return nil, common.NewError("latest_write_marker_read_error", "Error reading the latest write marker for allocation. "+err.Error())
@@ -539,7 +539,7 @@ func (fsh *StorageHandler) GetLatestWriteMarker(ctx context.Context, r *http.Req
539539
return nil, common.NewError("latest_write_marker_read_error", "Latest write marker not found for allocation.")
540540
}
541541
if latestWM.WM.PreviousAllocationRoot != "" {
542-
prevWM, err = writemarker.GetWriteMarkerEntity(ctx, latestWM.WM.PreviousAllocationRoot)
542+
prevWM, err = writemarker.GetWriteMarkerEntity(ctx, allocationId, latestWM.WM.PreviousAllocationRoot)
543543
if err != nil {
544544
return nil, common.NewError("latest_write_marker_read_error", "Error reading the previous write marker for allocation."+err.Error())
545545
}
@@ -655,7 +655,7 @@ func (fsh *StorageHandler) getReferencePath(ctx context.Context, r *http.Request
655655
if allocationObj.AllocationRoot == "" {
656656
latestWM = nil
657657
} else {
658-
latestWM, err = writemarker.GetWriteMarkerEntity(ctx, rootRef.Hash)
658+
latestWM, err = writemarker.GetWriteMarkerEntity(ctx, allocationID, rootRef.Hash)
659659
if err != nil {
660660
errCh <- common.NewError("latest_write_marker_read_error", "Error reading the latest write marker for allocation."+err.Error())
661661
return
@@ -744,7 +744,7 @@ func (fsh *StorageHandler) getReferencePathV2(ctx context.Context, r *http.Reque
744744
if allocationObj.AllocationRoot == "" {
745745
latestWM = nil
746746
} else {
747-
latestWM, err = writemarker.GetWriteMarkerEntity(ctx, allocationObj.AllocationRoot)
747+
latestWM, err = writemarker.GetWriteMarkerEntity(ctx, allocationId, allocationObj.AllocationRoot)
748748
if err != nil {
749749
errCh <- common.NewError("latest_write_marker_read_error", "Error reading the latest write marker for allocation."+err.Error())
750750
return
@@ -821,7 +821,7 @@ func (fsh *StorageHandler) GetObjectTree(ctx context.Context, r *http.Request) (
821821
if allocationObj.AllocationRoot == "" {
822822
latestWM = nil
823823
} else {
824-
latestWM, err = writemarker.GetWriteMarkerEntity(ctx, allocationObj.AllocationRoot)
824+
latestWM, err = writemarker.GetWriteMarkerEntity(ctx, allocationID, allocationObj.AllocationRoot)
825825
if err != nil {
826826
return nil, common.NewError("latest_write_marker_read_error", "Error reading the latest write marker for allocation."+err.Error())
827827
}
@@ -1086,7 +1086,7 @@ func (fsh *StorageHandler) GetRefs(ctx context.Context, r *http.Request) (*blobb
10861086
if allocationObj.AllocationRoot == "" {
10871087
latestWM = nil
10881088
} else {
1089-
latestWM, err = writemarker.GetWriteMarkerEntity(ctx, allocationObj.AllocationRoot)
1089+
latestWM, err = writemarker.GetWriteMarkerEntity(ctx, allocationID, allocationObj.AllocationRoot)
10901090
if err != nil {
10911091
return nil, common.NewError("latest_write_marker_read_error", "Error reading the latest write marker for allocation."+err.Error())
10921092
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,11 @@ func (wm *WriteMarkerEntity) OnChain() bool {
136136
}
137137

138138
// GetWriteMarkerEntity get WriteMarkerEntity from postgres
139-
func GetWriteMarkerEntity(ctx context.Context, allocation_root string) (*WriteMarkerEntity, error) {
139+
func GetWriteMarkerEntity(ctx context.Context, allocationID, allocationRoot string) (*WriteMarkerEntity, error) {
140140
db := datastore.GetStore().GetTransaction(ctx)
141141
wm := &WriteMarkerEntity{}
142142
err := db.Table((WriteMarkerEntity{}).TableName()).
143-
Where("allocation_root=?", allocation_root).
143+
Where("allocation_root=? AND allocation_id=?", allocationRoot, allocationID).
144144
Order("sequence desc").
145145
Take(wm).Error
146146
if err != nil {
@@ -190,7 +190,7 @@ func GetWriteMarkersInRange(ctx context.Context, allocationID string, startAlloc
190190
// seq of start allocation root
191191
startWM := WriteMarkerEntity{}
192192
err := db.Table((WriteMarkerEntity{}).TableName()).
193-
Where("allocation_root=? AND timestamp=?", startAllocationRoot, startTimestamp).
193+
Where("allocation_root=? AND timestamp=? AND allocation_id=?", startAllocationRoot, startTimestamp).
194194
Select("sequence").
195195
Take(&startWM).Error
196196

@@ -202,7 +202,7 @@ func GetWriteMarkersInRange(ctx context.Context, allocationID string, startAlloc
202202
// seq of end allocation root
203203
endWM := WriteMarkerEntity{}
204204
err = db.Table((WriteMarkerEntity{}).TableName()).
205-
Where("allocation_root=?", endAllocationRoot).
205+
Where("allocation_root=? AND allocation_id=?", endAllocationRoot, allocationID).
206206
Select("sequence").
207207
Order("sequence desc").
208208
Take(&endWM).Error

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func redeemWriteMarker(md *markerData) error {
155155
return nil
156156
}
157157

158-
wm, err := GetWriteMarkerEntity(ctx, alloc.AllocationRoot)
158+
wm, err := GetWriteMarkerEntity(ctx, alloc.ID, alloc.AllocationRoot)
159159
if err != nil {
160160
logging.Logger.Error("Error redeeming the write marker.", zap.Any("allocation", allocationID), zap.Any("wm", alloc.AllocationRoot), zap.Any("error", err))
161161
if err != gorm.ErrRecordNotFound {

0 commit comments

Comments
 (0)