From 409c9396213b3262cd916ee4b60a783150e8033b Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Thu, 28 Nov 2019 13:36:02 +0200 Subject: [PATCH] lib/backup: remove `flock.lock` file in empty dirs This fixes an issue when VictoriaMetrics doesn't see the restored data after the following operations: 1. Stop VictoriaMetrics. 2. Delete `<-storageDataPath>` dir. 3. Start VictoriaMetrics, then stop it. 4. Restore data from backup with `vmrestore`. 5. Start VictoriaMetrics. `vmrestore` didn't delete properly empty dirs in `<-storageDataPath>/indexdb` because of the remaining `flock.lock` files in these dirs. --- lib/backup/fscommon/fscommon.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/backup/fscommon/fscommon.go b/lib/backup/fscommon/fscommon.go index 157c9a31e..d6680aa62 100644 --- a/lib/backup/fscommon/fscommon.go +++ b/lib/backup/fscommon/fscommon.go @@ -173,6 +173,7 @@ func removeEmptyDirsInternal(d *os.File) (bool, error) { return false, fmt.Errorf("cannot read directory contents in %q: %s", dir, err) } dirEntries := 0 + hasFlock := false for _, fi := range fis { name := fi.Name() if name == "." || name == ".." { @@ -191,6 +192,10 @@ func removeEmptyDirsInternal(d *os.File) (bool, error) { continue } if fi.Mode()&os.ModeSymlink != os.ModeSymlink { + if name == "flock.lock" { + hasFlock = true + continue + } // Skip plain files. dirEntries++ continue @@ -244,6 +249,12 @@ func removeEmptyDirsInternal(d *os.File) (bool, error) { return false, nil } logger.Infof("removing empty dir %q", dir) + if hasFlock { + flockFilepath := dir + "/flock.lock" + if err := os.Remove(flockFilepath); err != nil { + return false, fmt.Errorf("cannot remove %q: %s", flockFilepath, err) + } + } if err := os.Remove(dir); err != nil { return false, fmt.Errorf("cannot remove %q: %s", dir, err) }