mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-09 23:24:05 -08:00
Improve wal.go segments sequential validation (#8859)
Signed-off-by: XiaoYu Zhang <ideoutrea@163.com>
This commit is contained in:
parent
03b354d4d9
commit
ef584a9df6
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue