fix: set scanning details locally to avoid cached values (#18092)

atomic variable results such as scanning must not use
cached values, instead rely on real-time information.
This commit is contained in:
Harshavardhana
2023-09-25 08:26:29 -07:00
committed by GitHub
parent 21e8e071d7
commit ac3a19138a
2 changed files with 15 additions and 2 deletions
+10 -1
View File
@@ -30,6 +30,7 @@ import (
"strconv"
"strings"
"sync"
"sync/atomic"
"time"
"github.com/minio/madmin-go/v3"
@@ -134,6 +135,8 @@ func toStorageErr(err error) error {
// Abstracts a remote disk.
type storageRESTClient struct {
scanning int32
endpoint Endpoint
restClient *rest.Client
diskID string
@@ -207,6 +210,9 @@ func (client *storageRESTClient) Healing() *healingTracker {
}
func (client *storageRESTClient) NSScanner(ctx context.Context, cache dataUsageCache, updates chan<- dataUsageEntry, scanMode madmin.HealScanMode) (dataUsageCache, error) {
atomic.AddInt32(&client.scanning, 1)
defer atomic.AddInt32(&client.scanning, -1)
defer close(updates)
pr, pw := io.Pipe()
go func() {
@@ -281,6 +287,8 @@ func (client *storageRESTClient) DiskInfo(_ context.Context, metrics bool) (info
// transport is already down.
return info, errDiskNotFound
}
// Do not cache results from atomic variables
scanning := atomic.LoadInt32(&client.scanning) == 1
client.diskInfoCache.Once.Do(func() {
client.diskInfoCache.TTL = time.Second
client.diskInfoCache.Update = func() (interface{}, error) {
@@ -306,8 +314,9 @@ func (client *storageRESTClient) DiskInfo(_ context.Context, metrics bool) (info
})
val, err := client.diskInfoCache.Get()
if val != nil {
return val.(DiskInfo), err
info = val.(DiskInfo)
}
info.Scanning = scanning
return info, err
}