mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
wal: don't warn when opening wal directory with stale tmp files
This commit is contained in:
parent
6686833e51
commit
71a9d6fc8b
@ -90,14 +90,10 @@ func Repair(dirpath string) bool {
|
||||
|
||||
// openLast opens the last wal file for read and write.
|
||||
func openLast(dirpath string) (*fileutil.LockedFile, error) {
|
||||
names, err := fileutil.ReadDir(dirpath)
|
||||
names, err := readWalNames(dirpath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
names = checkWalNames(names)
|
||||
if len(names) == 0 {
|
||||
return nil, ErrFileNotFound
|
||||
}
|
||||
last := path.Join(dirpath, names[len(names)-1])
|
||||
return fileutil.LockFile(last, os.O_RDWR, 0600)
|
||||
}
|
||||
|
16
wal/util.go
16
wal/util.go
@ -67,12 +67,26 @@ func isValidSeq(names []string) bool {
|
||||
}
|
||||
return true
|
||||
}
|
||||
func readWalNames(dirpath string) ([]string, error) {
|
||||
names, err := fileutil.ReadDir(dirpath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
wnames := checkWalNames(names)
|
||||
if len(wnames) == 0 {
|
||||
return nil, ErrFileNotFound
|
||||
}
|
||||
return wnames, nil
|
||||
}
|
||||
|
||||
func checkWalNames(names []string) []string {
|
||||
wnames := make([]string, 0)
|
||||
for _, name := range names {
|
||||
if _, _, err := parseWalName(name); err != nil {
|
||||
plog.Warningf("ignored file %v in wal", name)
|
||||
// don't complain about left over tmp files
|
||||
if !strings.HasSuffix(name, ".tmp") {
|
||||
plog.Warningf("ignored file %v in wal", name)
|
||||
}
|
||||
continue
|
||||
}
|
||||
wnames = append(wnames, name)
|
||||
|
@ -156,14 +156,10 @@ func OpenForRead(dirpath string, snap walpb.Snapshot) (*WAL, error) {
|
||||
}
|
||||
|
||||
func openAtIndex(dirpath string, snap walpb.Snapshot, write bool) (*WAL, error) {
|
||||
names, err := fileutil.ReadDir(dirpath)
|
||||
names, err := readWalNames(dirpath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
names = checkWalNames(names)
|
||||
if len(names) == 0 {
|
||||
return nil, ErrFileNotFound
|
||||
}
|
||||
|
||||
nameIndex, ok := searchIndex(names, snap.Index)
|
||||
if !ok || !isValidSeq(names[nameIndex:]) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user