mirror of https://github.com/minio/minio.git
avoid crash when initializing bucket quota cache (#20258)
This commit is contained in:
parent
743ddb196a
commit
db78431b1d
|
@ -34,7 +34,6 @@ import (
|
||||||
"github.com/klauspost/compress/zip"
|
"github.com/klauspost/compress/zip"
|
||||||
"github.com/minio/madmin-go/v3"
|
"github.com/minio/madmin-go/v3"
|
||||||
"github.com/minio/minio/internal/auth"
|
"github.com/minio/minio/internal/auth"
|
||||||
"github.com/minio/minio/internal/cachevalue"
|
|
||||||
"github.com/minio/minio/internal/config/dns"
|
"github.com/minio/minio/internal/config/dns"
|
||||||
"github.com/minio/mux"
|
"github.com/minio/mux"
|
||||||
xldap "github.com/minio/pkg/v3/ldap"
|
xldap "github.com/minio/pkg/v3/ldap"
|
||||||
|
@ -1235,18 +1234,6 @@ func (a adminAPIHandlers) AccountInfoHandler(w http.ResponseWriter, r *http.Requ
|
||||||
return rd, wr
|
return rd, wr
|
||||||
}
|
}
|
||||||
|
|
||||||
bucketStorageCache.InitOnce(10*time.Second,
|
|
||||||
cachevalue.Opts{ReturnLastGood: true},
|
|
||||||
func(ctx context.Context) (DataUsageInfo, error) {
|
|
||||||
ctx, done := context.WithTimeout(ctx, 2*time.Second)
|
|
||||||
defer done()
|
|
||||||
|
|
||||||
return loadDataUsageFromBackend(ctx, objectAPI)
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
dataUsageInfo, _ := bucketStorageCache.Get()
|
|
||||||
|
|
||||||
// If etcd, dns federation configured list buckets from etcd.
|
// If etcd, dns federation configured list buckets from etcd.
|
||||||
var err error
|
var err error
|
||||||
var buckets []BucketInfo
|
var buckets []BucketInfo
|
||||||
|
@ -1333,15 +1320,12 @@ func (a adminAPIHandlers) AccountInfoHandler(w http.ResponseWriter, r *http.Requ
|
||||||
rd, wr := isAllowedAccess(bucket.Name)
|
rd, wr := isAllowedAccess(bucket.Name)
|
||||||
if rd || wr {
|
if rd || wr {
|
||||||
// Fetch the data usage of the current bucket
|
// Fetch the data usage of the current bucket
|
||||||
var size uint64
|
bui := globalBucketQuotaSys.GetBucketUsageInfo(ctx, bucket.Name)
|
||||||
var objectsCount uint64
|
size := bui.Size
|
||||||
var objectsHist, versionsHist map[string]uint64
|
objectsCount := bui.ObjectsCount
|
||||||
if !dataUsageInfo.LastUpdate.IsZero() {
|
objectsHist := bui.ObjectSizesHistogram
|
||||||
size = dataUsageInfo.BucketsUsage[bucket.Name].Size
|
versionsHist := bui.ObjectVersionsHistogram
|
||||||
objectsCount = dataUsageInfo.BucketsUsage[bucket.Name].ObjectsCount
|
|
||||||
objectsHist = dataUsageInfo.BucketsUsage[bucket.Name].ObjectSizesHistogram
|
|
||||||
versionsHist = dataUsageInfo.BucketsUsage[bucket.Name].ObjectVersionsHistogram
|
|
||||||
}
|
|
||||||
// Fetch the prefix usage of the current bucket
|
// Fetch the prefix usage of the current bucket
|
||||||
var prefixUsage map[string]uint64
|
var prefixUsage map[string]uint64
|
||||||
if enablePrefixUsage {
|
if enablePrefixUsage {
|
||||||
|
|
|
@ -50,6 +50,9 @@ func (sys *BucketQuotaSys) Init(objAPI ObjectLayer) {
|
||||||
bucketStorageCache.InitOnce(10*time.Second,
|
bucketStorageCache.InitOnce(10*time.Second,
|
||||||
cachevalue.Opts{ReturnLastGood: true, NoWait: true},
|
cachevalue.Opts{ReturnLastGood: true, NoWait: true},
|
||||||
func(ctx context.Context) (DataUsageInfo, error) {
|
func(ctx context.Context) (DataUsageInfo, error) {
|
||||||
|
if objAPI == nil {
|
||||||
|
return DataUsageInfo{}, errServerNotInitialized
|
||||||
|
}
|
||||||
ctx, done := context.WithTimeout(ctx, 2*time.Second)
|
ctx, done := context.WithTimeout(ctx, 2*time.Second)
|
||||||
defer done()
|
defer done()
|
||||||
|
|
||||||
|
@ -59,7 +62,9 @@ func (sys *BucketQuotaSys) Init(objAPI ObjectLayer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetBucketUsageInfo return bucket usage info for a given bucket
|
// GetBucketUsageInfo return bucket usage info for a given bucket
|
||||||
func (sys *BucketQuotaSys) GetBucketUsageInfo(ctx context.Context, bucket string) (BucketUsageInfo, error) {
|
func (sys *BucketQuotaSys) GetBucketUsageInfo(ctx context.Context, bucket string) BucketUsageInfo {
|
||||||
|
sys.Init(newObjectLayerFn())
|
||||||
|
|
||||||
dui, err := bucketStorageCache.GetWithCtx(ctx)
|
dui, err := bucketStorageCache.GetWithCtx(ctx)
|
||||||
timedout := OperationTimedOut{}
|
timedout := OperationTimedOut{}
|
||||||
if err != nil && !errors.Is(err, context.DeadlineExceeded) && !errors.As(err, &timedout) {
|
if err != nil && !errors.Is(err, context.DeadlineExceeded) && !errors.As(err, &timedout) {
|
||||||
|
@ -73,10 +78,10 @@ func (sys *BucketQuotaSys) GetBucketUsageInfo(ctx context.Context, bucket string
|
||||||
if len(dui.BucketsUsage) > 0 {
|
if len(dui.BucketsUsage) > 0 {
|
||||||
bui, ok := dui.BucketsUsage[bucket]
|
bui, ok := dui.BucketsUsage[bucket]
|
||||||
if ok {
|
if ok {
|
||||||
return bui, nil
|
return bui
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return BucketUsageInfo{}, nil
|
return BucketUsageInfo{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseBucketQuota parses BucketQuota from json
|
// parseBucketQuota parses BucketQuota from json
|
||||||
|
@ -118,11 +123,7 @@ func (sys *BucketQuotaSys) enforceQuotaHard(ctx context.Context, bucket string,
|
||||||
return BucketQuotaExceeded{Bucket: bucket}
|
return BucketQuotaExceeded{Bucket: bucket}
|
||||||
}
|
}
|
||||||
|
|
||||||
bui, err := sys.GetBucketUsageInfo(ctx, bucket)
|
bui := sys.GetBucketUsageInfo(ctx, bucket)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if bui.Size > 0 && ((bui.Size + uint64(size)) >= quotaSize) {
|
if bui.Size > 0 && ((bui.Size + uint64(size)) >= quotaSize) {
|
||||||
return BucketQuotaExceeded{Bucket: bucket}
|
return BucketQuotaExceeded{Bucket: bucket}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1090,11 +1090,6 @@ func serverMain(ctx *cli.Context) {
|
||||||
globalSiteReplicationSys.Init(GlobalContext, newObject)
|
globalSiteReplicationSys.Init(GlobalContext, newObject)
|
||||||
})
|
})
|
||||||
|
|
||||||
// Initialize quota manager.
|
|
||||||
bootstrapTrace("globalBucketQuotaSys.Init", func() {
|
|
||||||
globalBucketQuotaSys.Init(newObject)
|
|
||||||
})
|
|
||||||
|
|
||||||
// Populate existing buckets to the etcd backend
|
// Populate existing buckets to the etcd backend
|
||||||
if globalDNSConfig != nil {
|
if globalDNSConfig != nil {
|
||||||
// Background this operation.
|
// Background this operation.
|
||||||
|
|
|
@ -171,7 +171,7 @@ func veeamSOSAPIGetObject(ctx context.Context, bucket, object string, rs *HTTPRa
|
||||||
}
|
}
|
||||||
|
|
||||||
q, _ := globalBucketQuotaSys.Get(ctx, bucket)
|
q, _ := globalBucketQuotaSys.Get(ctx, bucket)
|
||||||
binfo, _ := globalBucketQuotaSys.GetBucketUsageInfo(ctx, bucket)
|
binfo := globalBucketQuotaSys.GetBucketUsageInfo(ctx, bucket)
|
||||||
|
|
||||||
ci := capacityInfo{
|
ci := capacityInfo{
|
||||||
Used: int64(binfo.Size),
|
Used: int64(binfo.Size),
|
||||||
|
|
Loading…
Reference in New Issue