From 26ffc7762285f3e325b8903115db81d38dba5038 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Sat, 2 Nov 2019 02:26:02 +0200 Subject: [PATCH] lib/{storage,mergeset}: create missing partition directories after restoring from backups Backup tools could skip empty directories. So re-create such directories on the first run. --- lib/mergeset/table.go | 5 ++++- lib/storage/partition.go | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/mergeset/table.go b/lib/mergeset/table.go index 973ca36652..8eddea0435 100644 --- a/lib/mergeset/table.go +++ b/lib/mergeset/table.go @@ -911,7 +911,10 @@ var mergeWorkersCount = func() int { }() func openParts(path string) ([]*partWrapper, error) { - // Verify that the directory for the parts exists. + // The path can be missing after restoring from backup, so create it if needed. + if err := fs.MkdirAllIfNotExist(path); err != nil { + return nil, err + } d, err := os.Open(path) if err != nil { return nil, fmt.Errorf("cannot open difrectory: %s", err) diff --git a/lib/storage/partition.go b/lib/storage/partition.go index 50cae5d643..9b3d9a73d1 100644 --- a/lib/storage/partition.go +++ b/lib/storage/partition.go @@ -1253,7 +1253,10 @@ func appendPartsToMerge(dst, src []*partWrapper, maxPartsToMerge int, maxRows ui } func openParts(pathPrefix1, pathPrefix2, path string) ([]*partWrapper, error) { - // Verify that the directory for the parts exists. + // The path can be missing after restoring from backup, so create it if needed. + if err := fs.MkdirAllIfNotExist(path); err != nil { + return nil, err + } d, err := os.Open(path) if err != nil { return nil, fmt.Errorf("cannot open directory %q: %s", path, err)