Merge pull request #12846 from pyiyun/fix-snaptmpfile-bug

etcdserver: remove temp files in snap dir when etcdserver starting
This commit is contained in:
Piotr Tabor
2021-04-17 12:58:46 +02:00
committed by GitHub
3 changed files with 88 additions and 0 deletions

View File

@@ -26,6 +26,7 @@ import (
"path"
"regexp"
"strconv"
"strings"
"sync"
"sync/atomic"
"time"
@@ -337,6 +338,17 @@ func NewServer(cfg config.ServerConfig) (srv *EtcdServer, err error) {
zap.Error(err),
)
}
if err = fileutil.RemoveMatchFile(cfg.Logger, cfg.SnapDir(), func(fileName string) bool {
return strings.HasPrefix(fileName, "tmp")
}); err != nil {
cfg.Logger.Error(
"failed to remove temp file(s) in snapshot directory",
zap.String("path", cfg.SnapDir()),
zap.Error(err),
)
}
ss := snap.New(cfg.Logger, cfg.SnapDir())
bepath := cfg.BackendPath()