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

View File

@@ -462,6 +462,7 @@ func (s *xlStorage) readMetadata(ctx context.Context, itemPath string) ([]byte,
func (s *xlStorage) NSScanner(ctx context.Context, cache dataUsageCache, updates chan<- dataUsageEntry, scanMode madmin.HealScanMode) (dataUsageCache, error) {
atomic.AddInt32(&s.scanning, 1)
defer atomic.AddInt32(&s.scanning, -1)
var err error
stopFn := globalScannerMetrics.log(scannerMetricScanBucketDrive, s.drivePath, cache.Info.Name)
defer func() {
@@ -650,6 +651,9 @@ func (s *xlStorage) NSScanner(ctx context.Context, cache dataUsageCache, updates
// DiskInfo provides current information about disk space usage,
// total free inodes and underlying filesystem.
func (s *xlStorage) DiskInfo(_ context.Context, _ bool) (info DiskInfo, err error) {
// Do not cache results from atomic variables
scanning := atomic.LoadInt32(&s.scanning) == 1
s.diskInfoCache.Once.Do(func() {
s.diskInfoCache.TTL = time.Second
s.diskInfoCache.Update = func() (interface{}, error) {
@@ -677,7 +681,6 @@ func (s *xlStorage) DiskInfo(_ context.Context, _ bool) (info DiskInfo, err erro
// - if we found an unformatted disk (no 'format.json')
// - if we found healing tracker 'healing.bin'
dcinfo.Healing = errors.Is(err, errUnformattedDisk) || (s.Healing() != nil)
dcinfo.Scanning = atomic.LoadInt32(&s.scanning) == 1
dcinfo.ID = diskID
return dcinfo, err
}
@@ -687,6 +690,7 @@ func (s *xlStorage) DiskInfo(_ context.Context, _ bool) (info DiskInfo, err erro
if v != nil {
info = v.(DiskInfo)
}
info.Scanning = scanning
return info, err
}