From 89441a22aa36553c3bb81d561b95e6df0465515d Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Wed, 5 Jan 2022 17:05:28 -0800 Subject: [PATCH] enforceRetentionForDeletion should return false early for delete-marker (#14033) --- cmd/bucket-object-lock.go | 4 ++++ cmd/bucket-quota.go | 14 +++++--------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/cmd/bucket-object-lock.go b/cmd/bucket-object-lock.go index 6fa327c60..ac7b360ea 100644 --- a/cmd/bucket-object-lock.go +++ b/cmd/bucket-object-lock.go @@ -58,6 +58,10 @@ func (sys *BucketObjectLockSys) Get(bucketName string) (r objectlock.Retention, // enforceRetentionForDeletion checks if it is appropriate to remove an // object according to locking configuration when this is lifecycle/ bucket quota asking. func enforceRetentionForDeletion(ctx context.Context, objInfo ObjectInfo) (locked bool) { + if objInfo.DeleteMarker { + return false + } + lhold := objectlock.GetObjectLegalHoldMeta(objInfo.UserDefined) if lhold.Status.Valid() && lhold.Status == objectlock.LegalHoldOn { return true diff --git a/cmd/bucket-quota.go b/cmd/bucket-quota.go index 67780ad3c..bd4e46665 100644 --- a/cmd/bucket-quota.go +++ b/cmd/bucket-quota.go @@ -154,7 +154,7 @@ func enforceFIFOQuotaBucket(ctx context.Context, objectAPI ObjectLayer, bucket s // ModTime to find the oldest objects in bucket to delete. In // the context of bucket quota enforcement - number of hits are // irrelevant. - scorer, err := newFileScorer(toFree, time.Now().Unix(), 1) + scorer, err := newFileScorer(toFree, UTCNow().Unix(), 1) if err != nil { logger.LogIf(ctx, err) return @@ -162,11 +162,6 @@ func enforceFIFOQuotaBucket(ctx context.Context, objectAPI ObjectLayer, bucket s rcfg, _ := globalBucketObjectLockSys.Get(bucket) for obj := range objInfoCh { - if obj.DeleteMarker { - // Delete markers are automatically added for FIFO purge. - scorer.addFileWithObjInfo(obj, 1) - continue - } // skip objects currently under retention if rcfg.LockEnabled && enforceRetentionForDeletion(ctx, obj) { continue @@ -178,6 +173,7 @@ func enforceFIFOQuotaBucket(ctx context.Context, objectAPI ObjectLayer, bucket s if scorer.seenBytes <= cfg.Quota { return } + // Calculate how much we want to delete now. toFreeNow := scorer.seenBytes - cfg.Quota // We were less over quota than we thought. Adjust so we delete less. @@ -211,9 +207,9 @@ func enforceFIFOQuotaBucket(ctx context.Context, objectAPI ObjectLayer, bucket s _, deleteErrs := objectAPI.DeleteObjects(ctx, bucket, objects, ObjectOptions{ Versioned: versioned, }) - for i := range deleteErrs { - if deleteErrs[i] != nil { - logger.LogIf(ctx, deleteErrs[i]) + for j := range deleteErrs { + if deleteErrs[j] != nil { + logger.LogIf(ctx, deleteErrs[j]) continue }