wal: don't warn when opening wal directory with stale tmp files

This commit is contained in:
Anthony Romano 2016-05-28 20:18:30 -07:00
parent 6686833e51
commit 71a9d6fc8b
3 changed files with 17 additions and 11 deletions

View File

@ -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)
}

View File

@ -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)

View File

@ -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:]) {