From 978dcb4574bade605a3ec6b812470aecd654b756 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Tue, 13 Sep 2022 13:30:55 +0300 Subject: [PATCH] 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. --- lib/storage/storage.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/storage/storage.go b/lib/storage/storage.go index 12b4043a30..991bfc759a 100644 --- a/lib/storage/storage.go +++ b/lib/storage/storage.go @@ -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) }