Improve wal.go segments sequential validation (#8859)

Signed-off-by: XiaoYu Zhang <ideoutrea@163.com>
This commit is contained in:
ide-rea 2021-05-25 18:08:35 +08:00 committed by GitHub
parent 03b354d4d9
commit ef584a9df6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -304,20 +304,19 @@ func (w *Watcher) segments(dir string) ([]int, error) {
}
var refs []int
var last int
for _, f := range files {
k, err := strconv.Atoi(f.Name())
if err != nil {
continue
}
if len(refs) > 0 && k > last+1 {
return nil, errors.New("segments are not sequential")
}
refs = append(refs, k)
last = k
}
sort.Ints(refs)
for i := 0; i < len(refs)-1; i++ {
if refs[i]+1 != refs[i+1] {
return nil, errors.New("segments are not sequential")
}
}
return refs, nil
}