From c9547f4fbae4883a8a7b6e347820b828959c76f8 Mon Sep 17 00:00:00 2001 From: Zakhar Bessarab Date: Sat, 25 Feb 2023 00:38:42 +0400 Subject: [PATCH] lib/{fs,mergeset,storage}: skip `.must-remove.` dirs when creating snapshot (#3858) (#3867) --- lib/fs/fs.go | 6 +++++- lib/mergeset/table.go | 2 +- lib/storage/partition.go | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/fs/fs.go b/lib/fs/fs.go index 92ae1e67d5..81d77911bb 100644 --- a/lib/fs/fs.go +++ b/lib/fs/fs.go @@ -262,7 +262,7 @@ func MustRemoveTemporaryDirs(dir string) { continue } dirName := fi.Name() - if strings.Contains(dirName, ".must-remove.") { + if IsScheduledForRemoval(dirName) { fullPath := dir + "/" + dirName MustRemoveAll(fullPath) } @@ -467,3 +467,7 @@ func isHTTPURL(targetURL string) bool { return err == nil && (parsed.Scheme == "http" || parsed.Scheme == "https") && parsed.Host != "" } + +func IsScheduledForRemoval(name string) bool { + return strings.Contains(name, ".must-remove.") +} diff --git a/lib/mergeset/table.go b/lib/mergeset/table.go index 9ca34650b4..bac671194b 100644 --- a/lib/mergeset/table.go +++ b/lib/mergeset/table.go @@ -1835,5 +1835,5 @@ func removeParts(pws []*partWrapper, partsToRemove map[*partWrapper]bool) ([]*pa func isSpecialDir(name string) bool { // Snapshots and cache dirs aren't used anymore. // Keep them here for backwards compatibility. - return name == "tmp" || name == "txn" || name == "snapshots" || name == "cache" + return name == "tmp" || name == "txn" || name == "snapshots" || name == "cache" || fs.IsScheduledForRemoval(name) } diff --git a/lib/storage/partition.go b/lib/storage/partition.go index 15b9e1a0ea..ea66d5c996 100644 --- a/lib/storage/partition.go +++ b/lib/storage/partition.go @@ -2022,7 +2022,7 @@ func (pt *partition) createSnapshot(srcDir, dstDir string) error { // Skip non-directories. continue } - if fn == "tmp" || fn == "txn" { + if fn == "tmp" || fn == "txn" || fs.IsScheduledForRemoval(fn) { // Skip special dirs. continue }