lib/storage: properly remove cache directory contents if reset_cache_on_startup file is located there

Previously the cache directory was removed. This could result in error when the cache directory
is mounted to a separate filesystem.
This commit is contained in:
Aliaksandr Valialkin 2022-09-13 13:30:55 +03:00
parent 5f28ca1f42
commit 978dcb4574
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1

View file

@ -169,11 +169,10 @@ func OpenStorage(path string, retentionMsecs int64, maxHourlySeries, maxDailySer
// See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1447 for details.
if fs.IsPathExist(s.cachePath + "/reset_cache_on_startup") {
logger.Infof("removing cache directory at %q, since it contains `reset_cache_on_startup` file...", s.cachePath)
wg := getWaitGroup()
wg.Add(1)
fs.MustRemoveAllWithDoneCallback(s.cachePath, wg.Done)
wg.Wait()
putWaitGroup(wg)
// Do not use fs.MustRemoveDirAtomic() here, since the cache directory may be mounted
// to a separate filesystem. In this case the fs.MustRemoveDirAtomic() will fail while
// trying to remove the mount root.
fs.RemoveDirContents(s.cachePath)
logger.Infof("cache directory at %q has been successfully removed", s.cachePath)
}