Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c7e1148

Browse files
authored
fix(cdn): insert item unit on deduplication (#5882)
1 parent a8d98aa commit c7e1148

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

engine/cdn/storage/storageunit_run.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,16 @@ func (x *RunningStorageUnits) runItem(ctx context.Context, db *gorp.DbMap, dest
129129

130130
if has {
131131
log.Info(ctx, "item %s has been pushed to %s with deduplication", item.ID, dest.Name())
132-
return nil
132+
tx, err := db.Begin()
133+
if err != nil {
134+
return sdk.WrapError(err, "unable to start transaction")
135+
}
136+
defer tx.Rollback() //nolint
137+
// Save in database that the item is complete for the storage unit
138+
if err := InsertItemUnit(ctx, x.m, tx, iu); err != nil {
139+
return err
140+
}
141+
return sdk.WrapError(tx.Commit(), "unable to commit tx")
133142
}
134143

135144
t1 := time.Now()
@@ -140,7 +149,7 @@ func (x *RunningStorageUnits) runItem(ctx context.Context, db *gorp.DbMap, dest
140149
return err
141150
}
142151
if writer == nil {
143-
return nil
152+
return sdk.NewErrorFrom(sdk.ErrNotFound, "unable to get writer")
144153
}
145154
rateLimitWriter := shapeio.NewWriter(writer)
146155
rateLimitWriter.SetRateLimit(dest.SyncBandwidth())

0 commit comments

Comments
 (0)