From c7e1148030b5319ef72e7a6d1fb0085575b4b6aa Mon Sep 17 00:00:00 2001 From: Guiheux Steven Date: Thu, 8 Jul 2021 13:26:14 +0200 Subject: [PATCH] fix(cdn): insert item unit on deduplication (#5882) --- engine/cdn/storage/storageunit_run.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/engine/cdn/storage/storageunit_run.go b/engine/cdn/storage/storageunit_run.go index 9e6281dbb1..0ff74b63a4 100644 --- a/engine/cdn/storage/storageunit_run.go +++ b/engine/cdn/storage/storageunit_run.go @@ -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() @@ -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())