Apply quota usage cache invalidation per second (#10127)

Allow faster lookups for quota check enforcement
master
Harshavardhana 4 years ago committed by GitHub
parent 4752323e1c
commit 57ff9abca2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 25
      cmd/bucket-quota.go
  2. 3
      cmd/object-handlers.go

@ -68,27 +68,19 @@ func (sys *BucketQuotaSys) check(ctx context.Context, bucket string, size int64)
return errServerNotInitialized return errServerNotInitialized
} }
q, err := sys.Get(bucket)
if err != nil {
return nil
}
if q.Type == madmin.FIFOQuota {
return nil
}
if q.Quota == 0 {
// No quota set return quickly.
return nil
}
sys.bucketStorageCache.Once.Do(func() { sys.bucketStorageCache.Once.Do(func() {
sys.bucketStorageCache.TTL = 10 * time.Second sys.bucketStorageCache.TTL = 1 * time.Second
sys.bucketStorageCache.Update = func() (interface{}, error) { sys.bucketStorageCache.Update = func() (interface{}, error) {
return loadDataUsageFromBackend(ctx, objAPI) return loadDataUsageFromBackend(ctx, objAPI)
} }
}) })
q, err := sys.Get(bucket)
if err != nil {
return err
}
if q != nil && q.Type == madmin.HardQuota && q.Quota > 0 {
v, err := sys.bucketStorageCache.Get() v, err := sys.bucketStorageCache.Get()
if err != nil { if err != nil {
return err return err
@ -103,9 +95,10 @@ func (sys *BucketQuotaSys) check(ctx context.Context, bucket string, size int64)
return nil return nil
} }
if (bui.Size + uint64(size)) > q.Quota { if (bui.Size + uint64(size)) >= q.Quota {
return BucketQuotaExceeded{Bucket: bucket} return BucketQuotaExceeded{Bucket: bucket}
} }
}
return nil return nil
} }

@ -980,6 +980,7 @@ func (api objectAPIHandlers) CopyObjectHandler(w http.ResponseWriter, r *http.Re
} }
length = actualSize length = actualSize
} }
if !cpSrcDstSame { if !cpSrcDstSame {
if err := enforceBucketQuota(ctx, dstBucket, actualSize); err != nil { if err := enforceBucketQuota(ctx, dstBucket, actualSize); err != nil {
writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL, guessIsBrowserReq(r)) writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL, guessIsBrowserReq(r))
@ -1893,10 +1894,12 @@ func (api objectAPIHandlers) CopyObjectPartHandler(w http.ResponseWriter, r *htt
return return
} }
} }
if err := enforceBucketQuota(ctx, dstBucket, actualPartSize); err != nil { if err := enforceBucketQuota(ctx, dstBucket, actualPartSize); err != nil {
writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL, guessIsBrowserReq(r)) writeErrorResponse(ctx, w, toAPIError(ctx, err), r.URL, guessIsBrowserReq(r))
return return
} }
// Special care for CopyObjectPart // Special care for CopyObjectPart
if partRangeErr := checkCopyPartRangeWithSize(rs, actualPartSize); partRangeErr != nil { if partRangeErr := checkCopyPartRangeWithSize(rs, actualPartSize); partRangeErr != nil {
writeCopyPartErr(ctx, w, partRangeErr, r.URL, guessIsBrowserReq(r)) writeCopyPartErr(ctx, w, partRangeErr, r.URL, guessIsBrowserReq(r))

Loading…
Cancel
Save