From c08c7c52a09a5920d006605eb79b388f0724a62d Mon Sep 17 00:00:00 2001 From: Chlins Zhang Date: Thu, 8 Jun 2023 14:19:06 +0800 Subject: [PATCH] fix: optimize the mechanism of quota refresh (#18795) Signed-off-by: chlins --- src/controller/quota/controller.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/controller/quota/controller.go b/src/controller/quota/controller.go index a95143f68..7e6d8f095 100644 --- a/src/controller/quota/controller.go +++ b/src/controller/quota/controller.go @@ -185,6 +185,13 @@ func (c *controller) updateUsageWithRetry(ctx context.Context, reference, refere return retry.Abort(err) } + // The PR https://github.com/goharbor/harbor/pull/17392 optimized the logic for post upload blob which use size 0 + // for checking quota, this will increase the pressure of optimistic lock, so here return earlier + // if the quota usage has not changed to reduce the probability of optimistic lock. + if types.Equals(used, newUsed) { + return nil + } + q.SetUsed(newUsed) err = c.quotaMgr.Update(ctx, q)