mirror of
https://github.com/minio/minio.git
synced 2025-02-04 10:26:01 -05:00
cache DiskInfo() metrics call separately (#18270)
This commit is contained in:
parent
e37508fb8f
commit
8e32de3ba9
@ -145,6 +145,7 @@ type storageRESTClient struct {
|
|||||||
poolIndex, setIndex, diskIndex int
|
poolIndex, setIndex, diskIndex int
|
||||||
|
|
||||||
diskInfoCache timedValue
|
diskInfoCache timedValue
|
||||||
|
diskInfoCacheMetrics timedValue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieve location indexes.
|
// Retrieve location indexes.
|
||||||
@ -289,15 +290,16 @@ func (client *storageRESTClient) DiskInfo(_ context.Context, metrics bool) (info
|
|||||||
}
|
}
|
||||||
// Do not cache results from atomic variables
|
// Do not cache results from atomic variables
|
||||||
scanning := atomic.LoadInt32(&client.scanning) == 1
|
scanning := atomic.LoadInt32(&client.scanning) == 1
|
||||||
client.diskInfoCache.Once.Do(func() {
|
if metrics {
|
||||||
client.diskInfoCache.TTL = time.Second
|
client.diskInfoCacheMetrics.Once.Do(func() {
|
||||||
client.diskInfoCache.Update = func() (interface{}, error) {
|
client.diskInfoCacheMetrics.TTL = time.Second
|
||||||
|
client.diskInfoCacheMetrics.Update = func() (interface{}, error) {
|
||||||
var info DiskInfo
|
var info DiskInfo
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
vals := make(url.Values)
|
vals := make(url.Values)
|
||||||
vals.Set(storageRESTMetrics, strconv.FormatBool(metrics))
|
vals.Set(storageRESTMetrics, "true")
|
||||||
respBody, err := client.call(ctx, storageRESTMethodDiskInfo, vals, nil, -1)
|
respBody, err := client.call(ctx, storageRESTMethodDiskInfo, vals, nil, -1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return info, err
|
return info, err
|
||||||
@ -312,7 +314,37 @@ func (client *storageRESTClient) DiskInfo(_ context.Context, metrics bool) (info
|
|||||||
return info, nil
|
return info, nil
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
val, err := client.diskInfoCache.Get()
|
} else {
|
||||||
|
client.diskInfoCache.Once.Do(func() {
|
||||||
|
client.diskInfoCache.TTL = time.Second
|
||||||
|
client.diskInfoCache.Update = func() (interface{}, error) {
|
||||||
|
var info DiskInfo
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
vals := make(url.Values)
|
||||||
|
respBody, err := client.call(ctx, storageRESTMethodDiskInfo, vals, nil, -1)
|
||||||
|
if err != nil {
|
||||||
|
return info, err
|
||||||
|
}
|
||||||
|
defer xhttp.DrainBody(respBody)
|
||||||
|
if err = msgp.Decode(respBody, &info); err != nil {
|
||||||
|
return info, err
|
||||||
|
}
|
||||||
|
if info.Error != "" {
|
||||||
|
return info, toStorageErr(errors.New(info.Error))
|
||||||
|
}
|
||||||
|
return info, nil
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
var val interface{}
|
||||||
|
if metrics {
|
||||||
|
val, err = client.diskInfoCacheMetrics.Get()
|
||||||
|
} else {
|
||||||
|
val, err = client.diskInfoCache.Get()
|
||||||
|
}
|
||||||
if val != nil {
|
if val != nil {
|
||||||
info = val.(DiskInfo)
|
info = val.(DiskInfo)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user