mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-24 05:04:05 -08:00
tsdb: fix sequence check for WAL segments (#7032)
Signed-off-by: zhulongcheng <zhulongcheng.dev@gmail.com>
This commit is contained in:
parent
24ecae9956
commit
e813f60fd6
|
@ -763,21 +763,21 @@ func listSegments(dir string) (refs []segmentRef, err error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var last int
|
||||
for _, fn := range files {
|
||||
k, err := strconv.Atoi(fn)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if len(refs) > 0 && k > last+1 {
|
||||
return nil, errors.New("segments are not sequential")
|
||||
}
|
||||
refs = append(refs, segmentRef{name: fn, index: k})
|
||||
last = k
|
||||
}
|
||||
sort.Slice(refs, func(i, j int) bool {
|
||||
return refs[i].index < refs[j].index
|
||||
})
|
||||
for i := 0; i < len(refs)-1; i++ {
|
||||
if refs[i].index+1 != refs[i+1].index {
|
||||
return nil, errors.New("segments are not sequential")
|
||||
}
|
||||
}
|
||||
return refs, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue