diff --git a/pkg/chunk/disk_cache.go b/pkg/chunk/disk_cache.go index e8761bfbd463..450346ab77c4 100644 --- a/pkg/chunk/disk_cache.go +++ b/pkg/chunk/disk_cache.go @@ -236,13 +236,9 @@ func (cache *cacheStore) remove(key string) { cache.Unlock() if path != "" { _ = os.Remove(path) - stagingPath := cache.stagePath(key) - if fi, err := os.Stat(stagingPath); err == nil { - size := fi.Size() - if err = os.Remove(stagingPath); err == nil { - cache.m.stageBlocks.Sub(1) - cache.m.stageBlockBytes.Sub(float64(size)) - } + if err := os.Remove(cache.stagePath(key)); err == nil { + cache.m.stageBlocks.Sub(1) + cache.m.stageBlockBytes.Sub(float64(parseObjOrigSize(key))) } } } @@ -543,13 +539,14 @@ func (cache *cacheStore) scanStaging() { logger.Warnf("Ignore invalid file in staging: %s", path) return nil } - if parseObjOrigSize(key) == 0 { + origSize := parseObjOrigSize(key) + if origSize == 0 { logger.Warnf("Ignore file with zero size: %s", path) return nil } logger.Debugf("Found staging block: %s", path) cache.m.stageBlocks.Add(1) - cache.m.stageBlockBytes.Add(float64(fi.Size())) + cache.m.stageBlockBytes.Add(float64(origSize)) cache.uploader(key, path, false) count++ }