diff --git a/lib/fs/fs.go b/lib/fs/fs.go index 2392b6178..373c59fbd 100644 --- a/lib/fs/fs.go +++ b/lib/fs/fs.go @@ -219,7 +219,12 @@ func IsEmptyDir(path string) bool { // If the process crashes after the step 1, then the directory must be removed // on the next process start by calling MustRemoveTemporaryDirs on the parent directory. func MustRemoveDirAtomic(dir string) { + if !IsPathExist(dir) { + return + } mustRemoveDirAtomic(dir) + parentDir := filepath.Dir(dir) + MustSyncPath(parentDir) } var atomicDirRemoveCounter = uint64(time.Now().UnixNano()) diff --git a/lib/fs/fs_nix.go b/lib/fs/fs_nix.go index 54dc570c4..8e6694373 100644 --- a/lib/fs/fs_nix.go +++ b/lib/fs/fs_nix.go @@ -6,7 +6,6 @@ package fs import ( "fmt" "os" - "path/filepath" "sync/atomic" "github.com/VictoriaMetrics/VictoriaMetrics/lib/logger" @@ -18,15 +17,10 @@ func freeSpace(stat unix.Statfs_t) uint64 { } func mustRemoveDirAtomic(dir string) { - if !IsPathExist(dir) { - return - } n := atomic.AddUint64(&atomicDirRemoveCounter, 1) tmpDir := fmt.Sprintf("%s.must-remove.%d", dir, n) if err := os.Rename(dir, tmpDir); err != nil { logger.Panicf("FATAL: cannot move %s to %s: %s", dir, tmpDir, err) } MustRemoveAll(tmpDir) - parentDir := filepath.Dir(dir) - MustSyncPath(parentDir) } diff --git a/lib/fs/fs_openbsd.go b/lib/fs/fs_openbsd.go index 27e3f9dac..6f3d4904e 100644 --- a/lib/fs/fs_openbsd.go +++ b/lib/fs/fs_openbsd.go @@ -3,7 +3,6 @@ package fs import ( "fmt" "os" - "path/filepath" "sync/atomic" "github.com/VictoriaMetrics/VictoriaMetrics/lib/logger" @@ -15,15 +14,10 @@ func freeSpace(stat unix.Statfs_t) uint64 { } func mustRemoveDirAtomic(dir string) { - if !IsPathExist(dir) { - return - } n := atomic.AddUint64(&atomicDirRemoveCounter, 1) tmpDir := fmt.Sprintf("%s.must-remove.%d", dir, n) if err := os.Rename(dir, tmpDir); err != nil { logger.Panicf("FATAL: cannot move %s to %s: %s", dir, tmpDir, err) } MustRemoveAll(tmpDir) - parentDir := filepath.Dir(dir) - MustSyncPath(parentDir) } diff --git a/lib/fs/fs_solaris.go b/lib/fs/fs_solaris.go index c5cb04ec1..923f69e65 100644 --- a/lib/fs/fs_solaris.go +++ b/lib/fs/fs_solaris.go @@ -3,7 +3,6 @@ package fs import ( "fmt" "os" - "path/filepath" "sync/atomic" "github.com/VictoriaMetrics/VictoriaMetrics/lib/logger" @@ -11,17 +10,12 @@ import ( ) func mustRemoveDirAtomic(dir string) { - if !IsPathExist(dir) { - return - } n := atomic.AddUint64(&atomicDirRemoveCounter, 1) tmpDir := fmt.Sprintf("%s.must-remove.%d", dir, n) if err := os.Rename(dir, tmpDir); err != nil { logger.Panicf("FATAL: cannot move %s to %s: %s", dir, tmpDir, err) } MustRemoveAll(tmpDir) - parentDir := filepath.Dir(dir) - MustSyncPath(parentDir) } func mmap(fd int, length int) (data []byte, err error) { diff --git a/lib/fs/fs_windows.go b/lib/fs/fs_windows.go index 949829e9b..f455c78cf 100644 --- a/lib/fs/fs_windows.go +++ b/lib/fs/fs_windows.go @@ -25,17 +25,14 @@ func mustSyncPath(path string) { } func mustRemoveDirAtomic(dir string) { - if !IsPathExist(dir) { - return - } n := atomic.AddUint64(&atomicDirRemoveCounter, 1) tmpDir := fmt.Sprintf("%s.must-remove.%d", dir, n) if err := os.Rename(dir, tmpDir); err != nil { logger.Panicf("FATAL: cannot move %s to %s: %s", dir, tmpDir, err) } - err := os.RemoveAll(tmpDir) - if err != nil { - logger.Warnf("cannot remove dir: %q: %s, restart VictoriaMetrics process to complete file deletion", tmpDir, err) + if err := os.RemoveAll(tmpDir); err != nil { + logger.Warnf("cannot remove dir: %q: %s; restart VictoriaMetrics to complete dir removal; "+ + "see https://github.com/VictoriaMetrics/VictoriaMetrics/issues/70#issuecomment-1491529183", tmpDir, err) } }