Skip to content

Commit f4f5fde

Browse files
committed
fix delete dir
1 parent 1fc3eec commit f4f5fde

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,7 @@ func (cc *AllocationChangeCollector) ApplyChangesV2(ctx context.Context, allocat
301301
logging.Logger.Error("ApplyChangesV2Error", zap.Error(err))
302302
return err
303303
}
304-
if sizeChange > 0 {
305-
atomic.AddInt64(&cc.Size, sizeChange)
306-
}
304+
atomic.AddInt64(&cc.Size, sizeChange)
307305
return nil
308306
})
309307

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ func (nf *DeleteFileChange) ApplyChange(ctx context.Context, rootRef *reference.
4343
}
4444

4545
func (nf *DeleteFileChange) ApplyChangeV2(_ context.Context, _, _ string, numFiles *atomic.Int32, _ common.Timestamp, trie *wmpt.WeightedMerkleTrie, collector reference.QueryCollector) (int64, error) {
46-
var changeSize int64
46+
var (
47+
changeSize int64
48+
refType string
49+
)
4750
err := datastore.GetStore().WithNewTransaction(func(ctx context.Context) error {
4851
ref, err := reference.GetLimitedRefFieldsByLookupHashWith(ctx, nf.AllocationID, nf.LookupHash, []string{"id", "type", "size"})
4952
if err != nil {
@@ -65,8 +68,9 @@ func (nf *DeleteFileChange) ApplyChangeV2(_ context.Context, _, _ string, numFil
6568
LookupHash: nf.LookupHash,
6669
Type: ref.Type,
6770
}
71+
refType = ref.Type
6872
collector.DeleteRefRecord(deleteRecord)
69-
changeSize = ref.Size
73+
changeSize = -ref.Size
7074
return nil
7175
}, &sql.TxOptions{
7276
ReadOnly: true,
@@ -77,10 +81,12 @@ func (nf *DeleteFileChange) ApplyChangeV2(_ context.Context, _, _ string, numFil
7781
}
7882
return 0, err
7983
}
80-
decodedKey, _ := hex.DecodeString(nf.LookupHash)
81-
err = trie.Update(decodedKey, nil, 0)
82-
if err != nil && err != wmpt.ErrNotFound {
83-
return 0, err
84+
if refType == reference.FILE {
85+
decodedKey, _ := hex.DecodeString(nf.LookupHash)
86+
err = trie.Update(decodedKey, nil, 0)
87+
if err != nil && err != wmpt.ErrNotFound {
88+
return 0, err
89+
}
8490
}
8591
numFiles.Add(-1)
8692
return changeSize, nil

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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=? AND allocation_id=?", startAllocationRoot, startTimestamp).
193+
Where("allocation_root=? AND timestamp=?", startAllocationRoot, startTimestamp).
194194
Select("sequence").
195195
Take(&startWM).Error
196196

0 commit comments

Comments
 (0)