From 1b6ba0d0620ae24d28ff11394f11ca304ac4c61f Mon Sep 17 00:00:00 2001 From: poornas Date: Tue, 28 Jul 2020 10:06:52 -0700 Subject: [PATCH] Add validation in cache for offline drives (#10146) closes #10144 --- cmd/disk-cache.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/cmd/disk-cache.go b/cmd/disk-cache.go index f11bea306..602d6f258 100644 --- a/cmd/disk-cache.go +++ b/cmd/disk-cache.go @@ -684,11 +684,13 @@ func newServerCacheObjects(ctx context.Context, config cache.Config) (CacheObjec c.cacheStats.GetDiskStats = func() []CacheDiskStats { cacheDiskStats := make([]CacheDiskStats, len(c.cache)) for i := range c.cache { - cacheDiskStats[i] = CacheDiskStats{ - Dir: c.cache[i].stats.Dir, + dcache := c.cache[i] + cacheDiskStats[i] = CacheDiskStats{} + if dcache != nil { + cacheDiskStats[i].Dir = dcache.stats.Dir + atomic.StoreInt32(&cacheDiskStats[i].UsageState, atomic.LoadInt32(&dcache.stats.UsageState)) + atomic.StoreUint64(&cacheDiskStats[i].UsagePercent, atomic.LoadUint64(&dcache.stats.UsagePercent)) } - atomic.StoreInt32(&cacheDiskStats[i].UsageState, atomic.LoadInt32(&c.cache[i].stats.UsageState)) - atomic.StoreUint64(&cacheDiskStats[i].UsagePercent, atomic.LoadUint64(&c.cache[i].stats.UsagePercent)) } return cacheDiskStats } @@ -712,7 +714,9 @@ func (c *cacheObjects) gc(ctx context.Context) { continue } for _, dcache := range c.cache { - dcache.triggerGC <- struct{}{} + if dcache != nil { + dcache.triggerGC <- struct{}{} + } } } }