mirror of
https://github.com/minio/minio.git
synced 2025-01-12 07:23:23 -05:00
Add remote Diskinfo caching (#10824)
Add 1 second remote disk info cache. Should decrease need for remote calls a great deal due to how actively it is used now.
This commit is contained in:
parent
5c72a34fa8
commit
1e11b4629f
@ -28,6 +28,7 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/minio/minio/cmd/http"
|
"github.com/minio/minio/cmd/http"
|
||||||
xhttp "github.com/minio/minio/cmd/http"
|
xhttp "github.com/minio/minio/cmd/http"
|
||||||
@ -115,6 +116,8 @@ type storageRESTClient struct {
|
|||||||
endpoint Endpoint
|
endpoint Endpoint
|
||||||
restClient *rest.Client
|
restClient *rest.Client
|
||||||
diskID string
|
diskID string
|
||||||
|
|
||||||
|
diskInfoCache timedValue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wrapper to restClient.Call to handle network errors, in case of network error the connection is makred disconnected
|
// Wrapper to restClient.Call to handle network errors, in case of network error the connection is makred disconnected
|
||||||
@ -195,19 +198,28 @@ func (client *storageRESTClient) SetDiskID(id string) {
|
|||||||
|
|
||||||
// DiskInfo - fetch disk information for a remote disk.
|
// DiskInfo - fetch disk information for a remote disk.
|
||||||
func (client *storageRESTClient) DiskInfo(ctx context.Context) (info DiskInfo, err error) {
|
func (client *storageRESTClient) DiskInfo(ctx context.Context) (info DiskInfo, err error) {
|
||||||
respBody, err := client.call(ctx, storageRESTMethodDiskInfo, nil, nil, -1)
|
client.diskInfoCache.Once.Do(func() {
|
||||||
if err != nil {
|
client.diskInfoCache.TTL = time.Second
|
||||||
return
|
client.diskInfoCache.Update = func() (interface{}, error) {
|
||||||
}
|
var info DiskInfo
|
||||||
defer http.DrainBody(respBody)
|
respBody, err := client.call(ctx, storageRESTMethodDiskInfo, nil, nil, -1)
|
||||||
err = gob.NewDecoder(respBody).Decode(&info)
|
if err != nil {
|
||||||
if err != nil {
|
return info, err
|
||||||
return info, err
|
}
|
||||||
}
|
defer http.DrainBody(respBody)
|
||||||
if info.Error != "" {
|
err = gob.NewDecoder(respBody).Decode(&info)
|
||||||
return info, toStorageErr(errors.New(info.Error))
|
if err != nil {
|
||||||
}
|
return info, err
|
||||||
return info, nil
|
}
|
||||||
|
if info.Error != "" {
|
||||||
|
return info, toStorageErr(errors.New(info.Error))
|
||||||
|
}
|
||||||
|
return info, nil
|
||||||
|
}
|
||||||
|
})
|
||||||
|
v, err := client.diskInfoCache.Get()
|
||||||
|
info = v.(DiskInfo)
|
||||||
|
return info, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// MakeVolBulk - create multiple volumes in a bulk operation.
|
// MakeVolBulk - create multiple volumes in a bulk operation.
|
||||||
|
Loading…
Reference in New Issue
Block a user