Skip to content

Commit

Permalink
fix(cdn): insert item unit on deduplication (#5882)
Browse files Browse the repository at this point in the history
  • Loading branch information
sguiheux authored Jul 8, 2021
1 parent a8d98aa commit c7e1148
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions engine/cdn/storage/storageunit_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,16 @@ func (x *RunningStorageUnits) runItem(ctx context.Context, db *gorp.DbMap, dest

if has {
log.Info(ctx, "item %s has been pushed to %s with deduplication", item.ID, dest.Name())
return nil
tx, err := db.Begin()
if err != nil {
return sdk.WrapError(err, "unable to start transaction")
}
defer tx.Rollback() //nolint
// Save in database that the item is complete for the storage unit
if err := InsertItemUnit(ctx, x.m, tx, iu); err != nil {
return err
}
return sdk.WrapError(tx.Commit(), "unable to commit tx")
}

t1 := time.Now()
Expand All @@ -140,7 +149,7 @@ func (x *RunningStorageUnits) runItem(ctx context.Context, db *gorp.DbMap, dest
return err
}
if writer == nil {
return nil
return sdk.NewErrorFrom(sdk.ErrNotFound, "unable to get writer")
}
rateLimitWriter := shapeio.NewWriter(writer)
rateLimitWriter.SetRateLimit(dest.SyncBandwidth())
Expand Down

0 comments on commit c7e1148

Please sign in to comment.