mirror of
https://github.com/pgsty/minio.git
synced 2026-07-22 21:50:22 +03:00
avoid reload of 'format.json' over the network under normal conditions (#18842)
This commit is contained in:
@@ -144,10 +144,12 @@ type storageRESTClient struct {
|
||||
// Indicate of NSScanner is in progress in this disk
|
||||
scanning int32
|
||||
|
||||
endpoint Endpoint
|
||||
restClient *rest.Client
|
||||
gridConn *grid.Subroute
|
||||
diskID string
|
||||
endpoint Endpoint
|
||||
restClient *rest.Client
|
||||
gridConn *grid.Subroute
|
||||
diskID string
|
||||
formatData []byte
|
||||
formatMutex sync.RWMutex
|
||||
|
||||
// Indexes, will be -1 until assigned a set.
|
||||
poolIndex, setIndex, diskIndex int
|
||||
@@ -251,7 +253,24 @@ func (client *storageRESTClient) NSScanner(ctx context.Context, cache dataUsageC
|
||||
return *final, nil
|
||||
}
|
||||
|
||||
func (client *storageRESTClient) SetFormatData(b []byte) {
|
||||
if client.IsOnline() {
|
||||
client.formatMutex.Lock()
|
||||
client.formatData = b
|
||||
client.formatMutex.Unlock()
|
||||
}
|
||||
}
|
||||
|
||||
func (client *storageRESTClient) GetDiskID() (string, error) {
|
||||
if !client.IsOnline() {
|
||||
// make sure to check if the disk is offline, since the underlying
|
||||
// value is cached we should attempt to invalidate it if such calls
|
||||
// were attempted. This can lead to false success under certain conditions
|
||||
// - this change attempts to avoid stale information if the underlying
|
||||
// transport is already down.
|
||||
return "", errDiskNotFound
|
||||
}
|
||||
|
||||
// This call should never be over the network, this is always
|
||||
// a cached value - caller should make sure to use this
|
||||
// function on a fresh disk or make sure to look at the error
|
||||
@@ -523,6 +542,19 @@ func (client *storageRESTClient) ReadAll(ctx context.Context, volume string, pat
|
||||
values := make(url.Values)
|
||||
values.Set(storageRESTVolume, volume)
|
||||
values.Set(storageRESTFilePath, path)
|
||||
|
||||
// Specific optimization to avoid re-read from the drives for `format.json`
|
||||
// in-case the caller is a network operation.
|
||||
if volume == minioMetaBucket && path == formatConfigFile {
|
||||
client.formatMutex.RLock()
|
||||
formatData := make([]byte, len(client.formatData))
|
||||
copy(formatData, client.formatData)
|
||||
client.formatMutex.RUnlock()
|
||||
if len(formatData) > 0 {
|
||||
return formatData, nil
|
||||
}
|
||||
}
|
||||
|
||||
respBody, err := client.call(ctx, storageRESTMethodReadAll, values, nil, -1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user